I am trying to send arrays of data from a transmitter to a receiver. I use Arduino Leonardo (Atmega32U4) and I use RFM98 RF transceivers. When I send an array of type BYTE, the message is clearly printed on the COM port. (Figure 1), However, when I try to send Microcontroller's Unique ID, It prints garbage values on the COM port. (Figure 2). My transmitter code only sends Bytes of data and I guess Unique ID is in uint8_t format.
I have included both UUID code and the send code on the transmitter for both cases. I'd be grateful if you could help.
The array that is NOT printed well:
// Unique ID has been declared in the header files
mode = TX_MODE;
bSendMessage(UniqueID8, 8);
LED_HIGH();
_delay_ms(250);
LED_LOW();
/****** the array that actually sends its values normally******
#define LEN 32
byte str[LEN]={'H','o','p','e','R','F',' ','R','F','M',' ','C','O','B','R','F','M','9','5','W','A','+','+','+'};
void loop (){
mode = TX_MODE;
bSendMessage(str, 21);
LED_HIGH();
_delay_ms(250);
LED_LOW();}
//******* UniqueID8 has been declared in the header files*******
mode = TX_MODE;
bSendMessage(UniqueID8, 8 );
LED_HIGH();
_delay_ms(250);
LED_LOW();
I don't know if what change should I make to the "UniqueID8" in order to be transmitted correctly.
The code that sends the good data is the following: #define LEN 32
byte str[LEN]={'H','o','p','e','R','F',' ','R','F','M',' ','C','O','B','R','F','M','9','5','W','A','+','+','+'};
void loop (){
mode = TX_MODE;
bSendMessage(str, 21);
LED_HIGH();
_delay_ms(250);
LED_LOW();
}
Let me ask my question this way...
How can I convert the UniqueID from the library I attached in my first post to something like :
byte str[LEN]={'H','o','p','e','R','F',' ','R','F','M',' ','C','O','B','R','F','M','9','5','W','A','+','+','+'};
If I can convert this UniqueID data type to an array, I can easily send and receive it.
dizzycoder:
Let me ask my question this way...
How can I convert the UniqueID from the library I attached in my first post to something like :
byte str[LEN]={'H','o','p','e','R','F',' ','R','F','M',' ','C','O','B','R','F','M','9','5','W','A','+','+','+'};
If I can convert this UniqueID data type to an array, I can easily send and receive it.
convert to string then send as string
string unikID = UniqueID;
serial.print(UnikID);
I tried that but didn't work, Error is as follows:
cannot convert 'String' to 'byte* {aka unsigned char*}' for argument '1' to 'byte bSendMessage(byte*, byte)'
It needs bytes. I did the following line and it compiled with no error, However, the Receiver outputs the figure below.
byte mac[LEN]= {'U','n','i','q','u','e','I','D','=',UniqueID8[0],UniqueID8[1],UniqueID8[2],UniqueID8[3],UniqueID8[4],UniqueID8[5],UniqueID8[6],UniqueID8[7],UniqueID8[8]};
How big is UniqueID8? If it has 8 elements as its name suggests, then UniqueID8[8] doesn't exist, and that can (most likely) cause issues (undefined behavior and such).
rzk:
i have look out your library from the source you provide.
ArduinoUniqueID.h and ArduinoUniqueID.cpp
by reading those file i can't find any function that resulting "HopeRF RFM...."
so this is pure logic error by human, the program ain't wrong.
the question
is that your code?
what is your purpose about unique id?
thx
Hi RZK,
The array containing byte str[LEN]={'H','o','p','e','R','F',' ','R','F','M',' ','C','O','B','R','F','M','9','5','W','A','+','+','+'}; is a random array i used in my main program to see if the data is being transmitted between the Receiver and Transmitter and has nothing to do with Unique ID. The Unique ID array from the corresponding library is what I'm intending to send as data and that's where I receive incorrect values on COM port. I think it has something to do with the type of data that I'm sending. On the receiver end, I use Serial.write (array,length) to read the incoming data.
dizzycoder:
Hi RZK,
The array containing byte str[LEN]={'H','o','p','e','R','F',' ','R','F','M',' ','C','O','B','R','F','M','9','5','W','A','+','+','+'}; is a random array i used in my main program to see if the data is being transmitted between the Receiver and Transmitter and has nothing to do with Unique ID. The Unique ID array from the corresponding library is what I'm intending to send as data and that's where I receive incorrect values on COM port. I think it has something to do with the type of data that I'm sending. On the receiver end, I use Serial.write (array,length) to read the incoming data.
okay i got it,
but it doesn't denying the logic error by human.
i did some googling and found out arduino uniqueid is library made by someone,
before combine with your code have you try the example by the library and see the result?
I calculated the Unique id length with the following code and it said it has 9 elements. Serial.println ( strlen (UniqueID) );
strlen can be used only on C strings. Is UniqueID a C string? From a cursory look at ArduinoUniqueID.h, that doesn't seem to be the case.
By calculating the "length" of UniqueID with strlen, the program just happens (accidentally) to find a byte with a value of zero 9 bytes into the buffer, even if the buffer is actually shorter than that. I'm pretty sure UniqueID (and UniqueID8) is only 8 bytes long.
the library example code print ID as hex format Serial.print(UniqueID8*, HEX); <--[/b]* but your code print as byte format, bSendMessage(UniqueID8, 8 ); by arduino every byte will show in serial monitor as ascii so you need to adjust your print function (bSendMessage()) capable to print hex, thx