Greetings, Im working on a connected vehicle and would like to trigger the door locks with ifttt. the problem is i cant seem to figure out how to do it using my I2C relay board. if anyone has the time to look over my code and perhaps give me some feedback i would be extremely grateful. The door locks are currently triggered with a app called BLYNK and are called using BLYNK.WRITE I know the code is a bit messy, im a total noob.
//#pragma SPARK_NO_PREPROCESSOR
#include "blynk/blynk.h"
#include "blynk/BlynkSimpleParticle.h"
#include "SparkCorePolledTimer/SparkCorePolledTimer.h"
#include "spark-dallas-temperature/spark-dallas-temperature.h"
#include "OneWire/OneWire.h"
#include "MCP23008-I2C/MCP23008-I2C.h" //I2C STUFF
#define ONE_WIRE_BUS D6 // Data wire is plugged into pin D5 on the particle
#define TEMPERATURE_PRECISION 12 // DS18B20 Thermometer Stuff
//#define lock BLYNK_WRITE(7) // lock doors
//#define unlock BLYNK_WRITE(6) // unlock doors
char auth[] = "a0eb3774535f476a92aa19a0b906f991"; //BLYNK CE3
//char auth[] = "7e4f909b23e94418b41507e855fc3d62"; //BLYNK CE2
OneWire oneWire(ONE_WIRE_BUS); // DS18B20 Thermometer Stuff
DallasTemperature sensors(&oneWire); // DS18B20 Thermometer Stuff
Adafruit_MCP23008 mcp; // I2C STUFF
SparkCorePolledTimer updateTimer(5000); //Create a timer object and set it's timeout in milliseconds
void OnTimer(void); //Prototype for timer callback method
float main, mainRaw, aux, auxRaw, acc, accRaw, light, lightRaw;
int lock(String command);
int unlock(String command);
//defince temp address
DeviceAddress Thermometer1 = { 0x28, 0xFF, 0x44, 0x50, 0x16, 0x15, 0x3, 0xC };
DeviceAddress Thermometer2 = { 0x28, 0xFF, 0xD5, 0x4D, 0x16, 0x15, 0x3, 0xD3 };
DeviceAddress Thermometer3 = { 0x28, 0xFF, 0x2D, 0x37, 0x16, 0x15, 0x3, 0xF8 };
DeviceAddress Thermometer4 = { 0x28, 0xFF, 0x6A, 0x24, 0x16, 0x15, 0x3, 0xF0 };
//DeviceAddress Thermometer5 = { 0x28, 0xFF, 0xF5, 0x4F, 0x16, 0x15, 0x3, 0x2C };
// define temp bit resolution ie: int, float, double
double InTempC = -1;
double Temp1 = -1;
double Temp2 = -1;
double Temp3 = -1;
double Temp4 = -1;
//double Temp5 = -1;
void update18B20Temp(DeviceAddress deviceAddress, double &tempC);
//end temp stuff
//setupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetup
void setup(){
Serial.begin(9600);
Blynk.begin(auth); // BLYNK initialization
updateTimer.SetCallback(OnTimer);
Particle.function("lock", lock);
Particle.function("unlock", unlock);
sensors.begin(); // DS18B20 initialization
sensors.setResolution(Thermometer1, TEMPERATURE_PRECISION);
sensors.setResolution(Thermometer2, TEMPERATURE_PRECISION);
sensors.setResolution(Thermometer3, TEMPERATURE_PRECISION);
sensors.setResolution(Thermometer4, TEMPERATURE_PRECISION);
// sensors.setResolution(Thermometer5, TEMPERATURE_PRECISION);
pinMode(A0, INPUT); //
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A5, INPUT);
pinmode(lock, OUTPUT);
pinmode(unlock, OUTPUT);
// I2C STUFF
mcp.begin(); // use default address 0
mcp.pinMode(0, OUTPUT);
mcp.pinMode(1, OUTPUT);
mcp.pinMode(2, OUTPUT);
mcp.pinMode(3, OUTPUT);
mcp.pinMode(4, OUTPUT);
mcp.pinMode(5, OUTPUT);
mcp.pinMode(6, OUTPUT);
mcp.pinMode(7, OUTPUT);
// END I2C STUFF
}// END VOID SETUP BUT WHAT ABOUT I2C CODE BELOW BEFORE LOOP
// BLYNY WRITE NEEDS TO BE ABOVE LOOP BUT NOT IN SETUP LIKE THIS
// I2C STUFF
BLYNK_WRITE(0) {
if (param.asInt()) {
mcp.digitalWrite(0, HIGH);
delay(3000);
} else {
mcp.digitalWrite(0, LOW);}}
BLYNK_WRITE(1) {
if (param.asInt()) {
mcp.digitalWrite(1, HIGH);
} else {
mcp.digitalWrite(1, LOW);}}
BLYNK_WRITE(2) {
if (param.asInt()) {
mcp.digitalWrite(2, HIGH);
} else {
mcp.digitalWrite(2, LOW);}}
BLYNK_WRITE(3) {
if (param.asInt()) {
mcp.digitalWrite(3, HIGH);
} else {
mcp.digitalWrite(3, LOW);}}
BLYNK_WRITE(4) {
if (param.asInt()) {
mcp.digitalWrite(4, HIGH);
} else {
mcp.digitalWrite(4, LOW);}}
BLYNK_WRITE(5) {
if (param.asInt()) {
mcp.digitalWrite(5, HIGH);
} else {
mcp.digitalWrite(5, LOW);}}
BLYNK_WRITE(6) {
if (param.asInt()) {
mcp.digitalWrite(6, HIGH);
delay(500);
mcp.digitalWrite(6, LOW);
delay(500);
mcp.digitalWrite(6, HIGH);
delay(500);
} else {
mcp.digitalWrite(6, LOW);}}
BLYNK_WRITE(7) {
if (param.asInt()) {
mcp.digitalWrite(7, HIGH);
delay(500);
mcp.digitalWrite(7, LOW);
delay(500);
mcp.digitalWrite(7, HIGH);
delay(500);
} else {
mcp.digitalWrite(7, LOW);}}
//I2C STUFF
//looplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooploop//looplooplooplooplooplooploopl
void loop()
{
Blynk.run();
updateTimer.Update();
}
void OnTimer(void) { //Handler for the timer, will be called automatically
// DS18B20
sensors.requestTemperatures();
update18B20Temp(Thermometer1, InTempC);
Temp1 = (InTempC * 9)/5 + 32;
update18B20Temp(Thermometer2, InTempC);
Temp2 = (InTempC * 9)/5 + 31.33;
update18B20Temp(Thermometer3, InTempC);
Temp3 = (InTempC * 9)/5 + 31.67;
update18B20Temp(Thermometer4, InTempC);
Temp4 = (InTempC * 9)/5 + 32;
// update18B20Temp(Thermometer5, InTempC);
// Temp5 = (InTempC * 9)/5 + 32.12;
//delay(5000); // READ DELAY - TOOK THIS OUT AND IT GOT JUMPY WITH -127'S C AND 196'S F
updateTimer.Update(); // new stuff
}
void update18B20Temp(DeviceAddress deviceAddress, double &tempC)
{
tempC = sensors.getTempC(deviceAddress);
// read temperature and discard reading between 150 and -30
if ( Temp1 < 150 && Temp1 > -30) {
Blynk.virtualWrite(21, Temp1);
}
if ( Temp2 < 150 && Temp2 > -30) {
Blynk.virtualWrite(22, Temp2);
}
if ( Temp3 < 150 && Temp3 > -30) {
Blynk.virtualWrite(23, Temp3);
}
if ( Temp4 < 150 && Temp4 > -30) {
Blynk.virtualWrite(24, Temp4);
}
//if ( Temp5 < 150 && Temp5 > -30) {
// Blynk.virtualWrite(25, Temp5);
//}
// read analog ports
mainRaw = analogRead(A0);
auxRaw = analogRead(A1);
accRaw = analogRead(A2);
lightRaw = analogRead(A5);
// map analog input scale output
main = map(mainRaw, 0, 4096, 0, 1865);
aux = map(auxRaw, 0, 4096, 0, 1865);
acc = map(accRaw, 0, 4096, 0, 1865);
light = map(lightRaw, 0, 4050, 1100, 1500);
// correct display decimal place
main = (main / 100);
aux = (aux / 100);
acc = (acc / 100);
light = (light / 100);
Blynk.virtualWrite(10, main);
Blynk.virtualWrite(11, aux);
Blynk.virtualWrite(12, acc);
Blynk.virtualWrite(15, light);
int lock(String command)
{
// look for the matching argument "coffee" <-- max of 64 characters long
if(command == "lock")
{
//things you want it to do
BLYNK_WRITE(7);
//Returns the value "1" if it was successful
return 1;
}
else return -1;
}
int unlock(String command)
{
// look for the matching argument "coffee" <-- max of 64 characters long
if(command == "unlock")
{
//things you want it to do
BLYNK_WRITE(6);
//Returns the value "1" if it was successful
return 1;
}
else return -1;
}
error logs
In file included from blynk/BlynkParticle.h:16:0,
from blynk/BlynkSimpleParticle.h:14,
from blynk/blynk.h:2,
from cruisecontrolce2.cpp:2:
blynk/BlynkApiParticle.h:78:6: warning: #warning "analogInputToDigitalPin not defined => Named analog pins will not work" [-Wcpp]
#warning "analogInputToDigitalPin not defined => Named analog pins will not work"
^
cruisecontrolce2.cpp: In function 'void setup()':
cruisecontrolce2.cpp:67:21: error: 'pinmode' was not declared in this scope
pinmode(lock, OUTPUT);
^
cruisecontrolce2.cpp: In function 'void update18B20Temp(uint8_t*, double&)':
cruisecontrolce2.cpp:216:1: error: a function-definition is not allowed here before '{' token
{
^
cruisecontrolce2.cpp:241:1: error: expected '}' at end of input
}
^
make[1]: *** [../build/target/user/platform-6cruisecontrolce2.o] Error 1
make: *** [user] Error 2
Error: Could not compile. Please review your code.