Hi everyone
I am using a 2x16 LCD with TCF 8574 serial input.
It is connected and works almost fine: I am sending it a message every 5 seconds (via a BT module) that has 25 characters.
It will truncate a part of the message the first time it receives it, and then on the 2nd instance it will display the rest of the truncated segment of the message.
Also, it seems it doe not recognize all characters such as % or ° (degree) and replace them by gibberish.
Normally the display should fold up the message on both lines ? it uses both of the lines but the message gets cut.
Here is the sketch:
// bluetooth RX sketch. HC-06_01
// HC-06 ZS-040
// Data 'temp' and 'hum' are received by HC06 via BT link. Both should be displayed on the Serial terminal and a Serial LCD display at the same time.
//
// Pins
// BT VCC to Arduino 5V out.
// BT GND to GND
// BT RX to Arduino pin 3 (through a voltage divider)
// BT TX to Arduino pin 2 (no need voltage divider)
//
/*
* Displays text sent over the serial port (e.g. from the Serial Monitor) on
* an attached LCD.
* SCL se connecte sur l entree A5 et SDA sur l entree A4.
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3); // RX | TX
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
BTSerial.begin(9600); // HC-06 default baud rate is 9600
lcd.init(); // initialize the lcd
lcd.backlight();
Serial.begin(9600);
Serial.println("This is HC06 RX, receiving ");
}
void loop()
{
if (BTSerial.available()) //if the BT module has received something
{
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (BTSerial.available() > 0)
{
// display each character to the LCD
lcd.write(BTSerial.read());
}
}
if (BTSerial.available())//if the BT module has received something
{
Serial.write(BTSerial.read()); // write what was received on the Nano Serial Monitor
}
}
It will truncate a part of the message the first time it receives it, and then on the 2nd instance it will display the rest of the truncated segment of the message.
These devices are not miniature replacements for a computer terminal so they are not set up wrap lines or respond to carriage return or linefeed commands. You have to take care of that by means of the cursor positioning commands.
For a complete description of what is happening you can follow the LCD Addressing link at http://web.alfredstate.edu/weimandn.
Please use 'code tags' when posting code. Highlight your code and click on the </> icon.
Don
Thanks Don and sorry for the code tags. I am not really used to upload, so I thought this was OK.
About the LCD: right, I know how to position the cursor in a paralell LCD. My problem is that here I am using a Serial version.
It refuses to keep the 2 lines format I am sending to it.
An idea ?
Thanks again !
Guillaume60:
About the LCD: right, I know how to position the cursor in a paralell LCD. My problem is that here I am using a Serial version.
After looking at your code it appears that you are using an LCD with a PCF8574 i2c i/o expander.
(NOTE: please go back and edit your initial post to use code tags for the code)
While your LCD h/w does use a serial bitstream at the h/w physical layer, that is typically not referred to as a "serial lcd".
When people say "serial lcd" the more common meaning is an lcd that uses a asynchronous serial interface.
In your case you are using i2c which is very different from asynchronous serial.
There are many "LiquidCrystal_I2C" libraries out there and they work differently and have different capabilities.
In terms of how to control the display, I think you have either not understood Don's comment or it is not sinking in. You are definitely not keeping your output limited to the LCD's two lines.
hd44780 LCDs are dumb devices. They do not perform any sort of line wrapping or vertical line scrolling.
In fact they really don't even know about lines or the boundaries of lines on the LCD display.
While line wrapping and vertical scroll could be done in the LCD library the library is not doing it either.
You must control how the characters are written to the display and ensure that any characters you wish to see do not spill over beyond the end of a line and since there is no vertical scrolling, println() will not work.
You could switch to my hd44780 library package.
It will autodetect the i2c backpack address, pin mappings, and backlight active level.
It fully supports the LCD API 1.0 spec so the API is compatible with the LiquidCrystal API.
It can be installed using the IDE library manager.
You can read more about it here:
Where you will find installation instructions and a summary of all the available API functions.
The i/o class for a PCF8574 based backpack is hd44780_I2Cexp
It is much faster than the LiquidCrystal_I2C libraries and the API provides some additional capabilities.
It will also not allow a sketch to use println() by issuing a compile error rather than generating code that will not work as expected.
I would recommend first running the included diagnostic sketch (I2CexpDiag) to test your i2c signals and verify the library can communicate with the LCD as well as test the internal memory of the LCD.
... thank you for your help,
I will use your library, menwhile, sorry but I really am a newbie not used to posting code sections, so if I got it right, my sketch was code tagged,, is it correctly posted this time ?
Let me know !
Thanks again !
Guillaume60:
here is my sketch again, is it correctly posted this time ?
no. I would recommend updating post #4 to remove the sketch. Then edit the original post to put the code inside code tags.
You can do this by simply highlighting all the sketch code and clicking on the code tags icon.
It is the left most icon at the top of the edit dialog box that looks like: </>
If you want to do it manually, the forum posts use brackets [] rather than <>
--- bill
Hi Bill
This time I got it !
Thanks for the 'how to', and sorry again for the disturbance.
Now, it seems I have to do some checking, and then try with your library instead of the one I had used.
To me it looks like a lib problem since everything works normally on a parallell interface.
It is easy to control lines from the TX sketch; but with a serial interface it seems I have no way to do it.
Now I have, with the same TX sketch:
- a proper dispaly with a parallelle interface,
- and a bad display with a serial interface, on the same LCD.
I will try as advised and come back to you.
Have a good day
The original post still does not have code tags around the code.
Again, I would delete the sketch code in post #4 and fix the sketch code in the original post of the thread.
Details and terminology is very important.
As I said in post #3, you don't have what is commonly called a "serial" interface LCD according to the code you have posted.
The code you are using is attempting to use an i2c backpack not a serial interface LCD.
While you have never said which "parallel interface" LCD library you are using, the most common one is the LiquidCrystal library that is bundled with the IDE. That library does not handle line line endings, line wrapping, or vertical line scrolling.
The IDE bundled LiquidCrystal library and the i2c backpack libraries use the same API. The function names are the same and they work the same way.
So it should work the same regardless of whether "parallel" (pin i/o) or a i2c backpack is used.
I think you are still understanding the limitations of these devices and libraries as don pointed out in post #1 and then I expanded on in post #3.
Your code is simply reading from a serial interface and sending the characters to the LCD library.
You will have issues when your output of characters exceeds the number of characters per LCD line since neither the LCD nor the library handle line wrapping or vertical line scrolling.
One potential issue that you might be having is that the LiquidCrystal library has much lower overhead than the LiquidCrystal_I2C library, so if all the serial characters have not come in after your delay(100), the some characters might get lost on the software serial port as software serial is pretty finicky and much more subject to character loss when other things are happing.
If that is the case, then my hd44780 library could help as it has much lower overhead and is much faster than LiquidCrystal_I2C.
--- bill
Good morning Bill,
I have modified the posts as you said, thanks for the instructions.
Now, with your explanations I am starting to understand a bit better. Yes, I am using the Liquidcristal_I2C library.
Strangely, the result is not the same with Parallell and Serial interface...
I wil start by using your library and then I will compare results.
The delay(100) will probably need to be set to lower, say 10 or none.
I will look a little bit further and then eventually let you know about the results. No magic there, probably some mistake of some sorts somewhere. Solving it will be the best lesson.
Keep you posted and again thanks for the highlights.
Billy
I think you may still not understand the potential line ending/wrap/scrolling issue as you said you are sending 25 character messages to a lcd display that has only 16 character positions per line.
Changing the delay you are using will not solve any LCD line overrun issue and likely will make things even worse - or at a minimum create a different set of issues.
You are not limiting the number of characters that you are sending to the LCD in your loop that is reading from BTserial so if you exceed the characters per line, the LCD display is likely not going to reflect what you expected/wanted.
This was talked about by Don in post #1 and my post #3.
Also I'm not sure if the code has changed or if I just noticed that you are also trying to read BTSerial characters and send them to the h/w serial port.
There is no guarantee which part of the loop() code will see characters in BTSerial first,
the code that puts all the available characters to the LCD or the code that puts a single character out to the h/w serial port (serial monitor).
Also, keep in mind that while sending characters to the LCD, more BTSerial characters could still be coming in.
--- bill