Pressure Sensor¶
Goal¶
To implement safety use cases in our door project, we use a pressure sensor to detect whether an obstacle keeps the door from closing.
There are a number of sensors out there. BMP280 comes with a nice breakout, it looks like a good candidate to try.
How¶
I2C devices speak a protocol over SDA/SCL which is documented in the
device’s data sheet. Lets use /dev/i2c-1
(a software
representation of Raspberry’s I2C pins) to implement that protocol in
userspace - inside a class which looks roughly like so …
class BMP280
{
public:
BMP280(const std::string& i2c_dev, unsigned address);
};
i2c_dev
: the I2C device node, e.g./dev/i2c-1
address
: the device’s address on the bus
Testing¶
This is not easily unit tested. Write a test program in tests/
that uses an object of type BMP280
to communicate with the device.