Difference between revisions of "250a Firmware Lab"

From CCRMA Wiki
Jump to: navigation, search
(Never Power Off The Board Without Halting It First)
(Optional: Linux Machine)
Line 36: Line 36:
 
Power up ccrma@satellite again using the same procedure as before, where you plug in the power to the USB hub first, and then following that you plug the power into the beagleboard itself. After about 30 seconds, the board should be booted up again, so you can log in again by running the command ''ssh -X ccrma@192.168.1.105''
 
Power up ccrma@satellite again using the same procedure as before, where you plug in the power to the USB hub first, and then following that you plug the power into the beagleboard itself. After about 30 seconds, the board should be booted up again, so you can log in again by running the command ''ssh -X ccrma@192.168.1.105''
  
== Optional: Linux Machine ==
+
== Optional: Programming Linux ==
Since ccrma@satellite runs ubuntu linux on an OMAP chip, many standard software packages have been compiled for it. This is why we were easily able to install software such as Jack, [http://audacity.sourceforge.net/ Audacity], [http://chuck.cs.princeton.edu/ ChucK], [http://faust.grame.fr/ Faust], and [https://ccrma.stanford.edu/groups/soundwire/software/jacktrip/ Jacktrip].
+
Since ccrma@satellite runs ubuntu linux on an OMAP chip, many standard software packages have been compiled for it. This is why we were easily able to install software such as Jack, [http://audacity.sourceforge.net/ Audacity], [http://chuck.cs.princeton.edu/ ChucK], [http://faust.grame.fr/ Faust], [https://ccrma.stanford.edu/groups/soundwire/software/jacktrip/ Jacktrip], and the Arduino software.
  
 
If you are lucky, you can install your favorite software using the ''apt-get'' utility. To get a list of packages available on the OMAP's ARM architecture, type
 
If you are lucky, you can install your favorite software using the ''apt-get'' utility. To get a list of packages available on the OMAP's ARM architecture, type
Line 45: Line 45:
 
and then look at it using ''emacs packages.txt'', or you search for a particular package, such as  
 
and then look at it using ''emacs packages.txt'', or you search for a particular package, such as  
 
''sudo apt-cache pkgnames | grep emacs''.
 
''sudo apt-cache pkgnames | grep emacs''.
 +
 +
Or, you can compile linux software yourself on the Beagleboard. The gcc, g++ tools etc. are already installed.
 +
 +
Type the ''df'' command. You can see that there is not a whole lot more than 1GB available on the SD card, so you should only install software if you decide that you need it.
  
 
== Headless Mode ==
 
== Headless Mode ==

Revision as of 19:52, 4 October 2010

Lab 3: Beagleboard and Firmware Programming
Due on Wednesday, October 13th at 5PM

For this lab you need your MaxKit, and Pd on a computer. During this lab, you will assemble your ccrma@satellite kit and start to use it.


The ccrma@satellite setup

First, you'll need to set up your beagleboard, USB hub, and breadboard on a foamcore base. Included in your kit, you should have:

- White USB hub with RJ45 Ethernet jack
- Beagleboard
- A 4GB SD card to plug into the beagleboard
- Two 5V power adaptors (one for the Beagleboard and one for the USB hub)
- One Ethernet cable
- Arduino Nano (from your old kit)
- A GT Max adjustable-length USB cable to connect the Arduino to the hub

If you are missing something, please go get it before assembling you kit.

[insert photo of the CCRMA Satellite set up here]

Powering Up For The First Time

When using your kit, always plug in the power to the USB hub before you plug in the power to the beagleboard. Otherwise, it can happen that the Arduino Nano is not initialized properly. So first power up the USB hub with the 5V adaptor with the smaller connector, and then power up the beagleboard itself by the other 5V power adaptor into the beagleboard. You will see some lights turn on, flickering every now and then. This means that ccrma@satellite is booting up.

Connect To ccrma@satellite

In order to see what your ccrma@satellite kit is doing, you need to log in to it. To do so, connect the USB hub to your laptop using the Ethernet cable and remotely open an SSH window on ccrma@satellite.

Never Power Off The Board Without Halting It First!

Would you take the battery out of your laptop and unplug its power adaptor without shutting down? I don't think so! The same goes for ccrma@satellite because it is a small computer running linux. If you power if off without shutting down, then you can corrupt the files on the SD card, which in the worst case could cause it to stop booting up anymore, and we would have to burn you a new SD card! So just remember this: HALT ccrma@satellite BEFORE DISCONNECTING IT FROM ITS POWER!

Now we will test the halt procedure. Run the halt command as superuser by typing sudo halt at the ccrma@satellite prompt. Then you will again have to type in the password temppwd' in order to have the privilege to run this command. The SSH connection will be closed, but it will still be 20 seconds or so before ccrma@satellite has completely shut down. (Note: The command sudo reboot would instead have caused ccrma@satellite to reboot itself.)

Wait an extra entire minute to ensure that ccrma@satellite is shut down. However, it will not power itself off. To do this, you need to disconnect the two 5V power adaptors.

Getting Comfortable

Power up ccrma@satellite again using the same procedure as before, where you plug in the power to the USB hub first, and then following that you plug the power into the beagleboard itself. After about 30 seconds, the board should be booted up again, so you can log in again by running the command ssh -X ccrma@192.168.1.105

Optional: Programming Linux

Since ccrma@satellite runs ubuntu linux on an OMAP chip, many standard software packages have been compiled for it. This is why we were easily able to install software such as Jack, Audacity, ChucK, Faust, Jacktrip, and the Arduino software.

If you are lucky, you can install your favorite software using the apt-get utility. To get a list of packages available on the OMAP's ARM architecture, type sudo apt-cache pkgnames You will notice that this list is way too long to look at. You can pipe it to the text file using the command sudo apt-cache pkgnames > packages.txt and then look at it using emacs packages.txt, or you search for a particular package, such as sudo apt-cache pkgnames | grep emacs.

Or, you can compile linux software yourself on the Beagleboard. The gcc, g++ tools etc. are already installed.

Type the df command. You can see that there is not a whole lot more than 1GB available on the SD card, so you should only install software if you decide that you need it.

Headless Mode

Install Firmata.

Plug a pair of ear buds, headphones, or loudspeakers into the 1/8" (2.54mm) jack labeled AUDIO OUT on the beagleboard. Probably by this point, some sound will come out if you touch the anaog input pins on the Arduino A0-A7. If not, then perhaps you have not waited long enough (about 1 minute after powering up ccrma@satellite), or you have not connected the 5V power adaptors in the right order. Ask for help if you cannot get any sound.

Type ps at the prompt to get a list of the currently running processes. jackd is the daemon for the audio driver jack,

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