I2C lcd display with teensy3

Status
Not open for further replies.

sjcomp

Member
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.
 
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
 
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?
 
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
 
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.

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.
 
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.
 
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.
 
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 )-- */
 
Status
Not open for further replies.
Back
Top