Whenever I Connect LCD .... Cayenne Dashboard Shows Offline


#1

My Project is water level detection using ultrasonic sensor and arduino uno … Everything works fine but when I include “LiquidCrystal lcd (12, 11, 5, 4, 3, 2 )” , Cayenne Shows “Offline” …

This is the code that i have uploaded:

#include <LiquidCrystal.h>
#define CAYENNE_DEBUG       // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTESP8266Shield.h>
#include <SoftwareSerial.h>
#include "Ultrasonic.h"
#include<LiquidCrystal.h>

// WiFi network info.
char ssid[] = "AndroidAP";
char wifiPassword[] = "12345678";
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";



#define EspSerial Serial
#define RELAY_VIRTUAL_CHANNEL 1
#define RELAY_ACTUATOR_PIN 7
#define VIRTUAL_CHANNEL 2
#define BUZZER_PIN 9

ESP8266 wifi(&EspSerial);
   
Ultrasonic ultrasonic(A0,A1);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


void setup()
{
lcd.begin(16, 2);
  Serial.begin(9600);
  delay(100);
pinMode(RELAY_ACTUATOR_PIN, OUTPUT);
  // Set ESP8266 baud rate
  EspSerial.begin(115200);
  delay(100);

  Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);
}

void loop()
{
  
    Cayenne.loop();
  int  distance = ultrasonic.Ranging(CM); 
   if (distance < 5 ){
 tone (BUZZER_PIN , 2000, 10000);
   }
    lcd.setCursor(0,0);          
  lcd.print("16x2 LCD MODULE"); 
  lcd.setCursor(2,1);           
  lcd.print("HELLO WORLD"); 

}

CAYENNE_OUT_DEFAULT()
{
  Cayenne.virtualWrite(0, millis());
}

CAYENNE_IN_DEFAULT()
{
  CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
}

// This function is called when data is sent from Cayenne.
CAYENNE_IN(RELAY_VIRTUAL_CHANNEL)
{
  // Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
  if (getValue.asInt() == 0) {
    digitalWrite(RELAY_ACTUATOR_PIN, HIGH);
  }
  else {
    digitalWrite(RELAY_ACTUATOR_PIN, LOW);
  }
}

CAYENNE_OUT(VIRTUAL_CHANNEL)
{
int  distance = ultrasonic.Ranging(CM); 
  Cayenne.virtualWrite(VIRTUAL_CHANNEL,distance );
  delay(1000);
}

#2

are you using arduino UNO and esp8266?


#3

Yes…


#4

with uno this library is less stable. Do you have a arduino mega? with mega we can also print out the error which is causing the disconnect.


#5

No I dont have mega board … Is there any alternative for achieving this


#6

Try this code.

#include <LiquidCrystal.h>
//#define CAYENNE_DEBUG       // Uncomment to show debug messages
//#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTESP8266Shield.h>
#include <SoftwareSerial.h>
#include "Ultrasonic.h"
#include<LiquidCrystal.h>

// WiFi network info.
char ssid[] = "AndroidAP";
char wifiPassword[] = "12345678";
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";



#define EspSerial Serial
#define RELAY_VIRTUAL_CHANNEL 1
#define RELAY_ACTUATOR_PIN 7
#define VIRTUAL_CHANNEL 2
#define BUZZER_PIN 9

ESP8266 wifi(&EspSerial);
   
Ultrasonic ultrasonic(A0,A1);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


void setup()
{
lcd.begin(16, 2);
  //Serial.begin(9600);
  delay(100);
pinMode(RELAY_ACTUATOR_PIN, OUTPUT);
  // Set ESP8266 baud rate
  EspSerial.begin(115200);
  delay(100);

  Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);
}

void loop()
{
  
    Cayenne.loop();
  int  distance = ultrasonic.Ranging(CM); 
   if (distance < 5 ){
 tone (BUZZER_PIN , 2000, 10000);
   }
    lcd.setCursor(0,0);          
  lcd.print("16x2 LCD MODULE"); 
  lcd.setCursor(2,1);           
  lcd.print("HELLO WORLD"); 

}

CAYENNE_OUT_DEFAULT()
{
  Cayenne.virtualWrite(0, millis());
}

CAYENNE_IN_DEFAULT()
{
  CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
}

// This function is called when data is sent from Cayenne.
CAYENNE_IN(RELAY_VIRTUAL_CHANNEL)
{
  // Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
  if (getValue.asInt() == 0) {
    digitalWrite(RELAY_ACTUATOR_PIN, HIGH);
  }
  else {
    digitalWrite(RELAY_ACTUATOR_PIN, LOW);
  }
}

CAYENNE_OUT(VIRTUAL_CHANNEL)
{
int  distance = ultrasonic.Ranging(CM); 
  Cayenne.virtualWrite(VIRTUAL_CHANNEL,distance );
  delay(1000);
}

#7

The LCD library shouldn’t cause you issues if your sketch is compiling.

Can you try physically disconnecting the LCD and see if you still show Cayenne online?

I’m wondering if you are driving into a mis-wired LCD and causing the Arduino to die.

Kreggly


#8

I tried shramiksalgaonkar, what you told me to do… But Same issue is occuring again.


#9

kreggly, I tried that but unfortunately nothing happens … When I introduce “LiquidCrystal lcd (12, 11, 5, 4, 3, 2 )” in my code … Arduino connects with cayenne but after 5 seconds it disconnects and shows offline …


#10

Are you getting errors in your serial output?


#11

No , I am not getting any error in serial


#12

it looks like it LCD is causing some problem with esp8266 when used on arduino uno. I tested it with arduino mega and it works fine. What i will suggest buy a arduino mega and start your project with it. i am working on trying to figure out the cause with arduino uno.


#13

Try this code:

/*
This sketch connects to the Cayenne server using an ESP8266 WiFi module as a shield connected via a hardware serial to an Arduino.

The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

Steps:
1. Install the ESP8266SerialLibrary.zip library via the Arduino IDE (Sketch->Include Library->Add .ZIP Library) from the Cayenne extras/libraries
   folder (e.g. My Documents\Arduino\libraries\CayenneMQTT\extras\libraries) to compile this example.
2. Connect the ESP8266 as a shield to your Arduino. This example uses the Serial hardware serial pins available on the UNO. 
3. Set the Cayenne authentication info to match the authentication info from the Dashboard.
4. Set the network name and password.
5. Compile and upload the sketch.
6. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.

NOTE: This code requires ESP8266 firmware version 1.0.0 (AT v0.22) or later.
*/

//#define CAYENNE_DEBUG       // Uncomment to show debug messages
//#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTESP8266Shield.h>
#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);
// WiFi network info.
char ssid[] = "";
char wifiPassword[] = "";


char username[] = "";
char password[] = "";
char clientID[] = "";

// Set ESP8266 Serial object. In this example we use the Serial1 hardware serial which is available on boards like the Arduino Mega.
#define EspSerial Serial

ESP8266 wifi(&EspSerial);

void setup()
{
  //Serial.begin(9600);
  delay(10);

  // Set ESP8266 baud rate
  EspSerial.begin(115200);
  delay(10);
    Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);

  lcd.begin(16, 2);
    lcd.print(" Cayenne!");
}

void loop()
{
  Cayenne.loop();
}

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
  // Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
  Cayenne.virtualWrite(0, millis());
  // Some examples of other functions you can use to send data.
  //Cayenne.celsiusWrite(1, 22.0);
  //Cayenne.luxWrite(2, 700);
  //Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

// 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()
{
  CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
  //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}