element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Print a string on lcd
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 11 replies
  • Subscribers 403 subscribers
  • Views 13770 views
  • Users 0 members are here
Related

Print a string on lcd

Former Member
Former Member over 13 years ago

Hello,

first of all, I’m new to Arduino’s world.

Sorry if this question is very basic.

 

I simply want to print a string on a Parallax YJ-162A lcd screen.

 

This is the code

 

SoftwareSerial lcd = SoftwareSerial(2, 6); //Set RX/TX pins for LCD

#include <SoftwareSerial.h>

SoftwareSerial lcd = SoftwareSerial(2, 6); //Set RX/TX pins for LCD

String ds;

 

void setup(){

      ds = "test";

      Serial.begin(9600);

      lcd.begin(9600);

      serial.print(ds);

      lcd.print(ds);

}

 

The compiler returns an error on line lcd.print(ds);

I don't understand why it is working with serial monitor and not with lcd.

this works fine : lcd.print("test");

If ds is a char it also works so I must convert a string to char ?

Or SoftwareSerial.h is wrong ?

 

Do you have a suggestion ?

Thanks for your help.

  • Sign in to reply
  • Cancel

Top Replies

  • ntewinkel
    ntewinkel over 13 years ago +1
    I don't know why that line would show an error for you, but not for me, as I simply did a cut and paste from what you had in your post. I'm using the very basic install of the Arduino software, without…
  • tronixstuff
    tronixstuff over 13 years ago +1
    Perhaps have a run through here - tronixstuff.com/tutorials and click on chapter 24
  • fustini
    fustini over 13 years ago in reply to Former Member +1
    Hi, I tried compiling your example and got in Arduino 022: sketch_jan31a:8: error: no matching function for call to ‘SoftwareSerial::print(String&)’ I found this thread: http://www.arduino.cc/cgi-bin/yabb2…
  • ntewinkel
    ntewinkel over 13 years ago

    Hi dakota77,

     

    It looks like the issue is with your lowercase "serial.print(ds);", which should read "Serial.print(ds);" - Serial starting with capital S.

     

    I compiled it here, and that's the only thing it complained about. Also, don't forget to include the void loop() function image

     

    Hope that helps!

    Cheers,

    -Nico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 13 years ago in reply to ntewinkel

    Hi Nico,

     

    Thanks for your reply.

    Serial.print(ds);  works without problem.

    The problem appears when I try to write to the lcd screen : lcd.print(ds)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • ntewinkel
    ntewinkel over 13 years ago

    I don't know why that line would show an error for you, but not for me, as I simply did a cut and paste from what you had in your post.

    I'm using the very basic install of the Arduino software, without any added libraries. On a Mac though, which might be different.

     

    Another line I just noticed, that may be causing issues, is the lcd.begin(9600) line - shouldn't that be lcd.begin(16,2) ?

     

    Also, have you already tried running the HelloWorld example? (File - Examples - LiquidCrystal - HelloWorld)

    It does the display, but without the serial printouts you have in your code. You could add that as a second step once the first hurdle is cleared.

     

    Cheers,

    -Nico

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • tronixstuff
    tronixstuff over 13 years ago

    Perhaps have a run through here -  tronixstuff.com/tutorials and click on chapter 24

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 13 years ago in reply to tronixstuff

    Hello, thanks for your replies...

    In fact all the samples of LCD wiring found on the net, represent a lcd with 6 wires.

    My LCD is a Parallax Serial LCD. It has 3 wires : + ground and data

    So I simply connect the data wire to a pin.

    The disavantage is that I can not use LiquidCrystal.h so but I have to use Softwareserial.h

     

    #include <SoftwareSerial.h>

    SoftwareSerial lcd = SoftwareSerial(2, 6); //Set RX/TX pins for LCD

    String ds;

     

    void setup(){

          ds = "test";

          lcd.begin(9600);  //start serial connection

          lcd.print("Hello World"); //works fine

          lcd.print(ds);  //The compiler returns an error

    }

     

    So my question is : with this type of display, how can I print a string on the lcd ?

     

    Thanks for your time.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • billabott
    billabott over 13 years ago in reply to Former Member

    Find a way to add a binary zero to the end of the string.  Your character array ds contains ds[0]='t' , etc.  You might really need to  make ds[4]=0.    The phrase "null terminated string" has real meaning in some apps.

     

    possibly this change would work:    ds = "test\0";

     

    Here is some more useful info.

     

    If you find this helpful; it would be appropriate to "Like" my post.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • fustini
    fustini over 13 years ago in reply to Former Member

    Hi,

     

    I tried compiling your example and got in Arduino 022:

    sketch_jan31a:8: error: no matching function for call to ‘SoftwareSerial::print(String&)’

    I found this thread:

     

    http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1289274437

     

    I states that SoftwareSerial is obsolete and to use NewSoftSerial instead.  I was able to compile this ok:

     

    #include <NewSoftSerial.h>
    
    NewSoftSerial lcd = NewSoftSerial(2, 6); //Set RX/TX pins for LCD
    String ds;
     
    void setup(){
          ds = "test";
          lcd.begin(9600);  //start serial connection
          lcd.print("Hello World"); //works fine
          lcd.print(ds);  //The compiler returns an error
    }
    
    void loop() {
      
    }

     

    Cheers,

    Drew

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 13 years ago in reply to fustini

    yes yes yes fantastic ! it works !

    thanks a lot for your help.

    Mario

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • billabott
    billabott over 13 years ago in reply to Former Member

    That is Great!  Would you mind specifing what change you made?

    "it" doesn't quite narrow down the possibilites.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 13 years ago in reply to billabott
    #include <NewSoftSerial.h>
    NewSoftSerial lcd = NewSoftSerial(2, 6); //Set RX/TX pins for LCD
    String ds;
    void setup(){
          ds = "test";
          lcd.begin(9600);  //start serial connection
          lcd.print("Hello World"); //works fine
          lcd.print(ds);            //works fine
    }
    void loop() {

    }Hello,

     

    Hello,

    I have simply used the NewsoftSerial library instead of SoftwareSerial.h

    I can now print a string to lcd without problem.

     

    Thanks gain for your help.

    Mario

     

    #include <NewSoftSerial.h>

     

    NewSoftSerial lcd = NewSoftSerial(2, 6); //Set RX/TX pins for LCD

    String ds;

     

    void setup(){

          ds = "test";

          lcd.begin(9600);  //start serial connection

          lcd.print("Hello World"); //works fine

          lcd.print(ds);                //works fine

    }

     

    void loop() {

     

    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube