system
March 25, 2014, 9:10am
1
How do i print an uint8_t using lcd.print ? My C is a little rusty so I've forgotten how to do this.
This is the code which receives data from a radio module. I've left out all the irrelevant stuff. I'm using the VirtualWire library
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
lcd.print(buf);
}
I tried casting but that didn't work. I don't know whether buf is null terminated and this could be a problem. Using lcd.write to print out individual characters until I reach buflen -1 works fine
system
March 25, 2014, 10:25am
2
I don't know whether buf is null terminated
It isn't.
I tried casting but that didn't work.
"it didn't work" means that something happened, but you couldn't be bothered to tell us what, and that that differs from what you want. How are we then supposed to help you?
system
March 25, 2014, 11:27am
3
Ok, what I should have said is that it didn't compile.
I get these error messages:
Arduino: 1.5.5 (Windows Vista), Board: "Arduino Leonardo"
radiomodulereceive.ino: In function 'void loop()':
radiomodulereceive:55: error: call of overloaded 'print(uint8_t [30])' is ambiguous
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:56: note: candidates are: size_t Print::print(const String&)
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:57: note: size_t Print::print(const char*)
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:58: note: size_t Print::print(char)
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:59: note: size_t Print::print(unsigned char, int)
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:60: note: size_t Print::print(int, int)
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:61: note: size_t Print::print(unsigned int, int)
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:62: note: size_t Print::print(long int, int)
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Print.h:63: note: size_t Print::print(long unsigned int, int)
system
March 25, 2014, 12:03pm
4
Ok, what I should have said is that it didn't compile.
That's a completely different story. How did you try to cast the value?
if (vw_get_message(buf, &buflen)) // Non-blocking
{
buf[buflen] = '\0'; // NULL terminate the array
lcd.print((char *)buf);
system
March 25, 2014, 2:10pm
5
That worked fine, thanks for the help!