CodilX 0 Posted April 14, 2013 Share Posted April 14, 2013 Hello there, I'm trying to output serial data received to the MSP430 and display it on the LCD. I do know that there is an example for it, but that way doesn't really work for me, the way I've planed my data to be received and outputed differs from the example. Here is what I'm tinkering with right now: #include <LiquidCrystal.h> LiquidCrystal lcd(7, 8, 9, 10, 11, 12); String Input; void setup() { lcd.begin(16, 2); Serial.begin(9600); } void loop() { while(Serial.available() > 0) { Input += (char)Serial.read(); } lcd.clear(); lcd.write(Input); delay(1000); } However it breaks on the lcd.write(Input); line, it won't accept my string! The full error: sketch_apr14b.cpp: In function 'void loop()':sketch_apr14b.cpp:18:18: error: no matching function for call to 'LiquidCrystal::write(String&)'sketch_apr14b.cpp:18:18: note: candidates are:C:\LPad\energia-0101E0008\hardware\msp430\libraries\LiquidCrystal/LiquidCrystal.h:82:18: note: virtual size_t LiquidCrystal::write(uint8_t)C:\LPad\energia-0101E0008\hardware\msp430\libraries\LiquidCrystal/LiquidCrystal.h:82:18: note: no known conversion for argument 1 from 'String' to 'uint8_t {aka unsigned char}'C:\LPad\energia-0101E0008\hardware\msp430\cores\msp430/Print.h:57:20: note: virtual size_t Print::write(const uint8_t*, size_t)C:\LPad\energia-0101E0008\hardware\msp430\cores\msp430/Print.h:57:20: note: candidate expects 2 arguments, 1 providedC:\LPad\energia-0101E0008\hardware\msp430\cores\msp430/Print.h:56:12: note: size_t Print::write(const char*)C:\LPad\energia-0101E0008\hardware\msp430\cores\msp430/Print.h:56:12: note: no known conversion for argument 1 from 'String' to 'const char*' Is there any way I can write a string to the LCD?.. Thanks Quote Link to post Share on other sites
grahamf72 169 Posted April 14, 2013 Share Posted April 14, 2013 lcd.write is for sending a single character. To send a string you need to use lcd.print. Quote Link to post Share on other sites
roadrunner84 466 Posted April 15, 2013 Share Posted April 15, 2013 You have a conflict between the String type and the potential types that lcd.write() accepts. There are multiple ways for the compiler to resolve this, but because it doesn't "know" which option is best it asks you. The "best" option is to create a c string (char*) the size of your display and use the toCharArray() method of String to convert it. But this takes a lot of memory (which it probably does anyway). Another option is to cast the string to a char array to aid the compiler in resolving the decision. // Option 1 // Replace lcd.write(Input); // With char lcd_buffer[20 + 1]; // I assume you have 1 1x20 display, change to the actual size. Input.toCharArray(lcd_buffer, sizeof(lcd_buffer)); lcd.write(lcd_buffer); // Option 2 // Replace lcd.write(Input); // With lcd.write((char*)Input); Quote Link to post Share on other sites
CodilX 0 Posted April 15, 2013 Author Share Posted April 15, 2013 Thanks! Changing to print solved it Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.