IF YOU DO NOT FEEL COMFORTABLE SOLDERING, DO NOT DO THIS PROJECT!
Have you ever wanted to have a display at your door to greet people? Or a shirt that has a display (that with WiFi) you can control from anywhere? Then this is the project for you!
Parts List
- ESP8266 development board (link to one I found on Amazon)
- 5 wires :)
- A breadboard
- Micro USB data cable (do not use a charging cable! If you do, you will not be able to upload anything to the ESP8266!)
- Adafruit's 0.54 alphanumeric display and backpack (link to white)
- Wire clippers (not required, but helpful)
- soldering iron
- solder
First, go to my other ESP8266 tutorial if you have not worked with an ESP8266 in the Arduino IDE yet to install the IDE and the driver and run the "Blink" program. Don't worry, we'll wait for you.
Now for the real deal. First, why don't you just go over to Adafruit's tutorial on how to set up the backpack. We're waiting... (I can see the smoke from your soldering. Be careful!)
Done testing and soldering your backpack? If not, try tweaking the file Adafruit_LEDBackpack.cpp like this:
See where it says "Wire.begin();" in the Adafruit_LEDBackpack::begin function? Replace that with "Wire.begin(4, 5); // SDA is GPIO4 (D2), SCL is GPIO5 (D1)". And yes, SDA (or D on the backpack) should be hooked up to D2, and SCL (or C on the backpack) should be hooked up to D1 in the circuit.
See where it says "Wire.begin();" in the Adafruit_LEDBackpack::begin function? Replace that with "Wire.begin(4, 5); // SDA is GPIO4 (D2), SCL is GPIO5 (D1)". And yes, SDA (or D on the backpack) should be hooked up to D2, and SCL (or C on the backpack) should be hooked up to D1 in the circuit.
Okay. Finally for the project. First, go to Adafruit IO and make an Adafruit account.
Then log in to Adafruit IO and create a dashboard. (go into Your Dashboards->Create Dashboard) and call it whatever you want. (maybe LED Display or something)
Then add a Text Block hooked up to feed "test-text-block". (press the blue "+" button and under "A text block can be used to send data as well as view data." there is a blue "Create" button. Click that. After you create it, do you see the feed dialog that pops up? See "New Feed Name" then "Create"? Type "test-text-block" into "New Feed Name" then hit "Create". Look for "test-text-block" then "Choose". Click "Choose". Then hit "Next Step". Choose your font size, then hit "Create Block".)
Then log in to Adafruit IO and create a dashboard. (go into Your Dashboards->Create Dashboard) and call it whatever you want. (maybe LED Display or something)
Then add a Text Block hooked up to feed "test-text-block". (press the blue "+" button and under "A text block can be used to send data as well as view data." there is a blue "Create" button. Click that. After you create it, do you see the feed dialog that pops up? See "New Feed Name" then "Create"? Type "test-text-block" into "New Feed Name" then hit "Create". Look for "test-text-block" then "Choose". Click "Choose". Then hit "Next Step". Choose your font size, then hit "Create Block".)
The Circuit:
Vi2c and VCC should be hooked up together on the backpack. I will call the two connected pins "+" in the circuit for simplicity. Keep the same circuit in the tutorial as in the project (+ hooked up to 3V3, - hooked up to GND, D hooked up to D2, and C hooked up to D1).
Vi2c and VCC should be hooked up together on the backpack. I will call the two connected pins "+" in the circuit for simplicity. Keep the same circuit in the tutorial as in the project (+ hooked up to 3V3, - hooked up to GND, D hooked up to D2, and C hooked up to D1).
The Code:
// Demo the quad alphanumeric display LED backpack kit
// scrolls through every character, then scrolls Serial
// input onto the display
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
#include <ESP8266WiFi.h>
#include <Adafruit_MQTT.h>
#include <Adafruit_MQTT_Client.h>
int len;
int serial = 0;
char *strength = "";
// function prototypes
void connect(void);
/****************************** Pins ******************************************/
/************************* WiFi Access Point *********************************/
#define WLAN_SSID "Your-WiFi-Network-Name"
#define WLAN_PASS "Your-WiFi-Network-Password"
/************************* Adafruit.io Setup *********************************/
#define AIO_SERVER "io.adafruit.com"
#define AIO_SERVERPORT 1883
#define AIO_USERNAME "your-adafruit-username"
#define AIO_KEY "your-aio-key"
#define FEED AIO_USERNAME "/feeds/test-text-block"
/************ Global State (you don't need to change this!) ******************/
// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;
// Store the MQTT server, client ID, username, and password in flash memory.
// This is required for using the Adafruit MQTT library.
const char MQTT_SERVER[] PROGMEM = AIO_SERVER;
// Set a unique MQTT client ID using the AIO key + the date and time the sketch
// was compiled (so this should be unique across multiple devices for a user,
// alternatively you can manually set this to a GUID or other random value).
const char MQTT_CLIENTID[] PROGMEM = __TIME__ AIO_USERNAME;
const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME;
const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_CLIENTID, MQTT_USERNAME, MQTT_PASSWORD);
/****************************** Feeds ***************************************/
// Setup a feed called 'lamp' for subscribing to changes.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
const char TEXT_FEED[] PROGMEM = FEED;
Adafruit_MQTT_Subscribe text = Adafruit_MQTT_Subscribe(&mqtt, TEXT_FEED);
// End of Feeds
Adafruit_AlphaNum4 alpha4 = Adafruit_AlphaNum4();
void setup() {
if (serial == 1) {
Serial.begin(9600);
}
alpha4.begin(0x70); // pass in the address
scroll("Bens Shirt", 1);
scroll(" ", 1);
scroll("Connecting to WiFi", 1);
scroll(" ", 1);
WiFi.begin(WLAN_SSID, WLAN_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
alpha4.writeDigitAscii(0, '.');
alpha4.writeDisplay();
}
scroll("Connected", 1);
scroll(" ", 1);
scroll("Signal Strength is ", 1);
checkstrength();
scroll(strength, 1);
scroll(" ", 1);
mqtt.subscribe(&text);
// connect to adafruit io
connect();
scroll("Boot finished", 1);
scroll(" ", 1);
delay(2000);
alpha4.clear();
}
char displaybuffer[4] = {' ', ' ', ' ', ' '};
void loop() {
Adafruit_MQTT_Subscribe *subscription;
// ping adafruit io a few times to make sure we remain connected
if(! mqtt.ping(3)) {
// reconnect to adafruit io
if(! mqtt.connected())
connect();
}
// this is our 'wait for incoming subscription packets' busy subloop
while (subscription = mqtt.readSubscription(1000)) {
// we only care about the lamp events
if (subscription == &text) {
// convert mqtt ascii payload to int
char *value = (char *)text.lastread;
int len = sizeof(value);
scroll(value, 1);
scroll(" ", 1);
scroll(value, 1);
scroll(" ", 1);
}
}
}
void connect() {
scroll("Still booting", 1);
scroll(" ", 1);
if (serial == 1) {
Serial.print(F("Connecting to Adafruit IO... "));
}
int8_t ret;
while ((ret = mqtt.connect()) != 0) {
switch (ret) {
if (serial == 1) {
case 1: Serial.println(F("Wrong protocol")); break;
case 2: Serial.println(F("ID rejected")); break;
case 3: Serial.println(F("Server unavail")); break;
case 4: Serial.println(F("Bad user/pass")); break;
case 5: Serial.println(F("Not authed")); break;
case 6: Serial.println(F("Failed to subscribe")); break;
default: Serial.println(F("Connection failed")); break;
}
}
if(ret >= 0)
mqtt.disconnect();
if (serial == 1) {
Serial.println(F("Retrying connection..."));
}
delay(5000);
}
if (serial == 1) {
Serial.println(F("Adafruit IO Connected!"));
}
}
void scroll(char *data, int iter) {
for (iter; iter > 0; iter--) {
for (int x = 0; x < 140; x++) {
char c = data[x];
if (! isprint(c)) return;
// scroll down display
displaybuffer[0] = displaybuffer[1];
displaybuffer[1] = displaybuffer[2];
displaybuffer[2] = displaybuffer[3];
displaybuffer[3] = c;
// set every digit to the buffer
alpha4.writeDigitAscii(0, displaybuffer[0]);
alpha4.writeDigitAscii(1, displaybuffer[1]);
alpha4.writeDigitAscii(2, displaybuffer[2]);
alpha4.writeDigitAscii(3, displaybuffer[3]);
// write it out!
alpha4.writeDisplay();
delay(500);
}
}
}
void checkstrength()
{
if (WiFi.RSSI() >= -69) {
strength = "Very Good";
return;
}
if (WiFi.RSSI() >= -79) {
strength = "Okay";
return;
}
if (WiFi.RSSI() < -79) {
strength = "Possibly Unreliable";
return;
}
}
// Demo the quad alphanumeric display LED backpack kit
// scrolls through every character, then scrolls Serial
// input onto the display
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
#include <ESP8266WiFi.h>
#include <Adafruit_MQTT.h>
#include <Adafruit_MQTT_Client.h>
int len;
int serial = 0;
char *strength = "";
// function prototypes
void connect(void);
/****************************** Pins ******************************************/
/************************* WiFi Access Point *********************************/
#define WLAN_SSID "Your-WiFi-Network-Name"
#define WLAN_PASS "Your-WiFi-Network-Password"
/************************* Adafruit.io Setup *********************************/
#define AIO_SERVER "io.adafruit.com"
#define AIO_SERVERPORT 1883
#define AIO_USERNAME "your-adafruit-username"
#define AIO_KEY "your-aio-key"
#define FEED AIO_USERNAME "/feeds/test-text-block"
/************ Global State (you don't need to change this!) ******************/
// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;
// Store the MQTT server, client ID, username, and password in flash memory.
// This is required for using the Adafruit MQTT library.
const char MQTT_SERVER[] PROGMEM = AIO_SERVER;
// Set a unique MQTT client ID using the AIO key + the date and time the sketch
// was compiled (so this should be unique across multiple devices for a user,
// alternatively you can manually set this to a GUID or other random value).
const char MQTT_CLIENTID[] PROGMEM = __TIME__ AIO_USERNAME;
const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME;
const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_CLIENTID, MQTT_USERNAME, MQTT_PASSWORD);
/****************************** Feeds ***************************************/
// Setup a feed called 'lamp' for subscribing to changes.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
const char TEXT_FEED[] PROGMEM = FEED;
Adafruit_MQTT_Subscribe text = Adafruit_MQTT_Subscribe(&mqtt, TEXT_FEED);
// End of Feeds
Adafruit_AlphaNum4 alpha4 = Adafruit_AlphaNum4();
void setup() {
if (serial == 1) {
Serial.begin(9600);
}
alpha4.begin(0x70); // pass in the address
scroll("Bens Shirt", 1);
scroll(" ", 1);
scroll("Connecting to WiFi", 1);
scroll(" ", 1);
WiFi.begin(WLAN_SSID, WLAN_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
alpha4.writeDigitAscii(0, '.');
alpha4.writeDisplay();
}
scroll("Connected", 1);
scroll(" ", 1);
scroll("Signal Strength is ", 1);
checkstrength();
scroll(strength, 1);
scroll(" ", 1);
mqtt.subscribe(&text);
// connect to adafruit io
connect();
scroll("Boot finished", 1);
scroll(" ", 1);
delay(2000);
alpha4.clear();
}
char displaybuffer[4] = {' ', ' ', ' ', ' '};
void loop() {
Adafruit_MQTT_Subscribe *subscription;
// ping adafruit io a few times to make sure we remain connected
if(! mqtt.ping(3)) {
// reconnect to adafruit io
if(! mqtt.connected())
connect();
}
// this is our 'wait for incoming subscription packets' busy subloop
while (subscription = mqtt.readSubscription(1000)) {
// we only care about the lamp events
if (subscription == &text) {
// convert mqtt ascii payload to int
char *value = (char *)text.lastread;
int len = sizeof(value);
scroll(value, 1);
scroll(" ", 1);
scroll(value, 1);
scroll(" ", 1);
}
}
}
void connect() {
scroll("Still booting", 1);
scroll(" ", 1);
if (serial == 1) {
Serial.print(F("Connecting to Adafruit IO... "));
}
int8_t ret;
while ((ret = mqtt.connect()) != 0) {
switch (ret) {
if (serial == 1) {
case 1: Serial.println(F("Wrong protocol")); break;
case 2: Serial.println(F("ID rejected")); break;
case 3: Serial.println(F("Server unavail")); break;
case 4: Serial.println(F("Bad user/pass")); break;
case 5: Serial.println(F("Not authed")); break;
case 6: Serial.println(F("Failed to subscribe")); break;
default: Serial.println(F("Connection failed")); break;
}
}
if(ret >= 0)
mqtt.disconnect();
if (serial == 1) {
Serial.println(F("Retrying connection..."));
}
delay(5000);
}
if (serial == 1) {
Serial.println(F("Adafruit IO Connected!"));
}
}
void scroll(char *data, int iter) {
for (iter; iter > 0; iter--) {
for (int x = 0; x < 140; x++) {
char c = data[x];
if (! isprint(c)) return;
// scroll down display
displaybuffer[0] = displaybuffer[1];
displaybuffer[1] = displaybuffer[2];
displaybuffer[2] = displaybuffer[3];
displaybuffer[3] = c;
// set every digit to the buffer
alpha4.writeDigitAscii(0, displaybuffer[0]);
alpha4.writeDigitAscii(1, displaybuffer[1]);
alpha4.writeDigitAscii(2, displaybuffer[2]);
alpha4.writeDigitAscii(3, displaybuffer[3]);
// write it out!
alpha4.writeDisplay();
delay(500);
}
}
}
void checkstrength()
{
if (WiFi.RSSI() >= -69) {
strength = "Very Good";
return;
}
if (WiFi.RSSI() >= -79) {
strength = "Okay";
return;
}
if (WiFi.RSSI() < -79) {
strength = "Possibly Unreliable";
return;
}
}
In the code, replace "Your-WiFi-Network-Name" with your WiFi network name (SSID) and "Your-WiFi-Network-Password" with your WiFi network password (PSK). Replace "your-adafruit-username" with your Adafruit account username, and replace "your-aio-key" with your AIO key (go to one of your dashboards and press the key button and the text inside is your AIO key). Now plug your ESP8266 into your computer and upload the code! Once it has said "Boot finished" on the display, go to the Adafruit IO dashboard you created and type in some text (less than 20 characters) and hit Enter. You should see what you type scroll twice across your display!