Teensy 4.0: LCD screen via I2C on wire2

As a final test, I tried the code @BriComp posted in msg #19. I copied and pasted into 3 tabs in Arduino IDE, with care to name the 2 new tabs with the filenames he said.

I hit just 1 small compile problem. The #include <LiquidCrystal_I2Cw2.h> lines needs to be #include "LiquidCrystal_I2Cw2.h" to use files from tabs in the sketch, rather than a properly installed library.

lcd7.png


With this minor edit, I'm happy to report this code works fine with the display connected to pins 24 & 25.

lcd8.jpg
 
Good question. Maybe the I/O expander powers up but the display doesn't?

Unfortunately I put all this stuff away and I'm moving on to final testing of bootloader update for compatibility for more flash memory chips, since people making DIY projects can't get the Winbond "M" flash chips right now.

Unless there's a serious need, I'm not planning to do more I2C character-type LCD testing. Maybe someone else will give it a try?
 
Just out of curiosity, does it show up when powered by 3.3V if you run an I2C scan?
Good question. Maybe the I/O expander powers up but the display doesn't?

Yes: when powered with 3V3 the I2C scanner program reports a device found at address 0x27.
The LCD displays the backlight in white, but no characters are displayed if I use the program above. Only the backlight is active, no blank digits at all.

I connected on a breadboard, with 5V power and adding 4.7K resistors to 3.3V.
Next I tried connecting the display power to 3.3V instead of 5V (using the exact same known-good example code from the previous test). I can confirm this display does *NOT* work with 3.3V power. The backlight turns on, but nothing appears on the screen.
OK but your display is a 5V version, whereas mine is supposed to be a 3V3 version.

I'm pretty sure the problems you're seeing are because the display simply does not work with 3.3V power, since your photo in msg #12 looks like this first case where the pixels in the first row are not turned on.
I don't know if powering it with 5V can damage it ?? (but it is not an expensive display, so ...).

So in order to perform the same test than you, I could let the 4K7 resistors in place between SDA & SCL and 3V3, and connect the Vcc pin of the I2C bus to 5V (instead of 3V3).

For doing this I plan to separate the 4 pins I2C connector coming from the LCD in two parts:

-part one: the SDA and SCL ins, that remain plugged on the MB in the same place. The 4K7 resistors will be between SDA & SCL and 3V3.
-part two: the GND and Vss pins (coming from LCD) will be connected elsewhere on the MB: GND to GND of course, and Vdd to 5V.

If you agree with this approach, I meantime modify the LiquidCrystal library as suggested (LiquidCrystal_I2Cw2.h and .cpp) to get the possibility to use wire2.

Thank you for your expertise !
 
Last edited:
OK but your display is a 5V version, whereas mine is supposed to be a 3V3 version.

Since the problems you're experiencing (at least to the extent I can see) appear like the 5V display not turning on with 3.3V power, for your next step I would recommend attempting to power the display with 3.3V and then with 5V. You don't even need Teensy for this, if you have a power supply which can provide those voltages. Just connect the 2 power wires and leave SDA and SCL unconnected. You're just looking for the first line to have the pixels all on, versus no pixels at all, like the 2 photos in msg #25.

My guess is your hardware may not actually be the 3.3V version. Maybe the Aliexpress vendor sent the wrong item? Or maybe the info about the product was wrong? Those are pretty common problems with the cheapest stuff from Aliexpress!


If you agree with this approach, I meantime modify the LiquidCrystal library as suggested (LiquidCrystal_I2Cw2.h and .cpp) to get the possibility to use wire2.

I tested those files by simply creating a new sketch in Arduino IDE with 3 tabs (click right side "..." menu and select "New Tab") and edit the include line, as you can see in the screenshot on msg #26. The goal was to give a way that is confirmed to work with pins 24 & 25.

You can edit libraries any way you like, and use PlatformIO instead of Arduino IDE, but for the sake of getting your hardware working, maybe a wise approach would be to use the exact software that is now confirmed working. Troubleshooting electronics is much more difficult when both the hardware and software are unknown to work.

After you have the hardware working, that is the time to customize and optimize. Before the hardware works, if you want to make this easier, try to use the confirmed working things as much as possible.
 
Last edited:
Since the problems you're experiencing (at least to the extent I can see) appear like the 5V display not turning on with 3.3V power, for your next step I would recommend attempting to power the display with 3.3V and then with 5V. You don't even need Teensy for this, if you have a power supply which can provide those voltages. Just connect the 2 power wires and leave SDA and SCL unconnected. You're just looking for the first line to have the pixels all on, versus no pixels at all, like the 2 photos in msg #25.
Yes I understand.
I have already changed the I2C cable, so I can separate SDA&SCL from the two other power supply wires, as shown on the photo herebelow:
04.cablage en 5V_s_b.jpg


You can edit libraries any way you like, and use PlatformIO instead of Arduino IDE, but for the sake of getting your hardware working, maybe a wise approach would be to use the exact software that is now confirmed working. Troubleshooting electronics is much more difficult when both the hardware and software are unknown to work.
OK, I will use PlatformIO with the program known to work and come back to you in a few hours.
I have slightly adapted my MB to get easy access to both 5V and 3V3.
05.MB with 5V_s_b.jpg


I come back to you in a few hours when I am back from work.

Thanks again.
 
Last edited:
I think that in order to fully understand what is going on, you need to get some idea of the interface board circuit.
irc display brd.png

I am pretty sure that R5 and R6 are I2C pull up resistors.
We need to determine what J1, J2 and J3 do.
Also what is Q1?
If we can generate a circuit then we will be better placed to understand how to drive the board.

ALSO probably try to use the module with the Teensy removed from your Motherboard, then you can try using Wire and Wire1.
 
I have tested following your guidelines, SDA&SCL not connected:
-The LCD powered with 3V3: same than before, i.e. the backlight is OK but no digits at all:
06.LCD sous 3V3 sans SDA ni SCL_s_b.jpg


-The LCD powered with 5V, SDA&SCL not connected, the result is exactly the same: the backlight is OK but nothing else is displayed:
07.LCD sous 5V sans SDA ni SCL_s_b.jpg


Consequently I see 2 possibilities:
a-.The LCD display is dead.
b-.The I2C->// backboard, soldered behind the LCD does not work, or is not soldered as it should, despite the pins numbering matching with the LCD.

I have another possible backboard, similar to the one you have used, like this:

08.Another I2C backboard_s_b.jpg


I have never used this kind of board, but I could try it, the problem being that I am not sure to unsolder the one that is currently soldered... will try but it is maybe simpler to order another LCD.

Last bad news, the program does not compile on PlatformIO (it says "Error 1"), nor on Arduino 1.8.19 (error at the same program location, related to the "#include <LiquidCrystal_I2Cw2.h>" line):
Code:
Executing task in folder I2C_T4_Helloworld_wire2: C:\Users\ordic\.platformio\penv\Scripts\platformio.exe run

Processing teensy40 (platform: teensy; board: teensy40; framework: arduino)
--------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/teensy/teensy40.html
PLATFORM: Teensy (5.0.0) > Teensy 4.0
HARDWARE: IMXRT1062 600MHz, 512KB RAM, 1.94MB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES:
 - framework-arduinoteensy @ 1.159.0 (1.59)
 - tool-teensy @ 1.159.0 (1.59)
 - toolchain-gccarmnoneeabi-teensy @ 1.110301.0 (11.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 92 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Wire @ 1.0
Building in release mode
Compiling .pio\build\teensy40\src\main.cpp.o
Archiving .pio\build\teensy40\libeb7\libWire.a
Compiling .pio\build\teensy40\FrameworkArduino\eeprom.c.o
Compiling .pio\build\teensy40\FrameworkArduino\extmem.c.o
Compiling .pio\build\teensy40\FrameworkArduino\fuse.c.o
Compiling .pio\build\teensy40\FrameworkArduino\interrupt.c.o
Compiling .pio\build\teensy40\FrameworkArduino\keylayouts.c.o
Compiling .pio\build\teensy40\FrameworkArduino\libc.c.o
Compiling .pio\build\teensy40\FrameworkArduino\main.cpp.o
Compiling .pio\build\teensy40\FrameworkArduino\memcpy-armv7m.S.o
Compiling .pio\build\teensy40\FrameworkArduino\memset.S.o
Compiling .pio\build\teensy40\FrameworkArduino\new.cpp.o
Compiling .pio\build\teensy40\FrameworkArduino\nonstd.c.o
Compiling .pio\build\teensy40\FrameworkArduino\pwm.c.o
Compiling .pio\build\teensy40\FrameworkArduino\rtc.c.o
Compiling .pio\build\teensy40\FrameworkArduino\serialEvent.cpp.o
Compiling .pio\build\teensy40\FrameworkArduino\serialEvent1.cpp.o
Compiling .pio\build\teensy40\FrameworkArduino\serialEvent2.cpp.o
Compiling .pio\build\teensy40\FrameworkArduino\serialEvent3.cpp.o
Compiling .pio\build\teensy40\FrameworkArduino\serialEvent4.cpp.o
src\main.cpp:7:10: fatal error: LiquidCrystal_I2Cw2.h: No such file or directory

*****************************************************************************
* Looking for LiquidCrystal_I2Cw2.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:LiquidCrystal_I2Cw2.h"
* Web  > https://registry.platformio.org/search?q=header:LiquidCrystal_I2Cw2.h
*
*****************************************************************************

    7 | #include <LiquidCrystal_I2Cw2.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~
Compiling .pio\build\teensy40\FrameworkArduino\serialEvent5.cpp.o
compilation terminated.
Compiling .pio\build\teensy40\FrameworkArduino\serialEvent6.cpp.o
Compiling .pio\build\teensy40\FrameworkArduino\serialEvent7.cpp.o
*** [.pio\build\teensy40\src\main.cpp.o] Error 1
============================================================== [FAILED] Took 1.02 seconds ==============================================================

 *  The terminal process "C:\Users\ordic\.platformio\penv\Scripts\platformio.exe 'run'" terminated with exit code: 1.
 *  Terminal will be reused by tasks, press any key to close it.

So after these bad news, I will read your feedback with pleasure, and I am going to try to unsolder the backboard...
 
Consequently I see 2 possibilities:
a-.The LCD display is dead.
b-.The I2C->// backboard, soldered behind the LCD does not work, or is not soldered as it should, despite the pins numbering matching with the LCD.

Agree, it's really looking like your display hardware isn't working.

One more possibility to add, maybe the contrast adjust pot on the back board is mis-adjusted so far that nothing can show in the display?
 
Agree, it's really looking like your display hardware isn't working.
I order another LCD and will use the same backboard than you.

There are 2 variants of LCD: 3V3 or 5V. I assume that the power supply of the LCD must be 3V3 or 5V respectively.
But what about SDA and SCL : is it possible to have SDA-SCL connected to 3V3 with a 5V LCD ?

Do you understand why the program does not compile and reports an error both in PlatformIO and Arduino 1.8.19 ??
 
I order another LCD and will use the same backboard than you.

There are 2 variants of LCD: 3V3 or 5V. I assume that the power supply of the LCD must be 3V3 or 5V respectively.
But what about SDA and SCL : is it possible to have SDA-SCL connected to 3V3 with a 5V LCD ?

Do you understand why the program does not compile and reports an error both in PlatformIO and Arduino 1.8.19 ??
As Paul mentioned if you have LiquidCrystal_I2Cw2.h in the "Libraries" directory use #include <LiquidCrystal_I2Cw2.h> else if it's in the same directory as your program use #include "LiquidCrystal_I2Cw2.h".
If you want the ultimate guarantee use #include "C:\Location of library\LiquidCrystal_I2Cw2.h".
 
As Paul mentioned if you have LiquidCrystal_I2Cw2.h in the "Libraries" directory use #include <LiquidCrystal_I2Cw2.h> else if it's in the same directory as your program use #include "LiquidCrystal_I2Cw2.h".
This fixed the problem on Arduino 1.8.19, but still doesn't work under PlatformIO, here is the compilation report:
Code:
Executing task in folder I2C_T4_Helloworld_wire2: C:\Users\ordic\.platformio\penv\Scripts\platformio.exe run

Processing teensy40 (platform: teensy; board: teensy40; framework: arduino)
--------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/teensy/teensy40.html
PLATFORM: Teensy (5.0.0) > Teensy 4.0
HARDWARE: IMXRT1062 600MHz, 512KB RAM, 1.94MB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES:
 - framework-arduinoteensy @ 1.159.0 (1.59)
 - tool-teensy @ 1.159.0 (1.59)
 - toolchain-gccarmnoneeabi-teensy @ 1.110301.0 (11.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 92 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Wire @ 1.0
Building in release mode
Compiling .pio\build\teensy40\src\main.cpp.o
Compiling .pio\build\teensy40\FrameworkArduino\sm_pool.c.o
src\main.cpp:7:10: fatal error: LiquidCrystal_I2Cw2.h: No such file or directory

*****************************************************************************
* Looking for LiquidCrystal_I2Cw2.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:LiquidCrystal_I2Cw2.h"
* Web  > https://registry.platformio.org/search?q=header:LiquidCrystal_I2Cw2.h
*
*****************************************************************************

    7 | #include <LiquidCrystal_I2Cw2.h>
      |          ^~~~Compiling .pio\build\teensy40\FrameworkArduino\sm_realloc.c.o
~~~~~~~~~~~~~~~~~~~
compilation terminated.
Compiling .pio\build\teensy40\FrameworkArduino\sm_realloc_i.c.o
Compiling .pio\build\teensy40\FrameworkArduino\sm_realloc_move.c.o
Compiling .pio\build\teensy40\FrameworkArduino\sm_szalloc.c.o
*** [.pio\build\teensy40\src\main.cpp.o] Error 1
============================================================== [FAILED] Took 0.69 seconds ==============================================================

 *  The terminal process "C:\Users\ordic\.platformio\penv\Scripts\platformio.exe 'run'" terminated with exit code: 1.
 *  Terminal will be reused by tasks, press any key to close it.

The librairies are both in the "lib" folder of the project:
07.compil error on HelloWorld.jpg


and here is the PlatformIO program:
Code:
#include <Arduino.h>

//www.buydisplay.com
//Compatible with the Arduino IDE 1.6.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2Cw2.h>

LiquidCrystal_I2Cw2 lcd(0x27,24,2);  // set the LCD address to 0x27(PCF8574T)

void setup()
{
  lcd.init();                      // initialize the lcd
 
  // Print a message to the LCD.
  lcd.backlight();
  lcd.print("Hello, world!");
}

void loop()
{
}
/*
// put function declarations here:
int myFunction(int, int);

void setup() {
  // put your setup code here, to run once:
  int result = myFunction(2, 3);
}

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

// put function definitions here:
int myFunction(int x, int y) {
  return x + y;
}
  */

Maybe I do something wrong with PlatformIO ?

By the way, do you know the answer to my previous question: "But what about SDA and SCL : is it possible to have SDA-SCL connected to 3V3 with a 5V LCD ?", because I am about to order a new LCD...

Thank you very very much,
 
By the way, do you know the answer to my previous question: "But what about SDA and SCL : is it possible to have SDA-SCL connected to 3V3 with a 5V LCD ?", because I am about to order a new LCD...
It would depend upon the circuit of the LCD.

I am not familiar with PlatformIO but you program still has #include <LiquidCrystal_I2Cw2.h> and potentially not #include "LiquidCrystal_I2Cw2.h".

PlatformIO is complaining that it cannot find LiquidCrystal_I2Cw2.h.
 
Also want to repeat my suggestion to use the known-good software setup from msg #19 and msg #26 until you have the hardware working. Thanks to @BriComp for preparing those 3 files.

Trying to resolve a hardware problem using software that's also unknown to work makes everything more than twice as hard.

I bought that display from Amazon and took several photos as I used it to give you (and everyone else using this type of display who later find this conversation) as much "known quantity" as possible.
 
Last edited:
Nounours, as suggested, try to play with the contrast potentiometer, even without any software running.
I would like but, sorry, I see no potentiometer on the back ? where is it located ?
I am not familiar with PlatformIO but you program still has #include <LiquidCrystal_I2Cw2.h> and potentially not #include "LiquidCrystal_I2Cw2.h".

PlatformIO is complaining that it cannot find LiquidCrystal_I2Cw2.h.
I also tried it, and the result is the same:
08.compil error on HelloWorld with quotes.jpg


Also want to repeat my suggestion to use the known-good software setup from msg #19 and msg #26 until you have the hardware working. Thanks to @BriComp for preparing those 3 files.
Of course I agree, but it seems to me that it is what I have done : I have copy/paste the "LiquidCrystal_I2Cw2.h" and "LiquidCrystal_I2C_Wire2.cpp" (put them in the "lib" folder of PlatformIO project) as well as the "Helloworld.ino" program: did I forget something ? (in the worst case I can continue with Arduino 1.8.19 until we find a solution with PlatformIO, this is not a pb).

The test we have performed was without any SDA&SCL connections, so the program should not matter .

I am sorry to not understand what you suggest me to do ?

P.S.: I have ordered a new LCD in case we do not find a solution with this one.
 
I am sorry to not understand what you suggest me to do ?

Just to repeat, power the display with 5V power and leave the SDA and SCL pins unconnected. Turn the pot while watching the display. The pot will probably be able to turn about 240 to 270 degrees. Don't apply too much torque, as these tiny pots are not strong and yours is on the cheapest of these Aliexpress products!

You're watching for all the pixels to appear on all or some of characters in the first line, like the photo I showed in msg #25.

Repeat this test with 3.3V power. Please let us know the result?

lcd9.jpg


And just to repeat yet again, if you do more tests involving software, please use Arduino IDE exactly as I demonstrated in msg #26. Stop making everything more complicated and difficult with PlatformIO. Only go back to PlatformIO after you have the hardware confirmed working with Arduino IDE and the known-good way shown in msg #26 using the code @BriComp gave in msg #19. We really are trying to help give you a way to eliminate the uncertainty on the software side. Please, use the known-good code with Arduino IDE.
 
Last edited:
Thank you Paul, I apologize for my poor understanding...
I have located the pot on the backboard, and do the tests you suggest.

Starting with the LCD powered with 5V and SDA-SCL not connected, the LCD did not show anything (like previously),
but by adjusting the potentiometer, it displayed the digits ! (y), as shown on the photoherebelow:
09.LCD 5V with pot adjust_s_b.jpg


Then I did not touch the potentiometer, have left SDA-SCL unplugged, but this time the LCD did not display anything:
10.LCD 3V3 with pot adjust_s_b.jpg


So this let me thing that the LCD is a 5V version, not a 3V3 version as it is supposed to be : do you agree ?

I suppose that the next step is to test the "Helloworld" program using Arduino 1.8.19 ? (no problem to stop using PlatformIO until we have definitely sort out this).

Thank you very much for your reply and for your time,
 
Good, at least now you can be certain the Aliexpress vendor sent the model which needs 5V power.

With the contrast pot, please understand it can be turned too far. If it is too much, you will always see all pixels on, even when text should be shown. On the power only test, usually the correct position is when you just barely start to the see all the pixels on 1 line.

Next step is to run the code from @BriComp in msg #19 in Arduino IDE as shown in msg #26. Hopefully you will see "Hello, World" on the display (probably up side down if the display is oriented at these photos).

If you see all pixels on both lines, not just 1 line as with power only, that is a sure sign the contrast adjust is turned too far.
 
Success !
With:
-5V P.S.,
-the pot adjustment (I have not changed its position since my msg #45),
-the library provided by Bricomp at line #19,
-SDA&SCL connected to wire2,
-the 4k7 pull-up resistors connected to 3V3 (important because my MB is designed to connect SDA&SCL to 3V3, not 5V, although it could be changed):

it seems to work (even with a3V3 SDA&SCL on a 5V LCD):
11.Success with Arduino IDE_s_b.jpg


I have not yet tried to print anything on the 2nd line but it should be OK.

3 weeks to get the I2C working whereas I have been using it for years, this is my absolute record: a serious candidate for the Guiness Book !!...
;)

I want to thank all of you for your time and effort !
Now I can restart to work on my main program that will use this I2C communication (but I have first to translate it on Arduino IDE, as I don't understand why PlatformIO reports an "error 1").

I will maybe open another topic for my main program, that is of course much more touchy than this "HelloWorld"...

Thanks again !
 
Last edited:
Back
Top