Cayenne Ethernet, how to confirm connection on lcd

Hi all,

I’ve got my project sensors all working and parsing to Cayenne nicely. Through the serial monitor I can see the standard connection process; MAC, IP and “Connecting” until you get the “Ready” and ping response time. I can’t figure out however how to translate this library function across for use with an LCD so when deployed outside where I have no serial monitor I can get confirmation on the lcd before proceeding.

I have had an attempt but it always indicates failure even though the connection runs through serial without difficulty.

#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>
#include <DHT.h>
#include <DHT_U.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x26, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display

#include <CayenneEthernet.h>
// Mac address should be different for each device in your LAN
byte arduino_mac[] = { yourinfo};
IPAddress arduino_ip(yourinfo);
IPAddress gateway_ip(yourinfo);
IPAddress subnet_mask(255, 255, 255, 0);

EthernetClient client;

// Virtual Pin & Config of the DS18B20
#define VIRTUAL_PIN1 V1
#define VIRTUAL_PIN2 V2
#define VIRTUAL_PIN3 V5
#define VIRTUAL_PIN4 V6
const int tmpPin = 2;
float cap1;
float cap2;
float cap3;
float cap4;
OneWire oneWire1(tmpPin);
DallasTemperature sensors(&oneWire1);

//Virtual Pin & Config of the BMP085
#define TEMPERATURE_PIN V3
#define BAROMETER_PIN V4
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10180);
bool bmpSensorDetected = true;

//Virtual Pin & Config for DHT11
#define DHT_HUMIDITY_PIN V7
#define DHT_TEMPERATURE_PIN V8
#define DHTPIN 4          // Pin which is connected to the DHT sensor.
#define DHTTYPE DHT11     // DHT 11 
float dht11T;
float dht11H;
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;                   //Delay between sensor reading

//Setup the Moister sensor variables (Analogue or digital read - set pin accordingly
int moisterPin = A1;
int moisterValue = 0;
#define MOISTER_PIN V9

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "yourinfo";

int runOnce = 0; //State variable for tracking the first time device runs

void setup()
{
  Serial.begin(115200);   //Ensure you set the correct Baud rate if you intend to add/use serial writes for debugging
  Cayenne.begin(token);
  sensors.begin();
  dht.begin();
  // Print temperature sensor details.
  sensor_t sensor;
  dht.temperature().getSensor(&sensor);
  // Print humidity sensor details.
  dht.humidity().getSensor(&sensor);
  // Set delay between sensor readings based on sensor details.
  delayMS = sensor.min_delay / 1000;

  if (!bmp.begin())
  {
    CAYENNE_LOG("No BMP sensor detected");
    bmpSensorDetected = false;
  }
}

void loop()
{
  Cayenne.run();
  if (runOnce == 0) {
    delay(5000);
    lcdInitialDisplay ();
    runOnce = 1;
  }
}

void DHTSensorT () {

  // Get temperature event from the DHT11 humidy/Temp Sensor
  sensors_event_t event;
  dht.temperature().getEvent(&event);
  dht11T = (event.temperature);
  Serial.print("Temperature:: ");
  Serial.print(dht11T);
  Serial.println("'C");
}

void DHTSensorH () {

  // Get humidity event from the DHT11 humidy/Temp Sensor
  sensors_event_t event;
  dht.humidity().getEvent(&event);
  dht11H = (event.relative_humidity);
  Serial.print("Humidity: ");
  Serial.print(dht11H);
  Serial.println("%");
  // Delay between measurements.
  //delay(delayMS);
}

void moisterSensor() {

  moisterValue = analogRead(moisterPin);
  //sensorValue = map(sensorValue,160,1023,0,1000);
  Serial.print("Moister: ");
  Serial.print(moisterValue);
  Serial.println("%");
}

// This function is called when the Cayenne widget requests data for DHT11 Humidity
CAYENNE_OUT(DHT_HUMIDITY_PIN)
{
  Cayenne.virtualWrite(DHT_HUMIDITY_PIN, (dht11H), HUMIDITY, PERCENT);
  DHTSensorH();
}

// This function is called when the Cayenne widget requests data for  DHT11 Temperature
CAYENNE_OUT(DHT_TEMPERATURE_PIN)
{
  Cayenne.virtualWrite(DHT_TEMPERATURE_PIN, (dht11T), TEMPERATURE, CELSIUS);
  DHTSensorT();
}

// START - These functions are called when the Cayenne widget requests data for the DS18B20 Temp Sensors (x4)
CAYENNE_OUT(VIRTUAL_PIN1)
{
  // Send the command to get temperatures.
  sensors.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Pin.
  cap1 = sensors.getTempCByIndex(0);
  Cayenne.celsiusWrite(VIRTUAL_PIN1, cap1);
}
CAYENNE_OUT(VIRTUAL_PIN2)
{
  // Send the command to get temperatures.
  sensors.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Pin.
  cap2 = sensors.getTempCByIndex(1);
  Cayenne.celsiusWrite(VIRTUAL_PIN2, cap2);
}
CAYENNE_OUT(VIRTUAL_PIN3)
{
  // Send the command to get temperatures.
  sensors.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Pin.
  cap3 = sensors.getTempCByIndex(2);
  Cayenne.celsiusWrite(VIRTUAL_PIN3, cap3);
}
CAYENNE_OUT(VIRTUAL_PIN4)
{
  // Send the command to get temperatures.
  sensors.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Pin.
  cap4 = sensors.getTempCByIndex(3);
  Cayenne.celsiusWrite(VIRTUAL_PIN4, cap4);
}

// START - This function is called when the Cayenne widget requests data for the BMP085 Barometer/Temp Sensor Virtual Pin.
CAYENNE_OUT(BAROMETER_PIN)
{
  if (bmpSensorDetected)
  {
    // Send the command to get data.
    sensors_event_t event;
    bmp.getEvent(&event);

    if (event.pressure)
    {
      // Send the value to Cayenne in hectopascals.
      Cayenne.hectoPascalWrite(BAROMETER_PIN, event.pressure);
    }
  }
  else
  {
    CAYENNE_LOG("No BMP sensor detected");
  }
}

// This function is called when the Cayenne widget requests data for the temperature's Virtual Pin on BMP085 Sensor
CAYENNE_OUT(TEMPERATURE_PIN)
{
  if (bmpSensorDetected)
  {
    float temperature;
    bmp.getTemperature(&temperature);
    // Send the value to Cayenne in Celsius.
    Cayenne.celsiusWrite(TEMPERATURE_PIN, temperature);
  }
  else
  {
    CAYENNE_LOG("No BMP sensor detected");
  }
}

void lcdInitialDisplay () {

  lcd.init();                      // initialize the lcd
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Pond M8 Version 1");
  lcd.setCursor(0, 2);
  lcd.print("IP: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    lcd.print(Ethernet.localIP()[thisByte], DEC);
    lcd.print(".");
  }

  lcd.setCursor(0, 3);
  lcd.print("Status: ");

  if (client.available()) {
    lcd.setCursor(8, 3);
    lcd.print("Connected");
  } else {
    lcd.setCursor(8, 3);
    lcd.print("Failed");
  }
}

Hi Dave,

Which Arduino device/Ethernet Shield are you trying to connect to Cayenne here?

Mega & W5100.

As I said, the Cayenne side is working fine but I’m being a bit thick trying to achieve the connection status response for use with lcd, error checking etc.

With the same code I’m also experiencing a strange conflict between Arduino, IFTTT and Wemo. I have my outside lights on a Wemo Smart switch, connected to IFTTT to activate at sunset. I also have Hue on IFTTT. Both run fine until i connect the Arduino, running the above code, and then the Wemo IFTTT activation doesn’t happen, yet the Hue does.

A problem for another thread though i suppose

Here is some info from another thread where they are running code based on connected/disconnected status. Does this help?

It’s working a treat and many many thanks for the pointer.

1 Like

Hello.
Did You finally manage to get working LCD with Cayenne? I have temperature monitoring system which works good until I adapt LCD into it. LCD code somehow interrupt temperature sensors reading and it shows -127C constantly.

-127 means the sensor was not detected. Check the cables and connections. This thread has some other pointers as well Please Help me!!!! DS18B20 I2C LCD board problem - Sensors - Arduino Forum Take note of the pins you are using for the LCD and the temp sensor as the may be overlapping.