I2C for LCD errors with Longan CanBed RP2040

Looking for some help trying to get an LCD to work. I am using a Longan CanBed RP2040
http://docs.longan-labs.cc/1030018/ which calls for use of Wire1 and SDA pin 6, SCL Pin 7.

On this board I have pulled the LCD ID as 0x27, tried with an UNO and couldn't even see the LCD ID, but can see I2C ID's for a Motor Shield.

I tried to follow the Diagnostic suggestion from @bperrybap in this old thread Cannot detect LCD display with I2C - #2 by bperrybap
But I'm getting compile errors before I can even upload the code to a board.

WARNING: library Wire claims to run on rp2040 architecture(s) and may be incompatible with your current board which runs on longan-rp2040 architecture(s).
<command-line>: warning: ISO C++11 requires whitespace after the macro name
C:\Users\...\AppData\Local\Temp\.arduinoIDE-unsaved2023030-18196-1cak6qw.drgx\I2CexpDiag\I2CexpDiag.ino: In function 'void showSystemConfig()':
C:\Users\...\AppData\Local\Temp\.arduinoIDE-unsaved2023030-18196-1cak6qw.drgx\I2CexpDiag\I2CexpDiag.ino:1242:26: error: 'SDA' was not declared in this scope
 1242 |  printDigitalPin(Serial, SDA);
      |                          ^~~
C:\Users\...\AppData\Local\Temp\.arduinoIDE-unsaved2023030-18196-1cak6qw.drgx\I2CexpDiag\I2CexpDiag.ino:1245:26: error: 'SCL' was not declared in this scope; did you mean 'SCK'?
 1245 |  printDigitalPin(Serial, SCL);
      |                          ^~~
      |                          SCK
C:\Users\...\AppData\Local\Temp\.arduinoIDE-unsaved2023030-18196-1cak6qw.drgx\I2CexpDiag\I2CexpDiag.ino: In function 'int i2cpulluptest()':
C:\Users\...\AppData\Local\Temp\.arduinoIDE-unsaved2023030-18196-1cak6qw.drgx\I2CexpDiag\I2CexpDiag.ino:1344:27: error: 'SDA' was not declared in this scope
 1344 |     if ( (s = pullupOnPin(SDA)) )
      |                           ^~~
C:\Users\...\AppData\Local\Temp\.arduinoIDE-unsaved2023030-18196-1cak6qw.drgx\I2CexpDiag\I2CexpDiag.ino:1362:27: error: 'SCL' was not declared in this scope; did you mean 'SCK'?
 1362 |     if ( (s = pullupOnPin(SCL)) )
      |                           ^~~
      |                           SCK
C:\Users\...\AppData\Local\Temp\.arduinoIDE-unsaved2023030-18196-1cak6qw.drgx\I2CexpDiag\I2CexpDiag.ino:1385:19: error: 'SDA' was not declared in this scope
 1385 |   s = pinsShorted(SDA, SCL);
      |                   ^~~
C:\Users\...\AppData\Local\Temp\.arduinoIDE-unsaved2023030-18196-1cak6qw.drgx\I2CexpDiag\I2CexpDiag.ino:1385:24: error: 'SCL' was not declared in this scope; did you mean 'SCK'?
 1385 |   s = pinsShorted(SDA, SCL);
      |                        ^~~
      |                        SCK

exit status 1

Compilation error: 'SDA' was not declared in this scope

You could try adding the missing definitions

#define SDA 6
#define SCL 7

That's an improvement!

Obviously I'm just getting started learning this stuff.

********************************************************************
Serial Initialized
--------------------------------------------------------------------
I2CexpDiag - i2c LCD i/o expander backpack diagnostic tool
--------------------------------------------------------------------
hd44780 lib version: 1.3.2
--------------------------------------------------------------------
Reported Arduino Revision: 1.6.7
Arduino Board: RASPBERRY_PI_PICO
CPU ARCH: arm - F_CPU: 125000000
--------------------------------------------------------------------
SDA digital pin: 6
SCL digital pin: 7
--------------------------------------------------------------------
Checking for required external I2C pull-up on SDA - YES
Checking for required external I2C pull-up on SCL - YES
Checking for I2C pins shorted together - Not Shorted
--------------------------------------------------------------------
Scanning i2c bus for devices..
 i2c device found at address 0x27
Total I2C devices found: 1
--------------------------------------------------------------------
Scanning i2c bus for all lcd displays (4 max)
LCD 0 begin() failed: -1
No working LCD devices

These were Amazon purchased 4 row displays with I2C installed.

So looks like at least it is detecting an I2C device... and 0x27 is a typical address for an LCD.

Not sure what the diagnostic tool is showing when it can't detect an LCD. @bperrybap might be able to provide some help.

Have you had the LCD working with any other Arduino?

Is the RPi 5v or 3.3v logic level?

PS. Make sure you tag the responder in with @red_car for example... that way they get notified of your reply.

@red_car unfortunately this is the first time trying to get this setup. I attempted to us the LCD on an UNO, but that board didn't even recognize the address.

I'm currently running on 5V, with the LCD power direct from the breadboard power supply vs the controller Vout.

Hmmm.
I've not seen either the board or the i2c backpack/display before.
I've seen MANY different i2c backpacks over the years, but I've not ever seen that one.
Can you post a link to the LCD device & backpack you purchased?

The missing SDA and SCL are issues in the variant file of the Longan-Labs core platform.
I'll have to see if I can bug it with the developers to get that fixed.
This type of thing has been quite common through the years. In most cases the developers are very willing to fix it. I've only encountered 1 case where the developer has outright refused to fix the issue.

On the begin() failed message, it means that the diag tool was unable to successfully initialize the LCD device. i.e. begin() failed.
The -1 means an i/o error occured.
During that portion of initialization in the hd44780 library, that error will occur if the code is unable to identify the i2c chip as being a PCF8574 chip or a MCP23008 chip.
For some reason the auto configuration probing is not working on that device.

There is a way to manually configure things using constructor parameters but I'd like to figure out why the auto configuration probing is not working.

Is there any technical information available for the LCD device and backpack?

--- bill

@bperrybap here's the display.

This wasn't recognized at all by an older UNO, but my Longan CanBed RP2040 is what the current results are from. Their Tech support was helpful and responsive to sort out another issue I was having with my CANBus communications, as well as their Board driver not loading the most current version with IDE 2.0.3. They updated it right away and now works. So I assume they would be helpful.

I'm just getting started, so I don't know what I don't know yet, if it's just my coding problems or library bugs.

@bmwracer, how do you have this wired up?
The photo of the RP2040 board on the link you provided shows an i2c connector that uses 3v which means the board expects to use a 3v i2c bus.

If the LCD is not a 3v device you will need to use a level shifter to run the LCD device at 5v and connect it to the board's 3v i2c bus.
If you wire the LCD to 5v and directly connect it to the 3v i2c bus, problems will occur since you are now connecting a 3v i2c bus to a 5v i2c bus.
Best case, things are funky and don't work correctly.
Worst case is the rpi chip can be damaged since the 5v powered LCD is pulling up signals to 5v which is too high for 3v logic.

My suggestion would be wire up the LCD device to a 5v Arduino and lets make sure the hd44780 library can properly talk to that LCD device before tossing in a new core and board and 3v logic.

--- bill

The backpack you showed in the photo in post #4 is not the same as the one in the photos show on amazon for the GeeekPi IIC I2C TWI product.
The amazon backpack is one I've seen and familiar with.
The one in post #4, I've not seen before.
At a minimum it has an extra set of holes and a jumper.
Likely to allow using the backpack on LCDs that have the more compact header pins.
But that may not be the only differences between the boards.

The amazon page says the LCD is 5v only.
That means you will need to use a i2c level shifter to interface to a 3v i2c bus which is what the rpi has.

--- bill

@bperrybap Ok, so I tried the LCD on the UNO I have and it works. I think the difference from before is that I was powering and grounding the display via the Breadboard PS, this time I took those off the UNO. So I guess I need to look into the Voltage variance with my CanBed board.


I2C scanner. Scanning ...
Found address: 39 (0x27)
Done.
Found 1 device(s).

********************************************************************
Serial Initialized
--------------------------------------------------------------------
I2CexpDiag - i2c LCD i/o expander backpack diagnostic tool
--------------------------------------------------------------------
hd44780 lib version: 1.3.2
--------------------------------------------------------------------
Reported Arduino Revision: 1.6.7
CPU ARCH: AVR - F_CPU: 16000000
--------------------------------------------------------------------
SDA digital pin: 6
SCL digital pin: 7
--------------------------------------------------------------------
Checking for required external I2C pull-up on SDA - NO
Checking for required external I2C pull-up on SCL - NO
Checking for I2C pins shorted together - Not Shorted
********************************************************************
WARNING: I2C requires external pullups for proper operation
It may appear to work without them, but may be unreliable and slower
Do not be surprised if it fails to work correctly
Install external pullup resistors to ensure proper I2C operation
********************************************************************
--------------------------------------------------------------------
Scanning i2c bus for devices..
 i2c device found at address 0x27
Total I2C devices found: 1
--------------------------------------------------------------------
Scanning i2c bus for all lcd displays (4 max)
 LCD at address: 0x27 | config: P01245673H | R/W control: Yes
Total LCD devices found: 1
--------------------------------------------------------------------
LCD Display Memory Test
Display: 0
 Walking 1s data test:	PASSED
 Address line test:	PASSED
--------------------------------------------------------------------
Each working display should have its backlight on
and be displaying its #, address, and config information
If all pixels are on, or no pixels are showing, but backlight is on, try adjusting contrast pot
If backlight is off, wait for next test
--------------------------------------------------------------------
Blinking backlight test: to verify BL level autodetection
If backlight is mostly off but
you briefly see "BL Off" on display with backlight on,
then the library autodetected incorrect BL level
and the library cannot autoconfigure the device
--------------------------------------------------------------------
Displaying 'uptime' on all displays
--------------------------------------------------------------------

You'll definitely need a common ground between the components that are trying to talk to each other.

LCD at address: 0x27 | config: P01245673H | R/W control: Yes

This information can be used to manually configure the library for the LCD device if there is an auto configuration issue.
However, since it is working on the AVR platform, the library can identify and talk to this LCD device and should be capable of doing so on the rpi board as well.

I recommend using a level shifter to connect the 5v LCD device to the 3v rpi board. It is the proper way to interface a 3v master to 5v slaves.

While I would not recommend it, there is a way to cheat that might work.
You could remove the pullups off the LCD backpack.
You have to probe the backpack to figure out which 2 resistors to remove.
This will keep the bus signals at 3v since the rpi has 3v pullups on it.
It also means that the PCF8574 will be 5v and expect to "see" 5v logic levels.
Even though this is out of spec, it often, will work as the 3v bus high signals created by the pullups are usually high enough to be seen as a high by the 5v PCF8574. That said, I have seen cases where it doesn't work at all.
Removing the two pullup resistors from the backpack can be tricky since they are surface mount parts. Sometimes you can just tear them off the PCB using pliers.

Have I ever done this? Yes, but I would only use this out of spec kludge for limited testing as it may not be reliable under various voltage and temperature ranges or even certain chips since it is running things out of spec.

I always use a level shifter when interfacing the 3v boards to the 5v LCDs.

--- bill

The errors you got in the diag on the uno are because of the SDA an SCL defines that were added to the sketch. The diag sketch code was testing the incorrect i2c pins but the hd44780 library was using the Wire library which used the correct i2c pins.

--- bill

@bperrybap thanks for the great info. This all makes sense. I jumped in not realizing the voltage difference, just expecting all the components would be the same. I service Lab Automation, but don't get down to this level. All our stuff is usually 5, 12, or 24V. Sensor, boards, motors.

I used to be able to swap surface mount parts, but not sure if I can see well enough anymore for that!

Not sure I'll be using the display in my final project, but this will be ending up in a Racecar steering wheel for a ButtonBox and possibly another for an LED controller, so I was kinda planning the LCD for CanBus signal monitoring during development/troubleshooting.

I use these:

You hook 5v to VIN, and leave 3v not connected.
Then hook the 3v i2c signals to the 3v side and the 5v signals to the 5v side.
The 3v signal on that board is an output.
The 3v signal on the board can be used when connecting a 5v master to 3v slaves to provide the 3v power.
In your case with a 3v master it won't be used.

--- bill

1 Like

I know that your backpack was detected on address 27 Hexadecimal. But I've got the same backpack and mine is on 3F Hexadecimal. Dunno if that'll help (probably not, sorry).

A quirk of the 20 x 4 character screen that I have (recently from Aliexpress): the 2nd and 4th line are "continued" from line 1 and 3. That is, it is a screen that in software thinks it's 40 x 2 but the 2 lines of 40 chars are in fact physically "chopped" in half. The first half is on line 1 and the second half on line 3 etc.

Good luck puzzeling!

@bperrybap everything works fine on my Uno, but still not able to get it working on the Longan board. I tried using these boards (ordered before you posted). I'm either totally missing something with my connections (most likely) or it the other components just don't like it.

Thread says it is solved. Has this been resolved? i.e. it is now working?

If not, are you using a level shifter?
How do you have everything wired up with the level shifter?
Can you show a wiring diagram and some photos?

--- bill

@bperrybap I'm coming back to this finally after some time away.

I marked it solved prematurely. First, I was able to get it working with a 5V UNO and I'm able to write to the display, etc.

However, I still cannot get the 3V board to work, which is what I ultimately want to do. I've tried a couple different ways to wire it with the Level shifter, but the only change I get is if I see the I2C or not, but it never sees the display. This is how I have it wired so it will recognize I2C, anything else either doesn't power the display or doesn't recognize I2C.