I2c

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:

Implementing a simple menu interface on OLED display

While working on a project to automate environmental control in our greenhouse, I needed to implement a menu interface on a small OLED display. In this sub-project, meant to test the concept, I’ve used a Teensy 3.1, a small I2C-driven 0.96" monochrome OLED display and a rotary encoder.

Bill of materials:

  • Teensy 3.1 - the Teensy 3.1 is no longer available, but you can easily find the compatible Teensy 3.2.
  • 0.96" yellow/blue I2C OLED module - I used the version with the yellow band at the top so that it this area could act as the highlighted region of the display.
  • Rotary encoder with push-button switch - I used this one from Adafruit, but there are many options.
  • {% asset_link MC74HC14.pdf 74HC14 Schmitt Trigger inverter %} - to debounce the pushbutton.

Description

This project is a proof-of-concept for using a rotary encoder to manipulate an on-screen menu of options. A number of electronics design concepts are used here.

Reading data from Si7021 temperature and humidity sensor using Raspberry Pi

The Si7021is an excellent little device for measuring temperature and humidity, communicating with the host controller over the I2C bus. This is a quick tutorial on using the Raspberry Pi to talk to this device. If you are unfamiliar with the conceptual framework of I2C or how to enable I2C access on the Raspberry Pi, I suggest starting here. Otherwise, let’s jump in.

You are probably working with the device mounted on a breakout board. I used this one from Adafruit. There are no surprises on the pins that it breaks out - Vin, 3v out, GND, SCL and SDA. One the 40-pin P1 header of the Raspberry Pi, SDA and SCL for I2C bus 1 occupy pins 2 and 3.

Using the Raspberry Pi to communicate over the I2C bus using C

I recently wrote about using the excellent bcm2835 library to communicate with peripheral devices over the SPI bus using C. In this post, I’ll talk about using the same library to communicate over the I2C bus. Nothing particularly fancy, but you’ll need to pay careful attention to the datasheet of the device we’re using. TheTSL2561 is a sophisticated little light sensor that has a very high dynamic range and is available on a breakout board from Adafruit. I’m not going to delve into the hookup of this device as you can take a look at the Adafruit tutorial for that. Note that we’re not going to use their library. (Well, I borrowed a bunch of their #define statements for device constants.)

ADC for Raspberry Pi

I’m working on launching a high-altitude balloon later this year with a Raspberry Pi serving as its flight computer. The Raspberry Pi is an excellent tool because it allows you to do most common tasks at a higher level of abstraction than other MCU platforms. However, it lacks at least one of the major conveniences of MCU’s like the AVR that I’m accustomed to working with - the analog-to-digital converter (ADC). In this article, I’ll describe one solution to the missing ADC, albeit a little complex. For this project, I’m using an ATTinyx61 to serve as the ADC, communicating with the RPi as a slave on the I2C bus.