A Random Collection Of Technological News and Random Musings on Current Events
By Alex Ferro on May 31, 2010 7:06 AM | No Comments
As mentioned in my previous post I attended the Maker Faire and more specifically the SparkFun SMD soldering workshop. The workshop was for a Simon game. Contrary to popular belief, I don't have the highest interest in actually playing Simon. Yes it is a fun game, but I wanted to learn SMD, and plan on using it as a 1.5V, 4x LED lit button pad Arduino

The day after I got home from the Maker Faire, I immediately began messing with the board to see what I could do with it. A simple test revealed that it did not have the Arduino boot-loader installed, no surprise there. That meant that I would have to install it myself. So I grabbed my AVRISP mkII, and proceeded to hook it up to the Simon game. The picture shows the pins on the ISP angled against the PTH ISP header holes in the Simon game. (Look Ma...No header) The first problem I ran into was that none of the existing Arduino boards really matched the combination an ATmega328p without a crystal running at 8MHz. That made the first step compiling the boot-loader for this specific board. The only changes made were in the makefile. I changed the target for the "atmega328_pro8" to use a slower baud rate since the internal oscillator is not as accurate as an external crystal. I don't actually remember why I didn't just create a new target for make, but I didn't. Sosumi. After recompiling the boot-loader, I created a boards.txt entry for the board with the correct build info. As part of that I also had to look up the the correct fuses to accomplish the same thing as the Arduino ones, but using the internal crystal. As part of these two steps I decided to have the Simonduino run at 8MHz rather than the default 1MHz. I costs a bit more power, but the platform is more compatible with the Arduino software as 8MHz is a "standard" speed. After performing this upgrade (by unsetting the stock CLOCKDIV8 fuse), I flashed the new compiled boot-loader on the board. I went to attempt to use the boot-loader and it worked once but would not work after that. I forgot the lock bits. After re-flashing it with the boot-loader agin and setting the lock bits correctly this time, I was able to upload sketches and have the boot-loader still work after. 

I used the boot-loader to flash the original Simon firmware back on the board and ran into the first big problem. The game ran too fast by a factor of eight with the stock firmware from SparkFun. I remembered reading something in the AVR features that allowed the speed of the chip to be changed at runtime. I did a little research to find some code that showed how to use the prescaler and set it to divide by 8. After a recompile and upload, the game worked at the correct speed. As I wasn't able to establish an accurate reuse permission from the code, I am offering just a diff file of my changes against Sparkfun's original code
This diff file was produced with the command-line diff utility. Just apply it to the Simon-v21.c source file and run make. The patcher complains about something, but the file still works after. The makefile still builds the source for the ATmega168, but that is just the smaller version of the ATmega328 and the less changed the better. 

With the clock speed issue solved I was able to continue and add more than cursory support to the Arduino IDE for this board. I originally modified the Arduino core and all of its supporting files to include my changes, but I realized how much a pain it would be to install and update if the IDE changes. I read the instructions for adding new hardware to the IDE and created the proper subdirectories within my Arduino folder to use the board without modification to the core. I also created a library the has wrapper functions that have the pin coded into them to avoid re-looking up the pin assignment every-time you use the board. I also overloaded the tone function in the library to just use the frequency argument and omit a pin. This function sets up the onboard buzzer and then calls tone. A call to noTone(); then disables the tone again. Using blue for an example here: blue(LOW|HIGH) // turns off or on the blue LED, while readBlue() // returns the state of the blue button. The acual code that implements these functions is below:  

Going back to the original simon firmware again. Since we have gone to all of this effort to set up the Simonduino, we don't want to ISP program the original Simon game back over the boot-loader. The correct avrdude command for programming the Simon firware back in the board is:
avrdude -p m328p -c avrisp -P /dev/cu.usbserial-FTDI-3.3 -b 19200 -F -U flash:w:"Simon-v21.hex"
This command does the same thing as the Arduino boot-loader sans the fancy gui.

The last modification I made to the board was hardware. I soldered a six pin right angle header to the board that allows me to connect my FTDI Basic to the board rather than angling its pins against the board as a long term solution. The header was soldered on in such a way that it did not stick up into the button pad and faced inwards over the board. This header is compatible with the FTDI cable but the reset may not work, I have not tested it. 

My files and modifications are available for download below. I do not really care what you do with this code as long as you respect the original licenses of the modified code.
The boot-loader source code and makefile (modified): Simon_Bootloader.zip. Unless you plan on modifying the boot-loader, you don't need this.
The Simon library (written by me): Simon_Lib.zip. This goes in the libraries subfolder of your sketchbook.
The Simon hardware spec for Arduino IDE: simon_Hardware.zip. This provides the board entry, build settings, and boot-loader for the IDE. This goes in the hardware subdirectory of your sketchbook.
Leave a comment
Powered by Movable Type Pro
This blog is licensed under a Creative Commons License.