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

Thread: I2C lcd display with teensy3

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    15

    I2C lcd display with teensy3

    I've got an I2C lcd display and I followed a tutorial written for Arduino. It seemed to me that to adapt it to teensy3 I did not need to change any code (shown below), but use pins 18 and 19 to drive lcd. Nothing happens. I see that the lcd is lit and the bottom row of the display shows white squares, but no messages were shown. The tutorial provides a link to download LiquidCrystal_I2C library and it has an object file. Now that I think of this, I guess, the library needs to be compiled for teensy, or is the object file board independent? Any suggestions? And if this should be recompiled, how can I do it?
    Code:
    /* YourDuino.com Example Software Sketch
     LCD Display Blue/Yellow: I2C/TWI Interface
     terry@yourduino.com */
    
    /*-----( Import needed libraries )-----*/
    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>
    /*-----( Declare Constants )-----*/
    /*-----( Declare objects )-----*/
    LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27
    /*-----( Declare Variables )-----*/
    
    
    void setup()   /*----( SETUP: RUNS ONCE )----*/
    {
      Serial.begin(9600);
      lcd.init(); // initialize the lcd
      lcd.backlight();
      // Print a message to the LCD.
      lcd.setCursor(0, 0);
      lcd.print("2-Line DISPLAY");
      delay(1500);
      lcd.setCursor(0, 1);
      lcd.print("YourDuino: HI!");  
    }/*--(end setup )---*/
    
    
    void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
    {
      {
        // when characters arrive over the serial port...
        if (Serial.available()) {
          // wait a bit for the entire message to arrive
          delay(100);
          // clear the screen
          lcd.clear();
          // read all the available characters
          while (Serial.available() > 0) {
            // display each character to the LCD
            lcd.write(Serial.read());
          }
        }
      }
    
    }/* --(end main loop )-- */
    
    /*-----( Declare User-written Functions )-----*/
    
    
    /* ( THE END ) */
    Thanks.

  2. #2
    Member
    Join Date
    Dec 2012
    Location
    Adelaide, SA
    Posts
    70
    Do you have pullup resistors on your I2C (SCL, SDA) pins ?

    If not, you'll need to add them. 1.5k to 3.3V on the Teensy 3 works for me, but the value isn't that critical, within reason.

    - Peter

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    15
    Quote Originally Posted by ploveday View Post
    If not, you'll need to add them. 1.5k to 3.3V on the Teensy 3 works for me, but the value isn't that critical, within reason.
    Thanks Peter! I will try that. But why would I connect to 3.3V, instead of +5 on VCC? How do I get an easy access to 3.3V for pull up, other than setting one of the pins to that level and using that?

  4. #4
    Member
    Join Date
    Dec 2012
    Location
    Adelaide, SA
    Posts
    70
    Because the Teensy3 is not 5V tolerant. Don't connect 5V logic to its pins.

    Have a look at your reference card, there's a 3.3V out on the RHS, 3rd down, with the USB at the top.

    - Peter

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    15
    Quote Originally Posted by ploveday View Post
    Because the Teensy3 is not 5V tolerant. Don't connect 5V logic to its pins.
    Thanks for the explanation! Let's see if I understand. Even though I am using 18,19 pins as outputs, we still do not want 5V there, as a precaution? I am using this opportunity to learn more. Pull up resistors are used to drive value of the output to a known level when the actual output is in high-impedance state. So I assume it is lcd that requires pull up resistors.

    Quote Originally Posted by ploveday View Post
    Have a look at your reference card, there's a 3.3V out on the RHS, 3rd down, with the USB at the top.
    Got it, obviously having the reference card in front of my nose is not close enough for me

    Now, to the real issue. Pull-up resistors did not help. Nothing changed in the output. What can I use to debug? I guess I need to confirm that indeed I am sending something to the pins and if I do, then I will need to make sure that this is what lcd expects. I am not sure how to approach this though.

  6. #6
    Senior Member
    Join Date
    Nov 2012
    Location
    Boston, MA, USA
    Posts
    1,108
    Quote Originally Posted by sjcomp View Post
    Thanks for the explanation! Let's see if I understand. Even though I am using 18,19 pins as outputs, we still do not want 5V there, as a precaution? I am using this opportunity to learn more
    Teensy 3.0 uses 0 volts as low and 3.3 volts as high. Your I2C display board uses 0V as low and 5V as high. Don't connect them directly. Also, I2C requires pull-up resistors.

    I suggest using this 4-channel I2C-safe Bi-directional Logic Level Converter.

  7. #7
    Senior Member
    Join Date
    Nov 2012
    Location
    Salt Lake City, UT, USA
    Posts
    276
    This bit me on Teensy3 which by default does not have the pullups AVR does. Worse, the Wire library basically waits forever if it sees the I2C bus locked in a low state. Therefore if you try a Wire.write with no I2C pullups, execution hangs hard. On my TODO list is to change this Wire behavior.

  8. #8
    I would like to use SDA2 SCL2 at teensy 3.5 for i2c lcd . do i use wire2 ? which library or any sample code ?

  9. #9
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,535
    The i2c_t3 library will satisfy your needs.

  10. #10
    It is our test program for teensy 3.5 , it works with 2.2K pullups SDA-SCL to vin . How do work with SDA2-SCL2 ? do we add pull up resistors? To add library i2c_t3

    #include "i2c_t3.h"
    #include <Wire2.h>
    #include <LiquidCrystal_I2C.h>

    LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27
    void setup() /*----( SETUP: RUNS ONCE )----*/
    {
    Serial.begin(9600);
    lcd.init(); // initialize the lcd
    lcd.backlight();
    // Print a message to the LCD.
    lcd.setCursor(0, 0);
    lcd.print("2-Line DISPLAY");
    delay(1500);
    lcd.setCursor(0, 1);
    lcd.print("teensy test !");
    }/*--(end setup )---*/


    void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
    {
    {
    // when characters arrive over the serial port...
    if (Serial.available()) {
    // wait a bit for the entire message to arrive
    delay(100);
    // clear the screen
    lcd.clear();
    // read all the available characters
    while (Serial.available() > 0) {
    // display each character to the LCD
    lcd.write(Serial.read());
    }
    }
    }

    }/* --(end main loop )-- */

Posting Permissions

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