Go Down

Topic: Trouble initializing i2c display (Read 4488 times) previous topic - next topic

xl15

I've made a display for my home made car to display temperatures, pressure, fuel level etc.
It works sometimes, but most of the time the display isn't initialized.
It is a large 4x20 LCD with i2c interface.
The strange thing is that if I have my laptop connected to the Arduino and upload the program again or open serial monitor, the display starts working every time.
But if I trigger a reset with the button on the Arduino it doesn't help.
Why is the reset triggered by serial monitor different from the button on the board?

The power supply is not the problem. It works with a 5 V, 500 mA USB power supply. And in the car it gets its power from a 7 V, 2 A supply.

Code: [Select]

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "RTClib.h"
#include "Adafruit_MAX31855.h"
#include <math.h>
#include <DallasTemperature.h>
#include <OneWire.h>

#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress waterThermometer = { 0x28, 0x42, 0x4F, 0x4C, 0x05, 0x00, 0x00, 0x44 };
DeviceAddress oilThermometer = { 0x28, 0x08, 0x89, 0x4C, 0x05, 0x00, 0x00, 0x40 };
RTC_DS1307 rtc;
Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO);
LiquidCrystal_I2C lcd(0x27 , 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
//SDA = A4
//SCL = A5

void setup() 
{
  Serial.begin(9600); 
  Wire.begin();        // join i2c bus
  rtc.begin();
  lcd.begin(20,4);   
  sensors.begin();

  lcd.noBacklight();
  delay(250);
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("Initializing...");
  delay(500);
  lcd.clear();
  delay(500);
}

void loop()   
{}


Bonus picture of display and car :)




Peter_n

#1
Aug 12, 2014, 03:03 pm Last Edit: Aug 12, 2014, 03:08 pm by Peter_n Reason: 1
I see a ribbon cable with 4 wires going to the display. Can seperate all those wires ? The SDA and SCL don't like it to be that close.

A reset via the serial monitor, or a reset via the button is the same. I think there might something else that has influence.

Can you add a delay after Wire.begin() and before you start using the I2C bus. For example 100ms should be enough, so make it 500ms.

What about pullup-resistors for the SDA and SCL ? For testing about 10k is okay, but in a noisy environment it should be 4k7 or a little less. The display and the sensors might already have pullup resistors, you have to calculate the resulting pullup impedance.

Is your MAX31855 compatible with a 5V Arduino ? It is the only device using the SPI ?

Suggestion : You could try a OLED display. That LCD display will always look cheap, but you can make a OLED display look awesome. But I don't know if they can be that big....

econjack

I haven't used the LiquidCrystal_I2C library, but the constructor call looks weird:

Code: [Select]

LiquidCrystal_I2C lcd(0x27 , 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address


For most Arduino boards, pins 0, 1 are used by the Serial object and pins 2,3 are for external interrupts. In most examples I've seen for I2C use, the constructor is:

Code: [Select]

LiquidCrystal_I2C lcd(0x27 , 16, 4);  // Set the LCD I2C address


which sets the slave/master address and the column/row count. Have you tried the simpler constructor?

xl15

I will add the delay and try.

The ribbon cable is from the testing. Now it is about 50 cm of round cable with 6 conductors, but I guess the problem is the same.

I'm using 4,7 k pullup resistors. Dont know if the display have internal too.

I aslo have a slave arduino communicating over i2c, can that affect things? I don't think so since that is after the display initialization. That communication works great by the way, and it is with 2 meter of the same cable (6 conductors)

The MAX31855 controller works with 5 V:
http://www.adafruit.com/products/269

The display matches my Arduino speedometer ;)


xl15

@econjack
I think the
Code: [Select]

LiquidCrystal_I2C lcd(0x27 , 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

is for the i2c to HD44780 converter and has nothing to do with the arduino itself.
The rows and columns are set with
Code: [Select]

lcd.begin(20,4);   

Peter_n

With a good cable (that has less coupling between SDA and SCL) you can get 2 meters with I2C.
With just a bunch of loose wires you can get more. If I remember it right, someone could do 5 meters with slow I2C. But I would not even try that. I think your cables are one of the problems.

An Arduino as i2c slave is only active when it has been addressed. But the 2 meters cable to the slave will hurt the whole I2C bus.
You might use the i2c slave in a way that it starts sending data to the master. That could destroy the I2C communication.
When you use the slave only as slave, with onRequest and onReceive, it is slower, but no chance for collision.

You can try lowering the I2C speed.

xl15

It's been a while, but now I'm back to troubleshooting this problem.

Even with just 20 cm cable and nothing else on the i2c bus, the problem is the same.

It doesn't work standalone, but if I connect my laptop and open serial monitor it works every time.

I tried a different arduino and a bare minimum progam, still the same.

I'm confused and starting to wonder i the i2c adapter is broken.

xl15

Standalone



Connected to laptop and serial monitor opened

aarg

You say the power supply is not the problem. But I think you should double check.
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

xl15

I'll do that. The external power supply is an ordinary switched module (cheap ebay LM2596) set to 7 V and connected to Vin.

The external power is connected when I get it to work with the "serial monitor trigger". I can then disconnect the laptop and it keeps on working fine.

I tried resetting the board with the button while connected to the laptop, thinking that the applied USB power should help. But it didn't.

aarg

What happens if you remove
Code: [Select]
  Serial.begin(9600); 
:)
I know it's kind of a random move, but...
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

xl15

That's a good question. I'll try that when I get home.

xl15

Still not working :)
Powered only from laptop, USB charger or powerbank (battery powered USB charger), no change.

Removed "Serial.begin(9600);"
No change. Doesn't work when powered on, but with serial monitor opened it works. No serial communication though :)

I added a lot of deleys just becouse

Code: [Select]
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27 , 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

void setup()  
{
  delay(1000);
  Serial.begin(9600);  
  delay(1000);
  Wire.begin();        
  delay(1000);
  lcd.begin(20,4);  
  lcd.noBacklight();
  delay(250);
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("Initializing...");
  delay(1000);
  lcd.clear();

}

aarg

Doesn't work when powered on, but with serial monitor opened it works. No serial communication though :)
You mean, it doesn't work when first powered on through the USB? But when you open the monitor window it does? Just to be clear.
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

xl15


Go Up