Two I2C 5v devices on a Teensy 3.5
Hi,
I'm new on the forum and in the Teensy Community. Let me apologize in advance for my poor english, I'm French.
I am trying to make an Arduino code work on a Teensy 3.5 and I've got troubles making I2C work. I think it's because my devices are 5V, so I'm very surprised to see you telling 5V devices can be connected to pin 18 (A4) and 19 (SCL) without level converter. I use two devices on the I2C network :
- A display : 20 columns x 4 lines with I2C converter included
- An analog to digital converter (used as voltmeter) : Adafruit ADS1115
My wiring is :
- On teensy 3.5 SDA0 : 4,7K resistor + SDA from screen + SDA from ADC converter
- On teensy 3.5 SCL0 : 4,7K resistor + SCL from screen + SCL from ADC converter
- Ground of every devices to ground
- +5v on : teensy Vin + screen vcc + ADC converter vdd + ADC chanel 0
When I try to use them both with this test program, there is no problem, everything works good :
Code:
#include <Adafruit_ADS1015.h>
#include <LiquidCrystal_I2C.h>
#define SERIAL_SPEED 115200
#define SCREEN_ADDRESS 0x27
#define NB_SCREEN_LINES 4
#define NB_SCREEN_COLUMNS 20
float VOLTMETER_RANGE = 6.144;
LiquidCrystal_I2C lcd(SCREEN_ADDRESS, NB_SCREEN_COLUMNS, NB_SCREEN_LINES);
Adafruit_ADS1115 voltmeter;
void setup() {
Serial.begin(SERIAL_SPEED);
Serial.println("Setting ADC...");
voltmeter.setGain(GAIN_TWOTHIRDS);
voltmeter.begin();
Serial.println("Setting screen...");
lcd.init();
lcd.backlight();
lcd.clear();
lcd.home();
lcd.print(F("Screen OK"));
delay(500);
}
byte line = 0;
void loop() {
line = (line == 0) ? 1 : 0;
lcd.clear();
lcd.setCursor(0, line);
lcd.print("Screen test");
int16_t voltmeter_U_B = voltmeter.readADC_SingleEnded(0); // Reading ADC chanel 0
float U_B = float(VOLTMETER_RANGE * voltmeter_U_B / pow(2, 15));
Serial.println(U_B);
delay(200);
}
So far, so good. But when I try it on a much bigger program without changing my wiring, it works like 20 seconds, and then there are unknown characters written on the screen, and then my teensy freezes.
What is very odd and surprising is that : when I take the screen out of the I2C network, the program is working well ! This make my think that it's a I2C problem…
If anybody could have a look on the code attached, it may probably help me a lot !
Note that this code was working well on an Arduino Mega, I just did some modifications to reach Teensy 3.5 requirements.
I tested my code on a Teensy++ 2.0 (also with some modifications to reach Teensy++ 2.0 requirements, especially with timers problems) and I've got the same problem of freezing.
View attachment cycle_battery.zip
I'm still trying to see a bug in my code, given that my test code seems not to have any issues.
Is it possible that it is not a problem with I2C but with anything else ?
I hope somebody can help me and I hope I am in the right section of the forum.