SubName: An ESP32 with a built in OLED display screen connected to WiFi.
Description: With this example source code you can connect your ESP32 microcontroller with a built in OLED display to your local WiFi network (Access Point) and show whatever information you want to on the display.
For this project I used Inline C and the SSD1306 library to power the built in OLED display. The current B4R library appears not to be fully compatible with this particular ESP8266 microcontroller, anyway that does not really matter as this was the perfect opportunity to use the B4R Inline C feature. This is where B4R Inline C comes into its own, using Inline C with the SSD1306 library allows you to fully utilise the methods listed below with no issues whatsoever.
I originally converted an Arduino IDE sketch to B4R that utilised the aforementioned library, I then decided to test the rESP8266WiFi library with this ESC32, it worked perfect. Once the WiFi was connecting I simply added the OLED display code below.
Using Inline C made purchasing this particular ESC32 worth every single penny (about £8.50 with an 18650 battery shield with built in charger).
Note: Download and unzip the attached files directly into your Arduino 'Documents\Arduino\libraries' folder.
Below is just one way to use Inline C to utilise a small part of the SSD1306 library.
Tags: ESP32, WiFi, OLED, Display, Inline, C, C++
Enjoy...
Description: With this example source code you can connect your ESP32 microcontroller with a built in OLED display to your local WiFi network (Access Point) and show whatever information you want to on the display.
For this project I used Inline C and the SSD1306 library to power the built in OLED display. The current B4R library appears not to be fully compatible with this particular ESP8266 microcontroller, anyway that does not really matter as this was the perfect opportunity to use the B4R Inline C feature. This is where B4R Inline C comes into its own, using Inline C with the SSD1306 library allows you to fully utilise the methods listed below with no issues whatsoever.
- display.drawRect
- display.fillRect
- display.drawHorizontalLine
- display.drawVerticalLine
- display.drawCircle
- display.fillCircle
- display.drawProgressBar
- display.setTextAlignment
- display.drawString
- display.setFont
I originally converted an Arduino IDE sketch to B4R that utilised the aforementioned library, I then decided to test the rESP8266WiFi library with this ESC32, it worked perfect. Once the WiFi was connecting I simply added the OLED display code below.
Using Inline C made purchasing this particular ESC32 worth every single penny (about £8.50 with an 18650 battery shield with built in charger).
Note: Download and unzip the attached files directly into your Arduino 'Documents\Arduino\libraries' folder.
Below is just one way to use Inline C to utilise a small part of the SSD1306 library.
B4X:
'***************************
'*** BOARD TYPE ***
'*** ESP32 Dev Module ***
'***************************
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public Serial1 As Serial
Private WiFiConnect As ESP8266WiFi
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Delay(1500)
Log("AppStart")
WiFiConnect.Connect2("[YOUR ACCESS POINT]", "[AP PASSWORD]")
RunNative("setup", Null)
RunNative("cleardisplay", Null)
RunNative("title", "B4R")
RunNative("connected", JoinStrings(Array As String("Connected = ", WiFiConnect.IsConnected)))
RunNative("localip", JoinStrings(Array As String("IP ", WiFiConnect.LocalIp)))
RunNative("updatedisplay", Null)
End Sub
#if C
#include "SSD1306.h"
//Initialize the OLED display
SSD1306 display(0x3c, 5, 4);
void setup(B4R::Object* unused)
{
display.init();
display.flipScreenVertically();
}
void title(B4R::Object* String)
{
const char* Text = (const char*)String->data.PointerField;
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.setFont(ArialMT_Plain_24);
display.drawString(64, 0, Text); //64 is half the display width in pixels
}
void connected(B4R::Object* String)
{
const char* Text = (const char*)String->data.PointerField;
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_16);
display.drawString(0, 25, Text);
}
void localip(B4R::Object* String)
{
const char* Text = (const char*)String->data.PointerField;
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_16);
display.drawString(0, 45, Text);
//display.drawHorizontalLine(0, 50, 128); //(Left, Down, Right)
}
void cleardisplay(B4R::Object* unused)
{
display.clear();
}
void updatedisplay(B4R::Object* unused)
{
display.display();
}
#End If
Tags: ESP32, WiFi, OLED, Display, Inline, C, C++
Enjoy...
Attachments
Last edited: