Ultimately, the input is the sensors, and the output is a value in Home Assistant
Sensors → STM32 Microcontroller → W5500 (TCP/IP + Ethernet PHY) → MQTT Server → Home Assistant
There are two primary sensors for measuring the environment:
- Bosch Sensortec BME280
- Temperature
- Humidity
- Pressure
- Texas Instruments OPT3002
- Luminosity
These sensors are connected to the main board with short RJ-11 cables that connect to the I2C bus on the microcontroller. In the case of the BME280 the external connection was necessary to obtain accurate measurements, the main PCB is hotter than the ambient environment, and it would skew temperature readings.
For the OPT3002 the external connection is to allow for easy positioning of the sensor.
The BME280 was chosen over cheaper alternatives, such as the Aosong AM2032 (DHT22) because this in depth review speaks highly of the BM280 as compared to similar devices.
The STM32F070CBTx was chosen because:
- STM provides a very good hardware adapter layer (HAL) for their micro-controllers.
- STM provides a FreeRTOS port for their micro-controllers.
- I wanted to do something new, my past projects have been mostly AVR.
The firmware uses FreeRTOS for scheduling, simply because it seemed like a fun learning experience, and it was!
The micro-controller has 4 main threads running:
- A sampling thread for the BM280
- A sampling thread for the OPT3002
- DHCP client
- MQTT client
The sampling threads take data from the sensors and place it in a queue for the MQTT task. The MQTT client thread pops the samples from the queue and publishes them to the MQTT server. The DHCP client thread handles the leasing of an IP from the DHCP server.
In the interest of learning new things I also made some poor choices intentionally; I implemented my own DHCP client code, and my own MQTT client code. This was not the smart choice, since there are polished DHCP clients out there, such as the one in LwIP, but this was the fun choice.
Instructions for using the firmware can be found here.
I wanted to get the PCB for this right on the first try, so I prototyped everything on a breadboard.
Naturally a lot of components were not available in 2.54mm friendly packages, I made some breadboard friendly boards for these components:
Debug tools used
- ST-LINK/V2 - USB debugger/programmer
- Saleae Logic 8 - USB Logic analyzer
- TP-Link TL-POE150S Injector - PoE Injector
- FTDI Friend v1.0 - USB to serial adapter
The PCB is bigger than it needs to be because I was using the sample footprint that I have used for previous projects.
The sensors are on their own PCB with an RJ-11 connector.
- UASRT1_TX is connected to PA11, UASRT1_TX should be connected to PA9
- The OPT3002 should be replaced with the OPT3001 since it has a response characteristic similar to the human eye.