Handy Commands for Raspberry Pi Sensors
I recently got an Enviro hat for my Raspberry Pi Zero W. And in tinkering with it, I found there's a ruby driver for interacting with the BME280 sensor.
You can use it like this -
require "i2c/device/bme280"
require "i2c/driver/i2c-dev"
I2CDevice::Bme280.new(driver: I2CDevice::Driver::I2CDev.new("/dev/i2c-1")).read_raw
In debugging, I learned a few useful commands to check the i2c port. Basically, I just needed to figure out what i2c port to use for the ruby driver.
Check if the i2c port is enabled (raspberry pi os)
sudo raspi-config nonint get_i2c # 0 if enabled, 1 if disabled
List all the i2c interfaces by ls
ing the dev node.
ls /dev/i2c*
Check if the i2c board interface is in the list of kernel modules
lsmod | grep i2c
Tweet