Air Quality Sensing
Goal
We will use a sensor hat to attach several I2C sensor modules.
We will install driver software and readout the sensors.
We will publish the data to MQTT data broker.
CAUTION
Do not attach the sensor board to the energized Pi without having it checked by course staff.
You need to measure resistance between 3.3V and GND and it should read more than 200 Ohms.
You need to measure resistance between 5V and GND and it should read more than 200 Ohms.
You need to measure resistance between 3.3V and 5 V and it should read more than 200 Ohms.
YOU CAN NOT MEASURE RESISTANCE WHEN YOUR CIRCUIT IS POWERED ON.
Thonny
In order to use Thonny and the virtual environment you need to change the Python interpreter in Thonny to the one in the virtual environment.
Switch Thonny to regular mode: Top right text link.
Restart Thonny.
In Tool->Options select interpreter.
Browse for python3 in the ~/pythonBME210/env/bin folder
Air quality Sensors for this Assignment
BMP180 (easiest for next lab)
Measures, barometric pressure, this sensor is no longer manufactured and was replaced with BMP280.
Board Make GY68
Distributor and cost, Aliexpress, $0.5
Supply Voltage 1.8..3.6
Datasheet: https://www.mouser.com/datasheet/2/783/BST-BMP180-DS000-1509579.pdf
I2C Address: 0x77, fixed
I2C Frequency: up to 3.4Mbit/s (standard, fast, high speed)
Example Code:
Installing the driver:
cd ~/pythonBME210
source env/bin/activate
pip3 install Adafruit-BMP
optional arguments in the code
if you create i2c interface with board command: sensor = BMP085.BMP085(i2c=Your_i2c_interface)
if i2cdetect -y 1 shows the sensor at an address different than 0x77: sensor = BMP085.BMP085(address=0xNumber_you_found)
BMP280 or BME280 (second best for next lab)
Measures, barometric pressure and temperature.
BME280 additionally measures humidity (likely all our sensors are BMP and dont have humidty module)
Board Make Hiletgo
Distributor and cost, Amazon, $2.0
Supply Voltage 3.3V only!
Datasheet:https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp280-ds001.pdf
I2C Address: 0x77 (SD0 VCC), 0x76 (SD0 GND), SD0 is bulled to GND on board, if you want 0x77 you need to connect to Vcc
I2C Frequency: up to 3.4Mbit/s (standard, fast, high speed)
Sample Rate: < 150Hz
Example Code:
The driver can be installed with:
cd ~/pythonBME210
source env/bin/activate
pip3 install adafruit_circuitpython_bmp280
HUT21D (easiest for next lab)
Measures Temperature and Humidity
Board Make HTU21D
Distributor and cost: Sparkfun, $8 ($1.4 on aliexpress)
Supply Voltage: 1.5..3.6V
Datasheet: https://cdn-shop.adafruit.com/datasheets/1899_HTU21D.pdf
I2C address: 0x40
I2C frequency: 400kHz max
Example Code:
The driver can be installed with:
cd ~/pythonBME210
source env/bin/activate
pip3 install adafruit_Circuitpython_HTU21D
Work Schedule
First Lab
Follow instructions on crimping.
Conectorize one sensor by crimping 4 wires of 6-12 indh length using the colors show below.
Obtain one pre-made sensor hat and one pre-made sensor. Make sure no connections are shorted and prevent shorts.
Obtain and install driver software.
Start developing software for at least two sensors.
Second Lab
Finish developing software and test sensors.
Third Lab
Publish data on MQTT server
Selection of Hardware per Student
Sensor Hat
One prebuilt Sensor Hat
Sensors
One prebuilt sensor
Select HTU21D, BMP180 or BMP280
One bare sensor breakout board,
Choose HTU21D or BMP280
5 crimpable pins
One 4 pin Dupont JST HX female connector
Wire red for 3.3V
Wire black for GND
Wire white for I2C clock (SCL)
Wire blue for I2C data (SDA)
Build Instructions
Sensors
Pre-built Sensor with Wires and Connector
Make sure all wires are connected properly.
Bare Sensor
Cut 4 wires of appropriate color (red, black, white, blue) for your sensor and 6 inches long.
Strip approximately 2mm of insulation on one sides.
Crimp the wire onto the metal pin as demonstrated here: https://youtu.be/l0rAEPJoWeE.
First crimp the middle of the connector to the bare wire,
do not push the wire past the middle section (see image below, the green wire).
use 1.3mm crimp.
insert the pin into the crimper, it will fit snug.
push the big flaps towards the crimper so that the end part of the pin that slides onto the pin in the connector is not getting damaged.
insert wire into the crimper so that insulation is on the big flaps and the bare wire in the crimper.
push crimper hard so that wire will not fall out when you are done.
Second crimp the big flaps onto the insulation of the wire. Use 1.9mm crimp.
do not push hard, otherwise you will damage the insulation.
Make sure the pins are fully attached to the wire by gently pulling on them.
Insert all pins with the wire into the Dupont JST connector. According to the following order: GND, 3.3V, SDA, SCL (as per diagram below). The sensors will need to be made so that they are interchangeable with any sensor-hat.
Cut all 4 wires to the same length
Strip the insulation on this side
Solder the wire to the appropriate pad on the bare sensor breakout board. You can stick it through the hole or attached over the hole.
Sensor Hat
Prebuilt Hat
Make sure the prebuilt sensor hat has a 40pin GPIO connector attached. It will need to have the long pins, so you can stack multiple boards on top of each other.
If the prebuilt board does not have the GPIO connector attached, place it through the holes. The long pins will need to come out at the same side as the Dupont JST HX connectors and the black plastic will need to be on the solder side of the sensor hat PCB.
The following legs will need to be soldered onto the sensor board: 3.3V (pin 1), SDA (pin 3), SCL (pin 5), GND (pin 9), GND (pin 39) and 5V (pin 2). Do not solder the other pins. Best is to solder one pin, then check if the connector is flush with the board. Then solder pin on the opposite side of the connector. Solder only at the pad not along the whole pin (otherwise you can no longer stack other hats on top of yours).
Make sure the installed sensor hat does not short on the CPU heatsink. If it is close to the cooling fins, you need to attach electrical tape to the bottom of the sensor hat.
Software
Install the drivers software as listed above for each sensor your team has. Read the description on the website. Make sure you have a test/demo program for each of your team's sensors on your raspberry pi. The code on github includes example programs. Make a copy on your Raspberry pi. Modify the program to match the sensors address.
if you want to see if your sensor is recognized:
sudo i2cdetect -y 1
Should show you hardware clock at 0x68, the sensors at 0x76, 0x77, 0x5B and perhaps 0x58.
The you will need to modify the sensors demo-programs:
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address = 0xaddress_from_i2cdetect...)
Lets try to read at least two sensors in a unified single program (BMP280 and HTU21D). You will need a single program to read all sensors because you can not run multiple python programs simultaneously accessing the same i2c bus.
Turn In
Your demo code for BMP280 and HTU21D sensors combined reading.
The screenshot showing data measured from both sensors in one program.
Continue Lab
Continue lab with MQTT data broker lab.