I’m running WifiManager(tzapu) OnDemand on ESP8266
The OnDemand works perfect.
I need to be able during the waiting for OnDemand button to display a message on the attached OLED.
Can someone guide me please?
Here is the sketch:
/**
* OnDemandConfigPortal.ino
* example of running the configPortal AP manually, independantly from the captiveportal
* trigger pin will start a configPortal AP for 120 seconds then turn it off.
*
*/
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// select which pin will trigger the configuration portal when set to LOW
#define TRIGGER_PIN 0
int timeout = 120; // seconds to run for
void setup() {
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("\n Starting");
pinMode(TRIGGER_PIN, INPUT_PULLUP);
}
// Here, waiting for the OnDemand button I would like to display on the attahed OLED the message "Press connect button"
void loop() {
// is configuration portal requested?
if ( digitalRead(TRIGGER_PIN) == LOW) {
WiFiManager wm;
//reset settings - for testing
wm.resetSettings();
// set configportal timeout
wm.setConfigPortalTimeout(timeout);
if (!wm.startConfigPortal("OnDemandAP")) {
Serial.println("failed to connect and hit timeout");
delay(3000);
//reset and try again, or maybe put it to deep sleep
ESP.restart();
delay(5000);
}
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}
// put your main code here, to run repeatedly:
}
Get the screen to work without any WiFi stuff first. Use the examples, read the library ‘s doc to use the right address and use the right pins to connect to it.
Until an example works there is no point going further in your application.
Yes the display address is 3C, and yes the display is working. I tested it on different sketch, just display using the same sequence of line code as here.
this is the current version of the sketch, that I’m waiting to compile (IDE compile is very slow for me):
/**
* OnDemandConfigPortal.ino
* example of running the configPortal AP manually, independantly from the captiveportal
* trigger pin will start a configPortal AP for 120 seconds then turn it off.
*
*/
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// select which pin will trigger the configuration portal when set to LOW
#define TRIGGER_PIN 0
int timeout = 120; // seconds to run for
void setup() {
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("\n Starting");
pinMode(TRIGGER_PIN, INPUT_PULLUP);
//showoled();
}
// Here, waiting for the OnDemand button I would like to display on the attahed OLED the message "Press connect button"
void loop() {
// is configuration portal requested?
if ( digitalRead(TRIGGER_PIN) == LOW) {
WiFiManager wm;
showoled();
//reset settings - for testing
wm.resetSettings();
// set configportal timeout
wm.setConfigPortalTimeout(timeout);
if (!wm.startConfigPortal("OnDemandAP")) {
Serial.println("failed to connect and hit timeout");
delay(3000);
//reset and try again, or maybe put it to deep sleep
ESP.restart();
delay(5000);
}
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
Serial.println("starting OLED ");
//delay(5000);
}
}
void showoled(){
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print("Push config button");
display.display();
}
As @J-M-L pointed out, you are missing display.begin(), but I was pointing out that the code in your post #5 is missing the ending '}' for the if statement.
I created a function called showoled. The commands sequence in this function are working on another sketch.
My problem, now, is where to call the function before the line that is tested for the OnDemand button.
/**
* OnDemandConfigPortal.ino
* example of running the configPortal AP manually, independantly from the captiveportal
* trigger pin will start a configPortal AP for 120 seconds then turn it off.
*
*/
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// select which pin will trigger the configuration portal when set to LOW
#define TRIGGER_PIN 0
int timeout = 120; // seconds to run for
void setup() {
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("\n Starting");
pinMode(TRIGGER_PIN, INPUT_PULLUP);
//showoled();
}
// Here, waiting for the OnDemand button I would like to display on the attahed OLED the message "Press connect button"
void loop() {
// is configuration portal requested?
/**
* OnDemandConfigPortal.ino
* example of running the configPortal AP manually, independantly from the captiveportal
* trigger pin will start a configPortal AP for 120 seconds then turn it off.
*
*/
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// select which pin will trigger the configuration portal when set to LOW
#define TRIGGER_PIN 0
int timeout = 120; // seconds to run for
void setup() {
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("\n Starting");
pinMode(TRIGGER_PIN, INPUT_PULLUP);
}
// Here, waiting for the OnDemand button I would like to display on the attahed OLED the message "Press connect button"
void loop() {
// is configuration portal requested?
if ( digitalRead(TRIGGER_PIN) == LOW) {
WiFiManager wm;
//reset settings - for testing
wm.resetSettings();
// set configportal timeout
wm.setConfigPortalTimeout(timeout);
if (!wm.startConfigPortal("OnDemandAP")) {
Serial.println("failed to connect and hit timeout");
delay(3000);
//reset and try again, or maybe put it to deep sleep
ESP.restart();
delay(5000);
}
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
//Serial.println("starting OLED ");
//delay(5000);
}
}
void showoled() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print("Push config button");
display.display();
}
if ( digitalRead(TRIGGER_PIN) == LOW) {
WiFiManager wm;
showoled();
//reset settings - for testing
wm.resetSettings();
// set configportal timeout
wm.setConfigPortalTimeout(timeout);
if (!wm.startConfigPortal("OnDemandAP")) {
Serial.println("failed to connect and hit timeout");
delay(3000);
//reset and try again, or maybe put it to deep sleep
ESP.restart();
delay(5000);
}
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
Serial.println("starting OLED ");
//delay(5000);
}
}
void showoled(){
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print("Push config button");
display.display();
}