Hello.
I had small Arduino project based on UNO + LCD on I2C + 2x DS18B20 onewire. It shows on LCD temperatures from 2 sensors and it worked perfectly for 2 years. Here is how code for that looks like:
Now I discovered Cayenne, so I immidiately wanted to export those readings to cloud and see those beautiful charts. Problem started when I merged Cayenne code with my code. Here is how it looks like now:
And results of that:
compilation runs ok
lcd works - shows strings from code
ethernet works - uploads data to cayenne
ds18b20 doesn’t work - shows -273,1C both in lcd and in dashboard
I thought that I messed some wiring during ethernet shield connection, but when I removed it and uploaded back old code it works ok and shows temperatures. When on working device i pull up probe pin from arduino it shows -273,1 on LCD so I think that the problem is here but I don’t know where exactly.
Things I tried to do and did not help:
unmounted ethernet shield and mounted it to second arduino - same result - -273,1C
increase power supply from 1A to 2A - thought maybe shield eats too much power so probes don’t work
disconnect and connect all wiring again
disconnect temp probe from PIN3 on shield and touch PIN3 on bottom of arduino
moved probe from PIN3 to PIN7 and PIN10 (both in code and in wiring :P) in case if PIN3 is somehow reserved by eth shield but no changes
Any ideas what can be wrong in here?
I can post photo of wiring, but I don’t think there is a point to do that. It was taken from the simplest onewire tutorial for DS18B20 and since it works when I upload old code and remove shield I assume that problem is with my code merging.
which pins are you using for LCD connection? can you try basic 2x DS18B20 code without cayenne code with ethernet shield attached and no LCD connection
I found Cayenne prepared sketch for DS18B20 (uses dallastemperature.h lib instead of ds18b20.h) and I used it and it works:
But when I add LCD code into it:
then it shows -127C. I thought there is a problem with converting sensor output to float in here:
float temperature0 = sensors.getTempCByIndex(0);
but -127C is not only on LCD but also in data uploaded to Cayenne. It is being uploaded with same code line as in top source code and there it works sp it is not matter of conversion. Clearly LCD messes something, maybe with two serials 115200 and 9600, no idea how that works, used ready I2C LCD code from tutorial, but it somehows disturbs probe readings.
i gave this a try as i don’t have PCF8574 for my LCD and it works fine. see if you can remove your PCF8574 and use this code :
// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";
#define SENSOR_PIN 2 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
OneWire oneWire(SENSOR_PIN);
DallasTemperature sensors(&oneWire);
#include <LiquidCrystal.h>
const int rs = 9, en = 8, d4 = 6, d5 = 5, d6 = 4, d7 = 3;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup()
{
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
Cayenne.begin(username, password, clientID);
sensors.begin();
}
void loop() {
Cayenne.loop();
}
CAYENNE_OUT_DEFAULT()
{
// Send the command to get temperatures.
sensors.requestTemperatures();
float t1 = sensors.getTempCByIndex(0);
float t2 = sensors.getTempCByIndex(1);
// This command writes the temperature in Celsius to the Virtual Channel.
Cayenne.celsiusWrite(10, t1);
Cayenne.celsiusWrite(11, t2);
lcd.print(t1);
lcd.setCursor(0, 1);
lcd.print(t2);
}
Thank You, finally worked.
Not exactly on Your code, but Your initializing of LCD gave me some thoughts and when I dig into it I changed LIB once more as it was returning some errors. I also managed to truncate floats to 1 decimal because charts were very messy when there were recordings like
24.17
24.19
24.15
now its just 24.1 three times.
Final code:
#include <LiquidCrystal_I2C.h>
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <OneWire.h>
#include <DallasTemperature.h>
#include <CayenneMQTTEthernet.h>
#include <Wire.h>
#include <LCD.h>
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";
#define SENSOR_PIN 2 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
OneWire oneWire(SENSOR_PIN);
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
lcd.begin(16, 2); // initialize the lcd
lcd.setBacklight(255);
lcd.home(); lcd.clear();
Cayenne.begin(username, password, clientID);
sensors.begin();
}
void loop()
{
Cayenne.loop();
}
CAYENNE_OUT_DEFAULT()
{
// Send the command to get temperatures.
sensors.requestTemperatures();
// This command writes the temperature in Celsius to the Virtual Channel.
float t0 = (float)((int)(sensors.getTempCByIndex(0)*10))/10;
float t1 = (float)((int)(sensors.getTempCByIndex(1)*10))/10;
Cayenne.celsiusWrite(0, t0);
Cayenne.celsiusWrite(1, t1);
lcd.setCursor(0, 0);
lcd.print(F("Temp1 "));
lcd.print(t0);
lcd.print(F("C"));
lcd.setCursor(0, 1);
lcd.print(F("Temp2 "));
lcd.print(t1);
lcd.println(F("C"));
}