Featherwing OLED Badge Project

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
md_dc
 
Posts: 11
Joined: Thu Mar 23, 2017 9:39 am

Featherwing OLED Badge Project

Post by md_dc »

I love the Adabox 003 and came across a Featherwing OLED Badge project pretty quickly after unboxing. I ran into a few issues with the code and got it to work thanks to the lovely help of people in the Adafruit forums!

Here is the summary of everything on my GitHub (very first one :) )

@Adafruit - it may be beneficial to update the code for this project since the PROGMEM command is no longer valid (I think with the MQTT library?)

User avatar
geoffreyf
 
Posts: 52
Joined: Fri Oct 24, 2014 10:37 pm

Re: Featherwing OLED Badge Project

Post by geoffreyf »

The problem I am having is that it gets hung up trying to connect to the WiFi Access point. The funny thing is that I have another simpler piece of code with the same logic that does connect fine. I tried removing progmem earlier and I then tried your code on GIT ... no joy and same issue as before. I'm wondering if I have a bad library or something.

User avatar
md_dc
 
Posts: 11
Joined: Thu Mar 23, 2017 9:39 am

Re: Featherwing OLED Badge Project

Post by md_dc »

What error messages are you getting?

User avatar
MrSteve
 
Posts: 4
Joined: Mon Dec 26, 2016 2:35 am

Re: Featherwing OLED Badge Project

Post by MrSteve »

Complete rewrite. So I was able to get loading was missing Adafruit GFX Library.

User avatar
md_dc
 
Posts: 11
Joined: Thu Mar 23, 2017 9:39 am

Re: Featherwing OLED Badge Project

Post by md_dc »

Ah, yep. I hit that issue too but then had to realize the libraries for the HUZZAH and OLED needed to be in IDE.

I also made the mistake of carelessly adding libraries from Git which I ended up installing different versions of the same *.h file which screwed stuff up. A complete uninstall/reinstall with new knowledge helped.

User avatar
geoffreyf
 
Posts: 52
Joined: Fri Oct 24, 2014 10:37 pm

Re: Featherwing OLED Badge Project

Post by geoffreyf »

md_dc - using the serial monitor, no error messages, just hangs trying to connect to the access point. So in the code for the oled badge this is just a "." with each fail, for ever. It never gets to do the OLED stuff. As I mentioned, a simple version of the same logic connects to the same access point just fine. So I am theorizing that the OLED library is interfering with the ESP8266 one.

I moved the display.begin, display.display lines to after the connection to the AP. Now it's connecting to the AP successfully. Somehow the OLED library was causing the problem.

User avatar
md_dc
 
Posts: 11
Joined: Thu Mar 23, 2017 9:39 am

Re: Featherwing OLED Badge Project

Post by md_dc »

Have you added the OLED library yet? I'm thinking it has nothing to access so it falls into an infinite loop of not knowing what to do.

User avatar
geoffreyf
 
Posts: 52
Joined: Fri Oct 24, 2014 10:37 pm

Re: Featherwing OLED Badge Project

Post by geoffreyf »

It's working now. The fix was as in my last post, moving OLED calls to after the Wifi client connection. However, maybe I have a different OLED library somehow?

lukekb
 
Posts: 13
Joined: Mon Nov 26, 2012 1:51 pm

Re: Featherwing OLED Badge Project

Post by lukekb »

Thats weird - I was having the same problem. Switching the OLED code to after the WIFI connect seemed to fix it!!

User avatar
geoffreyf
 
Posts: 52
Joined: Fri Oct 24, 2014 10:37 pm

Re: Featherwing OLED Badge Project

Post by geoffreyf »

I just noticed that when I did this my board was "Adafruit Huzzah ESP8266"
I noticed that in one of the learning things, It suggested "Generic ESP8266" module instead of the one I used.

Did those who didn't have to switch the OLED code, use the Generic?

User avatar
md_dc
 
Posts: 11
Joined: Thu Mar 23, 2017 9:39 am

Re: Featherwing OLED Badge Project

Post by md_dc »

I've seen the wifi info always be towards the top (after the libraries that are included are listed out). In their example that seems to be the way they are doing it. Did you try out their code?

lukekb
 
Posts: 13
Joined: Mon Nov 26, 2012 1:51 pm

Re: Featherwing OLED Badge Project

Post by lukekb »

I just tried using the Generic ESP8266 for the board and it couldn't even load. I can use the Featherwing Test program and that works fine. I think the trick is making the connection before doing anything with the display.

User avatar
geoffreyf
 
Posts: 52
Joined: Fri Oct 24, 2014 10:37 pm

Re: Featherwing OLED Badge Project

Post by geoffreyf »

After playing with the Adafruit IO Arduino examples, it seems to me that the program structure they use is better than the original OLED Badge Demo. So, I produced this very modified file after the fashion of those examples. (EG: adafruitio_09_analog_out)

If you do one of those examples, copy the config.h with your ssid, password, adafruit user name, key etc. from that one to this ones folder.

This one will provide the last hightemp in the feed more reliably.

I am curious from adafruit staff what the difference is between the MQTT stuff used in the original OLED Badge Demo and what is used adafruitio examples. Is one better for something than the other? It seems that this is a better, simpler path to go from what I see.

I did not polish off rough edges with this piece of code. If there is interest in a more presentable package, someone let me know.

CODE STARTS HERE ..........................................
/*
* WiFi OLED Display Badge
* guide: https://learn.adafruit.com/digital-display-badge/
* based on Home Automation sketch by M. Schwartz
* with contributions from Becky Stern and Tony Dicola
* Modified by Geoffrey Feldamn from adafruit published version.
* after the fasion of adafruit io examples 3/25/2015
* NOT under source control.
*/
// 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"
// Functions
// set up the 'analog' feed
AdafruitIO_Feed *hightemp = io.feed("hightemp");

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 3
Adafruit_SSD1306 display(OLED_RESET);

#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000011, B11100000,
B11110011, B11100000,
B11111110, B11111000,
B01111110, B11111111,
B00110011, B10011111,
B00011111, B11111100,
B00001101, B01110000,
B00011011, B10100000,
B00111111, B11100000,
B00111111, B11110000,
B01111100, B11110000,
B01110000, B01110000,
B00000000, B00110000 };

#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

// this constant won't change:
const int buttonPin = 2; // the pin that the pushbutton is attached to

// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button

void setup() {

// start the serial connection
Serial.begin(115200);

// wait for serial monitor to open
while(! Serial);

// connect to io.adafruit.com
Serial.print("Connecting to Adafruit IO");
io.connect();

// set up a message handler for the 'analog' feed.
// the handleMessage function (defined below)
// will be called whenever a message is
// received from adafruit io.
hightemp->onMessage(handleMessage);

// initialize the button pin as a input:
pinMode(buttonPin, INPUT_PULLUP);


// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
// init done

// Show image buffer on the display hardware.
// Since the buffer is intialized with an Adafruit splashscreen
// internally, this will display the splashscreen.
display.display();
delay(2000);

// Clear the buffer.
display.clearDisplay();

// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println( WIFI_SSID);


display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
}

int temp = 151;
int whichbutton = 0;

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();
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);

// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == LOW) {
// if the current state is LOW then the button was pressed
buttonPushCounter++;
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
}
}


//A button position - display today's high temperature
if (buttonPushCounter % 3 == 0) {
if(temp == 151){
display.clearDisplay();
display.setCursor(0,16);
display.println("Waiting for temp data");
display.display();
Serial.println(F("Printed: Waiting for temp data"));
}else{
display.clearDisplay();
display.setCursor(0,16);
display.print("Today's high: ");
display.print(temp);
display.println(" F");
display.display();
//Serial.print(F("Printed: "));
//Serial.println(temp);
}
}


//B button position - David Bowie quote
if (buttonPushCounter % 3 == 1) {

display.clearDisplay();
display.setCursor(0,0);
display.println("I'm an instant star. Just add water and ");
display.println("stir.");
display.println(" - David Bowie");
display.display();
}

//C button position - nametag
if (buttonPushCounter % 3 == 2) {
display.clearDisplay();
display.setCursor(0,0);
// If not me, change accordingly
display.println("Geoffrey Feldman");
display.println();
display.println("Engineer");
display.display();
}

// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;

}

// this function is called whenever an 'analog' message
// is received from Adafruit IO. it was attached to
// the analog feed in the setup() function above.
void handleMessage(AdafruitIO_Data *data) {


// convert the data to integer
temp = data->toInt();

Serial.print("received <- ");
Serial.println(temp);

}

CODE ENDS HERE............................

Locked
Please be positive and constructive with your questions and comments.

Return to “AdaBox! Show us what you made!”