LowPowerLab Forum

Hardware support => Moteino => Topic started by: Richelsdorfite on November 27, 2013, 05:00:53 AM

Title: How to interrupt my sensors reading loop when a packet is receiced ?
Post by: Richelsdorfite on November 27, 2013, 05:00:53 AM
Hello,

I use Moteino as node to drive a load (PWM D3) and an array of temp sensors (DS18B20) using an I2C I/O expander (PCF8574).

As the reading of the sensor array is quite long and as my Moteino gateway sending command at any time (when the user decide to change PWM or request temp data), I try to find the good way to interrupt my reading loop with an interruption.

So, does the RFM69 can generate a low or high state to warn 328 that a packet is ready to read ?

Yours,

Michel
Title: Re: How to interrupt my sensors reading loop when a packet is receiced ?
Post by: Richelsdorfite on November 27, 2013, 08:50:40 AM
Perhap with D2 which is connect to DIO0.


RFM69 datasheet p.55 :

5.5.5.2. Rx Processing
1. The data received is stored in the FIFO, The address, CRC interrupts are generated as usual because these
parameters were not encrypted.
2. Once the complete packet has been received. The data is read from the FIFO, decrypted and written back to FIFO.
The PayloadReady interrupt is issued once the decrypted data is ready in the FIFO for reading via the SPI interface.


So I will attach an interrupt on DP2.
Title: Re: How to interrupt my sensors reading loop when a packet is receiced ?
Post by: Felix on November 27, 2013, 10:47:16 AM
The interrupt in the library is fired to capture the data. It is connected to D2. You could add a call to that interrupt and inject your own function to call upon interrupt exit. But the interrupt should be as short as possible.
You're responsible to poll the radio to see if a packet was received, as shown in the examples. If another packet is received before you check, the existing packet will be overwritten with the new packet.
I never liked the dallas temp sensor because of the long delay it takes to do a measurement. Not to mention the cost...
Title: Re: How to interrupt my sensors reading loop when a packet is receiced ?
Post by: Richelsdorfite on November 27, 2013, 10:49:02 AM
And............................................No !

I can't attach an interrupt on D2 as the RFM69 librairie do it in the "bool RFM69::initialize(byte freqBand, byte nodeID, byte networkID)" & "attachInterrupt(0, RFM69::isr0, RISING);"

So how can I interrupt my loop when data from RFM69 is available ?

The if (radio.receiveDone()){.....} work but is too long as this statement is in void loop{}.

Title: Re: How to interrupt my sensors reading loop when a packet is receiced ?
Post by: Richelsdorfite on November 27, 2013, 10:59:51 AM
Thank you Felix.

I don't see your reply before sending my own.

Yes the DS18B20 is quite long and as I drive 8 of them with an I/O expander the time is lengthy.

I think I will try the TMP36 making the same drive setup (I/O expander) and a simple analogRead().
Title: Re: How to interrupt my sensors reading loop when a packet is receiced ?
Post by: Felix on November 27, 2013, 11:12:42 AM
TMP36 is easy to power from a digital pin and it requires an analog pin. Also a thermistor can be used in the same way. Both would need some calibration but are rather good alternatives and very cheap compared to the DS sensor.