PDA

View Full Version : I2C lcd display with teensy3



sjcomp
01-21-2013, 02:48 AM
I've got an I2C lcd display (http://arduino-direct.com/sunshop/index.php?l=product_detail&p=170) and I followed a tutorial (http://arduino-info.wikispaces.com/LCD-Blue-I2C) 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 (http://arduino-info.wikispaces.com/file/view/LiquidCrystal_I2C1602V1.zip/341635514/LiquidCrystal_I2C1602V1.zip) 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?

/* 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.

ploveday
01-21-2013, 03:46 AM
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

sjcomp
01-21-2013, 04:07 AM
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?

ploveday
01-21-2013, 04:11 AM
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

sjcomp
01-21-2013, 05:02 PM
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.

Nantonos
01-21-2013, 06:45 PM
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 (http://www.adafruit.com/products/757).

bboyes
12-10-2013, 12:17 AM
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.

turnarobo
02-13-2018, 08:03 AM
I would like to use SDA2 SCL2 at teensy 3.5 for i2c lcd . do i use wire2 ? which library or any sample code ?

Theremingenieur
02-13-2018, 08:12 AM
The i2c_t3 library will satisfy your needs.

turnarobo
02-13-2018, 08:20 AM
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 )-- */