knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

This vignette describes the hardware components I used for this project and the setup and configurations needed to collect sensor readings. Where available, I provided links to articles that describe steps with detailed instructions.

Hardware Components

The following hardware components enabled collection of humidity data:

  1. Raspberry Pi Zero W with 512 MB RAM, 1 GHz CPU, single core, 802.11 wireless LAN, 2.5a power supply, case and 40-pin GPIO header,
  2. Waveshare BME280 environmental sensor with I2C/SPI interface,
  3. A set of six-pin jumper wires, and
  4. 128 GB micro SD card.

Raspberry Pi Setup

Headless setup of the Raspberry Pi involves the following steps. A headless setup is the Raspberry Pi minus a monitor, keyboard, and mouse. Running a headless setup enables direct control the Raspberry Pi from computer via wifi connection.

This article provides detailed setup instructions.

  1. Insert the micro SD card in computer. Note you may need a card reader with USB connection if your computer does not have a built-in reader.

  2. Install and run the Raspberry Pi Imager (available for download from raspberrypi.com).

  3. Launch the imager application and install the Raspberry Pi OS on the micro SD card.

  4. Write an empty text file named "ssh" with no file extension to the root directory. When the Raspberry Pi OS sees the ssh file on its first boot-up, it will automatically enable SSH (Secure Socket Shell), which will allow you to remotely access the Pi command line from your computer.

  5. Configure a network connection for your Raspberry Pi using Wi-Fi Ethernet. Create a text file called wpa_supplicant.conf and place it in the root directory of the micro SD card with the following text included in the file.

country=US ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1

network={ scan_ssid=1 ssid="your_wifi_ssid" psk="your_wifi_password" }

  1. Establish an SSH connection to the Raspberry Pi using an SSH client. In my case, I used Putty, an SSH client for Windows using "raspberrypi" as the address and "pi" as a username with a corresponding password. This enables you to connect to the Raspberry Pi at the command prompt.

  2. If you want to access the Raspberry Pi via a GUI, you need to enable VNC on the Raspberry Pi.

GPIO Header Installation

To connect the BME280 sensor to the Raspberry Pi, you need to mount the Raspberry Pi on the GPIO 40-pin header and solder the header in place. When soldering the header to the Pi start with one of the corner pins. To make a good connection, heat the header pin and to let it melt the solder. Don’t melt the solder directly with the iron and expect it to stick. This article provides detail on how to go about soldering the GPIO to the Pi.

BME280 Sensor Connection

The Waveshare BME280 sensor supports both SPI and I2C interfaces and you'll need to decide what interface you will use. This article provides a good summary of each interface and comparison.

This webpage provides details instructions on how to connect the BME280 sensor to the Pi's GPIO board, according to the interface you choose to use.

Using the I2C interface, I wired the sensor as follows:

Connection | GPIO Pin | GPIO Description | BME280 Pin | BME280 Description -----------|----------|------------------|------------|------------------- Power Input | 1 | 3.3v power | 1 | VCC I2C data line | 3 | GPIO (SDA) | 3 | SDA I2C clock line | 5 | GPIO (SCL) | 4 | SCL Ground | 14 | GND | 2 | GND

After connecting the sensor, I enabled the I2C interface on the Pi, rebooted the Pi and confirmed that the I2C module was enabled. Using a VNC Viewer, you can access the Pi's configuration menu and enable the IC2 interface from within that menu.

I then checked to make sure that the sensor was connected to the Pi at correct address (0x77 by default) by using the command line prompt (logged into Pi via Putty) and command i2cdetect -y 1.

This article explains how to scan and detect I2C addresses.

Collecting BME280 Readings

Sensor readings are collected via a Python script written using the RPi.bme280 library. The script collects a single sensor reading and writes the reading to a text file stored on the Raspberry Pi.

The reading captures the following data from the sensor:

More details on the RPi.bme280 project can be found here. Note that this library was written to interface with the Bosch BME280 digital sensor module, however, it does work with the Waveshare sensor as well, based on my success using it for this project.

Reading Schedule

Crontab is used for configuring scheduled tasks on the Raspberry Pi. Cron is the name of the tool, and crontab is the cron table listing the jobs that Cron executes. To collect a series of readings, I added a crontab entry to execute the Python script every 60 seconds. At this rate, the script collects 1,440 observations per day.

Data Transfer from the Pi

I use the SSH R library to connect to the Pi remotely and transfer the text file containing the sensor readings, and then perform a series of transformations on the data before saving the data in a local Rda file. I periodically run the R script to refresh the local Rda file.



dtminnick/humidity documentation built on Jan. 3, 2023, 4:36 a.m.