Simple Python module that read data
from Sense Hat and share them on
the local DBus.
This repository is part of
the Smart Van Project.
FW Name: FW Sense Hat
FW Group: com.robypomper.smartvan.fw.sensehat
FW Version: 1.0.1
README | CHANGELOG | TODOs | LICENCE
Once ran, this script reads data from the Sense Hat board via I2C then notify
the DBus with updated values. The Sense Hat is a crucial component equipped
with a variety of sensors and accessible ICs through the I2C protocol. Each of
these components has its dedicated Python file (located in
the fw_sensehat/sense/chip
folder). These files facilitate the reading and
processing of raw data collected by the sensors. More info
on Supported devices
and value mapping.
Here the list of chips integrated into the Sense Hat:
Chip | Description | I2C Address |
---|---|---|
QMI8658C | 6D Inertial Measurement Unit with Motion Co-Processor and Sensor Fusion | 0x6B |
AK09918 | 3-Axis Electronic Compass | 0x0C |
SHTC3 | Humidity and Temperature Sensor IC | 0x70 |
ADS1015 | Ultra-Small, Low-Power, 12-Bit Analog-to-Digital Converter with Internal Reference | 0x48 |
LPS22HB | MEMS nano pressure sensor: 260-1260 hPa absolute digital output barometer | 0x5C |
TCS34087 | ALS/Color Sensor with Selective Flicker Detection | 0x29 |
This is a Python script, so python
is required to run it.
$ python --version
# if not installed, then run
$ sudo apt-get install python3 python3-pip
In addition, some other package must be installed in order to configure
python's dependencies like PyGObject
or pydbus
. If you are using a
debian/ubuntu based distribution, then you can run:
$ sudo apt-get install libcairo2-dev libgirepository1.0-dev dbus-x11
Once Python was installed on your machine, you can install the script's
requirements globally or create a dedicated venv
.
# Init venv (Optional)
$ python -m venv venev
$ source venv/bin/activate
# Install script's requirements
$ pip install -r requirements.txt
Now, you are ready to run the script with the command:
$ python run.py
or alternative options
$ python run.py --quiet
$ python run.py --debug --simulate
$ python run.py --dbus-name com.custom.bus --dbus-obj-path /custom/path --dbus-iface com.custom.IFace
For script's remote usage please see the dedicated page.
Defaults DBus params are:
- DBus Name:
com.waveshare.sensehat
- DBus Obj Path:
DEV_TYPE_*
as device code (eg:Sense Hat c
become/sense_hat_c
, see Supported devices for the full list ofDEV_TYPE_*
values) - DBus Interface:
DEV_IFACE_*
(eg:com.waveshare.sensehat_c
, see Supported devices for the full list ofDEV_IFACE_*
values)
The run.py
script accept following arguments:
-h
,--help
: show this help message and exit-v
,--version
: show version and exit--simulate
: Simulate a Sense Hat (C) Device (default:False
)--dbus-name DBUS_NAME
: DBus name to connect to (Default:com.waveshare.sense
)--dbus-obj-path DBUS_OBJ_PATH
: DBus object path to use for object publication (Default: thedevice_type_code
string)--dbus-iface DBUS_IFACE
: DBus object's interface (Default: current device'sdbus_iface
)--dev
: enable development mode, increase log messages--debug
: Set log level to debug--quiet
: Set log level to error and
The main goal for this script is to link the Device's protocol to the DBus. So, in addition to the main script, all other files are related to the Device or to the DBus protocols.
Module's files can be grouped in 2 categories:
Definitions:
- sense/mappings.py:
definition of
PID
,PROPS_CODES
andCALC_PROPS_CODES
tables - sense/_definitions.py: definitions of supported devices, DUbus ifaces and custom properties types
- sense/_parsers.py: custom properties parsers
- sense/_calculated.py: custom properties calculators and data generator methods for simulator
- sense/_dbus_descs.py: definition of DBus iface's descriptors
Operations:
- run.py: main firmware script
- sense/device.py: class that represent the device
- sense/simulator.py: class that represent the simulated device
- dbus/obj.py: class that represent aDBus object to publish
- dbus/daemon.py: methods to handle the DBus daemon
- base/commons.py: commons properties parsers and simulator methods
- base/device.py: base class for devices
- base/device_serial.py: base implementation for serial devices
- Sense Hat (C) Wiki
- Breakout board for Raspberry Pi, featuring several onboard sensors and ICs
- QMI8658C
- 6D Inertial Measurement Unit with Motion Co-Processor and Sensor Fusion
- AK09918
- 3-Axis Electronic Compass)
- SHTC3
- Humidity and Temperature Sensor IC
- LPS22HB
- MEMS nano pressure sensor: 260-1260 hPa absolute digital output barometer
- TCS34725
- ALS/Color Sensor with Selective Flicker Detection
- SGM58031
- Ultra-Small, Low-Power, 16-Bit Analog-to-DigitalConverter with Internal Reference