I left out all of the superfluous invalid library stuff since my libraries are always a mess and haven’t tackled housekeeping them yet.
Also if I don’t run IDE as administrator, it show an altogether error but that’s ok.
My code worked fine before I had them offline for awhile
Arduino: 1.8.1 (Windows 10), Board: “Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)”
c:\users\pancho\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.3-arduino2\bin../lib/gcc/avr/4.9.2/…/…/…/…/avr/bin/ar.exe: unable to rename ‘core\core.a’; reason: File exists
Multiple libraries were found for “Ethernet.h”
Used: C:\Users\Pancho\Arduino\libraries\Ethernet
Not used: C:\Users\Pancho\Documents\Arduino\libraries\arduino_618742
exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.
code:
#include <CayenneEthernet.h>
#include "CayenneDefines.h"
#include <CayenneTMP102.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>
#include <Wire.h>
char token[] = "";
const int tmp102Address = 0x48;
TMP102 tmpSensor(tmp102Address);
const int address = TSL2561_ADDR_FLOAT;
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(address, 12345);
float voltage0;
float voltage1;
float voltage2;
#define VOLTAGE0 V0
#define VOLTAGE1 V1
#define VOLTAGE2 V2
#define LIGHT_PIN V3
#define TEMPERATURE_PIN V4
#define BUTTON V5
#define RELAY_DIGITAL_PIN 4
void setup()
{
Serial.begin(9600);
Wire.begin();
Cayenne.begin(token);
if (!tsl.begin())
{
CAYENNE_LOG("No TSL2561 detected");
while (1);
}
tsl.enableAutoRange(true);
/* Changing the integration time gives you better sensor resolution (402ms = 16-bit data) */
tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); /* fast but low resolution */
// tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS); /* medium resolution and speed */
// tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS); /* 16-bit data but slowest conversions */
pinMode(RELAY_DIGITAL_PIN, OUTPUT);
}
void loop()
{
Cayenne.run();
int analogValue0 = analogRead(A0);
int analogValue1 = analogRead(A1);
int analogValue2 = analogRead(A2);
int a = 12;
float b = 0.00483398437; // 5V/1024=b
voltage0 = analogValue0 * a * b;
voltage1 = analogValue1 * a * b;
voltage2 = analogValue2 * a * b;
delay(500);
}
CAYENNE_OUT(VOLTAGE0)
{
Cayenne.virtualWrite(VOLTAGE0, voltage0);
}
CAYENNE_OUT(VOLTAGE1)
{
Cayenne.virtualWrite(VOLTAGE1, voltage1);
}
CAYENNE_OUT(VOLTAGE2)
{
Cayenne.virtualWrite(VOLTAGE2, voltage2);
}
CAYENNE_OUT(LIGHT_PIN)
{
// Send the command to get luminosity.
sensors_event_t event;
tsl.getEvent(&event);
if (event.light)
{
// Send the value to Cayenne in lux.
Cayenne.luxWrite(LIGHT_PIN, event.light);
}
else
{
/* If event.light = 0 lux the sensor is probably saturated
and no reliable data could be generated! */
CAYENNE_LOG("Sensor overload");
}
}
CAYENNE_OUT(TEMPERATURE_PIN)
{
// This command writes the temperature in Celsius to the Virtual Pin.
//Cayenne.celsiusWrite(VIRTUAL_PIN, tmpSensor.getCelsius());
// To send the temperature in Fahrenheit or Kelvin use the corresponding code below.
Cayenne.fahrenheitWrite(TEMPERATURE_PIN, tmpSensor.getFahrenheit());
//Cayenne.kelvinWrite(VIRTUAL_PIN, tmpSensor.getKelvin());
}
CAYENNE_IN(BUTTON)
{
// get value sent from dashboard
int currentValue = getValue.asInt(); // 0 to 1
// assuming you wire your relay as normally open
if (currentValue == 0) {
digitalWrite(RELAY_DIGITAL_PIN, HIGH);
} else {
digitalWrite(RELAY_DIGITAL_PIN, LOW);
}
}
Thanks.
William