Hi there! , Ive been tinkering with arduino from a while, and trying to make a wireless display using arduino, esp32, nrf24 radio modules and an 16x1(8x2) LCD display which i had laying around. everything worked out on the serial monitor and i had previously tested this lcd display and had no problems. but having some trouble with the code which i wrote.
arduinocodehttps://pastebin.com/dWyczSRq
transmitting string = "hello how are you" which is a 17 character string.
#include "SPI.h"
#include "NRFLite.h"
#include <LiquidCrystal.h>
const int rs = 5, en = 6, d4 = 4, d5 = 3, d6 = 2, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const static uint8_t RADIO_ID = 0; // Our radio's id. The transmitter will send to this id.
const static uint8_t PIN_RADIO_CE = 9;
const static uint8_t PIN_RADIO_CSN = 10;
NRFLite _radio;
char _hello[30];
int newsize;
char n[30];
char m[30];
void setup() {
lcd.begin(8, 2);
Serial.begin(115200);
if (!_radio.init(RADIO_ID, PIN_RADIO_CE, PIN_RADIO_CSN)) {
Serial.println("Cannot communicate with radio");
while (1)
; // Wait here forever.
}
}
void loop() {
while (_radio.hasData()) {
_radio.readData(&_hello);
Serial.println(_hello);
int newsize = strlen(_hello) - 1;
Serial.println(newsize);
if (newsize <= 30) {
Serial.println(" 0th row and 0th column");
for (int k = 0; k <= 7; k++) {
lcd.setCursor(0, 0);
n[k] = _hello[k];
delay(200);
lcd.print(n);
//Serial.print(n);
}
if (newsize > 8) {
Serial.println(" 0th row and 1st column \n");
for (int t = 8; t <= 15; t++) {
lcd.setCursor(0, 1);
n[t] = _hello[t];
delay(200);
lcd.print(n);
//Serial.print(n);
}
}
}
}
}
the first 8 characters of the display work fine, but right after changing the cursor position, the written code (which works right on the monitor) seems to be just ignored by the arduino.
Make a small test-sketch for the display only and show it here between code tags (three backslash single quotes).
It is normal to have a number of test-sketches before putting everything together.
```
Your sketch between code tags
```
Why is it 8*2 ? Are there two rows after each other ? Can you give a link to the display ?
Does it work with 16 characters ? If that works, then everything is okay. You are not supposed to write more characters than 16.
There is a better library, called "hd44780", so there are enough possibilities to try.
sorry for the trouble, i believe its visible now. so i first tried changing the lcd.begin to (16,1)
but turns out, it doesnt work and later i found that, 16x1 lcd should be treated as a 8x2 display and also you should change the cursor positions after 8 characters. which as usual works fine and with no errors.
sorry for the trouble. so i first tried changing the lcd.begin to (16,1)
but turns out, it doesnt work and later i found that, 16x1 lcd should be treated as a 8x2 display and also you should change the cursor positions after 8 characters. which as usual works fine.
@Koepel and @TomGeorge
There are actually two different varieties of 16 x 1 LCD displays and the vast majority of them are configured as 8x2. If there are two large IC controllers (or epoxy blobs) then it is a true 16x1. If there is only one then it is configured as 8x2.
You are saying that the second row should be selected for the right side of the display ?
Then I get this:
#include <LiquidCrystal.h>
const int rs = 5, en = 6, d4 = 4, d5 = 3, d6 = 2, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup()
{
lcd.begin(8, 2);
// lcd.begin(16, 1);
}
void loop()
{
// 0123456789012345
splitPrint( 0, "A Full Line Text");
delay( 2000);
splitPrint( 0, "ABCDEFGHIJKLMNOP");
delay( 2000);
splitPrint( 0, "This line of text is too long.");
delay( 2000);
}
// Print a line of text.
// The 'column' is where the text starts on the LCD display
// Warning: The code is easy, but the result is slow
void splitPrint( int column, char *text)
{
for( int i=0; i<strlen(text); i++)
{
int col = column + i;
if( col < 8)
{
lcd.setCursor( i, 0); // column, row
lcd.print( text[i]);
}
else if( col < 16)
{
lcd.setCursor( i-8, 1); // column, row
lcd.print( text[i]);
}
}
}
The hd44780 library has support for this type of display to allow making a 16x1 display that is really physically a 8x2 to work like a 16x1 display when using the library API functions.
Simply install the hd44780 library (available in the IDE library manager) and use the hd44780_pinIO i/o class. It is API compatible with LiquidCrystal.
You will initialize the LCD as a 8x2 display but then enable line wrapping using the lineWrap() API function. This will allow the sketch to treat treat the LCD as if it were a 16x1, including printing, and cursor positioning.
There is an example called LineWrap included in the hd44780_pinIO examples that shows how to use the lineWrap() capability and has more information about using 16x1 displays that are really 8x2 displays.
The hd44780 has quite a bit documentation that comes with the library (you can bring in up from the IDE GUI) and in wiki pages on the hd44780 library github page.
Before jumping in and using the hd44780 library, I would highly recommend doing some amount of reading of the hd44780 library documentation as the hd44780 library is a bit different from the typical Arduino library in that it has support for multiple h/w interfaces each with its own i/o class and set of examples.