rpi_serial 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 59

rpi_serial #

rpi_serial is a Dart package for using serial communication on the Raspberry Pi.

Overview #

  • The Serial library provides the API for accessing devices using the serial protocol

  • The RpiSerial library provides implementation of the serial protocol on the Raspberry Pi derived from the WiringPi library.

Setup #

Be sure to enable serial on the Raspberry Pi using

sudo raspi-config

Also make sure to disable the console on the serial port.

RpiSerial uses a native library written in C. For security reasons, authors cannot publish binary content to pub.dev, 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_serial package.

  1. Activate the rpi_serial package using the pub global command.
pub global activate rpi_serial
  1. From your application directory (the application that references the rpi_serial package) run the following command to build the native library
pub global run rpi_serial:build_lib
  1. Deactivate the rpi_serial package.
pub global deactivate rpi_serial

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

Connecting #

Refer to Raspberry Pi GPIO for connecting your serial device to the Raspberry Pi. By default pins 8 is TX and 10 is RX on the GPIO header.

Note that the Raspberry Pi actually has two UARTs. On the versions with Bluetooth (Raspberry Pi 3 and Raspberry Pi Zero W), the UART exposed to the GPIO pins is "/dev/ttyS0", while it is "/dev/ttyAMA0" on the rest of the boards. This can be changed (see Rapsberry Pi UART configuration). On the compute module, you can supposedly expose both serial interfaces on the GPIO.

Examples #

basic_device is a class containing most of the basic features that you would need to comunicate with a serial device. This is implemented using the API (Serial). No low-level interactions required. If you want to communicate with another device, you should probably create a similar class, but specific to that device.

example is for demonstrating basic read and write operations using the basic_device class.

Hopefully the examples are pretty self-explanatory.

Changelog #

0.1.0 #

  • Initial implementation


import 'dart:math';
import 'dart:async';
import 'package:rpi_serial/rpi_serial.dart';
import 'basic_device.dart';

main() async {
  final serial_connection = RpiSerial();
  await testSensor(BasicSerialDevice(serial_connection));

// Sends a random number between [0-9] to the serial port, and reads the incoming character.
// Place a jumper between the TX and RX pins to read the characters
testSensor(BasicSerialDevice device) async {
      "Entering endless loop mode. Please connect a cable between the rx and tx pins.");
  while (true) {
    await Future.delayed(Duration(milliseconds: 500));

Use this package as a library

1. Depend on it

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

  rpi_serial: ^0.1.0

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_serial/rpi_serial.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.

Maintenance suggestions

Package is getting outdated. (-0.82 points)

The package was last published 52 weeks ago.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.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