Embedding Programming


Fixing my board

For this week's assignment the first thing I had to do was go back to my board from electric design week and make some fixes. With the help of my friend, Dan Chen, we discovered that when I used an exacto knife to seperate the traces under the ATtiny 44 a few weeks ago, I unknowingly cut the trace connection for the 4th pin down on the left of the ATtiny. My initial instict was to think about desoldering and fixing the issue from underneath. Thankfully, Dan helped me realize that there were other solutions we could attempt. Ultimately, we decided to use an external wire as a jumper for the pin. I was really happy with how this little hack turned out. Another issue with my board was that my LED was in the wrong direction. This was a simple fix to get the board ready to be programmed.

Learning about AVR Programming

Since I do not know much about programming, Rob suggested I read the first few chapters of Elliot William's "Make:AVR Programming." I am glad he suggested it because I found William's writing style and approach to explanation very accessible. It was exciting to start to wrap my mind around this stuff. I highly recommend reading Chapters 1-4 for this assignment -particularly if you are a complete novice to it like me. The book is available through the Harvard library system, there are 2 copies in the Harvard shop, and Dixon found a PDF available online.Here are some helpful steps to summarize the process from Williams:

  • 1. PLAN - brain, paper, pencil, AVR data sheet - think through what you need the chip to do, and break it up into functions for logical step.
  • 2. CODE - Write your program using whatever text/code editor makes you happy. Here you're just translating the ideas behind the functions into valid C code.
  • 3. COMPILE - Turn your C code into AVR machine code and avr-gcc and its associated tools, most likely run from a makefile. Type make and read through the compiler errors, then go back and fix them.
  • 4. FLASH - Hook up a flash programmer to your target AVR and then run AVR DUDE to send the machine code through the programmer to the AVR chip, which saves it in flash memory (Or just type make flash and watch it go.)
  • 5. TEST - Once you've uploaded your code to the AVR, does it do what you want it
  • Understanding the ATtiny44

    The image to the left help me understand how the different traces on my board related to pins on the microprocessor. Using this diagram I was able to identify that my LED was positioned on pin 7 and the button was on pin 3.

    Programming in the Arduino Environment

    For the programming portion of the exercise I found it helpful to follow the tutorial from Rob linked from the Tutorial page, Alan Kwan from 2014 describes the Windows process quite nicely, and Dan Chen's page from 2014 is also incredibly helpful for quick access to key files. For the Arduino environment I first needed to download the software. From there I went to the examples -> Blink file and used it as the base to build from. I also received a button file from Dan that I used. All that was left was to change the pins to reflect my board the input levels to reflect that I wanted to the light to go on when the button is pushed.

    Programming in C

    I was having trouble installing the AVR driver on my windows device, I was also having trouble with FabISP (which was working weeks ago, but I still need to debug to figure out what is going on with it now.) I completed the C programming on the Mac in the shop instead once I had spend considerable time trying to figure out what was happening with the AVR driver installation. Some important things I learned about this process. First is to understand that the FTDI is only giving the board power and does not program it. Once I downloaded the make files and boot loader, it was time to make simple changes to the C to reflect my board and what I wanted it to do. Rob helped me understand how the board was organized into blocks. Both my LED and Button are in PortA to I had to use the DDRA register. I aslo wanted pin 7 to be high as this was my LED pin and I wanted it to have a high voltage to light up so it would be 10000000. For someone new to this I would again suggest the following resources: Make by Elliot Williams, Alan Kwan's page for Window's users, Dan Chen's page for a clean walk through, Rob's tutorial on simple C programs, and Dixon sent out a wonderful, clear tutorial I hope he posts for posterity.

    The Finished Product

    When you push the button it, it lights up! Simple, yet powerful.