Since the start of class we’ve been working with LEDs. LED stands for Light Emitting Diode. In this experiment we are going to work with an OLED display. OLED stands for Organic Light Emitting Diode.
Unless otherwise noted all images are under the Attribution-ShareAlike Creative Commons license by Adafruit.
The hardest part of this lab might be soldering on the headers onto the feather board. If you need help soldering let us know.
ture](pics/neopixelSmall_bb.png)
First you need to download the library at Download Adafruit_FeatherOLED from github. Unzip the file you download and move the resulting folder to your Arduino/libraries folder.
Here is the code:
// Simple OLED
//
// 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 Adafruit Industries
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_FeatherOLED.h>
Adafruit_FeatherOLED oled = Adafruit_FeatherOLED();
// integer variable to hold current counter value
int count = 0;
int down = 10000;
void setup()
{
Serial.begin(115200);
oled.init();
}
void loop()
{
// clear the current count
oled.clearDisplay();
oled.setCursor(0,0);
// print the count value to the OLED
oled.print("count: ");
oled.println(count);
// move 10 pixels down
oled.setCursor(0,10);
oled.print("Time remaining: ");
oled.println(down);
// update the display with the new count
oled.display();
// increment counters by 1
count++;
down--;
// delay 1 second
delay(1000);
}
Just demo the completed project with all the addons you want
Can you create a device that repeatedly displays Don’t worry for 2 seconds and then Be Happy! for another 2 seconds?
Can you do it in a different larger font? You do this in two steps. First you include the library using something like #include <Fonts/FreeSansBold9pt7b.h>
, which unsurprisingly loads a 9 point bold Sans font. Second, you set the display font using something like oled.setFont(&FreeSansBold9pt7b);
. For a list of all the fonts see This Adafruit page
Can you do the above using only one oled.display();
line in your loop? (Since there are only two states, the Don’t worry state and the Be happy state I only need to use 2 numbers, 0 and 1–that’s a hint)
So I was thinking our board (the mighty esp8266 Feather Huzzah) along with the OLED feather would make a nice micro Amazon Kindle. So I wrote this code to display a book.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_FeatherOLED.h>
Adafruit_FeatherOLED oled = Adafruit_FeatherOLED();
// integer variable to hold current counter value
int count = 0;
int down = 10000;
void setup()
{
Serial.begin(115200);
oled.init();
}
char* story[]={"When", "I", "wrote", "the", "following", "pages,", "or",
"rather", "the", "bulk", "of", "them,", "I", "lived", "alone,", "in", "the", "woods,",
"a", "mile", "from", "any", "neighbor,", "in", "a", "house", "which",
"I", "had", "built", "myself"};
void loop()
{
for (int i = 0; i< 31; i++) {
oled.clearDisplay();
oled.setCursor(0,15);
oled.println(story[i]);
oled.display();
delay(500);
}
delay(1000);
}
Try it out! (5xp if you know the book and the author). Anyway I got tired of typing in the book.
Even though our OLED is mounted on all the pins, it actually only uses 2:
That means we can connect the usual things to our esp8266 as long as we don’t use pins 4 and 5. On the side of the OLED are three buttons which are optionally available for use. These are connected to pins 2, 16, and 0:
If we are not using those buttons we can use those pins for other things.
Let’s keep the OLED connected but temporarily switch to the temperature/humidity sensor included in the kit.
It is wired up this way (again, no need to remove the OLED):
We need to install 2 libraries
Download the sensor library zip file, unzip it, rename the folder Adafruit_Sensor
and move the folder to your Arduino/libraries
folder.
Download the temperature sensor library zip file, unzip it, rename the folder DHT
and move the folder to your Arduino/libraries
folder.
When you loaded the libraries, you also installed several example programs. In the Arduino IDE, under the file menu select examples/DHT sample library/DHTtester
You may want to change Serial.begin(9600)
to Serial.begin(115200)
. When you upload that program you should see in the serial monitor:
Can you create a device that displays the temperature and humidity on the OLED display?
Can you add another sensor so that your device will also display whether it is sunny or cloudy (in addition to temperature and humidity)? Here are some pictures using previous hardware
Remember those Magic Eight Balls?
If not, check out this Wikipedia page
We would like to implement a Magic 8 Ball using our OLED screen.
As part of your solution you may need to generate a random number. To do so you can use the built-in function random
that does so. Here is some example code that generates random integers from 0 up to but not including 10:
void setup() {
Serial.begin(115200);
}
void loop() {
int i = random(10);
Serial.println(i);
delay(1000);
}
You device should generate slogans (negative, positive, whatever) when a user presses a button. Remember that we have three buttons on our OLED that we can use.
Can a button press on your device send a 8 Ball text message to your phone?
I have 2 dogs in my apartment. I would like a device that would text me when it gets too hot in the apartment for them. For testing purposes you can set the temperature low and use your hand to heat up the sensor.