230 lines
8.2 KiB
Markdown
Executable File
230 lines
8.2 KiB
Markdown
Executable File
# ModuleAir Pro 4G
|
|
Version Pro du ModuleAir avec CM4, SaraR4 et ecran Matrix LED p2 64x64.
|
|
|
|
**Capteurs d'air intérieur IoT avec écran LED RGB 128x64 contrôlé par bouton.**
|
|
|
|
## Fonctionnalités
|
|
- **Capteurs multi-polluants**: PM1, PM2.5, PM10, CO2, température, humidité
|
|
- **Connectivité 4G/WiFi**: Transmission automatique des données via modem SARA R4
|
|
- **Affichage LED interactif**: 4 modes d'écran commutables par bouton-poussoir
|
|
- **Interface web locale**: Configuration et visualisation en temps réel
|
|
- **Base de données SQLite**: Stockage local avec nettoyage automatique
|
|
|
|
# Installation
|
|
|
|
## Script
|
|
|
|
```
|
|
wget http://gitea.aircarto.fr/PaulVua/moduleair_pro_4g/raw/branch/main/installation.sh
|
|
chmod +x installation.sh
|
|
./installation.sh
|
|
```
|
|
|
|
## Detailed
|
|
```
|
|
sudo apt update
|
|
sudo apt install git gh apache2 sqlite3 php php-sqlite3 libsqlite3-dev python3 python3-pip jq g++ autossh i2c-tools python3-smbus -y
|
|
sudo pip3 install pyserial requests sensirion-shdlc-sfa3x RPi.GPIO gpiozero adafruit-circuitpython-bme280 crcmod psutil --break-system-packages
|
|
sudo git clone http://gitea.aircarto.fr/PaulVua/moduleair_pro_4g.git /var/www/moduleair_pro_4g
|
|
sudo mkdir /var/www/moduleair_pro_4g/logs
|
|
sudo touch /var/www/moduleair_pro_4g/logs/app.log /var/www/moduleair_pro_4g/logs/loop.log /var/www/moduleair_pro_4g/matrix/input_NPM.txt /var/www/moduleair_pro_4g/matrix/input_MHZ16.txt /var/www/moduleair_pro_4g/wifi_list.csv
|
|
sudo cp /var/www/moduleair_pro_4g/config.json.dist /var/www/moduleair_pro_4g/config.json
|
|
sudo chmod -R 777 /var/www/moduleair_pro_4g/
|
|
git config core.fileMode false
|
|
|
|
```
|
|
|
|
## Apache
|
|
Configuration of Apache to redirect to the html homepage project
|
|
```
|
|
sudo sed -i 's|DocumentRoot /var/www/html|DocumentRoot /var/www/moduleair_pro_4g|' /etc/apache2/sites-available/000-default.conf
|
|
sudo systemctl reload apache2
|
|
```
|
|
|
|
## Serial
|
|
|
|
Need to open all the uart port by modifying `/boot/firmware/config.txt`
|
|
|
|
```
|
|
enable_uart=1
|
|
dtoverlay=uart0
|
|
dtoverlay=uart1
|
|
dtoverlay=uart2
|
|
dtoverlay=uart3
|
|
dtoverlay=uart4
|
|
dtoverlay=uart5
|
|
```
|
|
And reboot !
|
|
|
|
Then we need to authorize connection over device on `/etc/ttyAMA*`
|
|
```
|
|
sudo chmod 777 /dev/ttyAMA*
|
|
```
|
|
|
|
## Sudo athorization
|
|
To make things simpler we will allow all users to use "nmcli" as sudo without entering password. For that we need to open the sudoers file with `sudo visudo` and add this to the bottom of the file:
|
|
```
|
|
ALL ALL=(ALL) NOPASSWD: /usr/bin/nmcli, /usr/sbin/reboot
|
|
www-data ALL=(ALL) NOPASSWD: /usr/bin/git pull
|
|
www-data ALL=(ALL) NOPASSWD: /usr/bin/ssh
|
|
www-data ALL=(ALL) NOPASSWD: /usr/bin/python3 *
|
|
```
|
|
|
|
## I2C
|
|
|
|
Decibel meter, BME280 and the RTC module (DS3231) is connected via I2C.
|
|
Need to activate by modifying `sudo nano /boot/firmware/config.txt`
|
|
|
|
```
|
|
dtparam=i2c_arm=on
|
|
```
|
|
|
|
And authorize access to `/dev/i2c-1`.
|
|
|
|
```
|
|
sudo chmod 777 /dev/i2c-1
|
|
```
|
|
|
|
Attention: sometimes activation with config.txt do not work, you need to activate i2c with `sudo raspi-config` and go to "Interface" -> I2C -> enable.
|
|
It is possible to manage raspi-config only with cli: `sudo raspi-config nonint do_i2c 0`
|
|
I2C addresses: use `sudo i2cdetect -y 1` to check the connected devices
|
|
|
|
## Matrix LED
|
|
|
|
### Library
|
|
|
|
To use the Matrix LED on the RPI we will use the [rpi-rgb-led-matrix](https://github.com/hzeller/rpi-rgb-led-matrix) repository from hzeller.
|
|
|
|
Before compiling any code we need the **include** folder and the **lib** folder from the library. Then we can compile any .cc code with g++.
|
|
```
|
|
g++ -Iinclude -Llib test.cc -o test -lrgbmatrix
|
|
sudo ./test --led-no-hardware-pulse --led-row-addr-type=3
|
|
```
|
|
|
|
### Pinout
|
|
|
|
Details of connection bewtween components can be found [here](https://docs.google.com/spreadsheets/d/1EJoq7nlJIN9nd_CbVmmozsGb-Ntp0cyxrEt9vokqc6g/edit?usp=sharing).
|
|
Some pins for the Matrix need to change because they use uart pins. For this we need to change pins inside `/lib/hardware-mapping.c` and recompile the library:
|
|
```
|
|
cd /var/www/moduleair_pro_4g/matrix/lib
|
|
make
|
|
```
|
|
|
|
### Matrix 64x32
|
|
|
|
Pour la matrix 64x32 (celle du ModuleAir mini) on utilise le pinout "regular"
|
|
|
|
Tests avec la biblio de hzeller sur un RPi4:
|
|
```
|
|
sudo examples-api-use/demo -D0 \
|
|
--led-no-hardware-pulse \
|
|
--led-chain=1 \
|
|
--led-cols=64 \
|
|
--led-rows=32 \
|
|
--led-gpio-mapping=regular
|
|
```
|
|
|
|
### Matrix 128x64
|
|
|
|
Pour le grand écran il faut mettre sur ground deux pins (E et D) et ajouter la commande `--led-row-addr-type=3` car il s'agit d'un panneau de type "ABC".
|
|
Il faut aussi préciser le type de chip-set avec `--led-panel-type=FM6126A`
|
|
|
|
Test avec la biblio de hzeller sur un RPi4:
|
|
```
|
|
sudo examples-api-use/demo -D0 \
|
|
--led-no-hardware-pulse \
|
|
--led-chain=1 \
|
|
--led-cols=128 \
|
|
--led-rows=64 \
|
|
--led-gpio-mapping=regular \
|
|
--led-row-addr-type=3 \
|
|
--led-parallel=1 \
|
|
--led-panel-type=FM6126A
|
|
```
|
|
|
|
Pour tester sur la CM4
|
|
```
|
|
sudo ./test_forms --led-no-hardware-pulse
|
|
```
|
|
|
|
### Fonts
|
|
|
|
Font "6x9.bdf" is 7 pixels height +1 (top) +1 (bottom) = 9 height.
|
|
Font "8x13.bdf" is 9 pixels height +2 (top) +2 (bottom) = 13 height.
|
|
Font "8x18.bdf" is 14 pixels height +2 (top) +2 (bottom) = 13 height.
|
|
|
|
### Troubleshooting
|
|
|
|
Switch off on-board sound:
|
|
* `dtparam=audio=off` in `/boot/firmware/config.txt`
|
|
* Add the file `sudo nano /etc/modprobe.d/blacklist.conf` with `blacklist snd_bcm2835`
|
|
* Command `lsmod | grep snd_bcm2835` should anwser nothing
|
|
|
|
Add `isolcpus=3` to `/boot/firmware/cmdline.txt`
|
|
|
|
## Affichage Matrix LED avec contrôle par bouton
|
|
|
|
Le système dispose de 4 modes d'affichage contrôlés par un bouton-poussoir connecté au GPIO6 (GND quand pressé):
|
|
|
|
### Modes d'affichage
|
|
|
|
1. **État du réseau**: Statut de connectivité 4G et WiFi avec qualité du signal
|
|
2. **Tous les capteurs**: PM1, PM2.5, PM10 et CO2 avec indicateurs de qualité
|
|
3. **CO2 + PM + Réseau**: CO2, PM2.5, PM10 et statut réseau résumé
|
|
4. **Écran noir**: Tous les pixels éteints
|
|
|
|
### Compilation des programmes d'affichage
|
|
|
|
```bash
|
|
# Compiler la bibliothèque matrix
|
|
cd /var/www/moduleair_pro_4g/matrix/lib && make
|
|
|
|
# Compiler tous les programmes d'affichage
|
|
cd /var/www/moduleair_pro_4g
|
|
g++ -I/var/www/moduleair_pro_4g/matrix/include -L/var/www/moduleair_pro_4g/matrix/lib /var/www/moduleair_pro_4g/matrix/screenNetwork/network_status.cc -o /var/www/moduleair_pro_4g/matrix/screenNetwork/network_status -lrgbmatrix -lsqlite3
|
|
g++ -I/var/www/moduleair_pro_4g/matrix/include -L/var/www/moduleair_pro_4g/matrix/lib /var/www/moduleair_pro_4g/matrix/screenSensors/displayAll4_v2.cc -o /var/www/moduleair_pro_4g/matrix/screenSensors/displayAll4_v2 -lrgbmatrix -lsqlite3
|
|
g++ -I/var/www/moduleair_pro_4g/matrix/include -L/var/www/moduleair_pro_4g/matrix/lib /var/www/moduleair_pro_4g/matrix/screenSensors/displayCO2_PM_Network.cc -o /var/www/moduleair_pro_4g/matrix/screenSensors/displayCO2_PM_Network -lrgbmatrix -lsqlite3
|
|
g++ -I/var/www/moduleair_pro_4g/matrix/include -L/var/www/moduleair_pro_4g/matrix/lib /var/www/moduleair_pro_4g/matrix/screenSensors/blank_screen.cc -o /var/www/moduleair_pro_4g/matrix/screenSensors/blank_screen -lrgbmatrix
|
|
```
|
|
|
|
### Contrôle du système d'affichage
|
|
|
|
```bash
|
|
# Démarrer le système avec contrôle par bouton
|
|
sudo systemctl restart moduleair-boot.service
|
|
|
|
# Démarrage manuel du contrôleur de bouton
|
|
sudo python3 /var/www/moduleair_pro_4g/matrix/button_screen_controller.py
|
|
|
|
# Test du bouton uniquement
|
|
sudo python3 /var/www/moduleair_pro_4g/test_button_controller.py
|
|
|
|
# Arrêter le système
|
|
sudo systemctl stop moduleair-boot.service
|
|
|
|
# Vérifier le statut
|
|
sudo systemctl status moduleair-boot.service
|
|
```
|
|
|
|
### Fonctionnalités du contrôleur
|
|
|
|
- **Debounce 500ms**: Évite les pressions accidentelles multiples
|
|
- **Redémarrage automatique**: Relance le programme d'affichage s'il plante
|
|
- **Arrêt propre**: Nettoyage GPIO et termination des processus
|
|
- **Gestion des signaux**: Réagit aux signaux SIGINT/SIGTERM
|
|
|
|
### Branchement du bouton
|
|
|
|
Connecter un bouton-poussoir entre GPIO6 et GND. Le système utilise une résistance de pull-up interne, donc aucune résistance externe n'est nécessaire.
|
|
|
|
## Hardware requis
|
|
|
|
- **Raspberry Pi CM4** avec connecteur GPIO
|
|
- **Bouton-poussoir** connecté GPIO6 → GND
|
|
- **Écran Matrix LED 128x64** FM6126A
|
|
- **Capteur NPM** (particules) via Modbus RTU
|
|
- **Capteur MH-Z19** (CO2) via UART
|
|
- **Module BME280** (T/H/P) via I2C
|
|
- **Modem SARA R4** (4G) via UART
|
|
- **Module RTC DS3231** via I2C
|