The DrFirmata firmata provides abstractions under the form of functions which allow you to program a micro-controller via the serial port of a computer. The library uses the Firmata protocol for communicating with the micro-controller. Firmata is a generic protocol popularized by the Arduino platform which supports both input and output for digital and analog pins. With this library you can develop small applications on a micro-controller without having to write any software on the host computer for the micro-controller itself. The micro-controller runs a small program that periodically sends updates about its state to the host computer, and listens for commands from the computer, for example, to turn on and of a led.
The DrFirmata library has only be used in conjunction with the Arduino platform so far. Therefore, the instructions to get started explain how to get the library up and running on an Arduino micro-controller. Getting the library to work for other micro-controllers should be analogous.
The easiest way to get started with DrFirmata is to download and install the software and the drivers that come with Arduino. Next, it is necessary to reprogram your Arduino micro-controller with the Firmata firmware. Firmata is included in the standard distribution of Arduino since version 12. In order to flash your Arduino with the Firmata firmware select the firmata program from the example sketches that come with the Arduino software. It can be found by selecting the following menu: File -> Examples -> Firmata -> StandardFirmata. Plug in your micro-controller board, and press the button upload from the Arduino software. Once you have installed Firmata on your Arduino, it is ready for DrFirmata.
We now show the functions for opening and closing the communication medium with the micro-controller. Communication with the micro-controller happens over the serial port. It is very important to open the serial port before applying any other functionality from the library.
> (require "firmata.rkt") > (open-firmata "/dev/cu.usbserial-A5002tPQ")
open-output-file: cannot open output file:
"/dev/cu.usbserial-A5002tPQ" (Permission denied; errno=13)
|(close-firmata) → (bool?)|
Many pins of a micro-controller have multiple purposes. The modes supported by the firmata firmware are INPUT_MODE, OUTPUT_MODE, ANALOG_MODE, PWM_MODE, SERVO_MODE. Before using a pin for a certain functionality, it is necessary to configure it as follows.
Once a connection with the micro-controller is established, it is possible to inform the micro-controller what kind of updates he needs to send to the host computer. You can register for updates on both analog and digital pins. Updates for analog pins can be controlled at the pin level by turning on its notification mechanism. Updates for digitial pins are controlled by turning on the notification mechanism of the port where they are attached to.
|(report-digital-port! int? int?) → ()|
|int? : port|
|int? : mode|
Only when a pin is set for input, its value can be read. It is very important to realize that the most recent updated value will be returned. Note also that if you do not register for updates for an input pin, its values are not updated.
|(is-pin-set? int? int?) → (bool?)|
|int? : port|
|int? : pin|
|(read-analog-pin int?) → (int?)|
|int? : pin|
Analogously, only when a pin is set for output, its valued can be changed.
The Firmata protocol divides all the pins of your micro-controller into ports of eight pins. However, Arduino boards number the pins from 0 till 13. The following functions can be used in order to set and clear pins while using the numbers of the pins as indicated on the Arduino board.
|(get-version) → (string?)|