Archery Timer Radio Link

Hi,

I am trying to write an archery timer to send a Struct of data to the receiver.
So far I have tested the NRF24 radios with the RF24 library using the Getting Started Sketch and stabilized 3.3v power supplies and can get good range from them.

I have then tried to merge the radio into my timer code.

It appears that the transmitter is sending based upon the serial port monitor results.

What I cannot seem to get going is the receiver end.

They are running on Mega 2560 units.

Please assist if you can.
I am a newbie when it comes to programming and have probably go parenthesis etc in the wrong place!

Thanks in advance.

Warren.

Archery_Timer_V2.ino.ino (7.17 KB)

Receiver_code_5.6.17.ino (1.2 KB)

printf.h (657 Bytes)

struct 
  {
      int timerSeconds;
      int ab;
      int blank;
      int endbuzz;
      int pretimer;
      int green;
      int red;
      int currentState;
  } MyStruct;

A struct is useful when it contains different types. An array makes more sense when the types are all the same.

 if (int(key) != 0 and currentState == 1) {

Why did you feel it necessary to cast a char to an int so you could compare it to 0?

Are there really enough states to warrant currentState being an int?

 if (ab = 0);{

Two major mistakes in only 14 characters. Must be some kind of record.

 tempVal[0] = currentTimeValue[0];
 tempVal[1] = currentTimeValue[1];
 tempVal[2] = currentTimeValue[2];
 tempVal[3] = 0;

Writing beyond the end of an array is stupid.

 tempVal[1] = 0;
 checkmin = atol(tempVal);
 if (checkmin > 3) {
 clearScreen();
 lcd.setCursor(0,0);
 lcd.print("ILLEGAL TIME");
 delay(2000);
 currentTimeValue[0]='0';
 currentTimeValue[1]='0';
 currentTimeValue[2]='0';
 currentState = 1;
 displayCodeEntryScreen();
 }
 senddata();

Your
indenting
sucks.

 if (currentState == 3) {
   senddata();
   showpretimer();
 delay(1000);
  --pretimer;{
   if (pretimer == 0 ){
    currentState = 4; //startbuzz state
   } 
 }
 }

Big
time.

 lcd.setCursor(13,1);

Row 13?

 bool ok = radio.write( &MyStruct, sizeof(MyStruct) );

What is the purpose of sending this struct, when you have not written any data to it?

  Serial.println(MyStruct.timerSeconds);
  Serial.println(MyStruct.ab);
  Serial.println(MyStruct.blank);
  Serial.println(MyStruct.endbuzz);
  Serial.println(MyStruct.pretimer);
  Serial.println(MyStruct.green);
  Serial.println(MyStruct.red);
  Serial.println(MyStruct.currentState);

Anonymous printing sucks.

al in all a pretty f....... valiant attempt.

have you had any part of the code working in pieces, you might want to start and get one single piece working ie. send some info through a communication stream.

i have NILL idea about RF but in the protocols(communication) ive seen only 1 byte can get sent ie (1,0,1,0,1,0,1,0) not a whole struct, i could be wrong in assumming, but i imaging that RF is no different.

PaulS:

struct 

{
      int timerSeconds;
      int ab;
      int blank;
      int endbuzz;
      int pretimer;
      int green;
      int red;
      int currentState;
  } MyStruct;



A struct is useful when it contains different types. An array makes more sense when the types are all the same.



if (int(key) != 0 and currentState == 1) {



Why did you feel it necessary to cast a char to an int so you could compare it to 0?

Are there really enough states to warrant currentState being an int?



if (ab = 0);{



Two major mistakes in only 14 characters. Must be some kind of record.



tempVal[0] = currentTimeValue[0];
tempVal[1] = currentTimeValue[1];
tempVal[2] = currentTimeValue[2];
tempVal[3] = 0;



Writing beyond the end of an array is stupid.



tempVal[1] = 0;
checkmin = atol(tempVal);
if (checkmin > 3) {
clearScreen();
lcd.setCursor(0,0);
lcd.print("ILLEGAL TIME");
delay(2000);
currentTimeValue[0]='0';
currentTimeValue[1]='0';
currentTimeValue[2]='0';
currentState = 1;
displayCodeEntryScreen();
}
senddata();



Your
indenting
sucks.



if (currentState == 3) {
  senddata();
  showpretimer();
delay(1000);
  --pretimer;{
  if (pretimer == 0 ){
    currentState = 4; //startbuzz state
  }
}
}



Big
time.



lcd.setCursor(13,1);



Row 13?



bool ok = radio.write( &MyStruct, sizeof(MyStruct) );



What is the purpose of sending this struct, when you have not written any data to it?

joeblogs:
al in all a pretty f....... valiant attempt.

have you had any part of the code working in pieces, you might want to start and get one single piece working ie. send some info through a communication stream.

i have NILL idea about RF but in the protocols(communication) ive seen only 1 byte can get sent ie (1,0,1,0,1,0,1,0) not a whole struct, i could be wrong in assumming, but i imaging that RF is no different.

Hi All,
Yes the serial printing was done for fault finding - all the data is working via Serial.print(variable) so I thouight I would add it to the struct - isn't that what I did when I defined the structure - does it not pick up the defined values?

Yes all the code so far works a treat - don't knock the keypad code - I stole it from somewhere else.

I am having real trouble getting the radio to send data - does this mean I have to populate the data in the struct first?

I would have thought I would have got a lot of zeros if it was not populated with data. Hoever my real problem appears that the radio does not receive any data - yet they work fine with the getting started example sketch. So I thought it must be linked somewhere around this.

Thanks for the critique to all - yes my indenting probably does suck - I am not a professional - just dabbling.
I have spent a lot of time on this to date. The countdown timer works nicely and does everything I need it to do, all I want to do now is transfer the data to the receiver and decode it do a second hand HUGE seven Seg archery timer display (dead micro).

My thought on using the struct was to be able to transfer it in one hit and then decode the data at the other end as per some examples on the web.

Thanks so far..
Cheers
Warren.

Your struct is a separate entity from your integer variables such as timerSeconds. Having a struct member with that name does not link them - you need to explicitly set the struct member:

MyStruct.timerSeconds=timerSeconds;

or you could drop the variables and work with the struct versions instead.

You should indeed be able to send the struct as a single entity, but I'd start with a simpler sender with the struct members initialized and just transmit it once to test the receiver.

isn't that what I did when I defined the structure - does it not pick up the defined values?

No. The struct is not bound to the variables. You need to create an instance of the struct, and set the members of the instance.

I am having real trouble getting the radio to send data - does this mean I have to populate the data in the struct first?

Well, duh!

yes my indenting probably does suck - I am not a professional - just dabbling.

Well, dabble your mouse over to the Tools menu, where you will find an Auto Format item. Dribble the mouse down, and click it. Instantly, your code will look like you knew what you were doing. Or, more like it, anyway.

My thought on using the struct was to be able to transfer it in one hit and then decode the data at the other end as per some examples on the web.

An array could be used the same way, and would make more sense, since all the members of the struct are the same type. Now, if you had bytes, char arrays, and floats, in addition to the ints, that would be a different story.

PaulS:
An array could be used the same way, and would make more sense, since all the members of the struct are the same type. Now, if you had bytes, char arrays, and floats, in addition to the ints, that would be a different story.

a tempest in a teacup...

The struct makes sense versus some anonymous array grouping, you can more easily address the element you want by name.

Plus it isn't a problem sending a struct, no more or less than any array.

a tempest in a teacup...

Maybe. But, it is easier to think that defining a struct has some meaning without creating an instance of the struct. It is not possible to define an array without creating an instance of the array.

Ok Gents,
That has given me some great tips.

  1. Format my code better. So easily done if you know how !
  2. Populate the Struct then send it.

Maybe I can make some progress now.

Cheers for the assist, will ket you know how I get on.
Maybe a couple of days before I can get back to it though.

I love the sarcastic comments - helps me keep on my toes. I need that at my age !

Cheers
Warren.