Here is a snippet of code to illustrate my issue ; if I take the delay time out then the "ThirtySec" variable increments twice for each received message. I'm interested in why this might happen and if you can see a reason in this loop. (I've not posted all my code as its in several linked sections). The radio messages are short and only appear every 30seconds.
#include <RFM69.h>
#include <RFM69_ATC.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
if (radio.receiveDone()) // Got one!
{
for (byte i = 0; i < radio.DATALEN; i++)
if (radio.DATA[1] == 80) // Ascii P rec'd
{
radio.DATA[1]=0;
//increment time every two pulses
if(ThirtySec == 2)//second pulse, 1 minute passed
{
ThirtySec = 0;
MINUTE++; // add one minute - this global is used elsewhere to display time.
TimeChangedFlag = 1; // used to only update the oled Ic2 display when whole minute has //passed.
}
delay(200); // needs this !!!
ThirtySec++;
}
I’m only looking at position “1” in the received array to hold ASCII 80. But you’ve made me look a bit closer !!!
I modded/chopped this up from the spark fun example sketch , Looking at it now on here , I don’t think I need the preceding “for i…” loop anyway, and guess it could well be the issue .
A signal is transmitted from a clock every 30seconds and rec’d in the code shown , if sends PP. Every minute the “ minutes” figure is updated ( 2x 30sec =1min) .
In the data I look for that “P” and if its there it’s a valid message
I made this so I could see the error in the sending clock over a few days , just quickly knocked it out , but causing a bit of grief ( missing the odd pulse atm now
I'm getting kinda confused here - sorry. I only want to see if the character at position[1] is Ascii 80 (P). I'm not bothered about the rest. I modded the code to that shown below; but get this output:
where both "received from node 1" messages (30s=1 and 30s=2) appear at the same time on the serial monitor and my minute counter increments..
if I add a delay (say 400mS), then each message only appears with each send , (whch is every 30sec) . Its as though without the delay the RFM69 doesn't have time to clear it message rec'd status.
received from node 1, message [P] 30s= 1
received from node 1, message [P] 30s= 2
1
received from node 1, message [P] 30s= 1
received from node 1, message [P] 30s= 2
2
received from node 1, message [P] 30s= 1
received from node 1, message [P] 30s= 2
3
received from node 1, message [P] 30s= 1
received from node 1, message [P] 30s= 2
4
received from node 1, message [P] 30s= 1
received from node 1, message [P] 30s= 2
5
void GetClockPulse()
{
// RECEIVING
// In this section, we'll check with the RFM69HCW (RFM69)to see
// if it has received any packets:
if (radio.receiveDone()) // Got one!
{
// Print out the information:
Serial.print(F("received from node "));
Serial.print(radio.SENDERID, DEC);
Serial.print(F(", message ["));
// The actual message is contained in the DATA array,
// and is DATALEN bytes in size:
//for (byte i = 0; i < radio.DATALEN; i++)
//{
Serial.print((char)radio.DATA[1]);
// }
Serial.print(F("] 30s= "));
if (radio.DATA[1] == 80) // Ascii P
{
radio.DATA[1] = 0;
radio.DATA[2] = 0;
/* display.setCursor(102, 1);
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE, BLACK); //clear noise botton of screen
display.print(ThirtySec);
display.display();
*/
//increment time every two pulses
Serial.println (ThirtySec);
//NOW=millis();
// TimeCheck();
if (ThirtySec >= 2) //second pulse
{
ThirtySec = 0;
MINUTE++; // add one minute
TimeChangedFlag = 1;
Serial.println( MINUTE);
}
//delay(1000);
ThirtySec++;
}
The loop was a left over from the example I copied it from , and no , not needed, nor has any effect ( I did use it to print the whole array) - as said it was supposed to be a quick and dirty modded code .
I took it out and makes no difference .