Page 1 of 1

LCD - startup problem

Posted: Tue May 17, 2022 8:34 am
by nawasaqi
Hi everyone, I've been trying for a few days now to try to run the LCD on the stm32f401 but to no avail. The LCD display is: LCD 2004A 4x20 HD44780 green. I connected the PB6 (SCL1) and PB7 (SDA1) + 5V and GND cables.
After connecting only the power supply, I adjusted the display so that there were two white lines visible.
After uploading the code below, the display is practically dim. In the upper left corner I have a small letter "o" and the cursor is blinking in the lower right corner.
I do not know what I am doing wrong, did someone have such a problem ??
Thank you in advance for your help.

Code: Select all

#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Clcd.h> // i2c LCD i/o class header


const int i2c_addr = 0x27;
hd44780_I2Clcd lcd(i2c_addr); // use device at this address


// LCD geometry
const int LCD_COLS = 20;
const int LCD_ROWS = 4;
void setup()
{
int status;

	// initialize LCD with number of columns and rows: 
	// hd44780 returns a status from begin() that can be used
	// to determine if initalization failed.
	// the actual status codes are defined in <hd44780.h>
	// See the values RV_XXXX
	//
	// looking at the return status from begin() is optional
	// it is being done here to provide feedback should there be an issue
	//
	status = lcd.begin(LCD_COLS, LCD_ROWS);

	// Print a message to the LCD
	lcd.print("Hello, World!");
}

void loop() {}

Re: LCD - startup problem

Posted: Sat May 21, 2022 8:39 am
by nawasaqi
Ok, I used a different library and it works. but I have another problem namely how to use a different SDA / SCL pair. When I connect by default in stm32F401 PB7 / PB6 it all works and if I try to use SDA2 / SCL2 or SDA3 / SCL3, it doesn't work.

Has anyone encountered such a problem, what could be wrong ??

Code: Select all

#include <LiquidCrystal_PCF8574.h>
#include <Wire.h>

//Wire.begin(SDA, SCK);
TwoWire Wire2(PB3, PB10);
TwoWire Wire3(PB4, PA8);

// Check the address via I2C Scanner
LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup() {
// put your setup code here, to run once:
 
Wire.begin();
Wire.beginTransmission(0x27);
Wire2.begin();
Wire2.beginTransmission(0x27);
Wire3.begin();
Wire3.beginTransmission(0x27);
 lcd.begin(20, 4); // initialize the lcd
}

void loop() {
// put your main code here, to run repeatedly:

lcd.setBacklight(100);
lcd.home();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("First Line ");
lcd.setCursor(0, 1);
lcd.print("...");
lcd.setCursor(0, 2);
lcd.print("...");
lcd.setCursor(0, 3);
lcd.print("...");
delay(1000);
}

Re: LCD - startup problem

Posted: Sat May 21, 2022 9:13 am
by fpiSTM
I guess the library used the Wire instance by default.
You can change the default pins of the wire instance.
https://github.com/stm32duino/wiki/wiki ... tance-pins

Re: LCD - startup problem

Posted: Sat May 21, 2022 11:06 am
by nawasaqi
I changed the code but unfortunately to no avail. it works on PB6 / PB7 and in the rest I have the start screen of the display ;(

Code: Select all

#include <LiquidCrystal_PCF8574.h>
#include <Wire.h>

TwoWire Wire2(PB3,PB10);
TwoWire Wire3(PB4, PA8);


LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 20 chars and 4 line display

void setup() {
 
Wire.begin(); 
Wire.beginTransmission(0x27);

//Wire.begin(SDA, SCL);
Wire2.setSDA(PB3);
Wire2.setSCL(PB10);
Wire2.begin();
Wire2.beginTransmission(0x27);

Wire3.setSDA(PB4); 
Wire3.setSCL(PA8);
Wire3.begin();
Wire3.beginTransmission(0x27);

lcd.begin(20, 4); // initialize the lcd


}

void loop() {
// put your main code here, to run repeatedly:
//Wire2.beginTransmission(0x27);

lcd.setBacklight(100);
lcd.home();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("First Line ");
lcd.setCursor(0, 1);
lcd.print("...");
lcd.setCursor(0, 2);
lcd.print("...");
lcd.setCursor(0, 3);
lcd.print("...");
delay(1000);
}

Re: LCD - startup problem

Posted: Sat May 21, 2022 2:56 pm
by GonzoG
LCD library use Wire object. You need to change pins for Wire, not to define new objects.