linkstation.mp4
An ESP32 WiFi cryptomonitor to display cryptocurrency prices based on quotes obtained via cryptocompare.com API. The code built on top of the Arduino framework is even for beginners easy to customize.
- Features overview
- Components and supplies
- IDE and libraries
- Project setup
- Breadboard and wires
- I2C OLED display
- Wiring
- Setup WiFi & API, upload
- Customization
- Acrylic case
- Thank you
- real-time quotes for cryptocurrencies
- BTC, ETH, LINK, ADA (default values)
- 24h price change in %
- current date and time
- graphical logos in 3 sizes (only for Chainlink implemented)
- factored, easy to extend
- every displayed page is a own function
- static defined text strings
- 2 text sizes
- ESP32 board (AZ-Delivery ESP-32 Dev Kit C V4)
- 0,96 inch OLED I2C SSD1306 Display 128x64 (AZ-Delivery 0,96 Zoll OLED I2C)
- Breadboard, 1/2 size
- 4 wires (Kopp 791560 150210001)
- USB cable for uploads and power supply
Code was written with platformIO/Atom, this means you have to alter the provided code before you can compile it using the Arduino IDE. Here is a quick guide on how to install the PlatformIO IDE package for Atom. It is assumed in this tutorial that you have installed platformIO/Atom and that your board is supported.
Regardless of your IDE you also have to install some additional libraries:
Before you explore the hardware components, breadboard arrangement and wiring, set up as first the code barebone of the project:
- Click on the PlatformIO Home button on the PlatformIO toolbar
- Click on New Project
- Name your project
- Search/Select your board
- Select Arduino framework
- Hit the Finish button
That's a empty but basically working project that you can upload to your board. Next you will add the required libraries to your project:
- Click on the PlatformIO Home button on the PlatformIO Toolbar
- Click on Libraries to open the library manager and search for Adafruit GFX
- Click the result Adafruit GFX library
- Click on the Installation tab
- Hit the Add to project button
Repeat the steps 2. - 4. To add the libraries Adafruit SSD1306 and ArduinoJson.
Your platformio.ini
project file should now look like this:
[env:az-delivery-devkit-v4]
platform = espressif32
board = az-delivery-devkit-v4
upload_port = /dev/ttyUSB0
framework = arduino
lib_deps =
adafruit/Adafruit GFX Library@^1.10.12
adafruit/Adafruit SSD1306@^2.4.7
bblanchon/ArduinoJson@^6.18.5
It's still a empty project but everything further is just to copy & paste the content of the attached main.cpp
file and to adjust some variable values. Stick to the code later. Focus now on hardware components, breadboard arrangement and wiring.
ESP32 boards have many outstanding features, but the dimensions are known to be not one of them. Many people consider them to be breadboard unfriendly because when prototyping they only leaves 1 row of available pinholes on the board. But that's not a big issue for this project. Just do the wiring first and then add the components to the breadboard. Use a half-size breadboard because it fits nearly perfect. The double-strip in the middle is ideal to hide the display wires. Pull of the power rails on both sides to make it as thin as possible.
You can try dozens of different types of wire, but you will end up coming to the same conclusion as most users: The best wire for breadboards is simple solid core wire, like the ordinary bell wire listet in the components list.
There are some benefits using a OLED display:
- I2C needs only 4 wires (GND, VCC, SCL, SDA)
- graphic displays, not limited to text
- high resolution and very legible
- low power, no backlight needed
- useable without external power supply (3.3V)
- fast refresh rates
- space-saving and not bulky
- popular Adafruit SSD1306 library
The ESP32 has two I2C bus interfaces. Using I2C communication protocol, wiring is as simple as connecting GND to GND, SDA to SDA, SCL to SCL and a positive power supply to a peripheral, usually 3.3V:
OLED Pin | ESP32 Pin |
---|---|
GND | GND |
VCC | 3V3 |
SCL | 22 |
SDA | 21 |
You know enough about connecting the ESP32 and the OLED display. Start now wiring the breadboard. Try bell wire to achieve this and stick to the wiring sketch exactly, the colors of the wires are of course irrelevant.
Then plug the display and the ESP32 into the breadboard. Be sure to use the correct pinholes:
- Display:
a1 - a4
- ESP32:
a30 - a12
andi30 - i12
Connect the ESP32 to your computer using the usual USB cable. Congrats, you are done with the hardware part.
To bring your new cryptostation to life, you have to add some code to it. You already created the project and installed all the necessary libraries. Now copy & paste the attached code into your main.cpp
file, adjust the values for your WiFi connection (line 89-90
) & cryptocompare API key (line 103
) and upload the project to your ESP32 board.
const char *SSID = "xxx";
const char *PASSWORD = "xxx";
String apiKey = "xxx";
main.cpp
is stored inside the src
directory of your project. When you create a project, platformIO automatically adds some required definitions and functions to main.cpp
, remove these before pasting the code. Compile and upload task can take a while. If everything goes right, you will soon see the Chainlink logo.
If you get past the hurdle of installing the IDE and libraries, customization will not be a hard challenge. Following happens inside the Arduino main loop:
setup()
configs the data filterupdate()
loads data from APIsetData()
prepares data for renderingdisplayPages()
,showPage__CRYPTO()
displays data, e.g.showPage__BTC()
The display output is implemented inside displayPages()
(line 271-283
). Within a for loop which defines the number of repetitions shown on the OLED display, separate functions are called for each cryptocurrency to display their data on a individual "page". This means more code, but it's easier to maintain.
// Display loop
for (int count = 0; count <= 1; count++) //2
{
if (cryptocompare_httpCode == 200)
{
showPage_BTC();
showPage_ETH();
showPage_LINK();
showPage_ADA();
}
}
This is what you have to keep in mind if you want to customize the program:
Customize | Variables | Functions |
---|---|---|
URL-Endpoint | String apiSyms , line 102 |
|
Data | e.g. double price_BTC , line 107 |
setup() , line 326 - 333 |
Data | setData() , line 286 - 305 |
|
Display | e.g. const char *CRYPTO_BTC , line 18 |
displayPages() , line 271 - 283 |
Display | e.g. showPage_BTC() , line 174 - 195 |
When you turn on your ESP32 you will see a big Chainlink logo and also a small one on the LINK page. This "images" are stored in flash memory (PROGMEM) (line 26, 57, 68
). You can delete the corresponding code or replace the code with your desired graphic.
Read more about the used Adafruit GFX library function and feel encouraged to learn more about the graphics library to get more out of your OLED display. Use image2cpp to convert an image into Arduino C code, it's the best tool you will find.
Code example to output a graphic: (line 228
):
...
display_1.drawBitmap(105, 0, logo_link_xs, 12, 13, WHITE);
...
A simple case can be put together quickly. You need two acrylic sheets with 3mm holes and some color anodized M3 screws & spacers. The acrylic sheets can be ordered online (German supplier, good quality), cut to size and drilled. Make sure that the sheets are laser cut and properly deburred. Nice spacers and screws of decent quality you will find at a well-sorted RC helicopter and drone shop.
The rear of most breadboards is self-adhesive. Simply stick the pre-wired breadboard to the rear acrylic sheet, plug the components into the breadboard and screw finally both sheets tightly using the screws and spacers.
- 1x acrylic sheet 10mm (back)
- 120mm x 60mm x 3mm
- 3mm holes, 5mm between center of hole and edge
- 1x acrylic plate 3mm (front)
- 120mm x 60mm x 3mm
- 3mm holes, 5mm between center of hole and edge
- 4x color anodized M3 spacers 20mm
- 8x color anodized M3 screws 16mm (M3x16)
Thank you for reading this very long tutorial. Hope you enjoyed it to built your own cryptostation. If you have code reladed questions, comment here or contact me on twitter.