Jump to content
43oh

LiquidCrystal print string error


Recommended Posts

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 provided
C:\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

Link to post
Share on other sites

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);
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...