3 minutes, 0 seconds

Reading time (calculated automatically): 3 minutes, 0 seconds

I recently bought the NodeMCU ESP32 Heltec (called "heltec_wifi_lora_32_V2") to just getting to know the platform a bit better. I've been hands-off on hardware for most of my years, but I figured with little time on my hand I could learn the basics of microcontroller chips fast and built something nice as a toy project.

The board

V3 can be viewed here, in case you're wondering how it looks. The additional sources I used are from here.

I didnt order it from AliExpress, which would've cost me probably under 5 EUR per, but I didnt want to go through the hassle of going through custom services in order to fetch my package from China, so I instead ordered it from a local store. It arrived within 1 business day including a nice book by "Danny Schreiter" called Arduino Kompendium - Elektronik, Programmierung und Projekte".

First start by giving power to this thing

First thing I did with this thing was start it with the (non included) USB Mini cable I had lying around (from the PS3 days luckily). The initial programm running on this chip was to showcase the mounted OLED 0,96" display with various text and ascii images.

Building my own examples

It was time to go through some examples and flash the chip myself.

Initially a small free pdf file that came with the purchase wanted me to use Arduino as my main editor for the code. After trying it I found it very old school and somewhat limiting, so I opted to go for the more up2date soluation using "PlatformIO" within VSCode. Usually I go with the Jetbrains IDE's but since I dont have a CLion license thats not an option for me at the moment.

It was very easy to get started in VSCode and PlatformIO. Simply install VSCode, install the excention "PlatformIO", "C/C++", "Clang-Format" from the marketplace and you're good to go.

After restarting VSCode you will notice this new icon on the "main bar":

The PlatformIO icon within VSCodes main navigation bar

Click it and select in the "Quick access" frame "Open" under "PIO Home". There you can open a project or create a new one. Select the target board from your ESP32 and after initialized (and downloaded necessary SDKs) you can start writing code.

For now lets write a simple "Hello World" program.

Open the "platformio.ini" file and add

monitor_speed = 921600

The full contents of this file for my board now are

[env:heltec_wifi_lora_32_V2]
platform = espressif32
board = heltec_wifi_lora_32_V2
framework = arduino
monitor_speed = 921600

And our "Hello World" program in the "main.cpp" file looks like this:

#include <Arduino.h>

void setup() {
  Serial.begin(921600);
  Serial.println("Hello World");
}

void loop() {
  delay(1000);
  Serial.println("Hello from loop");
}

Compiling and sending it in the bottom navbar of PlatformIO is two buttons each and afterwards you can go to the Serial monitor to see the messages come through.

Serial monitor showing our hello world messages

Same hello world but with the use of the OLED display

#include <Arduino.h>
#include <heltec.h>

void setup() {
    Serial.begin(921600);

    Serial.println("Loaded");

    Heltec.begin(true, false, true);
    Heltec.display->setFont(ArialMT_Plain_24);
    Heltec.display->clear();
}

void loop() {
    delay(1000);
    Heltec.display->clear();
    Heltec.display->setTextAlignment(TEXT_ALIGN_LEFT);

    Heltec.display->clear();
    Heltec.display->setFont(ArialMT_Plain_10);
    Heltec.display->drawString(0, 0, "Hello world");
    delay(1000);
    Heltec.display->display();

    Heltec.display->clear();
    Heltec.display->setFont(ArialMT_Plain_16);
    Heltec.display->drawString(0, 10, "Hello world");
    delay(1000);
    Heltec.display->display();

    Heltec.display->clear();
    Heltec.display->setFont(ArialMT_Plain_24);
    Heltec.display->drawString(0, 26, "Hello world");
    delay(1000);
    Heltec.display->display();
}

"heltec.h" is in the "lib" folder, from official sources.