SERIAL LCD DISPLAY

I am using an Arduino UNO with a sensor. I want the reading to show up on a LCD Serial display. This sketch does not work.#include<SoftwareSerial.h>

SoftwareSerial LCD(10, 11) // Arduino SS_RX = pin 10 pinn 11 is LED

long sensor1, cm;

void setup() {

LCD.begin(9600);
pinMode(pwPin1, INPUT);
}

void read_sensor(){
sensor1 = pulseIn(pwPin1, HIGH);
cm = sensor1/58;
}

void loop () {
read_sensor();
printall();
delay(100);
}

void printall(){
Serial.print("S1");
Serial.print(" = ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
}

void printall() {
LCD.write(0xFE) ; // clear display
LCD.write(0xFE) ; // set line 1
LCD.write(128) ;
LCD.print("S1") ;
LCD.print(" = ") ;
LCD.print(cm) ;
LCD.print("cm") ;

delay(500) ;

}

}

Just a few points, not a big problem for that sketch but could you please to go and read the forum instructions so that you can go back and modify that original post (not re-post it) - using the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window. Just highlight each section of code (or output if you later need to post that) from the IDE and click the icon.

In fact, the IDE itself has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read. While you are lucky this far, If you do not post it as "code" it can easily be quite garbled and is generally more difficult to read due to the font.

It is inappropriate to attach it as a ".ino" file unless it is clearly too long to include in the post proper. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And even that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space. Do use blank lines, but only single blanks between complete functional blocks.

Why do we think this is more important than just having your question answered? Because it is really difficult to write code properly - as with any other task requiring care - if everything is not well organised! :grinning:

Post a data sheet for the LDC or link to where you bought the LCD so we know what you have. A photo of your wiring often helps, too.

A lot of the be hd44780 character LCDs advertised as serial are actually I2C.

groundFungus:
Post a data sheet for the LCD or link to where you bought the LCD so we know what you have.

Always a critical requirement when asking a question. :sunglasses:

Here is your code with the errors corrected, tidied up a bit and formatted with the IDE autoformat tool (ctrl-t or Tools, Auto Format). See the comments.

#include<SoftwareSerial.h>

SoftwareSerial LCD(10,  11);   // ********* added ;

unsigned long sensor1;  // ***** sensor1 should be unsigned long
long cm;  

const byte pwPin1 = 4;  // **** added pwPin1 declaration.  Choose your pin

void setup()
{
   LCD.begin(9600);
   pinMode(pwPin1, INPUT);
}

void read_sensor()
{
   sensor1 = pulseIn(pwPin1, HIGH);
   cm = sensor1 / 58;
}

void loop ()
{
   read_sensor();
   printall();
   delay(100);
}

// ****** this block does nothing cause Serial is not opened
// ****** with Serial.begin(baud) in setup().
void printall()
{
   Serial.print("S1");
   Serial.print(" = ");
   Serial.print(cm);
   Serial.print("cm");
   Serial.println();
}

void LCDprintall()   // ***** canged to LCDprintall. You can only have 1 printall().
{
   LCD.write(0xFE) ; // clear display
   LCD.write(0xFE) ; // set line 1
   LCD.write(128) ;
   LCD.print("S1") ;
   LCD.print(" = ") ;
   LCD.print(cm) ;
   LCD.print("cm") ;

   delay(500) ;
}
//}  ****** extra } causes error

Still need to see what exact LCD that you have.

What is the sensor?

Hi frog11,
In addition to the comments by the gentlemen: a sharp picture of the front and the back of your LCD would certainly be of great help.
success, Photoncatcher

I can not edit my post, so I will try this. Sorry I am using a Arduino UNO with a MB 1260-000 sensor from Maxbotix and a LCD-09395 Serial Display from SparFun. I want distance reading to show up the Serial Display. I have tried using the following skitch. It does not work.

/*
Test code for the Arduino Uno
Written by Tom Bonar for testing
Sensors being used for this code are the MB70X0 from MaxBotix
*/
#define pwPin1 = 2; 

#include<SoftwareSerial.h> 

SoftwareSerial LCD(10,  11)  // Arduino SS_RX = pin 10 pinn 11 is LED

long sensor1, cm;
 
 void setup() { 
 
 LCD.begin(9600);
  pinMode(pwPin1, INPUT);
}

void read_sensor(){
  sensor1 = pulseIn(pwPin1, HIGH);
  cm = sensor1/58;
}

void loop () {
  read_sensor();
  printall();
  delay(100);
}

void printall(){
  Serial.print("S1");
  Serial.print(" = ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
}

void printall() {
  LCD.write(0xFE) ; // clear display
  LCD.write(0xFE) ; // set line 1 
  LCD.write(128) ; 
  LCD.print("S1") ; 
  LCD.print(" = ") ; 
  LCD.print(cm) ; 
  LCD.print("cm") ; 

  delay(500) ; 

} 
  
  
}

Thanks for any help and hope I did a better job with this post.

Does the display work with the code from the Sparkfun tutorial?

It will work with the Sparkfun tutorial

Add your sensor code to the Spark fun example.

frog11:
I am using an Arduino UNO with a sensor. I want the reading to show up on a LCD Serial display. This sketch does not work.#include<SoftwareSerial.h>

SoftwareSerial LCD(10, 11) // Arduino SS_RX = pin 10 pinn 11 is LED

long sensor1, cm;

void setup() {

LCD.begin(9600);
pinMode(pwPin1, INPUT);
}

void read_sensor(){
sensor1 = pulseIn(pwPin1, HIGH);
cm = sensor1/58;
}

void loop () {
read_sensor();
printall();
delay(100);
}

void printall(){
Serial.print("S1");
Serial.print(" = ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
}

void printall() {
LCD.write(0xFE) ; // clear display
LCD.write(0xFE) ; // set line 1
LCD.write(128) ;
LCD.print("S1") ;
LCD.print(" = ") ;
LCD.print(cm) ;
LCD.print("cm") ;

delay(500) ;

}

}
************************with 2 printall() functions ?????????

This topic was automatically closed after 120 days. New replies are no longer allowed.