Go Down

Topic: Wemos Lolin ESP32 OLED Module For Arduino ESP32 OLED WiFi + Bluetooth (Read 2190 times) previous topic - next topic

HermannSW

I always liked, and still do like, Arduino Due, with 84MHz available for 12$ from China.

Recently I stumbled over the Lolin module and ordered it for <10$:
https://www.banggood.com/Wemos-Lolin-ESP32-OLED-Module-For-Arduino-ESP32-OLED-WiFi-Bluetooth-Dual-ESP-32-ESP-32S-ESP8266-p-1148119.html

Normally clocked at 80MHz, it seems to be possible to run at 160MHz and 240MHz as well. Most importantly, while there are many ways to program it, it can be just programmed via Arduino IDE as well:
https://github.com/espressif/arduino-esp32

For the low price it brings not only WiFi and Bluetooth, but has mounted a 128x64 OLED display as well:




Graphics can be accessed by the Arduino SSD1306 library:
http://www.instructables.com/id/ESP32-With-Integrated-OLED-WEMOSLolin-Getting-Star/

My first application will be "ground altimeter" for Raspberry Pi Zero W flying aceess point
https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=190407&p=1198530#p1198530


on RC airplane:


Later maybe for streaming video from the airplane bottom mounted camera as well (on bigger, ILI9341 320x240 color LCD -- the videos are currently full HD and stored on SD card).

I thought this new Arduino might be of interest for others as well,

Hermann.

P.S:
The module has a dual core 32bit CPU, one core does WiFi, Bluetooth and other stuff, the second is for you only:
https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf

HermannSW

After I received a new Raspberry Pi Zero W I went ahead and worked on ground altimeter for the Lolin ESP32.

In the mean time I learned from other threads that "Wemos" may be incorrectly have been added to the module name, that can be found here:
https://www.banggood.com/search/lolin-esp32.html

So today (after having seen REALLY good Wifi distance, see below) I first wanted to verify that it is a real ESP32.

This simple for loop computes the sum of squares up to 100.000.000:
Code: [Select]
  long i,j,t0,t1, N=100000000;
    t0 = micros();
    for(i=0,j=0; i<N; ++i) { j+=i; }
    t1 = micros();
    DRAW(String((t1-t0)/0.001/N)+"\n"+String(j));


On OLED display I could read 887459712, which is correct modulo 2^32:
Code: [Select]
$ bc -q
(100000000*99999999/2)%(2^32)
887459712

1000/8.39
119


And I read 8.39 (ns per loop), which says that 119.000.000 loops per second can be computed, which is proof that CPU has >80MHz.


Now to WLAN far distance link quality between ESP32 and Pi Zero W, yesterday I was able to see 38/70 link quality (-72dBm) over a distance of 55m, and that inhouse!

Currently we are in youth hostel Friedrichshafen/Germany at Lake Constance, and I did measure the distance between Pi Zero W on one end of a very long floor and ESP 32 on the other end with Gmaps pedometer as 55m:
https://www.gmap-pedometer.com/?r=7132044

Here you can see the 38/70 and copied in 37/70 measurements I made at the other end of the floor on the ESP32 OLED display (zoom in to see the details):


So if inhouse 55m is possible, I hope for more distance possible outside with Pi Zero W flying with RC airplane, and ESP32 OLED displaying altimeter information on ground.


Now I describe the Arduino IDE code for ESP32, and the Raspberry Pi Zero W code.

The ESP32 starts as wireless access point (192.168.4.1) and waits for some computer to connect.
When Pi Zero W starts, it connects to that AP by these lines in WPA config:
Code: [Select]
pi@raspberrypi05:~ $ sudo tail -5 /etc/wpa_supplicant/wpa_supplicant.conf
network={
ssid="MyESP32AP"
psk="testpassword"
}


I did install Apache webserver on the Pi, so that it serves "http://192.168.4.2/wifi" web page. This web page gets refreshed every second by this script started via /etc/rc.local:
Code: [Select]
pi@raspberrypi05:~ $ tail -3 /etc/rc.local
/home/pi/iwconfig.Link &

exit 0
pi@raspberrypi05:~ $ cat /home/pi/iwconfig.Link
#!/bin/bash
while (true)
do
  export iw=`iwconfig wlan0 | grep Link`
  echo $iw | cut -f2 -d\  > /var/www/html/wifi
  echo $iw | cut -f3-5 -d\  >> /var/www/html/wifi
  sleep 1
done
pi@raspberrypi05:~ $


The content of /var/www/html/wifi looks like this:
Code: [Select]
pi@raspberrypi05:~ $ cat /var/www/html/wifi
Quality=70/70
Signal level=-38 dBm
pi@raspberrypi05:~ $


OK, this was the Raspberry side, now the Arduino IDE code for the ESP32 with OLED.
The sketch is based on BasicHttpClient.ino, but instead of connecting to an AP, the ESP32 gets AP itself via WiFi.softAP(). After Pi Zero W connects to ESP32 AP, the loop() does GET requests to "http://192.168.4.2/wifi", and in case of success, draws the response on OLED. 16 point font is a little bit too large, but only leading "S" and trailing "m" are missing for 2nd line. The code relies on Pi Zero W becoming 192.168.4.2, which seems to always be the case. No idea whether this is always the case, or how to determine the Pi Zero W IP address on ESP32 side:
Code: [Select]
/*
 *  Based on BasicHTTPClient.ino
 *  Instead of connecting ESP32 to AP, be one itself (softAP)
 *  Use SSD1306 lib for Lolin32 OLED display output
 *  https://www.banggood.com/search/lolin-esp32.html
 */

#include <Arduino.h>

#include <WiFi.h>
#include <WiFiMulti.h>

#include <HTTPClient.h>

#include "SSD1306.h"

WiFiMulti wifiMulti;

SSD1306  display(0x3c, 5, 4);

#define DRAW(s) \
    display.clear(); \
    display.setTextAlignment(TEXT_ALIGN_CENTER_BOTH); \
    display.drawString(DISPLAY_WIDTH/2, DISPLAY_HEIGHT/2, s); \
    display.display()

void setup() {

    //wifiMulti.addAP("ssid", "password");
    WiFi.softAP("MyESP32AP", "testpassword");
    
    display.init();
    display.flipScreenVertically();
    display.setContrast(255);
  
    display.setFont(ArialMT_Plain_16);
    display.setTextAlignment(TEXT_ALIGN_CENTER_BOTH);

    DRAW("waiting");

    while (!WiFi.softAPgetStationNum()) delay(1000);

    DRAW(String(WiFi.softAPgetStationNum()));
}

void loop() {
    HTTPClient http;

    http.begin("http://192.168.4.2/wifi"); //HTTP

    int httpCode = http.GET();

    if(httpCode > 0) {
        if(httpCode == HTTP_CODE_OK) {
            String payload = http.getString();
            DRAW(payload);
        }
    } else {
//        USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
    }

    http.end();

    delay(200);
}

 

I had to remove all Serial output lines from BasicHttpClient.ino, because otherwise the sketch does not work without a laptop connected, which is needed for ground altimeter. A final test showed that ESP32 and Pi Zero W work fine just powered, ESP32 has to be started first so that Pi Zero W can connect to AP:


After that scenario worked, I did order another Lolin ESP32 OLED module for 10.49$ with free shipping ;-)

Hermann.

HermannSW

First let me say that I have no relationship to Espressif/ESP32 or the seller of that ESP32 OLED module or Raspberry. I am just thrilled of the inhouse Wifi working distance between ESP32 and Pi ZeroW, that is why I document what I found here. Find the new Arduino sketch for the new youtube video below:
https://youtu.be/EBJ1ra3lxPM

As with a previous video where I walked the 55m youth hostel corridor and recorded ESP32 OLED display
https://www.youtube.com/watch?v=mOoj2ga0R-g

the new OLED screen has an action indicator that shows each update in the sketch loop(). New is bottom right continuous display of clients connected to ESP32 AP (I tested with laptop connecting to the AP and 2 got displayed).

In Böblingen/Germany IBM lab we have >20 connected buildings, and I used the longest straight line basement corridor I could find. To my surprise the 170m (again measured with Gmaps pedometer) of that corridor were not enough to see any Wifi connectivity issues!
https://www.gmap-pedometer.com/?r=7134090

Link quality was in 30-33/70 range, and signal level was in -(77-80)dBm range!


(I always had the plan to use the very long straight basement corridors of IBM Böblingen lab, but the plan was to do so for max. speed measurements of my fast driving autonomous robots)

Hermann.

Code: [Select]
/*
 *  Based on BasicHTTPClient.ino
 *  Instead of connecting ESP32 to AP, be one itself (softAP)
 *  Use SSD1306 lib for Lolin32 OLED display output
 *  https://www.banggood.com/search/lolin-esp32.html
 */

#include <Arduino.h>

#include <WiFi.h>
#include <WiFiMulti.h>

#include <HTTPClient.h>

#include "SSD1306.h"

WiFiMulti wifiMulti;

SSD1306  display(0x3c, 5, 4);

int pos1=0,pos0=0;

#define LINE(i) \
    display.setColor(INVERSE); \
    display.drawVerticalLine(pos##i, DISPLAY_HEIGHT-8-10*i, 8); \
    pos##i = (++pos##i % 100); \
    display.setColor(WHITE); \
    display.display()
        
#define DRAW1(s) \
    display.setColor(BLACK); \
    display.fillRect(112,48,16,16); \
    display.setTextAlignment(TEXT_ALIGN_LEFT); \
    display.setColor(WHITE); \
    display.drawString(112, 48, s); \
    display.display()

#define DRAW(s) \
    display.clear(); \
    display.setTextAlignment(TEXT_ALIGN_CENTER_BOTH); \
    display.drawString(DISPLAY_WIDTH/2, DISPLAY_HEIGHT/2, s); \
    display.display()

void setup() {

    //wifiMulti.addAP("ssid", "password");
    WiFi.softAP("MyESP32AP", "testpassword");
    
    display.init();
    display.flipScreenVertically();
    display.setContrast(255);
  
    display.setFont(ArialMT_Plain_16);
    display.setTextAlignment(TEXT_ALIGN_CENTER_BOTH);

    DRAW("waiting");

    while (!WiFi.softAPgetStationNum()) delay(1000);

    DRAW(String(WiFi.softAPgetStationNum()));
}

void loop() {
  if (WiFi.softAPgetStationNum()) {
    HTTPClient http;
    http.setTimeout(800);

    http.begin("http://192.168.4.2/wifi"); //HTTP
    LINE(1);

    int httpCode = http.GET();

    if(httpCode == HTTP_CODE_OK) {
        String payload = http.getString();
        DRAW(payload);
    } else {
        LINE(0);
    }
    http.end();
  }
  
  DRAW1(String(WiFi.softAPgetStationNum()));
  
  delay(200);
}

HermannSW

Yesterday I did try to fly RC airplane with ground altimeter. These were the only changes in Arduino sketch needed:
Code: [Select]
$ diff sketch_aug30a/sketch_aug30a.ino sketch_sep03a/sketch_sep03a.ino
53c53
<     display.setFont(ArialMT_Plain_16);
---
>     display.setFont(ArialMT_Plain_24);
68c68
<     http.begin("http://192.168.4.2/wifi"); //HTTP
---
>     http.begin("http://192.168.4.2/height");
$


The airplane wheight did increase to 40.9g by the added BMP180 pressure sensor. The airplane was not able to fly high, and therefore I removed the bottom camera and screws, which reduced weight by 3.0g landing in range of previous weight. After the airplane did not climb more than 5m today, I did even remove the now unneeded camera ribbon cable and its tape. This reduced wheight by another 0.9g. Still no luck in getting airplane fly high. I assume that the GND/VCC/SCL/SDA connectors from BMP180 soldered on Pi ZeroW do too much harm to the airplane upswing, and that the Pi ZeroW needs to be mounted somewhere else, perhaps below the airplane. Will try when back home at end of he week:


At least I found a good and non-intrusive way to connect the Wifi ground altimeter to remote control:


Hermann.

P.S:
I used an endless loop python script with time.sleep(1) based on this article, started via /etc/rc.local, to determine altitude and provide via .../height URL:
https://thepihut.com/blogs/raspberry-pi-tutorials/18025084-sensors-pressure-temperature-and-altitude-with-the-bmp180

I will provide the details when back home, interesting was that the (endless) python script always stopped 4 hours after startup. That is no problem since the Lipos will never hold for that time.

gilalmogy

Hi, how can we add this board to the Arduino IDE ?
thanks!

HermannSW

Hi, how can we add this board to the Arduino IDE ?
thanks!
As stated in 1st posting of this thread, it can be just programmed via Arduino IDE as well, see "Installation Instructions":
https://github.com/espressif/arduino-esp32

HermannSW

It seems that the ESP32 CPU clock is 160MHz, by above done measurement and the spec:
http://espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf#page=25

I stumbled over an integer performance comparison for many microcontrollers I did in an Arduino Due thread:
https://forum.arduino.cc/index.php?topic=397480.msg2854537#msg2854537

The sketch used is attached to this posting.

I did compute both values (-Os and -O3) for the ESP32 board this thread is about.
And I added Pi Zero W row, as well as W541 row because of 6μs time:
model-Os-O3speedprocessorWifi
MKR1000103882548MHzSAMD21 Cortex-M0+yes
Zero--48MHzATSAMD21G18-
10184679132MHzIntel® Curie-
Due54849484MHzATSAM3X8E-
ESP8266-12E61230480MHzTensilica Xtensa LX106yes
Lolin ESP32191149160MHzDual core Xtensa LX6yes
Raspberry Pi Zero-601GHzBroadcom BCM2835-
Raspberry Pi Zero W-601GHzBroadcom BCM2835yes
-
(W541)-62.8GHzIntel i7-4810MQ

Code: [Select]

 47| 29|101|
113| 59|  5|
 17| 89| 71|

149us


Hermann.

Go Up