skizziks_53

reddit/arduino/v2_2/24/2019

Feb 24th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.51 KB | None | 0 0
  1. /*
  2.    If you want help online, it is a good idea to list the sources for any non-standard Arduino IDE libraries.
  3.    Below is what I found searching for the header file names.
  4. */
  5.  
  6. #include <Adafruit_NeoPixel.h> // Source: https://github.com/adafruit/Adafruit_NeoPixel
  7. #include <Adafruit_TiCoServo.h> // Source: https://github.com/adafruit/Adafruit_TiCoServo
  8. #include <RtcDS3231.h> // Source: https://github.com/Makuna/Rtc
  9. #include <SoftwareSerial.h> // Source: standard IDE library
  10. // #include "SSD1306AsciiWire.h" <--------------------------------------- this was wrong
  11. #include <SSD1306AsciiWire.h> // Source: https://github.com/greiman/SSD1306Ascii
  12. // #include "WiFiEsp.h" <------------------------------------------------ this was wrong
  13. #include <WiFiEsp.h> // Source: https://github.com/bportaluri/WiFiEsp
  14. #include <Wire.h> // Source: standard IDE library
  15.  
  16. const byte neoPixels = 24;
  17. const byte neoPin = 10;
  18.  
  19. char ssid[] = "kjellnet";
  20. char pass[] = "metalotusinbingowebb";
  21.  
  22. const char server[] = "thingspeak.com";
  23. const char thingspeakAPIKey = "G9G9G9G9G9G9G9G9";
  24. const int postingInterval = 30;
  25.  
  26. SSD1306AsciiWire oled;
  27.  
  28. Adafruit_NeoPixel ring = Adafruit_NeoPixel(neoPixels, neoPin, NEO_GRB);
  29.  
  30. RtcDS3231<TwoWire> rtcModule(Wire);
  31.  
  32. WiFiEspClient client;
  33.  
  34. Adafruit_TiCoServo servo;
  35.  
  36. SoftwareSerial Serial1(6, 7);
  37.  
  38. int status = WL_IDLE_STATUS;
  39.  
  40. int hours;
  41. int minutes;
  42. int seconds;
  43. float temp;
  44.  
  45. int oldMinute;
  46. char lastSent[20];
  47.  
  48. // ################################################################################
  49. void setup() {
  50.  
  51.   Wire.begin();
  52.  
  53.   oled.begin(&Adafruit128x64, 0x3C);
  54.   oled.setFont(utf8font10x16);
  55.   oled.clear();
  56.   oled.print("starting");
  57.  
  58.   Serial.begin(115200);
  59.   servo.attach(9);
  60.  
  61.   rtcModule.Begin();
  62.  
  63.   ring.begin();
  64.   ring.setBrightness(100);
  65.   ring.show();
  66.  
  67.   oled.print(".");
  68.  
  69.   Serial.begin(9600);
  70.  
  71.   WiFi.init(&Serial1);
  72.  
  73.   oled.print(".");
  74.  
  75.   if (WiFi.status() == WL_NO_SHIELD) {
  76.     Serial.print("WiFi shield not present");
  77.  
  78.     // while (true); <----------------------------------------------------- what is this supposed to be doing?
  79.   }
  80.  
  81.  
  82.   // while (status != WL_CONNECTED); { <----------------------------------- this line has a semicolon in it, which is wrong.
  83.   while (status != WL_CONNECTED) {
  84.     Serial.print("Attempting to connect to SSID: ");
  85.     Serial.println(ssid);
  86.     status = WiFi.begin(ssid, pass);
  87.  
  88.     oled.print(".");
  89.   }
  90.   printWiFiStatus();
  91.   printOled();
  92.   updateTemp();
  93. }
  94.  
  95. // ################################################################################
  96. void loop() {
  97.  
  98.   updateTime();
  99.   updateNeoRing();
  100.  
  101.   if (seconds % postingInterval == 0) {
  102.     updateTemp();
  103.     sendThingspeak(temp);
  104.   }
  105.  
  106.   client.flush();
  107.   client.stop();
  108.   delay(500);
  109. }
  110. // ################################################################################
  111. void sendThingspeak(float value) {
  112.   if (client.connectSSL(server, 443)) {
  113.     Serial.println("Connected to server."); // <-------------------------------------- this was ----> Serial.printIn("Connected to server.");
  114.     client.println("Get /uplade?api_key=" + String(thingspeakAPIKey) + "%field1=" + String(value) + " HTTP/1.1"); // <-------------------------------------- this was ----> client.printIn( ,,,)
  115.     client.println("Host: api.thingspeak.com"); // <-------------------------------------- this was ----> client.printIn( ,,,)
  116.     client.println("Connection: close"); // <-------------------------------------- this was ----> client.printIn( ,,,)
  117.     client.println(); // <-------------------------------------- this was ----> client.printIn( ,,,)
  118.     Serial.println("Sent to server."); // <-------------------------------------- this was ----> Serial.printIn( ,,,)
  119.  
  120.     sprintf(lastSent, "Sent: %02d:%02d:%02d:", hours, minutes, seconds);
  121.  
  122.     printOled();
  123.     delay(1000);
  124.   }
  125. }
  126. // ################################################################################
  127. void updateTime() {
  128.   oldMinute = minutes;
  129.   RtcDateTime now = rtcModule.GetDateTime(); // <------------------------------------ the parentheses and semicolon was missing here
  130.  
  131.   hours = now.Hour();
  132.   minutes = now.Minute();
  133.   seconds = now.Second();
  134.  
  135.   if (minutes != oldMinute) {
  136.     printOled();
  137.   }
  138.  
  139.   updateNeoRing();
  140. }
  141. // ################################################################################
  142. void printOled() {
  143.  
  144.   oled.clear();
  145.   //oled.setFont(lcdnums14x14); // <---------------------------- There is no font named lcdnums14x14 , that is why it causes an error.
  146.   oled.setFont(fixednums7x15); // <------------------------------ There is a font named fixednums7x15. This line does not cause an error.
  147.  
  148.   oled.setCol(20);
  149.   char timeString[6]; // <--------------------------------------- This said "chat", I guess it is supposed to be "char"? -------> chat timeString[6];
  150.   sprintf(timeString, "%02d:%02d:", hours, minutes);
  151.   oled.println(timeString); // <--------------------------------- This said "oled.printIn(timeString);" ...... print-LINE, println, not printIn
  152.  
  153.   oled.setFont(utf8font10x16); // <----------------------------- This said urf8font10x16 (second letter was wrong).
  154.   oled.setRow(6);
  155.   oled.setCol(100);
  156.   oled.print(int(temp));
  157.   oled.write(176);
  158.  
  159.   oled.setCol(0);
  160.   oled.print(lastSent);
  161. }
  162. // ################################################################################
  163. void updateNeoRing() {
  164.  
  165.   int neoMin = round(minutes / 2.5 - 1);
  166.   int neoHour = hours % 12 * 2 - 1;
  167.  
  168.   int blue;
  169.   int red;
  170.  
  171.   for (int i = 0; i <= neoPixels; i++) {
  172.     if (i <= neoMin) {
  173.       blue = 255; // <-------------------------------------- this line was ----> blue 255;  (no equals sign)
  174.     } else {
  175.       blue = 0;
  176.     } // <------------------------------------------------- missing closing curly brace here.
  177.     if (i <= neoHour) {
  178.       red = 255;
  179.     } else {
  180.       red = 0;
  181.     }
  182.  
  183.     ring.setPixelColor(i, ring.Color(red, 0 , blue));
  184.   }
  185.  
  186.   ring.show();
  187. }
  188. // } <---------------------------------------------------------------------------------------------------- this is a stray closing bracket, that did not match up with any other function
  189. // } <---------------------------------------------------------------------------------------------------- this is a stray closing bracket, that did not match up with any other function
  190.  
  191. // ################################################################################ --------------------- your last two functions here were declared -inside- updateNeoRing()
  192. void updateTemp() {
  193.   RtcTemperature rtcTemp = rtcModule.GetTemperature();
  194.  
  195.   //temp = rtcTemp.AsFloat(); <------------------------- missing type declaration for "temp"
  196.   //                                                     there is no method named AsFloat().
  197.   //                                                     in the RtcTemperature.h file, there are two methods named AsFloatDegF() and float AsFloatDegC()
  198.   float temp = rtcTemp.AsFloatDegF(); // <-------------- this line works.
  199.  
  200.   int tempPointer = map(temp, 18, 28, 30, 140);
  201.  
  202.   servo.write(tempPointer);
  203. }
  204. // ################################################################################
  205. void printWiFiStatus() {
  206.  
  207.   Serial.print("SSID: ");
  208.   Serial.println(WiFi.SSID()); // <-------------------------------------- this was ----> Serial.printIn(WiFi.SSID());
  209.  
  210.   IPAddress ip = WiFi.localIP(); // <------------------------------------ this was ----> IPAdress (only had one d in it)
  211.  
  212.   Serial.print("IP Adress: ");
  213.   Serial.println(ip); // <-------------------------------------- this was ----> Serial.printIn(ip);
  214. }
Add Comment
Please, Sign In to add comment