• If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.



Page history last edited by PBworks 12 years, 10 months ago

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).




  • Added a Servo class that allows more object oriented handling of servos in Processing. Not yet tested.
  • Moved all files to CVS, module arduino-processing-library.


  • Added protocol+implementation documentation
  • Firmata_Servo_05.zip A link to this version was sent to the Arduino developer's list


  • Worked with Hans; switched from stuffing commands and data into one MIDI message to using the std. MIDI commands 0xA0..0xAF for angle write commands, and four different SysEx commands for attach/detach/setmin/setmax. Files need to be documented, but functionality is complete.


  • Downloaded the Arduino Library for Processing. This includes the Firmata firmware.
  • Arduino NG can only be programmed with Arduino0010 software, generates error in 0009.
  • To test communication, loaded Processing demo file arduino_input.

    Arduino.list()[n] opens the nth serial port for communication. On my machine, there were three serial ports: COM1,COM2,COM11. COM11 was the FTDI USB Serial port. Hence Arduino.list()[2] is the right initialization command.

  • Standard Firmata software (svn: 334, as included in Processing Arduino library) does not allow the use of pull-up resistors on digital inputs. Two options: we could either modify the test in outputDigitalBytes, line 251, two allow writes to inputs at any time, or replace the force to LOW in setPinMode, line 284 with HIGH, to always turn pull-ups on.  I went for the second choice.
  • For the needs of our class, we have to add servo support to Firmata firmware and Arduino.java. The quick and dirty way is add additional code in main that executes every 20ms and simply blocks while pulsing the servo; since servo pulses are ~ 1.25 to 1.75 milliseconds long (hmm, looks like the HiTec HS-322 takes 0.5-2.5ms pulses), this may be ok - but there is the danger that we'll lose serial input. The cleaner way would be to set up another timer (do we have a spare one?) that causes a software interrupt, which turns the pin back off. Danger here is that we may miss interrupts every once in a while, which leads to twitchy servos. We also need to pick a "MIDI" command for the servo (use 0xA0..0xAF - polyphonic aftertouch - still free), and a proxy function on the Java side (servoWrite(int pin, int value)).
  • Update 1: managed to get a first hacky implementation of servo support in Firmata up and running. There's only one servo supported, and min/max pulse lengths are hardcoded. Here is a zip with the modified firmata firmware, arduino.java library, and example processing sketch: Firmata_Servo_01.zip For the future, we may want to expose the functionality of the Arduino servo library i.e., add attach(), detach() methods, setting of min,max pulse lengths, and multiple servos; or use the Servo Timer 1 library which looks more promising because it uses hardware timers. The latter only supports two servos, but that should be ok for the class.
  • Update 2: incorporated Servo Timer 1. We can now control two servos on pins 9 and 10, and set their min/max pulse times. All files: Firmata_Servo_02.zip





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:


TO DO: Test this code with a real encoder


Comments (0)

You don't have permission to comment on this page.