FirmataExtensions


For Winter 2008, we will be teaching Arduino+Processing in ENGR231 and Arduino+Flash in CS247. In both cases, the Arduino boards will run Firmata firmware so that the application logic can reside entirely on the PC side. I'm currently adding functionality to support common tasks beyond reading/writing of digital values. The modified Firmata firmware and Firmata PC libraries will be distributed to students.

 

Servo Control

The goal is to have high level function calls to control servo motors from the PC application level (Processing/Flash).

 

Notes:

2008-01-06:

2008-01-05

2008-01-04:

2008-01-03:

 

 

 

 

Event Callbacks programming

We should teach the difference between polling and interrupts (even-based programming). The standard Arduino.java library for Processing only supports polling of digital inputs.

I've added event callbacks in the Processing reflection style, i.e., users add the following functions to their sketch:

public void digitalEvent(int pin, int value) //called when a digital pin's state has changed
public void analogEvent(int pin, int value) //called when an adc pin's value has changed

 

TO DO: careful with race conditions! If I understand correctly, callbacks generated from a Serial event will happen in the SerialProxy's thread, not in the GUI thread.

 

Encoder Input

Managing state of quadrature encoders is a standard task that should be factored out into a library so students don't have to watch the pins in their processing sketch. I'm adding an Encoder class to arduino.jar - the encoder registers itself as an event listener with the Arduino object to receive digital pin updates.

The Encoder class also offers both pollind and event callbacks to read encoder state. Callback syntax in :

public void encoderEvent(Encoder enc, int delta) //called when enc's position has changed. delta is the change (+1 or -1)

Polling functions:

encoder.getRelativePosition()
encoder.getAbsolutePosition()

TO DO: Test this code with a real encoder