Get started with microcontrollers (ESP32 using native 'C')

The Homebrew Forum

Help Support The Homebrew Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.
Joined
Jul 27, 2020
Messages
4,012
Reaction score
4,141
Location
St Albans, Herts
Want to build your own temperature controller or interface to some simple electronics...? Then use a microcontroller.

Costing less than a cup of posh coffee, microcontrollers are the unseen workhorse of almost every household electronic device. Tiny single-chip computers specialised to the task of monitoring and controlling external devices like switches, LCD displays, relays, temperature sensors and servos. Increasingly they also have WiFi capability which makes them extra useful for remote monitoring applications.


A modern WiFi enabled microcontroller, about the size of a postage stamp:
1632052288023.png

Programs for microcontrollers are typically written on a desktop PC in a high level language like 'C' or Python, then converted into microcontroller code using development tools and transferred to non-volatile memory on the device via a USB cable (or similar).

Many DIY 'makers' start out with the Arduino development tools and boards. These days however the original hardware is decidedly long-in-the-tooth and whilst the development tools are great for beginners they quickly get frustratingly restrictive. Nonetheless most of the instructables and online how-to's still concentrate on Arduino.

In reality if you have a modicum of familiarity with 'C', python etc. then you're probably better off using the free development tools provided by the device manufacturer. These generally give you the best and more reliable performance; but to a newcomer the terminology and diversity of choice can make this feel like a very daunting option.

The purpose of this thread therefore will be to provide a specific walk-though showing how to install and use the development tools for a powerful and widely-used modern microcontroller: the ESP32.

Next post: what to buy...
 
Last edited:
To get started with this walk-through you will need a PC or Mac, a micro-USB cable (e.g. Android charger lead) and an ESP32 microcontroller.
That will let us connect to the device and prove it's alive, but later on we will connect it to a few sensors and what-not.

So here is what you should get (other suppliers are of course available):

1) micro-USB cable: you've probably already got one of these hanging around, but otherwise something like this should work fine

2) ESP32 board: you want to get a board that mentions ESP32-WROOM-32D like this one.

These boards are widely available but there are some post-COVID shortages at the moment so prices are a bit variable, and make sure you get the right type: not one that mentions 'ESP8266' which is a legacy device, or 'ESP32S' which is a security-focussed variant.

Screenshot 2021-09-19 at 13.55.07.png


That should be all you need to get started - total cost less than a tenner.

Next post: obtaining and setting up the software
 
Last edited:
Next step is to obtain and set up the software.

As a reminder, what we are talking about here are the development tools that run on your PC/Mac in order to convert a program written in high-level language into microcontroller code, transfer that code onto the target device, and see the results.

The microcontroller on our board is an ESP32 made by espressif.com. It's based on the 32-bit Cadence/Tensilica IP core (don't worry if that just sounds like tech-babble).
Espressif devices have been around for a while but documentation used to be fairly sparse. Fortunately in recent years the company has advanced that aspect considerably - it now provides detailed instructions on how to get started and good amounts of example code.

As Espressif points out, you basically have two options: (1) get the standalone command line tools; or (2) get plugins for widely-used programming environments like Eclipse or VSCode. For the purposes of this how-to we will be going the command-line route.

Unsurprisingly the initial steps vary between MacOS / Linux and Windows. Personally I'm a Mac user.

MacOS
Before starting you need the essential parts of Apple's own software development tool (Xcode). Fortunately you only need to the command line tools because the full Xcode app is a 40GB download from the app store (albeit a free one).

Open a terminal and type: xcode-select --install. A confirmation dialogue will pop up and then the installation will proceed (it should take about 10min).
You should now be able to follow along with espressif's own step-by-step installation guide from
STEP 2

Windows
Disclaimer: I'm not a Windows user, however the good news for you guys and gals is that installing a standard set up appears to be much more of a ready-rolled process. Follow the instructions here.

Next post: a test project
 
Last edited:
This step assumes that you have already followed the Espressif 'step-by-step' guide up to the end of Step 4.

One of the great things about the Espressif development framework (esp-idf) is that is comes along with a load of ready-to-use examples.

All of the examples are useful, but the classic 'Hello World' one is a good way to check that development tools are working properly and that the device is alive.
This process is well described in the remaining steps of the guide starting from Step 5

If all goes well then after you've gone through all the steps you should be able to achieve something like this:

Screenshot 2021-09-19 at 16.51.28.png


1632066734371.png


Next post: OK I'm over the excitement... how do I talk to a temperature sensor?
 
How are your various esp32 builds going? We're you building something to weigh the kegs to see how much beer was left?
All going great, thanks for asking. One of the great things about these little ESP32 projects is that once they’re built, they just sit there and *work*: time after time without missing a beat. I use the heating controllers every time I brew, and the fridge controller has been running continuously ever since I did the kegerator build… the corny scales work nicely, but the problem is that the kegs are a bit too close together in the fridge to get proper independent readings so for the time being I am relying on the highly technical approach of ‘giving them a bit of a slosh’ to determine how full they are haha
 
I can't remember if it was on this forum or somewhere else, but a month or two back I was reading about a project to monitor how much beer had been poured from a keg that involved a device in the beer out line that monitored the volume of beer flowing through it.
That could make a nice little project.
 
I find that they are fine for use indoors but can be a bit temperamental if used outdoors (in a suitable box) I've not got to the bottom of why, I'm guessing humidity or temperature. Perhaps both.
I'd guess the Russian roulette of genuine vs. 'lookie-likey' products doesn't help.
But brilliant bits of kit for the money.
If / when one packs up the board can be changed out with a replacement complete with code in around ten minutes.

My current geek fest is using WLED for some tree lights.
 

Latest posts

Back
Top