Articles Hierarchy

Articles Home » Arduino Projects » ESP & OLED: test and MQTT client

ESP & OLED: test and MQTT client

for long time i not play with this stuff, even i have a still packed board here
ESP 8266 plus OLED
(i burned too much time at the raspberry pi forum, the questions there can give you some good ideas what to play with, but as i see, my own things got stuck, and my new Raspberry Pi 3B+ will come not for another month.)


i needed to check what
i did buy here?D-duino-B
SH1106
1.3 OLED
from LAZADA
and that must be its homepage
But the "WEMOS" text on the board and the ESP-8266 housing makes it a fake?copy?

first i need to get into this again and do a updated setup on my old desktop PC.
+ + arduino 1.8.5 or the nightly
see Installing with Boards Manager
yes, i even forget already how to use that:-1- arduino / file / preferences / add board manager / paste:
http://arduino.esp8266.com/stable/package_esp8266com_index.json
[ok]
-2- arduino / tools / board / board manager / find esp8266 [install] 150MB

info this release 2.4.1


fire it up:
connect via USB cable to PC and see some nice graph demo
white on black ( 128 * 64 pix)

i think it is this demo

a check with the mobile WIFI shows there seems to be no WIFI AP pre installed.


while my PC complains again some driver NOT successfully installed, but i think that serial chip i used already, and device manager tells me:

also the board info button works, so i have connection.
but actually i am lost, what board i have to select?
as he say it should be a ESP-8266-12F , while on his picture i read
MODEL: ESP8266MOD
VENDOR: AI-THINKER

and my board just say WEMOS ESP-8266
check on WEMOS and their shop i can not find that board.
but in the tutorial i see i correctly selected
NodeMCU 1.0 ESP-12E module

add:
download from esp8266-oled-ssd1306-master.zip and copy to
/arduino-1.8.5/libraries/esp8266-oled-ssd1306-master/
!!that does not fit with board info SH1106 but see his tutorial:

actually i like that guy: Travis Lin about and i am already sorry i buy a copy product, but i did not know.


now my first steps:
-1- play with the OLED DEMO
try take the example SSD1306SimpleDemo
and change to:
#include "SH1106Wire.h"
SH1106 display(0x3c, D1, D2);
get error 'SH1106' does not name a type

again:
#include <'Wire.h'>
#include "SH1106.h"
#include "images.h"
SH1106 display(0x3c, D1, D2);
did compile:
Sketch uses 277612 bytes (26%) of program storage space. Maximum is 1044464 bytes.
Global variables use 32856 bytes (40%) of dynamic memory, leaving 49064 bytes for local variables. Maximum is 81920 bytes.

add:void draw_KLL_Demo() {
int Rhalfwidth = 20;
int Rhalfhight = 10;
for (int i = 0; i < 64; i++) {
display.drawVerticalLine(2*i, 0, i+1);
}
display.setColor(BLACK);
display.fillRect(64-Rhalfwidth, 32-Rhalfhight, 2*Rhalfwidth, 2*Rhalfhight);
display.setColor(WHITE);
display.drawRect(64-Rhalfwidth, 32-Rhalfhight, 2*Rhalfwidth-1, 2*Rhalfhight);
display.setFont(ArialMT_Plain_16);
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.drawString(64,24, "KLL");

display.setFont(ArialMT_Plain_10);
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.drawString(0, 41, "OLED Test");
display.drawString(0, 52, "KLL engineering");
}


as you see in the settings, i did a full upload, no need to press any buttons ( the board has "reset" "flash" PB ) and while upload see a blue LED blinking. ( the old demo stopped until board booted anew )


also started about the clock example ( what arduino lib i need? ) and get a running digital clock ( starts with 0:00:00 at boot ) useless until i am online and can use a internet NTP time service.


-2- add a WIFI server in my LAN
i do webserver with ESP8266 already here, but as i use now a new library i think it is better to start new and copy over some custom details later.
start with the Advanced Web Server Example
-1- change ssid and psk
-2- upload
-3- monitor 115200

now, as much i love SVG, that random numbers chart is a piece of art, but i disabled it.
and included that tricky fix IP again.
and include the OLED ( try to show connection info there too ( not only on serial.print / monitor ))


this was only my first 2 steps with this board, now this looks much smarter!
my board is the with the 1.3" OLED, it has the buttons on the back
"RST" //RST pin// makes a RESET
"FLASH" works in my example as button_pin=0
( to toggle the relay ) but is it: // arduino 0 // GPIO0 //D3 :or: // arduino 16// GPIO16//D0 // WAKE


-3- make it a MQTT device

info: here and here and here

ok, try that igrr example and need add libs in arduino IDE:
[sketch][include library][manage libraries][search "pubsubclient"]

see homepage and spec:
[sketch][include library][manage libraries][search "bounce2"]
set ssid and password
and alread start thinking about that device and ?channel? naming

also need that fix IP in there first.
compared to the wifi webserver example above, this time i
cleaned the OLED part into a other TAB "OLED" and just call in main:
void setup() {
OLED_setup();
...}
void loop() {
show_OLED();
...}


make a new page for a 6 line message buffer for mqtt topics

and make the ESP send back a AKN when it gets a command



currently i switch between the 2 BLOG // here // RPI part //
knowing that would be difficult to read.
anyhow, there i just was thinking that it would be good to implement a sensor / data collection feature.
well, a ESP8266 has only one little Ain ( and that is questionable // and the ESP32 with more inputs i remember as same questionable.) but sensors could be linked to the ESP...
but all that is not the point here, now i just need a "analog" signal i can deal with in ESP, transport to broker, show in a web page, or better record to a database and later show the graph in a webpage. so i just make one up, a noisy sinus.
and yes, i worry correctly, float to string to char array to MQTT... pain in the ass

so make the data format JSON and connect command back to sinus generation,
using the inverted hardware logic.

now that will be later used also from the FLASK WEBSERVER site
what also show the by a python3 / mtqq sub / sqlite3 sql service saved data


to test exactly that program and its automatic understanding of several measuring columns
in the (flat) JSON record i now here create some more data.
-a- a filtered signal of that noisy sinus
-b- a feedback of the LED status ( but use 0.0 OR 1.0 float for easy structure)

but with this i found out there is a init problem for sinus (open)


for the RPI part pls. see my other BLOG
and for the code, that you can find at git


update: see a video about the ESP32 OLED version here