Electronics

A script to generate KiCad board outlines

PCB fabricators require a board outline on the `Edge.Cuts` layer to specify the board size and shape. While drawing the board outline in the PCB editor is straightforward and uses the standard line and shape drawing tools, it is convenient to retain standardized board outlines and related parts, such as fasteners, as reusable footprints. During the board layout process, you can simply plop a board outline, along with perfectly-placed mounting holes into the editor and you can concentrate on the placing components and routing. Also, having a standard library of board outlines gives you a predictable set of size choices for enclosures and for ordering SMD stencils.

This is why I created KiCadBoardOutlineGenerator, a script to generate board outlines from dimensions you specify.

GPIO initialization on the ESP32 in ESP-IDF

This is just a quick post on how not to initialize a GPIO in ESP-IDF. A tutorial on Embedded Explorer discusses GPIO use in ESP-IDF and suggests initialization in this way:

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"

#define LED_PIN     GPIO_NUM_32
#define BUTTON_PIN  GPIO_NUM_36

void app_main(void)
{
   gpio_set_direction(LED_PIN, GPIO_MODE_OUTPUT);   
   gpio_set_direction(BUTTON_PIN, GPIO_MODE_INPUT);
   
   while(1) {       
      if (gpio_get_level(BUTTON_PIN) == 0) {  // If button is pressed
         gpio_set_level(LED_PIN, 1);         // Turn the LED on
      } else {
         gpio_set_level(LED_PIN, 0);         // Turn the LED off
      }
      
      vTaskDelay(1); // Add 1 tick delay (10 ms) so that current task does not starve idle task and trigger watchdog timer
   }
}

This of course works, but I wanted to clear up matters because I think this takes some major shortcuts. Here is what I would suggest instead:

A quick word on ATtiny 1-series interrupts

The Atmel AVR 8-bit microcontrollers have always been a favourite for tinkering; and the massive popularity of the Arduino based on the ATmega 168 and 328 MCUs introduced a lot of hobbyists to this series. The companion ATtiny series from Atmel were the poor stepchildren of the ATmega controllers to an extent - useful for small projects but often quite limited. However, the acquisition of Atmel by Microchip Technology in 2016 ushered in a new series of MCUs bearing the same moniker of ATtiny, but much more capable and innovative. They have been around for a while now, but many hobbyists are just beginning to poke around with these new capable MCUs.

ESP32, DS18B20, TM1637 integration: Displaying temperature data

In a previous post I wrote about displaying arbitrary data on a TM1637-based 4 digit LED display, highlighting an ESP-IDF component that I extended to display positive and negative floating point numbers. Now we’re going to put that component to use and display actual data from a DS18B20 temperature sensor.

The {% asset_link DS18B20.pdf “DS18B20” %} temperature sensor operates on the Dallas Semiconductor 1-Wire bus. In this application, we aren’t powering the devices using parasitic power. Instead we’re powering the device from an external supply.

Interfacing an ESP32 to an MCP23017 GPIO expander

While the ESP32 sports a number of GPIO pins, not all are broken out on every board, meaning that sometimes a GPIO expander is necessary. This project is a simple design to test interfacing the ESP32 to an MCP23017 via the I2C interface.

MCP23017 I2C addressing

There are so many tutorials on the MCP23017 that I won’t delve in depth into how it works, but I’ll point out a few features of the custom MCP23017 component that I’m developing as part of this demonstration project. If you need to get up-to-speed developing applications using I2C within the ESP-IDF environment, this tutorial from Luca Dentella is excellent and concise.

Using TM1637-based LED displays with ESP32

There are three main types of 4 digit seven segment displays to be found on the market:

  • Bare displays without any driver. These come in a variety of colors and with either decimal points or clock-type display with a colon dividing two sets of two digits.
  • 74HC595-based displays. Usually these displays have two daisy-chained 74HC595 shift registers and rely on the host controller to fill the serial registers and handle the multiplexing. Depending on the processor speed, this ends up being a significant overhead.
  • TM1637-based displays. These displays reduce the burden on the host controller because all of the multiplexing is handled on the interface chip.

Getting ESP32 to talk to TM1637-based displays

This post is about the TM1637 LED displays. The {% asset_link Datasheet_TM1637.pdf TM1637 datasheet %} is terrible, but fortunately there are several libraries for Arduino that provide a little insight into how others have managed to make this work. First things first, the communication protocol for this device is not I2C despite what vendors on Aliexpress frequently claim.

Serving sensor data via ESP32

Previously, I wrote about using the ESP32 to read sensor data over I2C from the Si7021 temperature and humidity monitor. Today, I’m going to briefly take you through the process of serving this data via the web.

Basic project setup

Description

The project plan is to connect to WiFi in STA mode, collect temperature and humidity data every 5 seconds from a Si7021 sensor via the I2C bus. We will launch a web server and whenever we have a GET/ request we’ll serve a simple web page that reports the temperature and humidity. If the URL path is /h (e.g. 192.168.1.x/h) then we’ll turn on an LED connected to GPIO 4. If the path is /l (e.g. 192.168.1.x/l) then we’ll turn off the LED. In both latter cases, we’ll also serve the same page showing the temperature and humidity.

ESP32 reading Si7102 temperature and humidity data via I2C bus

Recently I wrote about reading Si7021 temperature and humidity data using a Raspberry Pi. Now let’s try a completely different platform, the ESP32. This is essentially a project to explore using I2C on the ESP32 platform and to understand the build process.

Project layout

Since we’re developing the Si7021 interface code as a reusable component, we need to structure our project in such a way that we can easily refer to it in our main code. Here’s how I structured this project:

Setting up Arduino IDE with Heltec ESP32 module for macOS

Heltec WiFi Kit 32 ESP32 module

The Heltec WIFI Kit 32 is an interesting little module that integrates a WiFi/MCU SoC and a small OLED display on a single board. If you want to set up the Arduino IDE to work with this device and you’re on macOS, this is for you. This particular ESP32 module has a number of impressive features: 240 MHz processor speed and 4 MB of flash memory. The onboard OLED display can be conveniently used for debugging.

A software debouncing class for rotary encoders

Rotary encoders are notoriously difficult to get right.

Although I haven’t used this new encoder class yet, it looks very interesting. From active Teensy forum user Theremingenieur, it allows initialization with upper and/or lower limits.

You can find the code in this thread.