VirtualWire DEC to ASCII

Hi!

I'm using virtualwire library to conect 433Mhz RF with arduino.

Here is the deal, I send the messange in ASCII and get it as DEC,
How I can receive text data on ? or convert this dec to ascii?

Thanks!!

TX

#include <VirtualWire.h>

void setup()
{
    Serial.begin(9600);	
    Serial.println("setup");
    vw_setup(2000);
}

byte count =1;

void loop()
{
    char msg[4] = {'o','i',count,'#'};
    msg[3] = count;
    digitalWrite(13, true);
    vw_send((uint8_t *)msg,3);
    vw_wait_tx();
    digitalWrite(13, false);
    delay(200);
    
    count++;
    if(count > 10)
      count=0;  
}

RX

#include <VirtualWire.h>

void setup()
{
    Serial.begin(9600);	
    Serial.println("setup");
    vw_setup(2000);
    vw_rx_start();
}

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    if (vw_get_message(buf, &buflen))
    {
	int i;
        digitalWrite(13, true);
        
	Serial.print("Got: ");
	for (i = 0; i < buflen; i++)
	{
	    Serial.print(buf[i]);
	    Serial.print(" ");
	}
	Serial.println("");
        digitalWrite(13, false);
    }
}

and over serial monitor I get:

Got: 111 105 0
Got: 111 105 1
Got: 111 105 2
Got: 111 105 3
Got: 111 105 4
Got: 111 105 5
Got: 111 105 6
Got: 111 105 7
Got: 111 105 8
Got: 111 105 9
Got: 111 105 10

and my desired RX is
Got: o i 0
Got: o i 1
Got: o i 2
...

try casting it to char like:

Serial.print((char)buf[i]);

o and i are the ASCII representation of 111 and 105 respectively.

You can force Serial.print to use the decimal representation by adding ",DEC" to the print function:

Serial.print(buf[i],DEC);

Ah i see i totally mis read, i though he wanted to print his output in ascii :slight_smile:

Thank you so much duality and majenkon.

You guys solved this issued!!
As duality said using (char) converts to ASCII.
And if I use ,DEC as majenko said it works great to convert as decimal.

THnaks so much!! :slight_smile:

Hello!!!

Can you guys help me again?

look I got buf*, but I want code something like this:*
if ( buf*=="something" )*
* dosomething*
Im having trouble =(

strcmp

if(strcmp(buf,"something")==0)
{
  // do something
}

Thank you again!
But using this code I get this error:

invalid conversion from uint8_t* to const char
any hint?

I need to study vectors,pointers and Strings

I need to study vectors,pointers and Strings

Study strings, not Strings. Forget that Strings even exist.

any hint?

Use a cast.

if(strcmp((char *)buf,"something")==0)

Thank you PaulS

using you code and reading about strings here is the code I come up with
it's working great!

           if(strcmp((char*)buf,"1 Msg")>0)
              {
                Serial.println("");
                Serial.print("1 recebida");
              }

Thanks!!