arduino - buf[i] returns the 8 bit max, ie 255, instead of character sent -


am having trouble understanding i'm getting in arduino setup.

scenario is: i'm sending character (could character) tx board rx board using chipset running virtualwire. rx receiving message , buffer length 1. when print out buf[i] on serial monitor, 255 (which 8 bit maximum integer assume) instead of character a. here relevant code:

tx file [code] void setup() {

c = 'a'; //for testing only

// wireless code...data pin on tx connected port 7...vw stands 'virtualwire'

vw_setup(2000); // initialize tx transmission rate vw_set_tx_pin(7); // declare arduino pin data transmitter ...

void loop() {

... vw_send((uint8_t *)c, 1); // turn buzzer on...transmit character

rx file

// rx data pin 8

void loop() {

serial.println("looping"); delay(2000);  uint8_t buflen = vw_max_message_len;// defines maximum length of message uint8_t buf[buflen]; // create array hold data; defines buffer holds message  if(vw_have_message() == 1) // satement added virtualwire library recommendation 1 of 3 statements use before get_message statement below// not in original humanharddrive code {   serial.println("message has been received"); }  if(vw_get_message(buf, &buflen)) // &buflen actual length of received message; message placed in buffer 'buf'  {   serial.print("buflen &buflen = ");   serial.println(buflen); // print out buffer length derived &buflen above    for(int = 0;i < buflen;i++)   {     serial.print("i = ");     serial.println(i);             <--prints 0     serial.print(" buf[0] = ");         serial.print(buf[0]);          <--prints 255       serial.print("   buf[i] = ");     serial.println(buf[i]);        <--prints 255       if(buf[i] == 'a')  <-- not recognize since buf[i] comes out 255 

[/code]

thanks suggestions!

the problem this:

vw_send((uint8_t *)c, 1);

c not pointer, passing value of 'a' pointer location read vw_send. you'll need address-of operator:

vw_send((uint8_t *) &c, 1);


there redundant if: if(vw_get_message(buf, &buflen)) not nested inside if(vw_have_message() == 1) runs regardless of fact vw_have_message() may not return 1.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -