I am unable to get my values to update on the Cayenne dashboard while simultaneously printing to an I2C LCD. Script running on Arduino Uno feeding to dashboard via serial connection to RPI 3B+. The idea is to be able to read the sensor values in our rig by looking at the LCD and also remotely from App. I’ve built a scale that can convert keg weight into ounces remaining as a gift. I know we’ve got the connection script on the Pi running right because you all just finished helping me recently getting that to happen on reboot.
Here is the code running on the Arduino.
//include I2C LCD Libraries
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//include HX711 Library
#include "HX711.h"
//include Cayenne MQTT Library for Serial Coms with Pi
#include <CayenneMQTTSerial.h>
//Cayenne authentication info
char username[] = "*************";
char password[] = "**************";
char clientID[] = "*****************";
const int readingChannel = 0;
//Set HX711 Pins
#define DOUT 3
#define CLK 2
//Create HX711 Object
HX711 scale(DOUT, CLK);
//Set Calibration Factor
#define calibration_factor -10180
#define zero_factor 1052867
//Set I2C address
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
//Create buffers for Reading and LCD printout
char vol_str [6];
char line1 [17];
//Name of Current Beer on Tap
char myBeer[] = "Cloud Landing";
void setup() {
//Open Serial Coomunication
Serial.begin(9600);
//Baud rate can be specified by calling Cayenne.begin(username, password, clientID, 9600);
Cayenne.begin(username, password, clientID, 9600);
//Initialize your LCD object as being a 16 column, 2 row LCD
lcd.begin(16,2);
for(int i= 0; i< 3; i++) //flash the LCD 3 times to test upon Power On
{
lcd.backlight();
delay(250);
lcd.noBacklight();
delay(250);
}
lcd.backlight(); //set backlight as ON after 3 flashes
//Introduction Line
lcd.setCursor(0,0);
lcd.print(myBeer);
//Turn on the Scale
scale.set_scale(calibration_factor);
scale.set_offset(zero_factor);
}
void loop() {
Cayenne.loop();
}
CAYENNE_OUT_DEFAULT()
{
float weight = scale.get_units();
float emptyKeg = 15.2; //weight of empty keg
float beerWeight = weight - emptyKeg;
float fullKegWeight = beerWeight * 16.0; // in ounces
float fullKegVolume = 231.0; //in fl.oz.
float beerVolume = map (fullKegWeight, 0,382.4 , 0, fullKegVolume);
dtostrf(beerVolume,5,1,vol_str);
sprintf(line1, "Level: %s oz", vol_str);
lcd.setCursor(0,1);
lcd.print(line1);
Cayenne.virtualWrite(readingChannel, beerVolume);
}
you code might be waiting in loop to connect to cayenne at Cayenne.begin(username, password, clientID, 9600);
Add #define CAYENNE_DEBUG
in your code and check the serial monitor output.
Thanks for the reply. Where exactly should this line be added? I am also confused about checking the serial monitor for output as the sample script reads
This requires the use of the Serial USB connection so you cannot use the Serial device for printing messages. If you need to print you can use SoftwareSerial and connect another device
to read messages via the SoftwareSerial pins.
Sorry, i did not check that you are using USB Serial for internet connection. Do you have an Ethernet shield or an esp8266-01. As it is difficult to debug what is causing the problem in USB serial communication.
Those are not options for me as the network I am connecting to is WPA-EAP and doesn’t work well with the ESP8266 wifi card. The ethernet connection isn’t ideal as I do not want to run a cable from the port to the the device across the room. I have not had issues with the serial communication before using the Pi as an access point. The trouble arose when adding the lcd.print command. I have already confirmed connection with the dashboard using this script without the print to the I2C LCD.
to which arduino pins have you connected your LCD ?
The LCD is I2C therefore there are only four wires necessary. SCL to Arduino A5, SDA to Arduino A4, Power to 5V, and GND to GND. The LCD works without the Cayenne script and the Cayenne scripts works without the LCD, but when I try to bring the two together, neither seem to work. Could there be a conflict in the LCD library?
Tagging @jburhenn for this.
Yeah, I suppose there could potentially be a conflict with the LCD library. Which library and version are you using? Are there any other libraries for your LCD device you could try?
What specifically is the error behavior you are seeing? The value shows on Cayenne, but not the LCD? Or vice versa? Or it doesn’t show on either once you add the lcd.print
? Does the agent remain connected to Cayenne with the lcd.print
in place?
1 Like
I am using the LiquidCrystal_I2C library. When I add the information for the LCD into the script originally used to virtualWrite to Cayenne, the device shows as “Offline” on the dashboard and the LCD does not display any values.
I’ve not tried any other LCD I2C libraries as this is the one that I’ve been using successfully prior to trying to interface with Cayenne. There are a number of such libraries out there. Here is the GitHub repo with header and .cpp files. It isn’t the exact one I am using, but if you do not read any find any conflicts I can give it a try.
LiquidCrystal_I2C on GitHub
So if you comment out the lcd.print
line, and only that line, it doesn’t show Offline and the dashboard correctly shows the values? Or do you have to comment out other LCD code for it to work?
I don’t see anything obvious that would conflict with Cayenne in the library you linked so it might be worth giving it a try and see if it has the same behavior.
I know it has been a bit of time since I last replied. Work and small children will do this. For whatever reason, the older version of the I2C Liquid Crystal library was in conflict with running the sketch that allows for serial connection between arduino and cayenne.
I installed a new I2C library from
Functional I2C LiquidCrystal Library
Now the arduino can make its reading, print it locally to the I2C LCD, and upload it to Cayenne via serial connection to a RPi 3B+. Couldn’t fish the specific reason out of the .cpp file of the old library, but I suppose changing the library out was the solution. Thanks for your help.
1 Like
Glad to hear it is working now and thanks for reporting the issue with old library.