B4R Code Snippet ESP32 with built in OLED display progress bar - Inline C

Discussion in 'B4R Code Snippets' started by Peter Simpson, Jul 7, 2017.

  1. Peter Simpson

    Peter Simpson Expert Licensed User

    SubName: An ESP32 with a built in OLED display screen updating a progress bar.
    Description: With this example source code, you can place a progress bar on the screen of an ESP32 microcontroller with a built in OLED display. You can display and update the progress bar using Inline C extremely easily. It's a pretty simple looking progress bar but it does look good if you need one in your project.

    Below is just one way to use Inline C to utilise a small part of the SSD1306 library.
    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 TmrPBar As Timer
    Private UpDown As Boolean
    Private Progress As Byte
    End Sub

    Private Sub AppStart


        TmrPBar.Enabled = 
    End Sub

    Sub TmrPBar_Tick

    If UpDown Then
            Progress = Progress - 
    If Progress <= 0 Then UpDown = False     
            Progress = Progress + 
    If Progress >= 100 Then UpDown = True
    End If

    End Sub

    #if c

    #include "SSD1306.h"

        // Initialize the OLED display
        SSD1306 display(0x3c, 5, 4);

    void setup(B4R::Object* unused)

    void drawbrogressbar(B4R::Object* unused)
        // draw the progress bar
        display.drawProgressBar(0, 32, 120, 10, b4r_main::_progress);

        // draw the percentage as String
        display.drawString(64, 15, String(b4r_main::_progress) + "%");

    void cleardisplay(B4R::Object* unused)

    void updatedisplay(B4R::Object* unused)

    #End If
    Tags: ESP32, OLED, Display, Progress, Bar, Inline, C, C++

    Here it is in action.

    Hypnos, Cableguy and Erel like this.
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. Peter Simpson

    Peter Simpson Expert Licensed User

    Of course I've seen that library @Erel :p
    I've previously posted code snippets on here using your SSD1306 library. For starters it's missing some methods like 'display.drawProgressBar', and in any case it does not connected to this particular ESP32 with built in OLED display.

    Look at the difference yourself.
    Initialising using C:
         SSD1306 display(
    0x3c54);    'Built-in OLED display
    Initialising using B4R:
    9810)    '7 pin OLED display
    40x3c)      '4 pin OLED display
    The library in your link point blank refuses to connect to this particular ESP32 with built in OLED and throws up some error messages, I can't remember the error messages as that was weeks ago. Anyway, all the above does not really matter as there's no drawProgressBar in your library full stop, so it's a waste of time me even looking at it for this particular code snippet example that I wanted to post for others to use.

    I do use your library if I'm coding with every other microcontroller that I own like an UNO, Mega or ESP8266 etc with either my 4 pin or 7 pin OLED displays ;)

    I don't like asking you or anybody else for that matter to update or create libraries especially in B4R as it's a free product and you're a very busy man, so the fact that you cleverly added the ability to use Inline X in B4X products is how I get around waiting for libraries or library updates or just using extra code in B4A and B4R.

    The most annoying thing is that it's taking me a lot longer than I expected to learn C++ and C# (plus I work full time for my clients), and with my currently limited C knowledge I've previously tried to wrap a library following your 'Building a library or wrap an existing library is not an easy task' txt file, man was it was not an easy task and in any case I failed to wrap the library I wanted, so I just used inline C instead :cool:
    Last edited: Jul 9, 2017
    Johan Hormaza and Erel like this.
  4. Hypnos

    Hypnos Active Member Licensed User

    Hi Peter,

    I got the following error, do you know how to fix?
    I tried to rename my Adafruit_SSD1306.h to SSD1306.h but still have error


    C:\Users\simon\Desktop\WEMOSO~1\Objects\bin\sketch\b4r_main.cpp:12:21: fatal error: SSD1306.h: No such file or directory
    compilation terminated.
  5. Cableguy

    Cableguy Expert Licensed User

    Arduino IDE does not like spaces in folders not filenames!
  6. Hypnos

    Hypnos Active Member Licensed User

    Seems not the folder spaces issue, there are many 1306 Library available (I'm using Adafruit's Library). Not sure which one Peter Simpson using?