BRIGADOON

Backyard Meteorological Instrumentation

Raspberry Pi 4 Set Up

Sensors Selection

The Raspberry Pi 4 has up to six (6) SPI controllers, six (6) I2C controllers, six (6) UARTS. However, most of these controllers are not activated by default. Most of these controllers are not activated by default.  As a result, the first thing that needs to be done is to decide which controllers are required for this project.

 SENSOR

 INTERFACE TYPE

 LOCATION

 DISCRIPTION

SEN0290

Lightning Sensor

 I2C plus Interrupt

 Main Radiation Shield on Pole or on top of the main enclosure (preferred)

Sensor requires clear access to sky away from items creating electromagnetic interference.

 K324
Geiger Counter

 

 Interrupt

 External Plastic Box

 Sensor element must not be shielded by metal.

Anemometer

Interrupt

Vertical Pole

This is a professional quality spinning cup anemometer that has been donated. It is  not in an ideal position, so the wind speed will only reflect the micro-climate in the location.

Rain Gauge

Interrupt

Vertical Pole or platform

Should be clear of all obstructions, but this is unlikely to be the case, so results are not optimal. This tipping bucket comes from an old Personal Weather Station that uses a magnetic switch to detect buck tips.

 PMS5003
Particle Air Quality

 TTL Serial UART

plus Control Pin

 Main Radiation Shield

 Sensor requires free access to the local atmosphere.

ADS1115

4 Channel 16-Bit ADC

I2C

Mounted in Main Enclosure

This ADC is connected to the next four (4) sensors.

 MQ135
Gas Air Quality

  Analogue Signal

 Main Radiation Shield

 Sensor requires free access to the local atmosphere.

 SEN0193

Soil Moisture

 Analogue Signal

(Plus Control Pin)

 Spiked into Ground

 Mounted in same box as Water Condensation (Rain Drop) Sensor. Not considered accurate.

Water Condensation

 Analogue Signal

Same box as Soil Moisture Sensor

NOTE: This sensor will not initially connected as there will not be a free ADC channel available. If will be included if a second ADC is installed.

HMP60
Humidity and Temperature

 Analogue Signal

Secondary Radiation Shield

Two (2) ADC Channels are required. High resolution channels are required for this project.

DS18B20
Ground Temperature
(x5)

 

 I2C

 Underground Tube

 From previous experience five (5) of these thermometers is about the limit that an I2C controller can drive over a distance.

BMP388
High Resolution

Barometric Pressure

 I2C

Main Radiation Shield

Must be kept out of the air flow from any cooling fans, etc. but still have good access to the outside atmosphere.

Ultra-Violet Monitor

I2C

Main Radiation Shield

Could be mounted on the top of the Main Radiation Shield.

Infra-Red Temperature

I2C

Main Radiation Shield

Could be mounted with ultra-violet sensor.

Flight Aware

Prostick Plus

ADS-B Receiver

 

USB

Main Enclosure - Receiver

External Mount - Antenna

 

CPU Temperature

DIgital Output Pin

Temperature sensor internal to the Raspberry Pi

The Digital Output Pin is used to trigger external cooling fans to provide additional air flow across the Raspberry Pi's heatsinks. The temperature reading is available via the operating system software and the pin is automatically controlled by the Operating System.

Selecting I/O Controllers

The image below is from the Raspberry Pi website. Select the image to go to the page with the diagram for more details, alternatively, you can try https://pinout.xyz. If you want some basic details of you Rasberry Pi without going onto the Internet, enter the following command:

$
pinout

The PMS5003 Air Quality Monitor is the only sensor in this project using a serial port. It was decided that the standard serial port would be used. The On/Off control line will be provided by the GPIO 18 pin as it is close to the Tx and Rx pins on the header.

There are currently four (4) sensors that provide an analogue output voltage, so an Analogue to Digital Converter (ADC) with at least four (4) channels is required. This project will use the GY-ADS1115 ADC to convert the output of these sensors to a digital signal. These sensors are sampled by the ADC at a fixed interval so this I2C controller will be available to share other local I2C sensors that are periodically sampled. This standard I2C controller (I2C-1) will be used for this task.

The SEN0290 Lightning detector requires  a I2C controller and an Interrupt that is triggered when a lightning event occurs. The I2C-4 controller will be used for this sensor.

The five (5) Ground Temperature sensors are contained in a tube dug into the ground. From previous experience, there are issues attempting to put more than five (5) of these sensors on a single I2C controller. The I2C-5 controller will  be used for this sensor set.

Along with the PMS5003, the BMP338 high resolution pressure sensor, the Ultra-Violet sensor and the Infra-Red sensor will be mounted in the Main Radiation Shield. These three (3) sensors are sampled on a fixed interval basis and are all I2C sensors. As a result, these sensors can be accommodated by a single I2C sensor. There are potential drive issues with the I2C lines being extended out to the Main Radiation Shield, and drivers may be needed to provide the range required. The I2C-6 controller will be used for this sensor set.

The Geiger Counter, Anemometer and the Rain Gauge each require an interrupt pin to detect the output of their respective sensor.

Sensor Pin Configuration File

Because the Raspberry Pi is dedicated to the Backyard Sensors, the I/O controllers can be hard wired into the boot sequence where it is convenient, other wise it can be done using the libgpiod (see Setting Control Pins below).The Controller pins are defines in the /boot/config.txt file which is read at boot time. The configuration entry for the I2C port is as follows

dtoverlay=i2c-gpio bus=<BUS>,i2c_gpio_sda=<SDA_GPIO>,i2c_gpio_scl=<SCL_GPIO>

Where
<BUS> is the I2C bus number (3,4,5,6), <SDA_GPIO> is the GPIO pin to be used as the SDA, and <SCL_GPIO> is the GPIO pin to be used for the SCL.

The following table lists the I2C port and standard pin allocations.

 I2C Bus No.

 SDA GPIO PIN

  SCL GPIO PIN

1

(Default Port)

2

(Physical Pin 3)

 

3

(Physical Pin 5)

 2

--

--

 

  3

  4
(Physical Pin 7)

  5
(Physical Pin 29)

  4

  8
(Physical Pin 24)

  9
(Physical Pin 21)

  5

    12
(Physical Pin 32)

    13
(Physical Pin 33)

  6

    22
(Physical Pin 15)

  23
(Physical Pin 16)

Combining the selected I2C controller numbers with the table above, the following I2C configuration lines need to be added to the /boot/config.txt on the Raspberry Pi.

dtoverlay=i2c-gpio,bus=3,i2c_gpio_sda=4,i2c_gpio_scl=5
dtoverlay=i2c-gpio,bus=4,i2c_gpio_sda=8,i2c_gpio_scl=9

dtoverlay=i2c-gpio,bus=5,i2c_gpio_sda=12,i2c_gpio_scl=13

The configuration is only processed at boot, but a controller can be turned on from the command line for debugging or development purposes using the following command:

$
dtoverlay i2c-gpio bus=<BUS> i2c_gpio_sda=<SDA_GPIO> i2c_gpio_scl=<SCL_GPIO>

Where
<BUS> is the I2C bus number (3,4,5,6), <SDA_GPIO> is the GPIO pin to be used as the SDA, and <SCL_GPIO> is the GPIO pin to be used for the SCL, as above.

Although not used to control a sensor, the system is designed to start the cooling fans when the Raspberry Pi's internal temperature reaches 80°
C. The following steps are required to set the Raspberry Pi to set the GPIO16 bit when its internal temperature exceeds 80°C.

$
sudo raspi-config

NOTE: The pin selections below are not used when the I/O Module is used for power control purposes.

Select 4. Performance Options, then select P4 Fan. When asked
"Would you like to enable fan temperature control?", select <Yes>. To the question "To Which GIO Pin is the fan connected?" enter 16, then select <Yes>.

When
asked "At what temperature in degrees Celsius should the fan turn on?" enter 80 and then select <Ok>. Select <Ok> at the prompt "The fan on GPIO 16 is enabled and will turn on at 80 degrees Celsius". Note: The temperature can be set in the range 60°C to 120°C, but too low and the fan will have excessive wear. Too high and the CPU will be throttled back, decreasing performance.

The MQ138 Gas Air Quality sensor requires a pin to control its power and GPIO 26 have been selected, so pre-set the pin state as an output that has a pull-up resistor and its state is set to LOW.

$
sudo raspi-gpio 26 op pu dl

The PMS5003 Particle Air Quality Monitor also needs a pin to control its fan, to reduce power consumption and extend the life of the fan. GPIO 18 has been selected as it is adjacent to the TXD & RXD serial pins that will e used to communicate with the PMS5003.

$
sudo raspi-gpio 18 op pu dl

Setting Control Pins Programatically

Although the function and status of the pins can be set using the raspi-gpio program, the setting of the control pins will be carried out in the program when the I/O Controller device drivers are initialised. The initialisation and management of those control pins will be carried out using the libgpiod library. Since this library does not automatically get installed, it needs to be installed before use with the following command which will install the library, development files and the documentation:

$
sudo apt install libgpiod*

The current status of the pins can be displayed with the following command:

$
raspi-gpio get

The current functions of the GPIO pins can be displayed using the following command:

$
raspi-gpio funcs

Additional functions are available using this program and entering the following command will provide additional information.

$
raspi-gpio help

Licenced under Creative Commons Attribution Share Alike 4.0 International or better by Mark Little (2022 - 2024)