remove sleep from sketch...

So cleaning up my sketch before i insert the magic part provided by Robert.... 

 

As i will power from a wall supply i don want to use sleep modes...

 

first line i see in the examples are:

 

rf12_sleep(RF12_SLEEP);

 

if i just remove that one it would no go to sleep right?

Robert Wall's picture

Re: remove sleep from sketch...

Why not? It only sleeps the transmitter - not the main processor. From RFu_RF12.cpp:

"This function can put the radio module to sleep and wake it up again. In sleep mode, the radio will draw only one or two microamps of current."

boelle's picture

Re: remove sleep from sketch...

it was more that i will power it from wall brick and dont worrie so much about the consumption...

and the board that monitors my electricity meter will send every 5 sec or so....

 

but i guess it will not hurt either, and i guess its the same no matter what radio module you use... 

 

last thing with this sketch.... i have a single line left

 

digitalWrite(PIN_LED, digitalRead(PIN_KAMSER_RX));

 

i need to remove the first part.... is the logic that this line could be converted to 2:

 

digitalWrite(PIN_LED)

digitalRead(PIN_KAMSER_RX);

 

?

Robert Wall's picture

Re: remove sleep from sketch...

No, that will not work as the original does.

In C, something like "digitalRead(PIN_KAMSER_RX)" is a function that returns a value - as it is a digital pin, it will be either LOW or HIGH. I presume this is a boolean but incredibly (and very stupidly) the Arduino documentation fails to specify the return value type. You can use that value in whatever way you like. Some possibilities:

bool Kamser_Receive = digitalRead(PIN_KAMSER_RX);

Serial.print("Kamser sent "); Serial.print(digitalRead(PIN_KAMSER_RX));

What the original statement does is use that LOW or HIGH it got from the digitalRead function to set the LED on or off, so to split it into two you have to do:

bool Kamser_Receive = digitalRead(PIN_KAMSER_RX);
digitalWrite(PIN_LED, Kamser_Receive);

The original did not use Kamser_Receive but put the value straight into digitalWrite( ).

"digitalWrite(PIN_LED)" is not legal as it requires two parameters, the first to tell it which pin and the second to set its state: HIGH or LOW.

boelle's picture

Re: remove sleep from sketch...

ohhh

 

did not see that, so i will just have to use the same name for the LED as emontx sketch's does... so there will be constant light when it gets data from heat meter and a flash when it transmit over rf

Robert Wall's picture

Re: remove sleep from sketch...

???  I can't see that necessarily working either. What does the LED do as per the original Kamser software, and what do you want the LED to do?

boelle's picture

Re: remove sleep from sketch...

the led should show when there was data incoming.... 

now i'm not using an arduino but EmonTX.... so i want the single LED on EmonTX both light up on incoming data and flash when it transmits over RF

Robert Wall's picture

Re: remove sleep from sketch...

It looks to me as if the LED is permanently on while data is available, and goes off when the receive data fails. In that case, I suspect turning the LED on and off when transmitting will have the effect of turning the LED off after data has been transmitted, it will then flash until the receive data succeeds again. [Remember, I have not studied your sketch in detail so I am guessing a lot of this.]

What I think you need to do is, at the start of the radio transmission, read the state of the LED, reverse it and set the LED to the new state, and do the same at the end of the radio transmission.

That way, if it is not getting data from the heat meter, the LED will flash briefly on, if it is getting data from the heat meter, the LED will flash briefly off.

boelle's picture

Re: remove sleep from sketch...

yes, my fault, LED in kamstrup bit is on when there is data.... 

and if not much mistaken led in emontx examples only flash when transmitting right?

 

but i guess you are right.... or just bite the dust and add a LED for the heat meter.... will thinker with that thought

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.