rpi_i2c 0.1.1

  • README.md
  • Example
  • Installing
  • Versions
  • 50


pub package Build Status

rpi_i2c is a Dart package for using I2C on the Raspberry Pi.


  • 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.


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.

  1. Activate the rpi_i2c package using the pub global command.
    pub global activate rpi_i2c
  1. 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_lib

pub global activate makes the Dart scripts in the rpi_i2c/bin directory runnable from the command line. pub global run rpi_i2c:build_lib runs the rpi_i2c/bin/build_lib.dart program which in turn calls the build_lib script to compile the native librpi_i2c_ext.so library for the rpi_i2c package.


Both of these 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 PinMPL3115A2TTP229
PIN #1 (3.3v)3V3V

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.



  • Add I2C readBytes support
  • Add TTP229 touchpad example
  • Add travic CI analysis
  • Update readme and fix example code


  • Initial implementation


import 'dart:async';

import 'package:rpi_i2c/rpi_i2c.dart';

import 'mpl3115a2.dart';

main() async {
  final i2c = new RpiI2C();
  await readSensor(new Mpl3115a2(i2c));

Future readSensor(Mpl3115a2 mpl3115a2) async {
  Mpl3115a2Data result;

  print('Pressure and temperature:');
  result = await mpl3115a2.read();
  print('  pressure: ${result.pressure} pascals');
  print('  temperature: ${result.temperature} celsius');

  print('Altitude and temperature:');
  result = await mpl3115a2.read(altitude: true);
  print('  altitude: ${result.altitude} meters');
  print('  temperature: ${result.temperature} celsius');

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  rpi_i2c: ^0.1.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:rpi_i2c/rpi_i2c.dart';
Version Uploaded Documentation Archive
0.1.1 Nov 18, 2018 Go to the documentation of rpi_i2c 0.1.1 Download rpi_i2c 0.1.1 archive
0.1.0 Sep 14, 2018 Go to the documentation of rpi_i2c 0.1.0 Download rpi_i2c 0.1.0 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7


Detected platforms: other

Primary library: package:rpi_i2c/rpi_i2c.dart with components: nativewrappers.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.60.0 <3.0.0
path >=1.0.0 <2.0.0 1.6.2
Dev dependencies
grinder ^0.8.0
pedantic ^1.1.0
test ^1.2.0