Project

i2c-bme280

0.0
No commit activity in last 3 years
No release in over 3 years
Ruby driver for the Bosch BME280 sensor.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 0.4
 Project Readme

I2C::BME280

Gem Version

Ruby driver for the Bosch BME280 sensor over the I2C protocol.

The driver uses the i2c gem which relies on the i2c-dev package.

It was mainly ported from the bme280_sample.py script.

Thanks and credits to:

Installation

The library depends on the i2c-dev package. Furthermore the I2C kernel module has to be enabled manually if you are using the Raspberry Pi.

i2c-dev

Debian based systems:

sudo apt-get install i2c-dev

Enable I2C (Raspberry Pi)

sudo raspi-config -> Select Advanced Options -> Select I2C -> Select Yes (2 times) -> Reboot

Gemfile

Just include the following line to your Gemfile to use the driver.

gem 'i2c-bme280'

Usage

Example:

require 'i2c/bme280'
require 'json'

# Make sure you specify the i2c device id in the constructor.
# The default device id on the raspberry pi is 1.
# You can also pass a string that points to the device file: e.g. '/dev/i2c-1'
bme280 = I2C::Driver::BME280.new(device: 1)

puts "Temperature: #{'%7.2f' % bme280.temperature} [°C]"
puts "Pressure:    #{'%7.2f' % bme280.pressure} [hPa]"
puts "Humidity:    #{'%7.2f' % bme280.humidity} [%]"
puts
puts "JSON: #{bme280.all.to_json}"

License

The gem is available as open source under the terms of the MIT License.