Skip to content
PekawayPekaway
Picoclick C3 with OLED display

Picoclick C3 with OLED display

The Picoclick C3 from @maker.moekoe is a simple little button that can be programmed with C++. It is based on an ESP32-C3, has WiFi on board and very low power consumption. This makes the Picoclick C3 perfect for use in an IoT environment. We want In this tutorial, you can send an http query to our system with a click and have the battery values ​​displayed on the connectable 0.49 inch OLED display.

For programming we use Visual Studio Code with the extension PlatformIO . We need PlatformIO so that we can compile Arduino code in VSC. Why don't we just use the Arduino IDE? PlatformIO is faster, VSC is clearer and offers significantly more options, especially when it comes to larger projects in which you want to use header files for general configurations, for example.

So after we have installed VSC, the next step is to install PlatformIO. To do this, we click on "Extensions" in the left sidebar, search for PLatformIO and install it.

Then we create our project folder somewhere on the hard disk, where the example code from Github . This can be done either with git via the console (assuming that git is installed), or you can save the Github repository manually. To do this, click on the green "Code" button and you can then download the whole thing as a ZIP file.

The console command with git would be:

git clone https://github.com/makermoekoe/Picoclick-C3 c:\path\to\target\folder

We want to open the example code for the OLED display in our programming environment. In Visual Studio Code we now see a new button for PlatformIO at the bottom of the bar on the left, where the Extensions button is. We now open the project we just downloaded there.

Specifically, we want the repository's project PC3_Hardwaretest_OLED_049, located in the code/Picoclick_C3/ folder.

This example project is specifically for the connected OLED display. With a click on the button, the LEDs turn blue and signal the switched on state, at the same time a scrolling text appears on the display. Another click sends the Picoclick into deep sleep mode.

From now on we will work in the file main.cpp.

We will now extend this code a bit by including the library HTTPClient.h in order to be able to make our http query.

#include <HTTPClient.h>

Then we add our variables at the top so that the Picoclick can connect to the Raspberry's WLAN

The void setup() function is started first when the ESP is switched on, here we connect to the WLAN with the following code:

At the same time, the http endpoint is addressed and we receive a response with the battery values. We save this response in the variable payload so that it can be displayed on the screen later.

A little further down, in line 108 (complete code in the appendix) we calculate the width of the pixels needed to display the text.

That's basically it as far as adjustments go. At this point, the Picoclick wakes up with the first click and queries the http endpoint, receives a response and runs it across the display.

We add the function "esp_deep_sleep_start();" at the very bottom of the code, at the point before the scrolling text starts again from the beginning.

This will display the answer to the query once and then the Picoclick will go back into deep sleep mode.

Please note that the Picoclick must be on in order to be able to flash the code again. If we send it back into deep sleep mode immediately, it could be difficult. That's why we just write a "delay(2000);" right before that, so that we wait 2 seconds (after the text has been run through) before the Pico goes back to sleep and we have enough time to start a flash process.

Now we have to compile the whole thing and upload it to the Pico. We do this using the buttons that PlatformIO provides us at the bottom left:

The hook compiles the code and displays any error messages, the arrow to the right first compiles the code and then loads it onto the Picoclick.

Tips and Tricks:

You can access any endpoint of the HTTP API, so we can also switch relays, etc. It should be noted that a payload must be passed with a "http.PUT("");" function. However, since our API does not expect a payload, we simply send an empty payload with the quotation marks in the brackets.

Of course, the code can be extended as desired, for example, you could make several requests and combine the answers.

If you're wondering whether the query really runs that quickly after you've pressed the button and whether some old saved values ​​aren't displayed: attach a debug node to the http endpoint and you'll see that a request really goes through every time.

API REQUEST IN VIDEO:

https://youtube.com/shorts/JxrJnkMEU04

More links:

https://makermoekoe.gitbook.io/picoclick-c3/

https://randomnerdtutorials.com/vs-code-platformio-ide-esp32-esp8266-arduino/#2

https://devdrik.de/arduino-in-vs-code/

PC3_Hardwaretest_OLED_049-main.cpp txt file:

https://share.12-s.de/s/tMeWqXWozqBZPk9

Leave a comment

Your email address will not be published..

more tutorials

Open Source needs support

become Patron now

More projects, more tutorials and more supported devices. Our community is growing and would appreciate your support. So become a patron now to always receive the latest content and support the VAN PI project at the same time.

Become a Patron
Cart 0

Your cart is currently empty.

Start Shopping