Code structure
Directory structure
On the file explorer on the left panel of VS Code, you will see that the basic directory structure of our hello
PIO project looks like this:
Let’s go over them.
.pio
Everything in this folder is auto-generated by compiling the code. All compiled binaries go to .pio/build
. firmware.bin
was generated by the krate build
command, and represents the krate
that we want to flash to kublet.
.pio/libdeps
contains all the dependencies of our project. All dependencies of the project are declared in the platformio.ini
file.
.vscode
VS configs. No reason to touch these.
src
main.cpp
contains the entry point of the firmware.
All .cpp
and .h
files go here.
.gitignore
You only need to track src/
and platformio.ini
.
platformio.ini
This file contains the configurations and dependencies of your project. You can edit this file accordingly.
platformio.ini
is a configuration file that lets you set up your development environment with declarations. In your platformio.ini
file, you will see that 3 dependencies are declared:
We use KGFX
, our graphics library for handling displays. KGFX
provides wrapper functions for common UI patterns on kublet. It is based on the TFT_eSPI library. We also need to install our OTAServer
library for enabling flashing code during the development process.
Code structure
Every Arduino code has a basic code structure that looks like this:
Let’s go over what we’ve added in main.cpp
.
On the file explorer on the left column of VS Code, open src/main.cpp
.
We won’t go over the basics of writing Arduino code here. If you’re just getting started with Arduino development, it would be helpful to refer to resources online to get up to speed on basics. If you feel stuck at any time, feel free to leave a question on our Discord channel.
Our code in main.cpp
is the entry point of the firmware. We’ve added code for enabling flashing firmware during development and displaying text on the kublet screen.
Flashing firmware
There are 3 lines in the code marked DO NOT EDIT
.
In void setup()
and in void loop()
These 3 lines of code are essential for a continued development process. Since our firmware is flashed over WiFi, the first part of the code ensures that we’re connected to WiFi before we enable kublet to listen for firmware updates.
If you wish to be able to develop and flash code to kublet during the development process, do not touch any part of the code that is marked as DO NOT EDIT
.
Font
Our default font is Arial. Our KGFX
library comes bundled with support for Arial fonts. Comes in bold and regular types.
Display
Our KGFX
library provides common display functions for display text, numbers, and graphs. Try changing the text, color, and position on the kublet like this. Go to main.cpp
, replace
Then build, and flash the firmware again. You should see changes on the screen.