rpi_i2c 0.3.1 rpi_i2c: ^0.3.1 copied to clipboard
rpi_i2c is a Dart library for using I2C on the Raspberry Pi.
rpi_i2c.dart #
rpi_i2c is a Dart package for using I2C on the Raspberry Pi.
Overview #
-
The I2C library provides the API for accessing devices using the I2C protocol
-
The RpiI2C library provides implementation of the I2C protocol on the Raspberry Pi derived from the WiringPi library.
Setup #
Be sure to enable I2C on the Raspberry Pi using
sudo raspi-config
RpiI2C uses a native library written in C. For security reasons, authors cannot publish binary content to pub.dartlang.org, so there are some extra steps necessary to compile the native library on the RPi before this package can be used. These two steps must be performed when you install and each time you upgrade the rpi_i2c package.
- Activate the rpi_i2c package using the pub global command.
pub global activate rpi_i2c
- From your application directory (the application that references the rpi_i2c package) run the following command to build the native library
pub global run rpi_i2c:build_native
pub global activate makes the Dart scripts in the rpi_i2c/bin directory runnable from the command line. pub global run rpi_i2c:build_native runs the rpi_i2c/bin/build_native.dart program which in turn calls the build_native script to compile the native librpi_i2c_ext.so library for the rpi_i2c package.
Examples #
File | Description |
---|---|
example.dart | instantiating and accessing an I2C device |
mpl3115a2.dart | Mpl3115a2 pressure sensor with altimetry |
ttp229.dart | TTP229 I2C touchpad |
tsl2561.dart | TSL2651 light sensor which is embedded in the Grove Light Sensor v1.1 |
Multiple devices can be connected to the I2C bus at the same time. Connect the following pins on the Raspberry Pi to pins on the Adafruit MPL3115A2 and pins on the TTP229 Touchpad
It is recommended to attach two 4.7K pullup resistors, one to the SDA line and a second to the SDL line, althrough with some device boards already have pullup resistors on them. If you have many I2C devices and/or a long I2C bus, you many need a different value as per I2C pullup resistor recommendations.
Rpi Pin | MPL3115A2 | TTP229 | Pull-up Resistors |
---|---|---|---|
PIN #1 (3.3v) | 3V | 3V | |
PIN #3 (SDA1 / I2C) | SDA | SDA | 4.7K resistor to 3.3V |
PIN #5 (SDL1 / I2C) | SDL | SDL | 4.7K resistor to 3.3V |
PIN #6 (GND) | GND | GND |
With thanks to Pierre Henelle for the RPi_MPL3115A2 library for wiring and inspiration. In that library's readme, there's a good picture of the RPi connected to the MPL3115A2.