LCD and Virtual wire

Hello,

This comes from a newbie. I am using the Virtual wire library to transmit (through a 433 MHz transmitter) in a loop a character at time 0, 1... 9 and the string "End" at the end of the loop:


#include <VirtualWire.h>

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

vw_set_tx_pin (12);
vw_setup(1000);
}

void loop()
{
char msg[27];

for (int i=0; i <= 9; i++){
sprintf(msg, "%i", i);
digitalWrite(13, true);
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx();
Serial.println(i);
digitalWrite(13, false);
delay(1000);
}
sprintf(msg, "End");
digitalWrite(13, true);
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx();
Serial.println(msg);
digitalWrite(13, false);
delay(1000);
}


Then, through another Arduino, I have a 433 MHz receiver end a 16x2 LCD attached. I am having success to display the number from 0 to 9 that I receive, but the string "End" only display the "E".


#include <VirtualWire.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
lcd.begin(16, 2);
Serial.begin(9600); // Debugging only
Serial.println("setup");
lcd.print("setup");
vw_set_rx_pin (7);
vw_setup(1000);
vw_rx_start();
}

void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
int i;
char msg;

if (vw_get_message(buf, &buflen))
{
lcd.clear();
digitalWrite(13, true);

Serial.print("Got: ");
Serial.write(msg);
Serial.println("");

lcd.setCursor(0,0);
lcd.print("Got:");
lcd.setCursor(0, 1);
msg = *buf;
lcd.print(msg);

digitalWrite(13, false);
}
}


I am having a hard time to understand the type uint8_t and its pointer and how I can convert buf into something that can be displayed with the function lcd.print. Can someone tell me what am I missing? How can I display on the LCD a longer (more than one character) string that comes from vw_get_message(buf, &buflen)?

Thanks a ton.

Test_Transmitter_433_VW.ino (584 Bytes)

LCD_Receiver_433_VM.ino (756 Bytes)

if (vw_get_message(buf, &buflen))
    {
        lcd.clear();
        digitalWrite(13, true);

   Serial.print("Got: ");
   Serial.write(msg);

Get some data. Store it in an array. Print some random garbage.

Please explain how that last part makes sense.

If I understood your reply correctly, you are talking about the Serial portion.

I am also using the serial to monitor the same data. It doesn't affect what I am trying to do with the LCD.

I am also using the serial to monitor the same data. It doesn't affect what I am trying to do with the LCD.

Doesn't it? msg is a char, not a pointer to char. So, when you do get around to valuing msg, it holds, and then prints to the LCD, exactly one character. And, wasn't that what you were complaining was happening?

You are right. I messed up when I copied the code here. I removed the "Serial.write(msg);" from my code and the lcd still only prints "E" out of the word "End".
The idea here:
msg = *buf;
lcd.print(msg);

is that msg will receive the contents of the pointer *buf. However since this is a string (more than one character) the pointer only point to the first letter. How can I associate msg to the whole string and not only the first letter?

Thanks and sorry for the newbie question.

The idea here:
msg = *buf;
lcd.print(msg);

That may be the idea, but it isn't reality. There is no way to store "End" in a character variable. You need an array to store more than one character. Which buf is. So, why not just use buf?

Because buf is of the type uint8_t * and when I use lcd.print(but); I get an error saying that I can use this type as an argument for lcd.print.

Because buf is of the type uint8_t * and when I use lcd.print(but); I get an error saying that I can use this type as an argument for lcd.print.

So, lie to the lcd.print() method.

lcd.print((char *)buf);

I've tried that before too. And in fact. It does print the whole word "End". However it also printed some "strange" characters that I can't get rid of it. Even if I use something like lcd.clear or lcd.print(" "); the characters remain there. That was the reason why I was also printing to the Serial. And when I looked at the serial output, some strange characters were also being printed.

However it also printed some "strange" characters that I can't get rid of it.

You could, it buf was actually a string. You can make it more like a string:

buf[buflen] = '\0';

after the receive call.

That worked!

Thanks a ton!