Dear Adam
Sorry for late reply. The LCD work if I comment out the following statements:
Cayenne.begin(username, password, clientID);
Cayenne.loop();
In this project, I have two load cells that measure the weight of grocery items and displays the value on the cayenne dashboard and LCD. The cayenne dashboard is working but only the LCD giving me problem.
Hope to hear from you soon.
Thanks
Umakandan
The code is as below:
#include <HX711.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <CayenneMQTTSerial.h>
#define DOUT2 5
#define CLK2 4
#define DOUT 3
#define CLK 2
int allGood=10;
int alert=11;
HX711 scale(DOUT, CLK);
HX711 scale2(DOUT2, CLK2);
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";
//Change this calibration factor as per your load cell once it is found you many need to vary it in thousands
float calibration_factor = -92050;//-106600 worked for my 40Kg max scale setup
float calibration_factor2 = -91850;
float weight1;
float weight2;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7);
//=============================================================================================
// SETUP
//=============================================================================================
void setup() {
//Cayenne.begin(username, password, clientID);
pinMode(12,OUTPUT);
pinMode(allGood,OUTPUT);
pinMode(alert, OUTPUT);
scale.set_scale(-92050);//Calibration Factor obtained from first sketch
scale2.set_scale(-91850);
scale.tare(); //Reset the scale to 0
scale2.tare();
lcd.begin(20, 4); // for 16 x 2 LCD module
lcd.setBacklightPin(3, POSITIVE);
lcd.setBacklight(HIGH);
lcd.home(); // set cursor to 0,0
lcd.print(" Welcome To ");
lcd.setCursor(0, 1); // go to start of 2nd line
lcd.print("Grocery Notifier");
}
//=============================================================================================
// LOOP
//=============================================================================================
void loop() {
weight1 = scale.get_units();
weight2 = scale2.get_units();
if ( (weight1 < 0.4 && weight1 > 0.05 )||(weight2 < 0.4 && weight2 > 0.05 ))
{
digitalWrite(alert, HIGH);
}
else
{
digitalWrite(alert,LOW);
}
if( weight1 >= 0.4 && weight2>= 0.4)
{
digitalWrite(allGood,HIGH);
}
else
{
digitalWrite(allGood,LOW);
}
lcd.setCursor(0, 2);
lcd.print("Tray 1 = ");
lcd.setCursor(9, 2);
lcd.print(scale.get_units());
lcd.setCursor(14, 2);
lcd.print("kg");
lcd.setCursor(0, 3);
lcd.print("Tray 2 = ");
lcd.setCursor(9, 3);
lcd.print(scale2.get_units());
lcd.setCursor(14, 3);
lcd.print("kg");
// Cayenne.loop();
}
CAYENNE_OUT_DEFAULT()
{
Cayenne.virtualWrite(1,weight1);
Cayenne.virtualWrite(2, weight2);
if ( (weight1 < 0.4 && weight1 > 0.05 )||(weight2 < 0.4 && weight2 > 0.05 ))
{
Cayenne.virtualWrite(5,HIGH);
Cayenne.virtualWrite(10,HIGH);
}
else
{
Cayenne.virtualWrite(5,LOW);
Cayenne.virtualWrite(10,LOW);
}
}
// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}
CAYENNE_IN(3)
{
digitalWrite(12,getValue.asInt());
}