rpi_i2c 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 35

rpi_i2c.dart #

pub package Build Status

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.

  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.

Examples #

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.

Changelog #

0.1.1 #

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

0.1.0 #

  • 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

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter 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';
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 Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.9+1

Health suggestions

Fix bin/build_lib.dart. (-4.41 points)

Analysis of bin/build_lib.dart reported 9 hints, including:

line 11 col 17: Unnecessary new keyword.

line 14 col 14: Unnecessary new keyword.

line 25 col 22: Unnecessary new keyword.

line 29 col 15: Unnecessary new keyword.

line 34 col 18: Unnecessary new keyword.

Fix lib/rpi_i2c.dart. (-4.41 points)

Analysis of lib/rpi_i2c.dart reported 9 hints, including:

line 12 col 33: Unnecessary new keyword.

line 20 col 23: Unnecessary new keyword.

line 21 col 20: Unnecessary new keyword.

line 30 col 30: Unnecessary new keyword.

line 48 col 27: Use isEmpty instead of length

Fix lib/i2c.dart. (-0.50 points)

Analysis of lib/i2c.dart reported 1 hint:

line 10 col 13: Unnecessary new keyword.

Maintenance suggestions

Package is getting outdated. (-61.92 points)

The package was last published 84 weeks ago.


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.7.0
Dev dependencies
grinder ^0.8.0
pedantic ^1.1.0
test ^1.2.0