|
| 1 | +# Example module Microsoft.PowerShell.IoT.BME280 |
| 2 | + |
| 3 | +This PowerShell module is for interacting with [BME280 environmental sensor](https://www.bosch-sensortec.com/bst/products/all_products/bme280) for reading temperature, pressure and humidity. |
| 4 | + |
| 5 | +## Hardware setup |
| 6 | + |
| 7 | +Several vendors have breakout boards with BME280 sensor. In this example we'll use [BME280 breakout board from Adafruit](https://www.adafruit.com/product/2652). |
| 8 | + |
| 9 | +BME280 sensor supports both I2C and SPI interfaces; in this example we'll use I2C. |
| 10 | + |
| 11 | +Later, in the software section, we'll need to use I2C address of the BME280 sensor. |
| 12 | +The default I2C address is 0x77. It can be changed to 0x76 by connecting SDO to GND. |
| 13 | + |
| 14 | +Wiring diagram with Raspberry Pi 3 is like this: |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +## Software setup |
| 19 | + |
| 20 | +### Install PowerShell Core on Raspberry Pi |
| 21 | + |
| 22 | +Installation instructions can be found [here](https://github.com/PowerShell/PowerShell/tree/master/docs/installation/linux.md#raspbian). |
| 23 | + |
| 24 | +### Enable I2C interface on Raspberry Pi |
| 25 | + |
| 26 | +1. `sudo raspi-config` |
| 27 | +2. `5 Interfacing options` |
| 28 | +3. `P5 I2C` |
| 29 | +4. `Would you like ARM I2C interface to be enabled -> Yes` |
| 30 | + |
| 31 | +### Start Powershell and install modules |
| 32 | + |
| 33 | +```powershell |
| 34 | +sudo pwsh |
| 35 | +Install-Module -Name Microsoft.PowerShell.IoT |
| 36 | +git clone https://github.com/PowerShell/PowerShell-IoT.git |
| 37 | +Import-Module ./PowerShell-IoT/Examples/Microsoft.PowerShell.IoT.BME280 |
| 38 | +``` |
| 39 | + |
| 40 | +### Collect Data |
| 41 | +```powershell |
| 42 | +PS /home/pi> $device = Get-BME280Device -Id 0x77 # I2C address of the sensor |
| 43 | +PS /home/pi> $data = Get-BME280Data -Device $device |
| 44 | +PS /home/pi> $data |
| 45 | +
|
| 46 | +Temperature Pressure Humidity |
| 47 | +----------- -------- -------- |
| 48 | + 26.08 1009.41 29.21 |
| 49 | +
|
| 50 | +PS /home/pi> "Temperature in Fahrenheit = $($data.Temperature * 1.8 + 32)" |
| 51 | +Temperature in Fahrenheit = 76.69 |
| 52 | +``` |
0 commit comments