Generic Sensor Hat

Some sensors like 3D sensors are suited to be mounted directly on a Hat, but a majority of sensors actually need to be mounted remotely to provide proper input. To interface to these I need an adapter card with connectors as illustrated above.

STM32F405 have 16 ADC inputs that also can be used as GPIO sampling at speeds up to 2.5Mhz with a 12 bit resolution. So, what I want to do is to pair an ADC with a pure Digital IO and 3V/5V and ground – a standard 4 wire interface for sensors.

The 2nd interface is I2C. I2C needs 4 wires – V, GND, SCL and SDA.

The 3rd interface is SPI. Combine V,GND, MISO,MOSI,CLK and a separate CS – a total of 6 wires per device as a standard SPI Sensor port.

The 4th is CAN with a classic 4 wire Interface.

The 5th is RS485 with a classic 4 wire Interface.

Most existing breakout boards and sensors can be wired into one of those connectors giving us a very generic sensor hat. Just a few case studies:

My last post was about a 3D Motion Sensor also known as a 9-DOF. It is 9 sensors available through either I2C, SPI or both.

Ultrasonic Wave Sensor is well known. They cost < 1USD and can detect movement/distance in ca 5 meters range. They send a 40Khz ultrasound pulse and detect the time to the feedback. These sensors have a pulse output, meaning you need a digital IO pin as interface. They also needs to be mounted remotely as they need to be positioned where on the edge of vehicles. They interface well to the 4 wire analogue ports.

Capacitance Soil Moisture Sensor is a long stick inserted into the soil that give an analogue value out describing how wet the soil is. Some of these sensors use a digital threshold chip so the actual output is digital 1. You basically need +3.3V, GND and an ADC signal for these. so it’s a good match for the 4 wire analogue port.

DMT22 is a temperature and humidity sensor. It basically report the readings using a proprietary digital, single wire protocol. You use a GPIO to read pulses that convert into a binary string etc. It is a good match for the 4 wire analogue port.

DS18B20 is a well know temperature sensors using it’s own single wire protocol. This sensor is low cost and you get it in 1m cable length well suited for outdoor usage. It is an excellent sensor to measure temperature at various points. DS18B20 is also available in TO92 package. Again an excellent match for the 4 wire analogue port.

KY-037 is a breakout board with a small microphone. It gives an analogue sound output as well as a digital sound indicator output. It cost < 0.5USD. It uses a 4 wire interface that is found on several sensors 5V, GND, Analogue Out, Digital out. The 5V is legacy on a lot of sensors. Again an excellent match for the 4 wire analogue port.

AH3503 is an example of a Hall Effect Sensor. These take 5V in and return an analogue value indicating the level of the magnetic field. They are used in motors to detect rotor positions etc. Again an excellent match for a 4-wire analogue port.

I have also made some RS485 sensors and CAN actuators that will interface well to this Hat.

I basically have all these interfaces already on some Hat’s, so this is more about making dedicated ports available for easy plug & play. What I actually put on this Hat will need to be a horse trade between MCU pins and edge space on the Hat. I already have plenty of CAN/RS485 interfaces, so those will only be added if I have the pins/space. I will need to look a bit into storage as well.

Leave a Reply