Adding sensor kills connection

Hello.
I can add arduino nano with basic template to dashboard.
When I try to add a sensor, then it never connects again.
I upload the basic sketch to arduino nano and it connects again!

Example:
//this works
#include <CayenneSerial.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token = “i*********p”;

void setup()
{
//Baud rate can be specified by calling Cayenne.begin(token, 9600);
Cayenne.begin(token);
}

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

//this doesn’t work
/*
Cayenne BMP180 Example

This sketch shows how to send luminosity data to a BMP180 Sensor in the Cayenne Dashboard.

The Cayenne 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 Adafruit Unified Sensor library (GitHub - adafruit/Adafruit_Sensor: Common sensor library) from the Arduino Library Manager.
  2. Install the Adafruit BMP085 Unified library (GitHub - adafruit/Adafruit_BMP085_Unified: Unified sensor driver for Adafruit's BMP085 & BMP180 breakouts) from the Arduino Library Manager.
  3. In the Cayenne Dashboard add a new BMP180 widget.
  4. Set the widget to Value Display.
  5. Select Virtual Pins and select virtual pins for the barometer and temperature.
  6. Set BAROMETER_PIN to the pin number you selected for the barometer.
  7. Set TEMPERATURE_PIN to the pin number you selected for the temperature.
  8. Attach a BMP180 to your Arduino.
    Schematic:
    BMP180 Arduino
    [VDD] — [3V3]
    [GND] — [GND]
    [SDA] — [Analog Pin 4] (The SDA may be different on some devices, e.g. for Arduino Mega the SDA pin is Digital Pin 20)
    [SCL] — [Analog Pin 5] (The SCL may be different on some devices, e.g. for Arduino Mega the SCL pin is Digital Pin 21)
  9. Set the token variable to match the Arduino token from the Dashboard.
  10. Compile and upload this sketch.
  11. Once the Arduino connects to the Dashboard it should automatically update the BMP180 widget with data.
    /
    //#define CAYENNE_DEBUG
    //#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
    #include <Wire.h>
    #include <Adafruit_Sensor.h>
    #include <Adafruit_BMP085_U.h>
    #include <CayenneSerial.h>
    #define BAROMETER_PIN V1
    #define TEMPERATURE_PIN V2
    Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10180);
    bool bmpSensorDetected = true;
    char token[] = "k
    ********q";
    void setup()
    {
    Serial.begin(9600);
    Cayenne.begin(token);
    if (!bmp.begin())
    {
    CAYENNE_LOG(“No BMP sensor detected”);
    bmpSensorDetected = false;
    }
    }
    void loop()
    {
    Cayenne.run();
    }

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”);
}
}
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”);
}
}

cli output

Connecting device at COM3 to arduino.mydevices.com:8442
OpenC0C(“\.\COM3”, baud=9600, data=8, parity=no, stop=1) - OK
Connect(“arduino.mydevices.com”, “8442”) - OK
InOut() START
DSR is OFF
Received EOF
EVENT_CLOSE
InOut() - STOP
Disconnect() - OK
Connect(“arduino.mydevices.com”, “8442”) - OK
InOut() START
DSR is OFF

how are you connecting to cayenne? ESP shield?

USB Serial Connection

Those sketches have different tokens (which I’m going to obscure since this is a public forum).

If you’ve previously connected the Nano to Cayenne and want to add code for a sensor, make sure you keep the same Cayenne token so our system knows that it is still the same device.

1 Like

hmmm, weird
let me try that

ok, that worked!
now modify the sketch to use BMP280 instead of BMP180…
Thanks!

3 Likes