Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. /*
  2. Cayenne ESP8266 Shield WiFi Example
  3. Adapted from Blynk's ESP8266_Shield_HardSer Example
  4.  
  5. This sketch connects to the Cayenne server using an ESP8266 WiFi module as a shield connected
  6. via a hardware serial to an Arduino.
  7.  
  8. You should install the ESP8266HardwareSerial.zip library via the Arduino IDE (Sketch->Include Library->Add .ZIP Library)
  9. from the Cayenne extras/libraries folder (e.g. My Documents\Arduino\libraries\Cayenne\extras\libraries) to compile this example.
  10.  
  11. NOTE: Ensure a stable serial connection to ESP8266!
  12. Firmware version 1.0.0 (AT v0.22) or later is needed.
  13. You can change ESP baud rate. Connect to AT console and call:
  14. AT+UART_DEF=115200,8,1,0,0
  15.  
  16. For Cayenne Dashboard widgets using digital or analog pins this sketch will automatically
  17. send data on those pins to the Cayenne server. If the widgets use Virtual Channels, data
  18. should be sent to those channels using virtualWrites. Examples for sending and receiving
  19. Virtual Channel data are under the Basics folder.
  20. */
  21.  
  22. //#define CAYENNE_DEBUG // Uncomment to show debug messages
  23. #define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
  24. #include <CayenneESP8266Shield.h>
  25. #include <PLDuino.h>
  26. #include <PLDuinoGUI.h>
  27. #include <TMRpcm_PLDuino.h>
  28. #include <SPI.h>
  29. #include <SD.h>
  30. #include <Adafruit_GFX.h>
  31. #include <Adafruit_ILI9341.h>
  32. #include <PLDuino.h>
  33. #include <PLDTouch.h>
  34. #include <PLDuinoGUI.h>
  35. #include <using_namespace_PLDuinoGUI.h>
  36. #include <DS3232RTC.h>
  37. #include <TimeLib.h>
  38. #include <Wire.h>
  39. #include <avr/io.h>
  40.  
  41. float voltage0;
  42. float voltage1;
  43. float voltage2;
  44.  
  45. #define VOLTAGE0 V0
  46. #define VOLTAGE1 V1
  47. #define VOLTAGE2 V2
  48.  
  49. Adafruit_ILI9341 tft = Adafruit_ILI9341(PLDuino::LCD_CS, PLDuino::LCD_DC);
  50. PLDTouch touch(PLDuino::TOUCH_CS, PLDuino::TOUCH_IRQ);
  51.  
  52. // Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
  53. char token[] = "b75dykxq07";
  54. // Your network name and password.
  55. char ssid[] = "free";
  56. char password[] = "zzZw23521041";
  57.  
  58. // Set ESP8266 Serial object
  59. #define EspSerial Serial2
  60. ESP8266 wifi(EspSerial);
  61.  
  62. void setup()
  63. {
  64. PLDuino::init();
  65. PLDuino::enableLCD();
  66. PLDuino::enableESP();
  67. tft.begin();
  68. tft.setRotation(3);
  69. touch.init(1);
  70.  
  71. Serial.begin(9600);
  72. delay(100);
  73. // Set ESP8266 baud rate
  74. EspSerial.begin(115200);
  75. delay(100);
  76.  
  77. Cayenne.begin(token, wifi, ssid, password);
  78.  
  79. // while(touch.dataAvailable()) touch.read();
  80. // while(!touch.dataAvailable()); touch.read();
  81. // tft.fillScreen(ILI9341_BLACK);
  82.  
  83. }
  84.  
  85. void loop()
  86. {
  87. Cayenne.run();
  88.  
  89. int analogValue0 = analogRead(A0);
  90. int analogValue1 = analogRead(A1);
  91. int analogValue2 = analogRead(A2);
  92.  
  93. int a = 12;
  94. float b = 0.00483398437; // 5V/1024=b
  95.  
  96. voltage0 = analogValue0 * a * b;
  97. voltage1 = analogValue1 * a * b;
  98. voltage2 = analogValue2 * a * b;
  99. delay(500);
  100. }
  101.  
  102. CAYENNE_OUT(VOLTAGE0)
  103. {
  104. Cayenne.virtualWrite(VOLTAGE0, voltage0);
  105. }
  106. CAYENNE_OUT(VOLTAGE1)
  107. {
  108. Cayenne.virtualWrite(VOLTAGE1, voltage1);
  109. }
  110. CAYENNE_OUT(VOLTAGE2)
  111. {
  112. Cayenne.virtualWrite(VOLTAGE2, voltage2);
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement