Another low-bandwidth week for me. Grad school (and specifically Member's Week) is hard! Hoping to return to this week to do some more with networking and communications. To start, I just focused on programming the board I made two weeks ago. I already programmed this board two weeks ago using the Arduino IDE and the High Low Tech tutorial. Here's a video of the blinking light program I loaded then:
I wanted to be comfortable programming the board using gcc, C and a makefile. Briefly, here are the steps I used (cobbled together from this image and this tutorial):
- Connect everything! Use a USB-MicroUSB cable to connect the FabISP to your computer. This both powers the FabISP board and provides a USB connection. Then, use the ISP-header cable to connect the FabISP and your board. Make sure the corresponding pins are connected correctly. Then, use the FTDI cable-USB cable to plug your board into your computer. This powers and provides a serial connection to your board.
- Download Neil's hello.ftdi.44.echo.c and hello.ftdi.44.echo.c.make files. The first file is the code that will be uploaded on your board. The second is the makefile that tells your computer the commands it needs to run to compile the C code into hex code, set the fuses (e.g. settings) on the microprocessor, and actually program your board.
- I am using OSX so I had to download the CrossPack for AVR Development. I already had the FTDI USB drivers installed.
- Navigate to the directory where your files are and type in the three commands described in this image. These commands (1) convert your c code to hex code that the microprocessor can read, (2) set the fuses (e.g. settings on the board), and (3) actually program your board by sending the hex code to the board.
- Instead of using term.py, I opted to use the built-in "screen" command in terminal. To do this, check which USB devices are connected to your computer by typing "ls /dev/tty.*" into a Terminal screen. This will show you the USB connections - you are probably looking for the one that looks like "/dev/tty.usbserial-XXXXXXXX". Then, type "screen /dev/tty.usbserial-XXXXXXXX 115200" into Terminal. This will open a screen with a serial connection to your board, where you can send data to the board. Make sure you type "ctrl-A ctrl-\" to leave this screen - otherwise the serial connection will stay busy.
Here is an image of the screen output of running the echo program and interacting with the program through the screen command. The formatting is a little funky. It also looks like the buffer saves whatever text you've typed in from the last session.
After a little investigation, I learned the format was funky because the serial monitor is getting just a newline ('\n' or 10) but no carriage return ('\r' or 13), which would bring the output back to the beginning of the line. (Perhaps term.py does this preprocessing for you, which is why this problem didn't come up for people using that serial interface?) I made a small modification in the code to add a carriage return, and my formatting in the serial monitor looked a lot better after that:
I also thought it could be nice to allow users to input a "clear" command and a "delete" command. With a bit of debugging (it's been a loooongggg time since I did string manipulation in C) I implemented these commands.
Playing around with the code like this got me more familiar with the toolchain. I felt pretty comfortable making quick changes, compiling and uploading them to the board, and testing the outcome. I realize this is made much easier by having the built-in "put_char" and "put_string" functions from Neil's code. For future steps, I'm hoping to mill another board to try some networking, and perhaps do something more interesting with the LED.