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 13768 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…
Parents
  • 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
Reply
  • 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
Children
  • Former Member
    Former Member over 13 years ago in reply to Former Member

    Hello, the code above is correct if you use the old Arduino editor named Alpha.

    But with the new one 1.0 the NewSoftSerial is integrated in the core. (do not copie the NewSoftSerial.h into the libraries directory). So the code must be :

     

    #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);  //works fine

    }

     

    Just a remark  :

    With editor Alpha I used the following code to blank the lcd screen : lcd.print(12,BYTE);

    With the new editor this line generates an error code : the BYTE keyword is no longer supported.

    So to blank the screen the command is lcd.write(12);

    • 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