Hi. Have a question re wireless messaging. I am sending the char 'A' from the TX board to the RX board using the following code:
vw_send((uint8_t *)c, 1); // Turn buzzer on...Transmit the character 'c' to RX board
c is set to 'A', ie c = 'A' in the setup part of the file
I am receiving the message on the RX board with the following code:
uint8_t buflen = VW_MAX_MESSAGE_LEN;// Defines maximum length of message
uint8_t buf[buflen]; // Create array to hold the data; defines buffer that holds the message
if(vw_get_message(buf, &buflen)) // &buflen is the actual length of the received message; the message is placed in the buffer 'buf'
I am sending just this one character 'A'. On the receiving end, on the serial monitor I print out
the loop counter i, ie (i=0,i<buflen,i++), buf[0] and buf I get the following i = 0 buf[0] = 255 buf = y with two tiny dots on top of the y I was expecting to get A. Not sure what 255 is (isn't ascii for A) or the y with two dots is...Also baffled why i would get different outputs for buf[0] and buf when i =0 anyway. using virtualwire library and the 433Mhz WL RF Transmitter + Receiver Module Link Kit for Arduino/ARM/MCU Wireless Any suggestions what I might try would be greatly appreciated.
Thanks for the replies...Pete. I'm using code straight from a working project from HumanHardDrive (Arduino Tutorial Lesson #12: Wireless Communication) for the wireless code. In his project he prompts for c on the TX side (1 or 0), then sends it to the RX....On mine I am sending the character without asking for it on a prompt.
I'm perplexed when I print out buf[0] on the RX side and get a different output than with buf when I is 0 too. shouldn't they be the same?
changed code from Serial.println((char) buf[ii]; to Serial.println(buf_; now both buf[0] and buf show 255 on the printout. Forgot we added the (char) element trying to troubleshoot. Apologies._ *Does anyone know why 255 shows up instead the character 'A' I'm sending? * I guess I could use 255 in my if statement, ie if(buf == 255); instead of if(buf == 'A'); but that doesn't satisfy my need to understand what's happening and have any confidence in the result. Thanks for your help.
crojai:
I'm perplexed when I print out buf[0] on the RX side and get a different output than with buf when I is 0 too. shouldn't they be the same?[/quote] No. buff[0] is the first unsigned character in the buffer array. Since it is unsigned (not just 'char') it is displayed as a decimal integer: 255. 'buff' is a character pointer, a.k.a. character string, apparently of length 1. The string contains a character of value 255 which displays as the ÿ.
John. I now see what the 255 signifies. If I'm not mistaken 255 is the larger integer which can be stored in an 8 bit word. Am I correct?
So I am sending the character A to the RX. I added the statement vw_have_message to confirm a message was received on the RX side. It does receive a message. But don't know why when I print out buf[0] on the serial monitor I get the 8 bit word max of 255 vs the actual message sent which is the character A.
if(vw_have_message() == 1) // Satement added by virtualwire library recommendation as one of three statements to use before the get_message statement below// not in original HumanHardDrive code
{
Serial.println("Message has been received");
}
if(vw_get_message(buf, &buflen)) // &buflen is the actual length of the received message; the message is placed in the buffer 'buf'
{
Serial.print("buflen from &buflen = ");
Serial.println(buflen); // Print out the buffer length derived from the &buflen above
for(int i = 0;i < buflen;i++)
{
Serial.print("i = ");
Serial.println(i);
Serial.print(" buf[0] = ");
Serial.print(buf[0]);
Serial.print(" buf[i] = ");
Serial.println(buf[i]);
if(buf[i] == 'A') <--- why not recognized???
It's impossible to be sure because you didn't include some of the vital parts of your code, like the declarations, but I think el_supremo probably got it right in Reply #3. Did you try his suggestion?
Thanks for the suggestion. I didn't try it because I am using the exact same syntax as a working program in a related tutorial did for that statement. The only declarations I use related to the vx_send(... statement
vw_send((uint8_t *)c, 1);
[\code]
are
char c; and
c = 'A'; in void setup()
Thanks for taking the time to reply.
Just a suggestion...
If you are using Virtualwire, try the Tx and Rx examples in the library itself.
Just make sure your Tx and Rx pins match the examples.