Go Down

Topic: When i2c connected the project does not work (Read 565 times) previous topic - next topic


May 31, 2019, 02:19 pm Last Edit: May 31, 2019, 02:21 pm by mlindeloef

I have a project that did work fine yesterday and running over night.

Today I just uploaded a codce to scan for my new OneWire-sensor. And then uploaded the old code again and now it does not work.

I use a 20x4 LCD with a I2C backpack.

When I restart the Arduino Uno now I have nothing in the serial monitor or on  my display. If I disconnect tie I2C-wires at A4 and A5 it works fine (I have information on the serial monitor but of course not on the display). Also If I comment away the "lcd.begin (20,4); // for 16 x 2 LCD module" line is the same thing. But as soon as I connect it. There is no printing on the display or the serial monitor.

I have a potentiometer to adjust the temperature and this has no reaction at all when I2C is connected. When disconnecting the i2c cables the potentiometer functions.

Any ideas? Like I said this code worked since yesterday without a problem. Can it be that the 5vdc supply is not enough or something like that?

Here is the i2c backpack:

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

LiquidCrystal_I2C  lcd(0x27,2,1,0,4,5,6,7); // 0x27 is the I2C bus address for an unmodified backpack

const int heater = 2;
const int circulation = 3;
const int drain = 4;

int potPin = 1;
int tempPot = 0;
int presetTemp = 0;
float startTemp;

#define ONE_WIRE_BUS 10
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress airTemp = { 0x28, 0xFF, 0x62, 0x89, 0x53, 0x15, 0x01, 0x42 };
DeviceAddress waterTemp = { 0x28, 0xFF, 0x62, 0x89, 0x53, 0x15, 0x01, 0x42 };

void setup()
  pinMode(heater, OUTPUT);
  pinMode(circulation, OUTPUT);
  pinMode(drain, OUTPUT);

  sensors.setResolution(airTemp, 10);
  sensors.setResolution(waterTemp, 10);

  digitalWrite(heater, HIGH);
  digitalWrite(drain, HIGH);

   lcd.begin (20,4); // for 16 x 2 LCD module


void printTemperature(DeviceAddress deviceAddress)
 float tempC = sensors.getTempC(deviceAddress);
 Serial.print("Temp C: ");

void loop()

//Serial.print("Lufttemperaturen ar: ");
Serial.print("Vattentemperaturen ar: ");

tempPot = analogRead(potPin);
presetTemp = map(tempPot, 0, 1023, 10, 42);
Serial.print("Installd temp ar:");
float airTemperature;
float waterTemperature;
airTemperature = sensors.getTempC(airTemp);
waterTemperature = sensors.getTempC(waterTemp);

startTemp = presetTemp-0.5;

if (waterTemperature <= startTemp){
  digitalWrite(heater, LOW);
if (waterTemperature > presetTemp) {
  digitalWrite(heater, HIGH);
  lcd.home ();
  lcd.print("Vatten  :");
  lcd.setCursor (10,0);
  lcd.setCursor (15,0);
  lcd.setCursor (16,0);
  lcd.setCursor (0,1);
  lcd.print("Luft    :");
  //lcd.setCursor (10,1);
  lcd.setCursor (15,1);
  lcd.setCursor (16,1);
  lcd.setCursor (0,2);
  lcd.print("Inst llt:");
  lcd.setCursor (4,2);
  lcd.setCursor (10,2);
  lcd.setCursor (15,2);
  lcd.setCursor (16,2);



seems to be an electrical problem. I don't know your LCD specs, but I would check the voltages.
try to find a shortcircuit somewhere.
Symptom: with A5-A4 not connected analog and serial work together. check the LCD pinout again... or change the LCD.check the backlight pin.


This is a very confused post.  :smiley-eek:

Without a properly taken picture - in full daylight (unless you have a properly lit photographic studio; photos taken with a mobile phone in semi-darkness are pretty useless) - of all parts, we may never know what is happening.

Amongst other things, I cannot see how trying to take an analog reading of "potPin" as pin 1 which is the serial output pin - can actually "work"!


Jun 01, 2019, 08:20 am Last Edit: Jun 01, 2019, 08:23 am by bperrybap
Amongst other things, I cannot see how trying to take an analog reading of "potPin" as pin 1 which is the serial output pin - can actually "work"!
Because that is not what is happening. Using 1 is the same as using A1 - for analogRead() but NOT for analogWrite()
You have to go back many years and dive into the code to see why.
The "pin" argument to analogRead(pin) is not really an Arduino digital pin number.
Originally it was an analog channel number.
The code still internally uses an analog channel number but also now allows using an Arduino digital pin number.
For many years now it has worked this way.
The analogRead() code looks at the "pin" parameter and based on the processor type and some assumptions determines how to take what argument it was passed to get to the needed analog channel number.
IMO, This should never have been done this way.
The reason is that now the flexibility of the variant file (which is based on board type NOT processor type) has been lost/violated because the code in the analogRead() function assumes that there is a 1:1 mapping between a range of digital pins and analog channels in a increasing pin number order  based on the processor being used - not the board being used.
That violates what should be possible in the variant file. i .e. the ability to map things any way you want based on a board type.

To make things worse and more confusing analogWrite() is NOT and analog function. It is a DIGITAL function. The name analogWrite() sucks! And since analogWrite() is a digital functions the "pin" argument there IS an arduino digital pin number.
In the early days it was more confusing since analogRead() used a channel number but  analogWrite() used a digital pin number.
Each had its own numbering space and there were no A0, A1 etc defines.
And even today, there are still dual numbering spaces for the "analog" functions, it is just hidden from view in analogRead() by the combination of allowing the use of A0, A1, etc defines and the internal hard coding going on to map An defines to the analog channel numbers for analogRead().

--- bill


Hi all,

The above discussion is above my head :) I´m not a programmer. I just needed some way to control the heating and circulation of the hot tub i have built. I copy/past/edited some code in 2016 and it has been working since.

Now I just changed to i2c and a 20x4 LCD instead of serial and 16x2.

There must be something wrong with my Arduino Uno. I now changed to a "ali express Mega" and the display works like a charm.

Something I did not mention in the first post is that the backlight was working and it showed "squares" on the top and 3rd line.

But as said. Now everything works, the display is showing all and I can adjust with the potentiometer :)

Thanks anyways.

Go Up