Create a gist now

Instantly share code, notes, and snippets.

@wmontg5988 /PLduino3
Last active Jul 12, 2017

What would you like to do?
Sketch for Digital Logger WiFi plc Arduino Mega base. Credit @Kreggly at cayenne.mydevices.com for starting me out and showing me the way
/*
Cayenne ESP8266 Shield WiFi Example
Adapted from Blynk's ESP8266_Shield_HardSer Example
This sketch connects to the Cayenne server using an ESP8266 WiFi module as a shield connected
via a hardware serial to an Arduino.
You should install the ESP8266HardwareSerial.zip library via the Arduino IDE (Sketch->Include Library->Add .ZIP Library)
from the Cayenne extras/libraries folder (e.g. My Documents\Arduino\libraries\Cayenne\extras\libraries) to compile this example.
NOTE: Ensure a stable serial connection to ESP8266!
Firmware version 1.0.0 (AT v0.22) or later is needed.
You can change ESP baud rate. Connect to AT console and call:
AT+UART_DEF=115200,8,1,0,0
For Cayenne Dashboard widgets using digital or analog pins this sketch will automatically
send data on those pins to the Cayenne server. If the widgets use Virtual Channels, data
should be sent to those channels using virtualWrites. Examples for sending and receiving
Virtual Channel data are under the Basics folder.
*/
//#define CAYENNE_DEBUG // Uncomment to show debug messages
//#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneESP8266Shield.h>
#include <PLDuino.h>
#include <PLDuinoGUI.h>
#include <TMRpcm_PLDuino.h>
#include <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <PLDuino.h>
#include <PLDTouch.h>
#include <PLDuinoGUI.h>
#include <using_namespace_PLDuinoGUI.h>
#include <DS3232RTC.h>
#include <TimeLib.h>
#include <Wire.h>
#include <avr/io.h>
Adafruit_ILI9341 tft = Adafruit_ILI9341(PLDuino::LCD_CS, PLDuino::LCD_DC);
PLDTouch touch(PLDuino::TOUCH_CS, PLDuino::TOUCH_IRQ);
Button btnVoltage("Front Solar", ILI9341_YELLOW, ILI9341_BLACK);
Button btnVoltage1("Back Solar", ILI9341_BLUE, ILI9341_BLACK);
Button btnVoltage2("Back Solar", ILI9341_GREEN, ILI9341_BLACK);
Button btnVoltage3("Back Solar", ILI9341_RED, ILI9341_BLACK);
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "********";
// Your network name and password.
char ssid[] = "******";
char password[] = "********";
// Set ESP8266 Serial object
#define EspSerial Serial2
ESP8266 wifi(EspSerial);
void setup()
{
PLDuino::init();
PLDuino::enableLCD();
PLDuino::enableESP();
tft.begin();
tft.setRotation(3);
touch. init(1);
Serial.begin(9600);
delay(100);
// Set ESP8266 baud rate
EspSerial.begin(115200);
delay(100);
Cayenne.begin(token, wifi, ssid, password);
btnVoltage.setPositionAndSize(01, 01, 100, 75);
btnVoltage.draw(tft);
btnVoltage1.setPositionAndSize(01, 75, 100, 75);
btnVoltage1.draw(tft);
btnVoltage2.setPositionAndSize(01, 150, 100, 75);
btnVoltage2.draw(tft);
btnVoltage3.setPositionAndSize(100, 1, 100, 75);
btnVoltage3.draw(tft);
}
void loop()
{
Cayenne.run();
}
CAYENNE_OUT(V1)
{
int adcVal = analogRead(A0);
float adcVoltage = 10.0*adcVal/1024;
Cayenne.virtualWrite(V1,adcVoltage);
btnVoltage.setText(String(adcVoltage));
btnVoltage.draw(tft);
}
CAYENNE_OUT(V2)
{
int adcVal1 = analogRead(A1);
float adcVoltage1 = 10.0*adcVal1/1024;
Cayenne.virtualWrite(V2,adcVoltage1);
btnVoltage1.setText(String(adcVoltage1));
btnVoltage1.draw(tft);
}
CAYENNE_OUT(V3)
{
int adcVal2 = analogRead(A2);
float adcVoltage2 = 10.0*adcVal2/1024;
Cayenne.virtualWrite(V3,adcVoltage2);
btnVoltage2.setText(String(adcVoltage2));
btnVoltage2.draw(tft);
}
CAYENNE_OUT(V4)
{
int adcVal3 = analogRead(A3);
float adcVoltage3 = 10.0*adcVal3/1024;
Cayenne.virtualWrite(V4,adcVoltage3);
btnVoltage3.setText(String(adcVoltage3));
btnVoltage3.draw(tft);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment