-
Notifications
You must be signed in to change notification settings - Fork 8
Programming the H32
I assume that you have some familiarity with the Arduino IDE, because we will use it to program the H32. You might ask, why not a real development IDE, but an underlying decision was to make building this thing as simple as possible, and this means the Arduino IDE.
If you have never programmed a bare-bones micro-controller before then the following will be a new experience, but the process is as simple as programming an Arduino Nano.
The H32 uses an ESP32, and to compile software for it we need to install the correct board definition with its associated libraries (the core). Espressif has done a remarkable job providing a high-quality core. It can be installed by using the Board Manager (under "Tools->Board...->Boards Manager". Enter "ESP32" in the search field and hit the Install button for the Espressif core.
To install the needed libraries, go to "Tools->Library Manager". In the search field you can enter the respective library's name or the author's name and, when it is shown, click the Install button.
These are the versions of libraries, core and IDE that I used, newer ones shouldn't be a problem.
Library | Author | Version |
---|---|---|
Arduino IDE | Arduino | 1.8.19, 2.2.1 |
ESP32 core | Espressif | 2.0.2 |
Adafruit_AHTX0 | Adafruit | 2.0.1, until v.2.24.1 (adds additional libraries) |
AHTxx | enjoyneering | from 2.25.1 onward (has to be downloaded from https://github.com/enjoyneering/AHTxx) |
SparkFun MAX1704x Fuel Gauge Arduino Library | Sparkfun | from 2.25.1 onward |
WiFiManager | tzapu | 2.0.9-beta |
Thingspeak | Mathworks | 2.0.1 |
PubSubClient | Nick O’Leary | 2.8.0 |
ArduinoJson | Benoit Blanchon (https://arduinojson.org/) | 6.19.2 |
Download all the files in the H32_Basic subdirectory and open the corresponding directory in your Arduino IDE. Now change the target board to "ESP32 Dev Module", change the Partition Scheme to "default 4MB with spiffs (1.2MMB APP/1.5MB SPIFFS" if it is not selected already and leave all the other configuration options untouched.
Hit the Compile button and after some time the compilation should finish successfully. If not, then check the list of preparations again.
In the main file H32_Basic.ino there are two variables you might want to change. The setting H32_Debug decides whether debug messages are sent over the serial port. In the beginning this is very helpful to e.g., determine whether you configuration of a cloud service API was correct. Later on, you can remove it (simply by commenting it) if you want to further optimize the energy consumption. The second value that you could change is the password used for the captive portal. This is stored in the variable ap_value and you can change it to whatever value you wish.
Everything else is configured using the configuration page through your browser, so no further configuration has to be done at compile time.
By clicking the Upload button the code is sent through your trusted USB2Serial converter to the H32 board. When you connect your H32 for the first time, for simplicity's sake do it without a battery and connect the 3.3V of the converter to the H32. This way you don't have to worry about the power switch, whether or not your battery is charged etc. Later, when you have added the batteries to the board, you should not connect the Vcc cable of the converter to the H32, only the GND, TX and RX.