meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
groups:mg:temperature_pressure_and_humidity_monitoring [2022/01/21 14:17] – [Software] fienegroups:mg:temperature_pressure_and_humidity_monitoring [2024/03/20 09:37] (current) – Admin: Syntax-Update (Migration from deprecated "fontcolor" plugin to "color" plugin) klaus
Line 3: Line 3:
 ===== Hardware ===== ===== Hardware =====
  
-Besides a Raspberry Pi - in use is the Raspberry Pi 2 Model B V1.1, the datatransfer takes place over a ethernetcable, the Raspberry Pi 3 is the first one which has a build-in wireless chip - two sensors are needed. In use are the sensors [[https://cdn-shop.adafruit.com/datasheets/Digital+humidity+and+temperature+sensor+AM2302.pdf|AM2302]] for humidity and temperature and [[https://cdn-shop.adafruit.com/datasheets/BST-BMP280-DS001-11.pdf|BMP280]] for pressure and temperature. The only difference between AM2302 and DHT22 is that one has an integrated 5,1 K Pullup-Resistor and attached cables and the other one has pins and needs an external Pullup-Resistor (around 10 K) between the dataconnection and the VCC-Pin, both cases are covered below.+Besides a Raspberry Pi - in use is the Raspberry Pi 2 Model B V1.1, the datatransfer takes place over a ethernetcable, the Raspberry Pi 3 is the first one which has a build-in wireless chip - two sensors are needed. In use are the sensors [[https://cdn-shop.adafruit.com/datasheets/Digital+humidity+and+temperature+sensor+AM2302.pdf|AM2302]] for humidity and temperature and [[https://cdn-shop.adafruit.com/datasheets/BST-BMP280-DS001-11.pdf|BMP280]] for pressure and temperature. \\ 
 +\\ 
 +The only difference between AM2302 and DHT22 is that one has an integrated 5,1 K Pullup-Resistor and attached cables and the other one has pins and needs an external Pullup-Resistor (around 10 K) between the dataconnection and the VCC-Pin, both cases are covered below.
  
 First, you need to connect the sensors as following. First, you need to connect the sensors as following.
Line 29: Line 31:
 The communication with the sensors is written in C, but there are Python-packages from Adafruit to easily integrate the communication in personal codes and applications. Here's a short overview on how to read out the sensors: The communication with the sensors is written in C, but there are Python-packages from Adafruit to easily integrate the communication in personal codes and applications. Here's a short overview on how to read out the sensors:
  
-After setting up the Raspberry Pi you need to enable I2C and 1-Wire connection. Enter the command ''raspi-config'' and go to Interfacing Options or Advanced Options (depends on your model) and enable I2C and 1-Wire. Reboot afterwards.+After setting up and updating the Raspberry Pi with ''sudo apt-get update'' and ''sudo apt-get upgrade''you need to enable I2C and 1-Wire connection. Enter the command ''raspi-config'' and go to Interfacing Options or Advanced Options (depends on your model) and enable I2C and 1-Wire. Reboot afterwards.\\ 
 +You can check if the I2C kernel module is currently loaded by entering the command ''lsmod | grep i2c_''. It should print the following modules: 
 + 
 +''i2c_bcm2835            16384  0''\\ 
 +''i2c_dev                20480  0'' 
 + 
 +If you don't see anything like this, there are several things to do, to force your Raspberry Pi to load the module. Here are just some of them: 
 +  * Edit the configfile - which decides which modules should be loaded while booting - with ''sudo nano /boot/config.txt''. Edit or add the line ''dtparam=i2c_arm=on'', then recompile the rpi-firmware package with ''make rpi-firmware-rebuild'', regenerate the SD-Card image with ''make'' and reboot. 
 +  * If you can't find the i2c-1 bus in /dev, start the i2c module manually by entering ''modprobe i2c-bcm2835'' and ''modprobe i2c-bcm2835''. Go to /dev and check with ''ls -la /dev/i2c-1''if the i2c directory does exist now, which means it's usuable now. This does the same as just using the GUI as described previously, but maybe this way will solve your problem. 
 Next you need to install some packages using the following commands: Next you need to install some packages using the following commands:
  
-''sudo apt install -y python3-smbus i2c-tools''+''sudo apt install -y python3-smbus i2c-tools''\\ 
 +''sudo apt-get install build-essential python-dev python-openssl git-core''\\ 
 +''apt install python3-pip -y''\\ 
 +''pip3 install --user adafruit-circuitpython-bmp280''\\
  
-''sudo apt-get install build-essential python-dev python-openssl git-core''+To check if your Raspberry Pi found the sensor and to get it's address, enter ''i2cdetect -y 1''. There should be at least one entry, which is your address. If e.g. the last line of the output looks like this
  
 +''70: -- -- -- -- -- -- 76 --    ''
 +
 +the sensor has the address 0x76. If you can't see any entry and i2c is enabled and running, check your wires and connections.
 +Now you can write your python script! First create a file with e.g. ''touch bmp280.py'' and edit it with ''nano bmp280.py''. All it takes to read out temperature and pressure are the following lines. Be aware to enter the correct address!
 +
 +
 +<blockquote>
 +<color #008000>//#!/usr/bin/python3//</color>
 +
 +**<color #008000>import</color> <color #6495ed>board</color> \\
 +<color #008000>import</color> <color #6495ed>busio</color> \\
 +<color #008000>import</color><color #6495ed> adafruit_bmp280</color>**
 +
 +i2c = busio.I2C(board.SCL, board.SDA)\\
 +bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=0x76)
 +
 +<color #008000>print</color>(<color #ff0000>"Temperature: %0.1f C"</color> % bmp280.temperature)\\
 +<color #008000>print</color>(<color #ff0000>"Pressure: %0.1f hPa"</color> % bmp280.pressure)
 +</blockquote>
 +
 +You can execute the program with ''python bmp280.py''. If you create this file in the /usr/local/sbin directory and allow everybody to execute the program with ''chmod +x /usr/local/sbin/bmp280.py'' you can simply execute it everywhere by entering ''bmp280.py''.
 +Now we take care of the software for the AM2302 sensor. Therefor you don't even need to write a script.
 Go to your home directory with ''cd ~'' and clone the branch of the AM2302 python project with the following command. Go to your home directory with ''cd ~'' and clone the branch of the AM2302 python project with the following command.
  
Line 48: Line 84:
 ''sudo python setup.py install'' ''sudo python setup.py install''
  
-From now on you can manually read out humidity and temperatur by entering the following command in any directory. The first number is the argument for the sensormodel you use (11,22, or 2302), the second argument is the GPIO pin number (not the physical pin number!) you attached your dataconnection to. If the sensor is connected to +From now on you can manually read out humidity and temperatur by entering the following command in any directory. The first number is the argument for the sensormodel you use (11,22, or 2302), the second argument is the GPIO pin number (not the physical pin number!) you attached your dataconnection to. For example, if your AM2302 sensor is connected to Pin 12, you enter the following command
  
 ''./Adafruit_Python_DHT/examples/AdafruitDHT.py 2302 18'' ''./Adafruit_Python_DHT/examples/AdafruitDHT.py 2302 18''
 +
 +When you implement a continuous monitoring be aware that the AM2302 can only read a value every 3 seconds, otherwise it'll hang itself up - due to the slow 1-wire connection - and needs to be restartet (unplugged).
 +
 +===== Grafana =====
 +
 +If used continually, the data has to be sent to a server or similar. An existing sensor sends it's data to Grafana, here's described how:
 +
 +===== Applications =====
 +
 +Currently this sensor isn't in use anywhere, but one will monitor the conditions in the resonator in ResLab.