Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 15 of 15

Thread: Teensy 4.1 vs. LiquidCrystal_I2C

  1. #1
    Junior Member
    Join Date
    Sep 2020
    Posts
    7

    Teensy 4.1 vs. LiquidCrystal_I2C

    Howdy,

    I am having a perplexing issue where I can get an I2C LCD to partially work with my Teensy 4.1 with LiquidCrystal_I2C. The LCD has an I2C 'backpack' board which is connected to 3.3V, GND, and SDA & SCL (pins 18 & 19) on the Teensy. The LCD responds to lcd.setBacklight(); but not to lcd.print()

    Here is my code:

    Code:
    #include <LiquidCrystal_I2C.h>
    LiquidCrystal_I2C lcd(0x27, 8, 2);
    
    void setup() {
      lcd.init();
      lcd.backlight();
      lcd.setCursor(0, 0);
      lcd.print("setup");
    }
    
    void loop() {
      lcd.setBacklight(1);
      delay(1000);
      lcd.setBacklight(0);
      delay(1000);
      lcd.print("loop");
    }
    What is weirding me out is that the LCD backlight blinks as expected, it just doesn't want to print. So I assume I2C is working or at least mostly working...

    I have tried (to no effect):
    • two different I2C LCD modules (a 16x2 and 8x2). Both modules work with Arduino Uno so it's not LCD contrast or faulty LCDs.
    • adding 2.2k ohm pullup resistors on SDA & SCL (pins 18 & 19) to 3.3V However, the LCD's I2C backpack datasheet listed it as 3.3V compatible (in addition to 5V) without indicating pullup resistors are required.
    • I tried one or two alternative LCD libraries with no luck (don't remember which ones, should've written it down)


    Any suggestions?

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,030
    Please be specific about which hardware you're using, as many products on the market fit this description.

    Also tell us exactly which LiquidCrystal_I2C.h you are using. There are at least 2 with the same name.

    Photos of how you've actually connected the hardware might also help. Sometimes these things end up being just a misunderstanding about wiring which we can only see if we have photos to actually see the wiring.

  3. #3
    Junior Member
    Join Date
    Sep 2020
    Posts
    7
    Thanks Paul!

    I'm using John Rickman's LiquidCrystal_I2C library intended for DFRobot I2C LCD displays: https://github.com/johnrickman/LiquidCrystal_I2C

    The 16x2 I2C LCD I test with is an HD44780 which looks to be a knockoff of the DFRobot DFR0063
    The other 8x2 I2C LCD is an ERM802SYG-3-504 from EastRising/BuyDisplay

    Here's my connections (when testing the MicroUSB is connected to USB power)
    Click image for larger version. 

Name:	IMG_3494.jpg 
Views:	17 
Size:	178.0 KB 
ID:	21598

    and here's the backs of the LCDs:
    Click image for larger version. 

Name:	IMG_7235.jpg 
Views:	15 
Size:	177.3 KB 
ID:	21599

    I should also mention I also verififed the I2C address of 0x27 is correct; I used a library to list connected I2C addresses and 0x27 shows up when the LCD is connected correctly (by correctly I mean when the backlight blinks on/off with the code)

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,030
    Looks like you have the wires on pins 16 & 17. But that library uses Wire, not Wire1, so you need to use pins 18 & 19.

    Or you could edit the library code to replace all "Wire" with "Wire1" if you *really* want to use those pins... but just moving the wires to pin 18 & 19 is easier.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,030
    Also looks like SDA & SCL might be backwards. Hard to tell for sure since the wires are both yellow. But looks like the wire on pin 17 (SDA1) goes to the pin farthest from GND on the display, which is labeled as SCL in the other photo.

  6. #6
    Junior Member
    Join Date
    Sep 2020
    Posts
    7
    I'm using pins 19 (SCL) and 18 (SDA) and have them wired up correspondingly (I Sharpie'd a black stripe on the SCL wire to make sure) and have tried reversing them and have also tried using the SDA1/SCL1 pins 16 & 17; with any of these combinations the LCD backlight no longer blinks, nor do I get the text to print.

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,030
    You definitely need pins 18 & 19.

    Try running File > Examples > Wire > Scanner to confirm if the wires really are connected correctly. It will also give you the I2C address, which might not necessarily be 0x27.

  8. #8
    Junior Member
    Join Date
    Sep 2020
    Posts
    7
    Scanner says:
    Code:
    Scanning...
    Device found at address 0x27  (MCP23017,MCP23008,PCF8574,LCD16x2,DigoleDisplay)
    done

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,030
    That's a good sign. At least you know you've got SDA & SCL connected properly now, and the I2C address is good.

    Any chance this particular display wants one of the other LiquidCrystal_I2C libraries?

  10. #10
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,881
    Back when I used those displays, some of the displays I had would only run if feed 5v of power and not 3.3v. There are some boards that do a proper bi-directional level shift for I2C, but with shipping, etc. it may be cheaper to get a display that runs on 3.3v.

    For example, if you have a Microcenter nearby, you might be able to get this voltage shifter:


    Back when I still used those devices, I tended to like this shifter over the Adafruit and Sparkfun devices, but with shipping and handling being more than the shifter, it tends to only make sense if you are ordering multiple things:


    In terms of displays for USA delivery from ebay, many of the 16x2 displays listed seem to say 5v needed. The 128x32 and 128x64 OLED displays tend to work well. These are graphic mono displays, so they aren't limited to just 2 lines of text, but you would have to switch libraries:


    Note, I haven't used these exact displays, but in the past I did use similar displays.

  11. #11
    Senior Member
    Join Date
    Dec 2015
    Location
    LA
    Posts
    191
    Haven't tried those particular displays, but have had similar startup issues with others using serial data and long wires. The solution was to add a delay(100) before the lcd.init().

    The print statements in your main loop will scroll off the right and print nothing without a setCurser(0,0) ?

  12. #12
    Junior Member
    Join Date
    Sep 2020
    Posts
    7
    I tried out the following:



    No luck With the alternate libraries I continue to be able to control the backlight via I2C but unable to print.

    I have ordered a couple of bidirectional 5V to 3.3V logic level converters... so we'll see when they get here.
    Last edited by zachSounds; 09-03-2020 at 04:31 PM. Reason: formatting mistake!

  13. #13
    Junior Member
    Join Date
    Sep 2020
    Posts
    7
    Welp, tried a couple more things:
    • Modified Wire.write() to also do Serial.println() so I could verify both the Arduino and Teensy are issuing the same I2C codes (they are)
    • per a suggestion I found on Reddit I tried removing the jumper for the LCD backlight to provide more power to the rest of the LCD; no dice

    And then I found this element14 blog post which pointed out that the empty U3 SOIC-8 pad on both LCDs is for an ICL7660 voltage converter; I'm pretty sure this is how you use the board for 3.3V. From the specsheet for the LCD I most recently bought it includes instructions for both 5V and 3.3V operation and digging more into the product page it seems like they're actually separate products; one with the ICL7660 preinstalled (for 3.3V operation) and the other without (for 5V operation). If my Chinese were better I probably would've been able to see that much more quickly!

    So my assumption right now is that on 3.3V the LCD is barely able to receive a single byte message from the Teensy to turn on the backlight, but when it comes time to print letters on the screen (which require 6 bytes and I assume fire off in rapid sequence) the LCD isn't able to keep up.

    I'll try the logic level converters when they get here and report back for completeness and posterity... but I'm feeling pretty optimistic now that that'll resolve the issue.

  14. #14
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,030
    I'd try disconnecting the SDA & SCL wires and power the display with 5V. Then measure the voltage on its SDA and SCL pins. It will probably be 5V if the display has pullup resistors.

    Then I'd try a 1K resistor between SDA and 3.3V. Worst case, that will feed 1.7mA into the 3.3V supply, which is safe since Teensy uses more than 1.7mA on 3.3V power. But a far more likely case is you'll get some voltage like 3.5V. The actual voltage will depend on whatever resistors are on that display. If you measure 3.6V or less, then it should be safe to connect to Teensy. Just make sure than 1K resistor stays in place, so the pulled-up voltage is 3.6V or less.

    Of course using a level shifter is best. But a couple 1K resistors will probably do, if the resistors on that display are 10K or higher.

  15. #15
    Junior Member
    Join Date
    Sep 2020
    Posts
    7
    I received the level shifter and guess what: it works! Using the level shifter I'm able to work with both of my LCD modules, able to print() and everything else too.

    Thanks again for the help everyone!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •