Skip to content

Commit 6adb6ca

Browse files
committed
Split individual sensors into separate example sketches.
1 parent ba645c3 commit 6adb6ca

File tree

4 files changed

+280
-0
lines changed

4 files changed

+280
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
Cayenne BMP180 Pressure Example
3+
4+
This sketch shows how to send BMP180 Pressure Sensor data to the Cayenne Dashboard.
5+
6+
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.
7+
8+
Steps:
9+
1. Install the Adafruit Unified Sensor library (https://github.com/adafruit/Adafruit_Sensor) from the Arduino Library Manager.
10+
2. Install the Adafruit BMP085 Unified library (https://github.com/adafruit/Adafruit_BMP085_Unified) from the Arduino Library Manager.
11+
3. Attach a BMP180 to your Arduino.
12+
Schematic:
13+
BMP180 Arduino
14+
[VDD] --- [3V3]
15+
[GND] --- [GND]
16+
[SDA] --- [Analog Pin 4] (The SDA may be different on some devices, e.g. for Arduino Mega the SDA pin is Digital Pin 20)
17+
[SCL] --- [Analog Pin 5] (The SCL may be different on some devices, e.g. for Arduino Mega the SCL pin is Digital Pin 21)
18+
4. Set the VIRTUAL_CHANNEL value below to a free virtual channel (or the virtual channel of the BMP180 Pressure Sensor widget you have added) in the Dashboard.
19+
5. Set the Cayenne authentication info to match the authentication info from the Dashboard.
20+
6. Compile and upload this sketch.
21+
7. Once the Arduino connects to the Dashboard it should automatically create a temporary display widget (or update the BMP180 Pressure Sensor widget you have added) with data.
22+
To make a temporary widget permanent click the plus sign on the widget.
23+
*/
24+
25+
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
26+
#include <Wire.h>
27+
#include <Adafruit_Sensor.h>
28+
#include <Adafruit_BMP085_U.h>
29+
#include <CayenneMQTTEthernet.h>
30+
31+
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
32+
char username[] = "MQTT_USERNAME";
33+
char password[] = "MQTT_PASSWORD";
34+
char clientID[] = "CLIENT_ID";
35+
36+
#define VIRTUAL_CHANNEL 1
37+
38+
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10180);
39+
bool bmpSensorDetected = true;
40+
41+
void setup()
42+
{
43+
Serial.begin(9600);
44+
Cayenne.begin(username, password, clientID);
45+
if (!bmp.begin())
46+
{
47+
CAYENNE_LOG("No BMP sensor detected");
48+
bmpSensorDetected = false;
49+
}
50+
}
51+
52+
void loop()
53+
{
54+
Cayenne.loop();
55+
}
56+
57+
// This function is called at intervals to send barometer sensor data to Cayenne.
58+
CAYENNE_OUT(VIRTUAL_CHANNEL)
59+
{
60+
if (bmpSensorDetected)
61+
{
62+
// Send the command to get data.
63+
sensors_event_t event;
64+
bmp.getEvent(&event);
65+
66+
if (event.pressure)
67+
{
68+
// Send the value to Cayenne in hectopascals.
69+
Cayenne.hectoPascalWrite(VIRTUAL_CHANNEL, event.pressure);
70+
}
71+
}
72+
else
73+
{
74+
CAYENNE_LOG("No BMP sensor detected");
75+
}
76+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Cayenne BMP180 Temperature Example
3+
4+
This sketch shows how to send BMP180 Temperature Sensor data to the Cayenne Dashboard.
5+
6+
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.
7+
8+
Steps:
9+
1. Install the Adafruit Unified Sensor library (https://github.com/adafruit/Adafruit_Sensor) from the Arduino Library Manager.
10+
2. Install the Adafruit BMP085 Unified library (https://github.com/adafruit/Adafruit_BMP085_Unified) from the Arduino Library Manager.
11+
3. Attach a BMP180 to your Arduino.
12+
Schematic:
13+
BMP180 Arduino
14+
[VDD] --- [3V3]
15+
[GND] --- [GND]
16+
[SDA] --- [Analog Pin 4] (The SDA may be different on some devices, e.g. for Arduino Mega the SDA pin is Digital Pin 20)
17+
[SCL] --- [Analog Pin 5] (The SCL may be different on some devices, e.g. for Arduino Mega the SCL pin is Digital Pin 21)
18+
4. Set the VIRTUAL_CHANNEL value below to a free virtual channel (or the virtual channel of the BMP180 Temperature Sensor widget you have added) in the Dashboard.
19+
5. Set the Cayenne authentication info to match the authentication info from the Dashboard.
20+
6. Compile and upload this sketch.
21+
7. Once the Arduino connects to the Dashboard it should automatically create a temporary display widget (or update the BMP180 Temperature Sensor widget you have added) with data.
22+
To make a temporary widget permanent click the plus sign on the widget.
23+
*/
24+
25+
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
26+
#include <Wire.h>
27+
#include <Adafruit_Sensor.h>
28+
#include <Adafruit_BMP085_U.h>
29+
#include <CayenneMQTTEthernet.h>
30+
31+
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
32+
char username[] = "MQTT_USERNAME";
33+
char password[] = "MQTT_PASSWORD";
34+
char clientID[] = "CLIENT_ID";
35+
36+
#define VIRTUAL_CHANNEL 1
37+
38+
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10180);
39+
bool bmpSensorDetected = true;
40+
41+
void setup()
42+
{
43+
Serial.begin(9600);
44+
Cayenne.begin(username, password, clientID);
45+
if (!bmp.begin())
46+
{
47+
CAYENNE_LOG("No BMP sensor detected");
48+
bmpSensorDetected = false;
49+
}
50+
}
51+
52+
void loop()
53+
{
54+
Cayenne.loop();
55+
}
56+
57+
// This function is called at intervals to send temperature sensor data to Cayenne.
58+
CAYENNE_OUT(VIRTUAL_CHANNEL)
59+
{
60+
if (bmpSensorDetected)
61+
{
62+
float temperature;
63+
bmp.getTemperature(&temperature);
64+
// Send the value to Cayenne in Celsius.
65+
Cayenne.celsiusWrite(VIRTUAL_CHANNEL, temperature);
66+
}
67+
else
68+
{
69+
CAYENNE_LOG("No BMP sensor detected");
70+
}
71+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
Cayenne VCNL4000 Distance Example
3+
4+
This sketch shows how to send VCNL4000 Distance Sensor data to the Cayenne Dashboard.
5+
6+
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.
7+
8+
Steps:
9+
1. Attach a VCNL4000 to your Arduino.
10+
Schematic:
11+
VCNL4000 Arduino
12+
[VDD] ------- [3V3]
13+
[GND] ------- [GND]
14+
[SDA] ------- [Analog Pin 4] (The SDA may be different on some devices, e.g. for Arduino Mega the SDA pin is Digital Pin 20)
15+
[SCL] ------- [Analog Pin 5] (The SCL may be different on some devices, e.g. for Arduino Mega the SCL pin is Digital Pin 21)
16+
2. Set the VIRTUAL_CHANNEL value below to a free virtual channel (or the virtual channel of the VCNL4000 Distance Sensor widget you have added) in the Dashboard.
17+
3. Set the Cayenne authentication info to match the authentication info from the Dashboard.
18+
4. Compile and upload this sketch.
19+
5. Once the Arduino connects to the Dashboard it should automatically create temporary display widget (or update the VCNL4000 Distance Sensor widget you have added) with data.
20+
To make a temporary widget permanent click the plus sign on the widget.
21+
*/
22+
23+
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
24+
#include <CayenneVCNL4000.h>
25+
#include <CayenneMQTTEthernet.h>
26+
27+
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
28+
char username[] = "MQTT_USERNAME";
29+
char password[] = "MQTT_PASSWORD";
30+
char clientID[] = "CLIENT_ID";
31+
32+
#define VIRTUAL_CHANNEL 1
33+
34+
VCNL4000 proximitySensor;
35+
bool sensorDetected = true;
36+
37+
void setup()
38+
{
39+
Serial.begin(9600);
40+
Cayenne.begin(username, password, clientID);
41+
if (!proximitySensor.begin())
42+
{
43+
CAYENNE_LOG("No sensor detected");
44+
sensorDetected = false;
45+
}
46+
}
47+
48+
void loop()
49+
{
50+
Cayenne.loop();
51+
}
52+
53+
// This function is called at intervals to send distance data to Cayenne.
54+
CAYENNE_OUT(VIRTUAL_CHANNEL)
55+
{
56+
if (sensorDetected)
57+
{
58+
//The getMillimeters() function only provides a rough estimate of distance. If greater accuracy is desired
59+
//settings can be tweaked in CayenneVCNL400.h.
60+
int distance = proximitySensor.getMillimeters();
61+
if (distance != NO_PROXIMITY) {
62+
Cayenne.virtualWrite(VIRTUAL_CHANNEL, distance, TYPE_PROXIMITY, UNIT_MILLIMETER);
63+
}
64+
}
65+
else
66+
{
67+
CAYENNE_LOG("No sensor detected");
68+
}
69+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Cayenne VCNL4000 Luminosity Example
3+
4+
This sketch shows how to send VCNL4000 Luminosity Sensor data to the Cayenne Dashboard.
5+
6+
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.
7+
8+
Steps:
9+
1. Attach a VCNL4000 to your Arduino.
10+
Schematic:
11+
VCNL4000 Arduino
12+
[VDD] ------- [3V3]
13+
[GND] ------- [GND]
14+
[SDA] ------- [Analog Pin 4] (The SDA may be different on some devices, e.g. for Arduino Mega the SDA pin is Digital Pin 20)
15+
[SCL] ------- [Analog Pin 5] (The SCL may be different on some devices, e.g. for Arduino Mega the SCL pin is Digital Pin 21)
16+
2. Set the VIRTUAL_CHANNEL value below to a free virtual channel (or the luminosity channel of the VCNL4000 Sensor widget you have added) in the Dashboard.
17+
3. Set the Cayenne authentication info to match the authentication info from the Dashboard.
18+
4. Compile and upload this sketch.
19+
5. Once the Arduino connects to the Dashboard it should automatically create temporary display widget (or update the VCNL4000 Luminosity Sensor widget you have added) with data.
20+
To make a temporary widget permanent click the plus sign on the widget.
21+
*/
22+
23+
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
24+
#include <CayenneVCNL4000.h>
25+
#include <CayenneMQTTEthernet.h>
26+
27+
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
28+
char username[] = "MQTT_USERNAME";
29+
char password[] = "MQTT_PASSWORD";
30+
char clientID[] = "CLIENT_ID";
31+
32+
#define VIRTUAL_CHANNEL 1
33+
34+
VCNL4000 proximitySensor;
35+
bool sensorDetected = true;
36+
37+
void setup()
38+
{
39+
Serial.begin(9600);
40+
Cayenne.begin(username, password, clientID);
41+
if (!proximitySensor.begin())
42+
{
43+
CAYENNE_LOG("No sensor detected");
44+
sensorDetected = false;
45+
}
46+
}
47+
48+
void loop()
49+
{
50+
Cayenne.loop();
51+
}
52+
53+
// This function is called at intervals to send luminosity data to Cayenne.
54+
CAYENNE_OUT(VIRTUAL_CHANNEL)
55+
{
56+
if (sensorDetected)
57+
{
58+
Cayenne.luxWrite(VIRTUAL_CHANNEL, proximitySensor.getLux());
59+
}
60+
else
61+
{
62+
CAYENNE_LOG("No sensor detected");
63+
}
64+
}

0 commit comments

Comments
 (0)