Circuits with Output Devices
This week, I am continuing work on my accelerometer/magnetometer board for the self-assembling tiles final project. To see the work up to this point, please see Circuits with Input Devices
Though my "output" is relatively simple initially (just an LED), I have designed the board to be primarily a sensor (aka input) device, with flexibility for testing new sensors in the future, and a responsive LED to indicate information about the status of the sensors and final project tile neighbors. By choosing a modular design and separating the processor from sensor via a breakout board, I am able to rapidly test new sensors without redesigning and fabricating a new board each time. My output LEDs give important status information for two things initially: a red LED for power status (post voltage regulator) and a green LED on digital pin 13 (I'll explain the mapping between chip pins and Arudino "digital pins" below) for programmable function based on scripts loaded onto the board. This programmable function can be dependent on the sensor data, thus offering a visual mode of interpretation.
Finishing up Board Design Steps & Soldering
Continuing from where I left off in the Inputs week, I needed to first re-design the sensor board, mill and stuff it. I realized after making the initial design and milling an early sensor board, that I had not flipped the directionaliy of the pins as required for proper mating with the female headers on the chip board. You can see the redesigned sensor board below, freshly milled, partially "stuffed" and fully stuffed:
A tip for soldering on pin headers that will need to match precisely with the distance of the receiving (female) pins: In eagle, make sure the distance between the two rows of pins/female headers is the same on each board. Then, when soldering, solder on both sets for one board and only one of the matching sides for the second board. Connect the two boards gently, and get a visual idea for where the final piece will need to be soldered for good alignment.
A note on soldering the 6 or 9DOF LSM packages. These sensors have very tiny pads on the underside of the "package", making them quite difficult to solder. The technique that worked for me (luckily the first time) was to "tin" the board layout where the chip should be placed, gently lower the chip over the cold solder pads with proper orientation, and bring the heat gun in until the solder melts and the chip bonds to the board. You'll want to be careful that you don't hold the heat gun on too long, lest you fry your board, but this technique seems to be the most reliable method of firmly soldering on these sensor packages. Thanks to Caroline Jaffe for the tip on this one!
Now, for assembly of the "modular" chip board + sensor board:
With both boards milled and the soldering complete, we can first test the connections via the continuity setting on the multimeter and then test the modular function. I carefully checked each board for shorts (there were none, yay!) and checked that the pins on the microcontroller that had traces going under the chip were properly connected. You can see that the boards fit together nicely, below:
Programming the board!
There are many approaches you can take for programming the chip on a homemade board. I chose to treat my chip like an arduino, and wanted to be able to load sketches directly onto my board via the ardunio IDE. This saves some of the pains of the straight C file approach, though both have their merits.
Programming Steps for ATMEGA 328p
- You will need to burn the Arduino "bootloader" onto your board. To do this, you'll need a programmer (like the FabISPs we made in a prior week, or a commerical programmer like the AVRISP mkii).
- Make sure your board is separately powered (this is usually done over FTDI), and connected to the programmer over the ISP header. Then connect the programmer to the computer where you will be working with the arduino software.
- For the arduino software to recognize the type of chip you are working with, you'll need to add a new "board" in the "boards.txt" Ardunio config files. The text to add to the file is below. These entries define a custom board, with the internal clock speed and proper fuse settings. You can determine whether you'll want different fuse settings by reading the datasheet of your processor for which bits are used in the "Low", "High" and "Extended" fuse profiles. You can check the same for unlock bits. The text below assumes you are using an ATMEGA 328p chip, which is a chip commonly found on Arduino boards (like the Uno and Pro).
hello.name=hello.arduino, ATmega328P, 5V, 8MHz internal oscillator
- With the boards.text file edited, you should now be able to select the correct board, programmer and port selection as shown in the screen shots below and then "Burn Bootloader" onto your chip.
- For additional programming help and other approaches, I recommend Yuval's and Amanda's pages, which I found quite helpful in going through this and last week's assignment.
- If your prior step was successful, you should now be able to load programs onto your chip by just using the FTDI serial connection to your board and the Arduino IDE (i.e. you no longer need a separate programmer). Test this with the Blink Sketch provided in the Ardunio Examples library. Make sure to both Compile and Upload your new code, and check to see if the LED is blinking as expected.
Reading sensor output
Now that your board is able to receive new programs, you can begin reading data from your sensors. It's helpful to start with a sample sketch for your sensor, if you have picked a sensor for which there are adafruit tutorials (such as the LSM303dlhc, that I'm using on this breakout board set). To get started, you'll also want to download the arduino/adafruit libraries for the sensor in question, if they're available. I downloaded the generic Sensor and LSM303DLHC-specific adafruit libraries, and saved the unzipped folders to the proper Arduino "libararies' folder in your application's data files. In addition, it's helpful to know that Arduino programs have their own numbering systems for the 328p pins, as seen below:
Below, you can see the sample arduino sketch that prints out the X,Y, and Z coordinates of the accelerometer data to the serial output window (behind the Tools menu selection pane), and what this output looks like. The output for the magnetometer is quite similar.When you first open the serial output window, make sure the baud rate is set to match what is defined in the script. .
"Outputs" for this ciruit
Because I am using this week to continue design work on my final board, I did not explore more complex "output" options like servos. I am most interested in outputing sensor data from the self-assembling geodesic dome and analyzing this properly. I did however include an extra output LED on digital pin 13 to be able to communicate status visually, either based on sensor data (what it's currently programmed to do) or based on an independently defined function that uses this output (say, to blink only when all the tiles have joined and assembled correctly...presaging my work in the networking week).