Now that you've got a graphing weather device using IO, you can add an OLED feather so you can see network status, IP address, and the latest measurements!
Plug the OLED FeatherWing on top of your Feather, and check out our guide to get set up and test it! Once you've verified that the OLED works, you can use this new code. Use the same config.h
file from the previous section, just replace the 'main' tab of code:
This is just the main code, and does not include the config.h - use the same config.h you had from the previous working demo!
// Adafruit IO Temperature & Humidity Example // Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-temperature-and-humidity // // Adafruit invests time and resources providing this open source code. // Please support Adafruit and open source hardware by purchasing // products from Adafruit! // // Written by Todd Treece for Adafruit Industries // Copyright (c) 2016-2017 Adafruit Industries // Licensed under the MIT license. // // All text above must be included in any redistribution. /************************** Configuration ***********************************/ // edit the config.h tab and enter your Adafruit IO credentials // and any additional configuration needed for WiFi, cellular, // or ethernet clients. #include "config.h" /************************ Example Starts Here *******************************/ #include <Adafruit_Sensor.h> #include <DHT.h> #include <DHT_U.h> #include <Adafruit_SSD1306.h> // oled display Adafruit_SSD1306 oled = Adafruit_SSD1306(128, 32, &Wire); // pin connected to DH22 data line #define DATA_PIN 2 // create DHT22 instance DHT_Unified dht(DATA_PIN, DHT22); // set up the 'temperature' and 'humidity' feeds AdafruitIO_Feed *temperature = io.feed("temperature"); AdafruitIO_Feed *humidity = io.feed("humidity"); void setup() { oled.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) oled.display(); // start the serial connection Serial.begin(115200); // wait for serial monitor to open while(! Serial); // initialize dht22 dht.begin(); // connect to io.adafruit.com Serial.print("Connecting to Adafruit IO"); io.connect(); // wait for a connection while(io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } // we are connected Serial.println(); Serial.println(io.statusText()); // text display tests oled.setTextSize(1); oled.setTextColor(WHITE); } void loop() { // io.run(); is required for all sketches. // it should always be present at the top of your loop // function. it keeps the client connected to // io.adafruit.com, and processes any incoming data. io.run(); sensors_event_t event; dht.temperature().getEvent(&event); float celsius = event.temperature; float fahrenheit = (celsius * 1.8) + 32; Serial.print("celsius: "); Serial.print(celsius); Serial.println("C"); Serial.print("fahrenheit: "); Serial.print(fahrenheit); Serial.println("F"); // save fahrenheit (or celsius) to Adafruit IO temperature->save(fahrenheit); dht.humidity().getEvent(&event); Serial.print("humidity: "); Serial.print(event.relative_humidity); Serial.println("%"); // save humidity to Adafruit IO humidity->save(event.relative_humidity); // print it to the OLED oled.clearDisplay(); oled.setCursor(0,0); oled.print("SSID: "); oled.println(WIFI_SSID); oled.print("IP: "); oled.println(WiFi.localIP()); oled.print("Temp: "); oled.print(fahrenheit,0); oled.print(" *F "); oled.print("Hum: "); oled.print(event.relative_humidity,0); oled.println(" %"); oled.print("IO Status: "); aio_status_t aio_status = io.status(); Serial.print("Status: "); Serial.println(aio_status); switch (aio_status) { case AIO_IDLE: oled.println("IDLE"); break; case AIO_DISCONNECTED: case AIO_NET_DISCONNECTED: oled.println("DISCONNECT"); break; case AIO_NET_CONNECTED: case AIO_CONNECTED_INSECURE: case AIO_CONNECTED: oled.println("CONNECTED"); break; } oled.display(); // wait 5 seconds (5000 milliseconds == 5 seconds) delay(2000); }
Page last edited March 08, 2024
Text editor powered by tinymce.