16x2 lcd and wifi data display problems

Hi,

I have been given a task of getting ultrasonic distance sensor data transmitted over wifi to another arduino board and being displayed on a 16x2 lcd.

I have been able to use example sketches and combine them in a way that I can now transmit the sensor data over wifi and I can even view it on the lcd. But the problem is the lcd.

I would like to be able to have the first line say "distance" and the second line to actually display the data it receives. Right now the distance is showing up on the first line and I don't know how to get it to the second line.

There's also some weird symbols on the screen. I have tried searching for the symbols but couldn't find them.
I have attached the sketches to this post so you can check if something is wrong.

Thank you in advance!

Attached files:

DistanceOverWifiManual - server code
WifiWebClientRepeatingt - client code
symbols - Paint illustration of the symbols

DistanceOverWifiManual.ino (2.26 KB)

WiFiWebClientRepeatingt.ino (2.97 KB)

Understand how to write to the LCD first.

To do that, write a sketch that can do just that and that alone.

Once you have that working, you can then make use of parts of that sketch to use in your wifi data sketch.

Right now the distance is showing up on the first line and I don't know how to get it to the second line.

Look at the following sketch and see if you can figure it out.

#include <LiquidCrystal.h>

//LiquidCrystal lcd(RS, E, D4, D5, D6, D7);
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);      // put your pin numbers here

void setup()
  {
  lcd.begin(16, 2);                          // put your LCD parameters here
  lcd.print("hello, world!");
  lcd.setCursor(0,1);
  lcd.print("it works!");
  }

void loop()
  {
  }

There's also some weird symbols on the screen. I have tried searching for the symbols but couldn't find them.

These usually appear when you send control characters such as and to the LCD. The result is the display of two of the user defined characters but since you have not defined those characters you get quasi random symbols.

Don

ieee488:
Understand how to write to the LCD first.

To do that, write a sketch that can do just that and that alone.

Once you have that working, you can then make use of parts of that sketch to use in your wifi data sketch.

I already have the lcd working in a different sketch. I have one which displays the data from the distance sensor wired directly to the arduino. And in that sketch the display works correctly showing "distance" on the first row and the value on the second row.

But it won't work if the data is coming over the internet.

floresta:
Look at the following sketch and see if you can figure it out.

These usually appear when you send control characters such as and to the LCD. The result is the display of two of the user defined characters but since you have not defined those characters you get quasi random symbols.

Don

I have tried using the set cursor function but it just prints all the characters on top of each other.

How could I define those characters to be something like empty spaces or letters?

lollero2:
But it won't work if the data is coming over the internet.

This makes no sense.
Data is data.

What is the function that you are using to write to the LCD?

But it won't work if the data is coming over the internet.

Once again you are probably sending non-printable codes to the LCD and it is going bonkers. Try filtering out everything except the displayable characters ( 0x20 <--> 0x7F ).

Don

floresta:
Once again you are probably sending non-printable codes to the LCD and it is going bonkers. Try filtering out everything except the displayable characters ( 0x20 <--> 0x7F ).

Don

How would I filter it out? I tried searching google but couldn't really find anything.

ieee488:
This makes no sense.
Data is data.

What is the function that you are using to write to the LCD?

You can check the attached client code for better view of what's happening but here's the part with the lcd:

void loop() {
  
  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  while (client.available()) {
    
    char c = client.read();
    Serial.write(c);    
    lcd.print(c); 
    
  }

  // if ten seconds have passed since your last connection,
  // then connect again and send data:
  if (millis() - lastConnectionTime > postingInterval) {
    httpRequest();
    lcd.clear();
  }

}

It's very likely that it's not the best way of doing this.

Thank you for helping me!

I got the problem solved with this code:

And now I'm able to change the characters with the help of this tool:

http://omerk.github.io/lcdchargen/

lollero2:
Thank you for helping me!

I got the problem solved with this code:

Custom LCD Characters with Arduino - hackmeister.dk

And now I'm able to change the characters with the help of this tool:

Custom Character Generator for HD44780 LCD Modules

Those links are about generating custom characters and are actually irrelevant if your problem was not being able to write to the LCD correctly.

Hi ieee488,
I was searching for a similar response I have a 16x2 lcd "Serial Enabled 16x2 LCD - White on Black 5V - LCD-09395 - SparkFun Electronics"
and I have used serial in and recently tried the 4 bit serial // input. I have read the net to bits when i couldn't independently write to the 2nd line in the parallel mode.
My programming skills are Very Recent!
Is there such a way to do set cursor to line 2?
I have read thru several libraries and they gave me the impression that it always starts at line,0
and some discussion on how the display control chip works re line wrap.
My question is i want to display some numbers on the top and have an analogue bar running below.

Which is the better option when it comes to writing the code re LCD Libraries 1 wire serial or the
parallel option?
your experience would be appreciated
Cheers.

My programming skills are Very Recent!
Is there such a way to do set cursor to line 2?

There is an example of how to do this in reply #2. Have you tried running that sketch and then figuring out how it works?

I have read thru several libraries and they gave me the impression that it always starts at line,0
and some discussion on how the display control chip works re line wrap.

The cursor is positioned to the left end of the first line by the initialization sequence. The line wrapping will differ depending on the configuration of the particular display and you won't be happy with the default operation of any of them. For a complete explanation follow the LCD Addressing link at http://web.alfredstate.edu/weimandn

Which is the better option when it comes to writing the code re LCD Libraries 1 wire serial or the
parallel option?

The HD44780 LCD controller inherently has a parallel interface. All devices using this controller (or a derivative) operate in essentially the same manner had hence the generic LiquidCrystal library will work equally well (or equally poorly) with all LCD modules.

When you introduce any kind of serial interface the entire picture changes. There are no standards, hence a library written for one interface will rarely work well, if at all, with another. Currently the only exception is the 'New LiquidCrystal' library written by Francisco Malpartida.

Don

Thank you for your reply,
I have now worked out..derr that the extra chip on the board is a shift register of some kind to do a serial to // conversion
I'll read some more and make compromises I guess we're not making Nuclear reactors here :slight_smile:
Thanks again for the links .
albert

ieee488:
Those links are about generating custom characters and are actually irrelevant if your problem was not being able to write to the LCD correctly.

By adding the code on that page to my sketch the display printed an "h" and an arrow to right. And then I was able to change them to "c" and "m". So now the display shows it correctly. I still wasn't able to make the text jump to the second line because the setcursor function wasn't working, so I just printed a bunch of spaces before the distance and was able to move it to the second line.

lollero2:
By adding the code on that page to my sketch the display printed an "h" and an arrow to right. And then I was able to change them to "c" and "m". So now the display shows it correctly. I still wasn't able to make the text jump to the second line because the setcursor function wasn't working, so I just printed a bunch of spaces before the distance and was able to move it to the second line.

You wrote that your code was working and that you were able to write to the LCD.
You wrote that your only problem was that you did not know how to write the wifi data.
I told you that data is data and that the wifi data is not anything special.

Now, you write that you needed another piece of code, because you couldn't write the 2nd line.

Then, I would say what you wrote the first time was incorrect. You did not have working code or you won't need to add more code.

Next time you want help, I suggest you post facts.

ieee488:
You wrote that your code was working and that you were able to write to the LCD.
You wrote that your only problem was that you did not know how to write the wifi data.
I told you that data is data and that the wifi data is not anything special.

Now, you write that you needed another piece of code, because you couldn't write the 2nd line.

Then, I would say what you wrote the first time was incorrect. You did not have working code or you won't need to add more code.

Next time you want help, I suggest you post facts.

My code was working to a point that I got the data displayed but it didn't show the way I wanted it to. The problem wasn't that I didn't know how to write the wifi data.

Also it's funny that floresta understood what was wrong and was also able to guide me in the right direction, while you probably didn't even read the post or check the code I attached.

Thank you very much floresta for helping me with the problem!

ps. ieee488 you shouldn't be responding to peoples guestions if you just want to be arrogant.