Hi there,
I have 4 of these sets and the OLED's all behave the same, they don't power on unless reset button is pushed. Power on and everything works except the display, push reset and display comes on. Have read through all the comments in the forum and this apparently this OLED should not have any issues, below the code I use to enable the display - any guidance?
Adafruit_SSD1306 display = Adafruit_SSD1306();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
I have tried display.begin(SSD1306_SWITCHCAPVCC, 0x3C, true); to force a reset but doesnt seem like this display has a reset pin.
Kind regards, Emil
Adafruit Feather HUZZAH ESP8266 with FeatherWing OLED - 128x
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- emildev
- Posts: 4
- Joined: Thu May 17, 2018 2:02 pm
- emildev
- Posts: 4
- Joined: Thu May 17, 2018 2:02 pm
Re: Adafruit Feather HUZZAH ESP8266 with FeatherWing OLED -
Full code if needed;
Code: Select all
/*
*/
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <Bounce2.h>
#include <EEPROM.h>
#include <WiFiUdp.h>
// #include <SPI.h> // Removed as SPI for SD wont be used
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "TimeLib.h"
#include "RTClib.h"
RTC_PCF8523 rtc;
Adafruit_SSD1306 display = Adafruit_SSD1306(1);
WiFiClient espClient;
PubSubClient client(espClient);
Bounce debouncer1 = Bounce();
Bounce debouncer2 = Bounce();
Bounce debouncer3 = Bounce();
IPAddress timeServerIP;
WiFiUDP udp;
int i;
int string1;
int string2;
int string3;
int string4;
int string5;
int string6;
unsigned int localPort = 2390;
const int timeZone = 7200;
const char* ntpServerName = ":-)";
const int NTP_PACKET_SIZE = 48;
byte packetBuffer[ NTP_PACKET_SIZE];
const char* ssid = "wifi";
const char* password = ":-)";
const char* mqtt_server = ":-)";
long lastMsg = 0;
char msg[50];
int value = 0;
String mqttClientName;
String topicRelayA;
String topicRelayB;
String topicSystem;
String topicSystemNtp;
int relayApin = 12;
int relayBpin = 15;
bool relayAstate = LOW;
bool relayBstate = LOW;
int buttonApin = 0;
int buttonBpin = 16;
int buttonCpin = 2;
String macToStr(const uint8_t* mac)
{
String result;
for (int i = 0; i < 6; ++i) {
result += String(mac[i], 16);
if (i < 5)
result += "";
}
return result;
}
void setup_wifi()
{
delay(10);
WiFi.begin(ssid, password);
String getMac;
uint8_t mac[6];
WiFi.macAddress(mac);
getMac = macToStr(mac);
mqttClientName = getMac;
topicRelayA = "32west/" + getMac + "/relay/a";
topicRelayB = "32west/" + getMac + "/relay/b";
topicSystem = "32west/" + getMac + "/system";
topicSystemNtp = "32west/" + getMac + "/system/ntp";
}
void callback(char* topic, byte* payload, unsigned int length)
{
if (strcmp(topic, ((char*) topicRelayA.c_str ())) == 0) {
if ((char)payload[0] == '0') {
digitalWrite(relayApin, LOW);
relayAstate = LOW;
EEPROM.write(0, relayAstate);
EEPROM.commit();
}
else if ((char)payload[0] == '1') {
digitalWrite(relayApin, HIGH);
relayAstate = HIGH;
EEPROM.write(0, relayAstate);
EEPROM.commit();
}
else if ((char)payload[0] == '2') {
relayAstate = !relayAstate;
if (relayAstate == 1) {
client.publish((char*) topicRelayA.c_str (), "1");
}
else if (relayAstate == 0) {
client.publish((char*) topicRelayA.c_str (), "0");
}
digitalWrite(relayApin, relayAstate);
EEPROM.write(0, relayAstate);
EEPROM.commit();
}
}
if (strcmp(topic, ((char*) topicRelayB.c_str ())) == 0) {
if ((char)payload[0] == '0') {
digitalWrite(relayBpin, LOW);
relayBstate = LOW;
EEPROM.write(1, relayBstate);
EEPROM.commit();
}
else if ((char)payload[0] == '1') {
digitalWrite(relayBpin, HIGH);
relayBstate = HIGH;
EEPROM.write(1, relayBstate);
EEPROM.commit();
}
else if ((char)payload[0] == '2') {
relayBstate = !relayBstate;
if (relayBstate == 1) {
client.publish((char*) topicRelayB.c_str (), "1");
}
else if (relayBstate == 0) {
client.publish((char*) topicRelayB.c_str (), "0");
}
digitalWrite(relayBpin, relayBstate);
EEPROM.write(1, relayBstate);
EEPROM.commit();
}
}
if (strcmp(topic, ((char*) topicSystemNtp.c_str ())) == 0) {
if ((char)payload[0] == '2') {
rtcTimeNtp ();
}
}
}
void reconnect()
{
while (!client.connected()) {
if (client.connect((char*) mqttClientName.c_str ())) {
client.publish((char*) topicSystem.c_str (), "0");
if (relayAstate == 1) {
client.publish((char*) topicRelayA.c_str (), "1");
}
else if (relayAstate == 0) {
client.publish((char*) topicRelayA.c_str (), "0");
}
if (relayBstate == 1) {
client.publish((char*) topicRelayB.c_str (), "1");
}
else if (relayBstate == 0) {
client.publish((char*) topicRelayB.c_str (), "0");
}
client.subscribe((char*) topicRelayA.c_str ());
client.subscribe((char*) topicRelayB.c_str ());
client.subscribe((char*) topicSystem.c_str ());
client.subscribe((char*) topicSystemNtp.c_str ());
} else {
rtcTime();
relayStatus();
for (int i = 0; i < 500; i++) {
extButtonA();
extButtonB();
extButtonC();
delay(1);
}
}
}
}
void extButtonA()
{
debouncer1.update();
if ( debouncer1.fell() ) {
Serial.println("Debouncer fell");
relayAstate = !relayAstate;
digitalWrite(relayApin, relayAstate);
EEPROM.write(0, relayAstate);
EEPROM.commit();
if (relayAstate == 1) {
client.publish((char*) topicRelayA.c_str (), "1");
}
else if (relayAstate == 0) {
client.publish((char*) topicRelayA.c_str (), "0");
}
}
}
void extButtonB()
{
debouncer2.update();
if ( debouncer2.fell() ) {
relayBstate = !relayBstate;
digitalWrite(relayBpin, relayBstate);
EEPROM.write(1, relayBstate);
EEPROM.commit();
if (relayBstate == 1) {
client.publish((char*) topicRelayB.c_str (), "1");
}
else if (relayBstate == 0) {
client.publish((char*) topicRelayB.c_str (), "0");
}
}
}
void extButtonC()
{
debouncer3.update();
if ( debouncer3.fell() ) {
rtcTimeNtp ();
}
}
void rtcTime()
{
DateTime now = rtc.now();
display.setCursor(0, 10);
if (now.hour() < 10 ) {
display.print('0');
}
display.print(now.hour(), DEC);
display.print(":");
if (now.minute() < 10 ) {
display.print('0');
}
display.print(now.minute(), DEC);
display.print(":");
if (now.second() < 10 ) {
display.print('0');
}
display.print(now.second(), DEC);
display.print(" ");
if (now.day() < 10 ) {
display.print('0');
}
display.print(now.day(), DEC);
display.print("/");
if (now.month() < 10 ) {
display.print('0');
}
display.print(now.month(), DEC);
display.print("/");
display.println(now.year(), DEC);
display.display();
}
void relayStatus()
{
display.setCursor(0, 24);
display.print(" ");
if ((relayAstate == 0) && (relayBstate == 0)) {
display.setCursor(0, 24);
display.print("RelA: Off | RelB: Off");
}
else if ((relayAstate == 1) && (relayBstate == 1)) {
display.setCursor(0, 24);
display.print("RelA: On | RelB: On ");
}
else if ((relayAstate == 0) && (relayBstate == 1)) {
display.setCursor(0, 24);
display.print("RelA: Off | RelB: On");
}
else if ((relayAstate == 1) && (relayBstate == 0)) {
display.setCursor(0, 24);
display.print("RelA: On | RelB: Off");
}
}
void rtcTimeNtp ()
{
DateTime now = rtc.now();
WiFi.hostByName(ntpServerName, timeServerIP);
sendNTPpacket(timeServerIP);
delay(500);
int cb = udp.parsePacket();
if (!cb) {
}
else {
udp.read(packetBuffer, NTP_PACKET_SIZE);
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
unsigned long secsSince1900 = highWord << 16 | lowWord;
const unsigned long seventyYears = 2208988800UL;
unsigned long epoch = secsSince1900 - seventyYears + timeZone;
string1 = (year(epoch));
string2 = (month(epoch));
string3 = (day(epoch));
string4 = (hour(epoch));
string5 = (minute(epoch));
string6 = (second(epoch));
rtc.adjust(DateTime(string1, string2, string3, string4, string5, string6));
display.setCursor(0, 10);
display.print(" ");
display.setCursor(0, 10);
display.print("RTC NTP Sync ");
for (i = 0; i < 8; i++) {
delay (500);
display.print(".");
display.display();
}
display.setCursor(0, 10);
display.print(" ");
display.display();
}
}
void sendNTPpacket(IPAddress & address)
{
memset(packetBuffer, 0, NTP_PACKET_SIZE);
packetBuffer[0] = 0b11100011;
packetBuffer[1] = 0;
packetBuffer[2] = 6;
packetBuffer[3] = 0xEC;
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
udp.beginPacket(address, 123);
udp.write(packetBuffer, NTP_PACKET_SIZE);
udp.endPacket();
}
void setup()
{
display.begin(SSD1306_SWITCHCAPVCC, 0x3C, true);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);
display.drawLine(0, 20, 128, 20, WHITE);
EEPROM.begin(512);
pinMode(relayApin, OUTPUT);
pinMode(relayBpin, OUTPUT);
pinMode(buttonApin, INPUT_PULLUP);
pinMode(buttonBpin, INPUT_PULLUP);
pinMode(buttonCpin, INPUT_PULLUP);
relayAstate = EEPROM.read(0);
digitalWrite(relayApin, relayAstate);
relayBstate = EEPROM.read(1);
digitalWrite(relayBpin, relayBstate);
debouncer1.attach(buttonApin);
debouncer1.interval(50);
debouncer2.attach(buttonBpin);
debouncer2.interval(50);
debouncer3.attach(buttonCpin);
debouncer3.interval(50);
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
udp.begin(localPort);
}
void loop()
{
if (WiFi.status() != WL_CONNECTED) {
display.setCursor(0, 0);
display.print("System: Offline ");
}
else {
display.setCursor(0, 0);
display.print("System: Online ");
}
rtcTime();
relayStatus();
if (!client.connected()) {
reconnect();
}
client.loop();
extButtonA();
extButtonB();
extButtonC();
}
Last edited by adafruit_support_carter on Thu May 17, 2018 3:40 pm, edited 1 time in total.
Reason: added [code] tags
Reason: added [code] tags
- adafruit_support_carter
- Posts: 29483
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Adafruit Feather HUZZAH ESP8266 with FeatherWing OLED -
Let's trouble shoot with a simpler sketch. Try running the one from the guide here:
https://learn.adafruit.com/adafruit-ole ... ample-code
https://learn.adafruit.com/adafruit-ole ... ample-code
- emildev
- Posts: 4
- Joined: Thu May 17, 2018 2:02 pm
Re: Adafruit Feather HUZZAH ESP8266 with FeatherWing OLED -
I started with this one - same result - if sketch is loaded from pc display comes up first time no issue - unplug and connect to same pc or another usb supply or battery requires a push of the reset button to power up screen - note first boot the code runs perfectly just no display, second boot with reset button powers up the screen.
- adafruit_support_mike
- Posts: 67485
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Adafruit Feather HUZZAH ESP8266 with FeatherWing OLED -
Try adding a few milliseconds of delay() before calling display.begin().
The OLED driver needs time to bring its internal charge pumps up to voltage (OLEDs operate at 10V to 15V), and the microcontroller can execute setup() before the driver is ready to accept commands.
We redesigned some of the OLED breakouts with a new startup circuit, but adding some delay is easy enough that it's worth a try.
The OLED driver needs time to bring its internal charge pumps up to voltage (OLEDs operate at 10V to 15V), and the microcontroller can execute setup() before the driver is ready to accept commands.
We redesigned some of the OLED breakouts with a new startup circuit, but adding some delay is easy enough that it's worth a try.
- emildev
- Posts: 4
- Joined: Thu May 17, 2018 2:02 pm
Re: Adafruit Feather HUZZAH ESP8266 with FeatherWing OLED -
Legend!!!!
All sorted thank you so much - 100ms did the trick :-)
Maybe add to example?
All sorted thank you so much - 100ms did the trick :-)
Maybe add to example?
- adafruit_support_mike
- Posts: 67485
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Adafruit Feather HUZZAH ESP8266 with FeatherWing OLED -
Glad to hear that got things working!
We haven't put it in the example code because it doesn't happen with all boards, and boards that do have problems tend to want different amounts of delay.
We haven't put it in the example code because it doesn't happen with all boards, and boards that do have problems tend to want different amounts of delay.
- awebber33
- Posts: 2
- Joined: Fri Aug 29, 2014 5:23 am
Re: Adafruit Feather HUZZAH ESP8266 with FeatherWing OLED -
Maybe add it to the FAQ then? There are several unanswered posts out there with this issue. There's only so many processors used in the feather line so it would be nice to know from the outset.
- adafruit_support_carter
- Posts: 29483
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Adafruit Feather HUZZAH ESP8266 with FeatherWing OLED -
Thanks. We just added this:
https://learn.adafruit.com/adafruit-ole ... leshooting
https://learn.adafruit.com/adafruit-ole ... leshooting
Please be positive and constructive with your questions and comments.