Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Latest commit

 

History

History

Microsoft.PowerShell.IoT.BME280

Example module Microsoft.PowerShell.IoT.BME280

This PowerShell module is for interacting with BME280 environmental sensor for reading temperature, pressure and humidity.

Hardware setup

Several vendors have breakout boards with BME280 sensor. In this example we'll use BME280 breakout board from Adafruit.

BME280 sensor supports both I2C and SPI interfaces; in this example we'll use I2C.

Later, in the software section, we'll need to use I2C address of the BME280 sensor. The default I2C address is 0x77. It can be changed to 0x76 by connecting SDO to GND.

Wiring diagram with Raspberry Pi 3 is like this:

bme280_schema

Software setup

Install PowerShell Core on Raspberry Pi

Installation instructions can be found here.

Enable I2C interface on Raspberry Pi

  1. sudo raspi-config
  2. 5 Interfacing options
  3. P5 I2C
  4. Would you like ARM I2C interface to be enabled -> Yes

Start Powershell and install modules

sudo pwsh
Install-Module -Name Microsoft.PowerShell.IoT
git clone https://github.com/PowerShell/PowerShell-IoT.git
Import-Module ./PowerShell-IoT/Examples/Microsoft.PowerShell.IoT.BME280

Collect Data

PS /home/pi> $device = Get-BME280Device -Id 0x77 # I2C address of the sensor
PS /home/pi> $data = Get-BME280Data -Device $device
PS /home/pi> $data

Temperature Pressure Humidity
----------- -------- --------
      26.08  1009.41    29.21

PS /home/pi> "Temperature in Fahrenheit = $($data.Temperature * 1.8 + 32)"
Temperature in Fahrenheit = 76.69