250a Firmware Lab

From CCRMA Wiki
Revision as of 11:20, 4 October 2010 by Wendyju (Talk | contribs)

Jump to: navigation, search

Lab 3: Firmware Programming
Due on Wednesday, October 14th at 5PM

For this lab you need your MaxKit, and PD on a computer.


The CCRMA Satellite setup

First, you'll need to set up your Beagleboard, USB hub, and breadboard on a foamcore base.

[insert photo of the CCRMA Satellite set up here]

Then, you'll need to get the operating system up and running on the Beagleboard. We have 2 GB SD cards that have a working Ubuntu Linux Operating System; get one.

[more detailed information on first time boot]

Now connect your computer so that you can talk to your Beagleboard.

[more detailed information on setting up Xterm connection]

[try running some normal Unix programs so that you feel like this is in fact Unix]

Get Arduino up and running on the Beagleboard

At the command prompt, type Arduino.

Compiling and uploading firmware code in the Arduino Program

For this class, we assume that you will be adapting existing working code for your own applications. While this is certainly easier than writing firmware from scratch, it does require understanding how existing code functions.

Please upload the following firmware programs from your Arduino program's Sketchbook->Examples folders to your Arduino controller and see how they function. Do attach LEDs, buttons, as is appropriate:

* Digital->Blink
* Digital->BlinkWithoutDelay
* Analog->Fading
* Digital->Button (Even though it works, there is a bug in this file. Can you find it?)

Modify the following programs:

  • Digital->Melody: Use the piezo speakers supplied with the lab for this one (there are some already wired in a drawer marked "speakers" in the lab). Change the song. Incorporate some user interaction so that the song does not loop endlessly.
  • Analog->AnalogInput: Change the code so that you create a digital metronome whose speed can be controlled by a continuous sensor.

Custom Communication

Another reason that you might want to program the Arduino microcontroller even if you are connected to a laptop or desktop computer is to enable greater control over the communications from the Arduino. In this segment of the laboratory, we learn a wider variety of ways to send data from the Arduino hardware to the computer than we have previously used.

Serial communication with the Arduino software

You might have noticed in the previous lab segment that it can be very hard to know what is going wrong when the Arduino hardware is in autonomous mode. Here, we send serial communications between the Arduino hardware and the Arduino software.

  • Sketchbook->Examples->Analog->Smoothing: Use the Serial Monitor (icon on the far left on the Arduino software toolbar) to get data back from the Arduino.
  • Sketchbook->Examples->Communication->SerialCallandResponse.

Serial communication with PD

Now let's try using serial to communicate with PD.

First let's try outputting information to the Arduino hardware:

  • Load Examples->Communication->PhysicalPixel
    • The PD patch for communicating with this firmware is linked here; use "Save Link As" to save it to your lab3 directory. PhysicalPixel.pd

Next let's try getting information from the Arduino hardware:

  • Load Examples->Communication->Graph
    • The PD patch for communicating with this firmware is linked here; use "Save Link As" to save it to your lab3 directory. Graph.pd

Low-latency sensing

Encoder input

One final reason that you would want direct control over the Arduino firmware is that you might have very low-latency sensing needs. As an example of this, we show you here how to use encoder input with the Arduino.

Now you will learn how to use a rotary encoder. Quit Pd or Max/MSP. Then download encoder.zip and use the Arduino software to download the encoder.pde firmware file to your Arduino board.

Build this schematic: http://cm-wiki.stanford.edu/mediawiki/images/c/c1/Encoder_filter.png.

Connect pin 2 of the Arduino to Phase A. Connect pin 3 of the Arduino to Phase B, and you're ready to send out the position of the encoder over the serial bus.

You can read the values coming in from the encoder with the patches included in the ZIP file.

The values should start near zero and increase or decrease, depending on which direction you turn the encoder. How are negative numbers represented? Why does the encoder always start near 0 when the program on the Arduino is restarted?

Sensor instrument, optimized (optional)

Now, try reimplementing your instrument from the end of Lab 2 in firmware! Program the Arduino firmware so that it only detects inputs and performs outputs to the pins you use, and modify your Lab 2 patch to work with it.

Your code on the Arduino should be running your program a lot faster than Firmata. Does your instrument work any better?

Reaction time sensing (optional)

For the very ambitious: Write a program that tests how fast people can respond to light vs. sound trigger! Please include your code in your lab write-up.

Restore Firmata?

If, after all of this, you just long for the halcyon days where you just had to program in Max or PD, you are welcome to reflash your Arduino hardware with the Firmata software.

In your lab write-up, please say something about whether you preferred using Firmata (like in Lab 2) or writing your own firmware (like in this lab). Our feelings will not be hurt! We just want to know how you feel...


250a 2009