Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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>
- float voltage0;
- float voltage1;
- float voltage2;
- #define VOLTAGE0 V0
- #define VOLTAGE1 V1
- #define VOLTAGE2 V2
- Adafruit_ILI9341 tft = Adafruit_ILI9341(PLDuino::LCD_CS, PLDuino::LCD_DC);
- PLDTouch touch(PLDuino::TOUCH_CS, PLDuino::TOUCH_IRQ);
- // Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
- char token[] = "b75dykxq07";
- // Your network name and password.
- char ssid[] = "free";
- char password[] = "zzZw23521041";
- // 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);
- // while(touch.dataAvailable()) touch.read();
- // while(!touch.dataAvailable()); touch.read();
- // tft.fillScreen(ILI9341_BLACK);
- }
- 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);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement