Raspberry Pi talks to Arduino using Dart

RaspberryPi-Dart-Arduino

This post will show you how a Dart program running in a Raspberry Pi board can communicate to an Arduino board.

To show it we will send a text message from a Dart program running in a Raspberry Pi and we will visualize it in an LCD controlled by an Arduino board.

HARDWARE SETUP

The main components are:

  • A Raspberry Pi Model B revision 1.0 running Raspbian 2014-09-09
  • An Arduino Duemilanove
  • A 16×4 LCD
  • breadboard, wires and cables

The Raspberry Pi board is connected to the Arduino board through an USB cable.

RaspberryPi-Arduino-LCD-schema

The LCD is wired to the Arduino board following the schema proposed in the Liquid Crystal Library example.

LCD_bb

 SOFTWARE

For the Arduino side I wrote a simple sketch using the Liquid Crystal library.

In the loop block the sketch reads a String from the USB and writes it to the LCD. The sketch replies to the Raspberry Pi board with an “Hello Pi!” message.

For the Raspberry Pi side I wrote a Dart program that sends a message to the USB port using the serial_portal package.

The program initializes the USB port and sets a listener for the incoming bytes in order to write them in the console. After the setup it opens the USB port and sends the “Hello Dart!” message.

To run the program in the Raspbian environment I had to compile the Dart SDK.

In the screenshot you can see the Dart program running in the Raspbian terminal.

RaspberryPi-Dart

 

Here the source code: Dart-RaspberryPi-Arduino.zip