Wednesday 22 May 2013

16250 Gadgetry S13 notes archive



Installing the AVR Toolchain


The Atmel AVR microcontroller comes with an array of software and hardware tools used to write, compile, and download compiled code onto the microcontroller. Some of these programs are provided by Atmel, and some are open source and developed by the community. This document will describe the underlying software and hardware that allows programming of the AVR, two Windows OS environments that we frequently use, and guide you through compiling and downloading programs with these tools. It also points you to software in case you prefer to use Mac or Linux OS.
 

Development Environments

Windows

WinAVR. WinAVR is an integrated package that provides an IDE (programmer’s notepad) that has avrgcc, avr-libc, and avr-dude (see below) built in. We strongly suggest that you use WinAVR if you use Windows. You can download the WinAVR executable at:
 
The drivers for your avr-isp are located in WinAVR's utils/libusb/bin directory. If you have trouble because windows won't let you install the drivers because they're unsigned, you can signed drivers at http://mightyohm.com/blog/2010/09/avrisp-mkii-libusb-drivers-for-windows-7-vista-x64/
 
-- or --
 
AVR Studio. AVR Studio is the official development environment distributed by Atmel – it is a windows only application. You can use it to write code and to configure your AVR-ISP and use it to download code to the gadget. We never use AVR Studio for code development, and only use it with the AVR-ISP. We don't use AVR Studio, but you should know about it and if you'd prefer to be different, you can use it for both code development and firmware programming. See:
 
Important Note: You may need the ‘filter version’ of LIBUSB to use both AVRStudio and WinAVR simultaneously with your AVRISP2.
 

Mac

Crosspack. Mac has an integrated development environment like WinAVR for Mac OS called crosspack. You can get it:
 

Linux

From Ubuntu packages. On Ubuntu, you can simply install the packages (sudo apt-get install) avrdude and avr-gcc.
 
From source. You will need to install the low-level avr-gcc, avr-libc, and avr-dude tools (see below) separately. Here’s a step by step guide to installing these tools:
 

Tools

AVR-GCC. avr-gcc is the open source compiler that allows programs written for the AVR-series microcontroller to be turned into machine code (.hex files) that can be downloaded to an AVR. The language of AVR-GCC is C. You can read more about avr-gcc at:
 
AVR-LIBC. avr-libc provides the definitions for all of the address locations for the many registers on every current AVR device, and also provides a library of functions specific to AVR devices that are generally useful (things like delay program execution). Without avr-libc, programming for AVRs would be much more difficult as you would need to look up in the datasheet and write into your code things like the specific hex address location of the analog to digital converter’s register just to read a sensor input. More at:
 
AVR-DUDE. avr-dude is an open source downloader tool. It allows you to take the compiled code of your program and download it through a hardware device (like the AVR-ISP mkII) to your gadget. It also allows you to set up the gadgets’ fuses, or general settings. More at:
 
AVR-ISP (mkII). The AVR-ISP is a hardware device that allows you to download compiled files (.hex files) from the computer to your AVR microcontroller. In some ways, it is itself a gadget – it contains a PCB with an AVR microcontroller, a USB interface, and a blinky LED. Most importantly, it also has a six pin ribbon cable which goes to a mating connector on your board (at least if you included it when designing your PCB, which you should have done). You can connect the ribbon cable in two orientations: Wrong or Right. Fortunately, connecting it in the wrong orientation will not harm your gadget or the AVR-ISP, but if you do so the AVR-ISP’s LED will blink orange and you will not be able to download firmware to your gadget. More information at: http://www.atmel.com/tools/avrispmkii.aspx

---

Compiling and Download Programs

Printer-friendly version

How to Compile and Download Programs

This tutorial takes you through the following steps:
  • Configuring the makefile
  • Compiling code
  • Downloading the compiled code
  • Fuse Settings
The tutorial assumes that you're using a Gadgetry course mini-gadget and that you are using an AVR-ISP mkII to download code to the board.

The Makefile

The makefile is a big, scary file that configures how the low level tools will operate.  Fortunately for you, very few of the options are relevant.  Here’s what you’ll need to regularly adjust:
MCU.  Set this to whatever microcontroller you’re using. Like MCU = attiny84.
TARGET.  Set this to the name of the file with the “main” function that you would like to compile.  Leave off the .c extension.  Like TARGET = BlinkyProgram
F_CPU.  This option tells the compiler the clock speed of your board (it does not configure that clock speed – that’s done in the fuses).  Set it to whatever your input clock speed is in Hz. Like F_CPU = 8000000.
The following three you should rarely need to adjust.
AVRDUDE_PROGRAMMER.  This tells avr-dude which programming dongle you’ll be using. You bought an avr-isp mkII from us, so you’re probably using that. AVRDUDE_PROGRAMMER = avrisp2.
AVRDUDE_PORT.  Tells avr-dude what port on the computer you’re using (back in the day when computers had ports other than USB). For avr-isp mkii, this is just AVRDUDE_PORT = usb.
AVRDUDE_WRITEFLASH and AVRDUDE_WRITEEEPROM.   These are the configuration lines that tell avr-dude which flash and eeprom files to write and how quickly to do so.  Your makefile defaults should be fine.

Compiling Code

Compiling a program in is very easy (once you get the hang of it):
1. Make sure you’ve configured your makefile to point to the correct target program.
2. Open the program in programmer’s notepad and go to Tools->Make All, or if you aren’t using WinAVR or Crosspack, just use a command prompt, navigate to the directory of your program .c file and Makefile, and type “make all”.
3. If your program has no syntax errors, it will compile down to a .hex file, which you will find in your directory. If it has errors, enjoy interpreting the error messages to figure out what you did wrong and try again.

Downloading Code

Downloading code is easy:
1. Make sure your gadget is powered on, your AVR-ISP is plugged into your computer, and the gadget and AVR-ISP are plugged in.
2. Make sure you’ve plugged the AVR-ISP‘s ribbon cable in correctly (green light, instead of flashing orange light). The ribbon cable should hang over top of the serial/charging pins.
 
3. Once you’re ready, in programmer’s notepad go to Tools->Make Program, or from the
command line, just go to the directory of interest and type make program.
 
4. The AVR-ISP mkII’s LED should turn solid orange and you should see an ASCII progress bar made of # signs making its way from left to right.
 
5. Your gadget will do what you programmed it do, and you can do the dance of joy.

Setting Fuses

Fuses are configuration options for how the microcontroller will operate that are independent of your program. Thus, they typically only need to be set once for any gadget, and this should be done before you put a program on the gadget. There are a number of fuses that are typically configured:
 
Clock source and speed. This fuse sets the source of the clock (internal oscillator or external sources of different frequencies)
 
CKDIV8. This fuse divides the input clock by eight. We like to run our gadgets fast, so we typically uncheck this fuse, but it is on by default.
 
Brown-out detection. This fuse sets whether the microcontroller will reset or attempt to continue running if a brown-out is found. Brown-outs are voltage drops that can be caused by high-current events (like switching motors from full forward to full reverse). The fuse allows the brown-out detection to be set to several different voltage levels. If you use this, make sure to set it significantly under the regulated voltage that your gadget operates at.
 
BOOTRST. Enables or disables a boot reset vector. This needs to be enabled if you’d like your gadget to have a bootloader. A bootloader allows you to update the firmware over USB or another communications interface without using the AVR-ISP.
 
Bootloader size. Sets the amount of program memory dedicated to holding the bootloader. If you use a bootloader, this must be at least as big as the size of your bootloader firmware.
 
There are a number of other options that may be important based on your individual gadget, and we will provide the default fuse settings for your project 1 and 2 gadgets. Your mini-gadget was already configured with the correct fuse settings when the test program was loaded on it.

---

Gadget Serial Communication

Printer-friendly version

Testing Serial on your Gadget

Description

All gadgets in Gadgetry have a USB serial port which can be used to communicate with the computer.  This tutorial gives a brief overview of how to use a terminal program to communicate over serial with your gadget.

Serial Communication

The serial communication protocol we use on the gadget is a three-wire variation of an old protocol called RS-232.  RS-232 used to be used frequently on computers, but has been replaced entirely by USB; however, it is still often used in embedded devices.  There a number of characteristics of the protocol that can be modified:  Baud rate, Parity, Data bits, Stop bits, and Hardware Flow control.  For our purposes, only the baud rate matters and the rest of these should be left to the following default values:
Parity:  None
Data bits:  8
Stop bits:  1
Hardware Flow Control:  None
The baud rate is a measure of the speed of communication - higher baud rates allow more data to flow, but may also result in higher error rates.  Typically, we use 115,200.  A commonly used low speed backup is 9600.  

Serial Terminal Programs for Windows

A number of terminal programs are available for Windows:  HyperterminalTeraTerm, and RealTerm.  In our experience, RealTerm is by far the most flexible, and this guide will cover how to setup RealTerm to communicate with a gadget.
2.  Launch Realterm and go to the Port tab.
3.  Select a port number corresponding to the serial port number of your gadget.  You can find this by going to the device manager, expanding the Ports (COM&LPT) item, and seeing what number is next to the USB Serial Port (It should be COMXX).  Select a baud rate of 115200 (or whatever you are using), and make sure the rest of the settings are set to defaults:
4.  Once you have made the appropriate baud rate and port selections, hit the "Open" button to open the port.  If you have a program that prints something, it should now be appearing on the screen.  To send a character or file, you can either use the Send tab, or you can click on the black portion of the window and type your characters.
5.  Advanced:  The Display tab can come in handy for debugging non-Ascii characters - you can use it to print out received characters as hex, decimal, or even binary.

Serial Terminal Programs for Mac/Linux

Coolterm is recommended for those using a Mac.
There are two options for terminal programs that work in both Mac and Linux - minicom and gtkterm.

---


Programming Primer

Printer-friendly version

Programming in C, a Primer

Purpose

This document is meant as an aid for those who have minimal or no programming background. 

Description

In Gadgetry, we will be programming microcontrollers using a version of the C programming language that has been specialized to small 8-bit microcontrollers.  C is perhaps the most durable programming language ever; it is still relevant 30-40 years after it was designed.  This document will cover the very basics of programming in C.  We will discuss syntax, variables, conditionals, loops, and functions (concepts that are common to all programming languages) and do so while showing examples that use C syntax.

Syntax

Syntax for programming languages is like grammar for natural languages:  It is the rules under which statements are structured.  It is also the most common cause of errors for beginning programmers.  The syntactic rules of programming languages are very strict, and violating them will cause either compiler errors, or (possibly worse) logical errors that allow your program to compile but function in mysterious ways.  Here are two general syntactical rules:
End statements with a semicolon, except when otherwise indicated
Make sure every open brace has a matching close one, and keep track of brace pairings
Each of the following topics will show some proper syntax for using a given construct.

Variables

Variables are just program elements that store a value (that can be varied during program execution).  There are many types of variables, but there is only one that really matters to begin writing programs:  The int variable type (if you want to look up other types, you can also use char, bool, float, and double types in your programs).  An int is a variable that stores integers, or whole numbers.  This type has a natural range of numbers – it can store any number between -32,768 and +32,767 (it is 16 bit, so the range can have no more than 2^16th positions, and the range is centered on 0).  To declare a variable in C, do the following:
int theAnswer;
You can also give it an initial value:
int theAnswer = 42;
Variables must be declared at the start of a function.  Once declared, you can use them throughout the function (Which is not the same as your whole program if you have multiple functions).  Note that once declared, you don’t need (and aren’t allowed) to put the keyword ‘int’ before them.  For example:
int main(void)
{
// This is a comment – the start of the function comes after the open brace “{“
            // Here I am declaring three variables
            int theAnswer = 42;
            int questionOne = 6;
            int questionTwo;
            // Here I am using the variables in my program – note no “int”
            questionTwo = theAnswer/questionOne;
}
If you want to make a variable that can be used in multiple functions, you can declare what is known as a global variable.  You should do this right after any #include and #define statements are used, but outside of any function braces.  Global variables are commonly used in this type of embedded programming.
You can use regular mathematical operations with integers (+,-,*,/), but be aware that you should avoid exceeding the integer range.  Also, since ints are integers, if you divide and have a remainder, the remainder will be removed (so 23/5 = 4, NOT 4.6).  If you want to see what the remainder would be, use the modulus operator ‘%’ (as in 23%5 = 3).

If statements

If statements are ways to have your program execute fragments of code only if certain conditions are met.  Thus, they are very important to use if you have sensors on your gadget and want to do something based on a sensor value.  The following is the basic structure of an If-statement:
if(condition1 is true) {
            execute plan A;
}
else if(condition2 is true) {
            execute plan B;
}
else {
            execute plan C;
}

The structure is very flexible – the only required part is the if, you can opt to have an else, or an else if, and you may have as many else ifs as you like (though only one else). 
The part in the () is the conditional statement that is evaluated.  There are a number of logical operators that can be used to create a conditional statement – they are:  less than ‘<’, greater than ‘>’,less than or equal to ‘<=’, greater than or equal to ‘>=’, equals ‘==’ (yes, two equal signs, you use one for assigning a value to a variable, two when comparing two values).  Furthermore, you can chain statements together to make larger statements through the use of a logical or ‘||’, and a logical and ‘&&’.  Lastly, you can logically evaluate a single variable in an if-statement without any operators.  This works because in C, any value that is 0 is consider false, and a value that is not 0 is consider true.  So you can construct an if like:
if(theAnswer)
{
   print(“theAnswer is clearly non-zero”);
}
This is useful when you have digital inputs like buttons, as they will be read in as either 0 or 1, depending on if they are open or closed.
For an if-statement, you should place any code you wish to execute for each statement in { } after the if statement.  You should not place a semicolon after the if, else if, or else statements.  The following are some example statements using proper syntax:
int main(void)
{
            int theAnswer = 42;
            int question1 = 6;
            int question2 = 9;
            int sensorValue;

            if(theAnswer == (question1*question2)) {
                        blinkGreenLED();
            }
            else {
                        blinkRedLED();
            }
            // Here we’re calling a function that will return a value, which is copied into ‘sensorValue’
            sensorValue = readSensor();
            // In English, if the sensor is less than 100 and more than 50, do the following
            if((sensorValue < 100)) && (sensorValue > 50)) {
                        blinkGreenLED();
            }
            else if(sensorValue >= 200) {
                        blinkRedLED();
            }          
            else if((sensorValue <=50) || (sensorValue > 100)) {
                        blinkOrangeLED();     
            }
            else {
                        turnOffLEDs();           
            }

Looping

Looping is a way to specify repetition in your program without having to write repetitive code.  There are two types of loops you may wish to use – the while, and the for.  The for loop summarizes some things in the loop statement and so can make your code somewhat more concise.  The while loop looks like this:
while(condition is true) {
 do stuff;
}
You’ve learned about conditions from if-statements; the ones used by the while loop are of the same structure and can employ the same logical operators.
The for loop is a little trickier:
int counter;
int someValue = 14;
for(counter = 0; counter < someValue; counter++) {
  do stuff;
}
The for loop has three elements – first it sets a pre-declared variable to a value, in this case 0.  Then it has a conditional statement using that value (in this case, checking if it is less than someValue).  Finally, counter++ is a short hand way of saying increment the value of counter by one (equivalent to counter = counter+1;).  This is convenient if you wanted to run through some code a set number of times.  Just like if statements, for and while loops don’t end in semi-colons.
In our case, all programs you create will have a while loop that executes part of your program so long as the gadget is turned on.  This is called an infinite loop. This loop will contain the main elements of your program, and within it you will probably do something like check sensors –> evaluate sensor data with if-statements -> do something with outputs based on sensors.  You may also have loops within this infinite loop.  A loop within a loop is called a nested loop.

Functions 

Functions allow your program to be compartmentalized.  For example, you can have a function that reads a sensor, or blinks an LED.  By using a function, you only have to write the code once for that function, and you can then call that function in your program as much as you want.  All programs have at least one function, called main – this is where your program starts.  In main, you can call functions from a library, or functions you’ve written.  For each function, you can both send and receive values.  Values you send to a function are called arguments, values you receive are returned.  Some functions only have arguments and no return, some have just return values and no arguments, some have both, and some have neither.  

---


Circuit Board Checklist

Printer-friendly version

Circuit Board Checklist
Purpose
This checklist can be used to minimize errors made when creating the schematic and layout files of a gadget.  If any of the checklist items are unclear, email us with your question and put your files on your project page.
Schematic Items
___  The ISP header is in the schematic and the pins are connected to the same I/O pins as in the GadgetCore.sch.
___  There is a connector for the battery/power supply; either a three pin connector for a pack of AA or AAA batteries, or the coin cell holder if running from a coin cell, OR connection to VUSB for usb power.
___  You have used a voltage regulator for 3.3V or are using a coin cell.  You are using the medium voltage regulator (same circuit as the +5V, but different value) instead of the tiny one unless you are only running off USB or a coin cell.  An additional 5V regulator is required for the humidity, pressure, and sharp IR distance range finders.
___  The voltage regulator has a capacitor between the input voltage and ground, and one between VCC and ground.  The value of these capacitors is 1uF and 10uF.
___  The ERC does not produce errors.  The only warnings produced are about either missing values on connectors or about Power pins connected to signals.  Note: any errors/warnings from the GadgetCore schematic may be approved.
___  There is a capacitor to decouple the VCC and GND signals for every chip (Xmega, Hbridge, sensor chips).  The value of this capacitor is 0.1uF.
___  LEDs are connected to signals in series with a resistor.
___  Light sensors and thermistors use a voltage divider to read in the signal.
___  Buttons are not required to have an external pull-up resistor, but if this is the case they must be connected between the input signal and ground or input signal and vcc.  You will use PINCTRL to enable internal resistors.
___  Parts used have only come from the GadgetOne.lbr library, or you received special approval.
Layout
___  Decoupling capacitors are placed physically close to the VCC and GND pins on the part they need to decouple.  Copper wires between the capacitor and the chip’s pins are as short as possible.
___  Capacitors for the voltage regulator are placed as close as possible to the voltage regulator, with copper wires between the capacitors and the regulator as short as possible.
___  Connectors are placed logically, generally on the outside edges of the board.  When everything is plugged in, the connectors will not collide or obstruct one another (this is especially important for the female header of the ISP).
___  The parts are arranged in as tight a space as possible to still allow for routing of the copper wires.  Parts can be placed on both sides of the board, but it is strongly recommended that most surface mount parts be placed on the same side.
___  Mounting holes have been placed to mount the board to a housing.  You are not required to have any mounting holes if you prefer to use tape or Velcro.
___  The board dimensions (the rectangle that is brought up by default when the .brd file is first created) are moved to where you want the edges of the circuit board to be.
___  Copper wires for analog signals are slightly wider than average (12 mils is a good rule), and wires for high power signals are appropriately sized (seehttp://www.circuitcalculator.com/wordpress/2006/01/31/pcb-trace-width-calculator/)
___  The DRC rules are comfortably above the minimum specifications at this site:
___  The Copper/Dimension clearance in the distance tab in the DRC is 20 mil or more
___ The routed board passes the DRC with no errors.
___ Typing 'ratsnest' yields a message saying 'Nothing to do!'
___  Designators have been moved to clearly indicate part names and values.
___  You've run panelize.ulp to move all your tnames and bnames to layers 125/126 (or so).
___  Your name or initials and the gadget name are visible on the board somewhere.  This should be in either tvalues/bvalues or layers 125/126 (or what panelize creates).
___  You checked that your board passed www.freeDFM.com and you checked the plots of the different layers to make sure they looked right.
Handing Things In
___  .brd and .sch are posted on your project page
___ gerbers sent to freeDFM and the response email forwarded to us.  Note:  It must  say No Showstoppers! in the DFM results section, or you need to go back and fix your board!

---

Board Assembly Checklist

Printer-friendly version
You should print out and have this checklist near your board as you go through the steps.  For Gadgets One and Two.

  1. Acquire all parts, stencil, and PCB for your gadget.
  2. Fix the board and stencil to the table and apply a thin layer of paste.
  3. Place all surface mount parts on your board.
  4. Check all parts.  Double-check all polarities (dots / notches) of ICs and diodes.
  5. Place on griddle and heat until all paste is melted and flux dissipated.
  6. While still hot, visually inspect board and make sure parts are aligned to pads, particularly ICs.  Carefully adjust to ensure alignment, but do not worry about bridging or excess solder.
  7. Allow to cool.
  8. Double-check all polarities again in case things got moved during griddling.
  9. If parts are misaligned severely, use hot air gun and flux to adjust individual parts.
  10. Inspect board for excess solder / solder shorts (bridges).  Remove using hot air gun, flux, and copper braid.
  11. Solder on Through-Hole and/or any missing parts using the soldering iron and solder.
  12. Verify that all external/offboard parts can attach properly (sensors, servos, battery holders, etc).  Do not connect batteries at this time.  Attach any essential parts to your power circuit, such as power switches, but do not plug in power.
  13. Using a multimeter in resistance (or continuity) mode, verify that VCC and GND are not connected.  Large resistances are OK (such as 50k, 200k, 3 megaohm) and are probably your circuit elements.  Values close to zero indicate that you have a solder bridge, misaligned part, or wrongly placed part (dots not lining up).  Go back to #8 and look again.
  14. Using the multimeter again, verify that VDD and GND are also not connected except through large resistances.  Do the same with any other voltage nets you may have (UNREG, VLED, VMOTOR, etc).  Go back to step #8 as needed.
  15. USB:  Using a miniUSB cable, plug board in and verify that the device is properly recognized by your computer.  This should only take a few moments.  Be prepared to remove the device quickly.  If it is not recognized and/or the FTDI chip gets hot, remove it and go back to Step #8, taking extra care to inspect the FTDI and USB connector.
  16. Power Safety Test:  Connect your power circuit to a current-limited power supply.  Do not use batteries or wall adapters without a very low current fuse.  Set the power supply voltage to your normal unregulated voltage.  Set the current to 100-200mA.  Use alligator clips to connect the power supply in lieu of your normal method - such as to the battery terminals, coax jack, etc. 
  17. Turn on your power switch.  Disconnect the power immediately if the current limit maxes out.  Go back to Step #8 and look carefully.  If nothing bad happens, proceed to the next step.
  18. Using a multimeter in voltage mode, verify that your VCC to GND potential is 3.3V.  Your power led, if any, should be lit up.  If VCC is 3.3V, then your LED may be backwards and need to be flipped.
  19. If nothing seems to be going wrong, observe your board for a minute or two.  Ensure that no chips are getting unusually hot. 
  20. Load the bootloader on and try to program on your first program!

---

Gadget Progress Report

Printer-friendly version
Overview:

Completing a self-evaluation of your progress helps us determine how timely your efforts have been and how far along you are.  But more importantly it helps you figure out what still needs to be done on  your gadget!

Since this is a progress report it is expected that not all tasks will be complete.  But that does not mean you can just throw 'did not do yet' on everything!  We will be grading on how well-thought out your evaluation is as well as whether you've made reasonable progress in the 2.5 school weeks you've had to work on this.

Submission:

Respond to this questionnaire by March 24th via an email titled 'Gadget One Progress Report' to cmugadgetry@gmail.  Please, no pdfs or attachments, simply quote it in email and respond under each relevant section.

Progress Report Sections


Circuit Board & Parts:

The first step in getting your gadget together is making sure your circuit board is assembled and working.  You should have all of your parts on the board, and any external sensors and actuators should be mounted and ready to test.

Have you assembled your PCB?
Did you run into any issues completing the Board Assembly Checklist (in Course Documents)?
Have you loaded on the Bootloader?
Do you have all of your external components (if any) attached to your board and ready to test?

Housing:

The housing is a key component - this is what turns yet another green fiberglass rectangle into a human-usable device.  This is the what a user will see and this creates the first impression on your gadget's utility.  Ideally it is informative and not mysterious.

Have you thought about Assignment 10 and posted your sketches/designs?
Have you assembled your prototype housing?  How did it go?
Have you revisited Assignment 10 and completed the self-evaluation section?
Is your housing workable as-is?  Or what do you plan on improving before the final demonstration?

Firmware:

Firmware is simply software that is not expected to change much, if at all, over the course of a device's lifetime.  For extremely well-engineered (for cost and volume) systems, reprogrammability is not always an option.  In our case, however, it gives you flexibility as you fine tune your prototype to perform a desired task, whether it be what you initially planned for or a new, better idea that has come to you.

Since your gadget is designed to 'translate ambient information', we can think of the software not as a bunch of code but as a few simple functions or transformations.  While it sounds fancy, all it means is that you wish to take one type of information and convert it to another in a predictable way.  If writing code is not your strong suit, having a clear understanding of the desired transformations will make the programming task far more straightforward.

Have you tested your bootloader?  This can be done with old assignments such as 'MysteryProgramtoCompile'.  You should be able to reliably enter the bootloader and reprogram new programs over and over.
What transformations do you need to achieve?  What is your input and what are your outputs?  In the case of sensor and actuators, it is important to understand the range of values you anticipate.  What values do your inputs vary between?  What desired variance do you want from your outputs?
Have you begun writing your Gadget One firmware?  You should have a new project - perhaps the 'GadgetOne.zip' skeleton from the 'Gadget One library' section of Course Documents.  Pasting in functionality from previous homeworks and AVR drivers is OK!
Plan for Unfinished Work:

Not having everything completed is OK.  Not knowing how you'll finish the remainder is not OK.  By now you should have a pretty good idea on how to approach the many miscellaneous tasks needed to put a gadget together.  If you are having trouble imagining how to complete a few of the remaining sections, then please let us know so we can talk it over or cover additional material in class.

Briefly summarize what you still have left to do. 
What do you see as the most difficult aspects?  What specifically makes them hard?
Were these aspects covered by any lecture or homeworks?  If so, which ones?  If not, which ones seem closest?

---

Bootloader and ISP

Printer-friendly version

Gadget Bootloaders

Included here are two bootloader files for Gadgetry Gadgets.  We utilize the XBoot, a nice and flexible bootloader from http://code.google.com/p/avr-xboot/ .  It lets you choose miscellaneous options like which port to look for data on and how to enter the program (such as holding the button down on powerup). 
The first, dated 1-11-2011, runs at 115200.  The second runs at 19200 and is standard on macs and all gadgets from G1 on.  The source code for our specific variants is also attached.

Loading Bootloaders

There are two steps in getting a bootloader working.  You need to load the bootloader on using an external In-Series Programmer (ISP).  Then you need toenable the bootloader reset fuse, also via the ISP.
  1. Load AVR Studio or equivalent onto your computer.  To use the AVR Dragons in the lab, best to use AVR Studio 5 beta.  It is already loaded on the REL laptop Lothlorien.
  2. Open AVR Studio and connect the AVR Dragon via USB.
  3. Connect the 6-pin cable between your gadget and AVR Dragon and ensure that your gadget is powered on.
  4. Go to the Menu and select 'Connect to AVR programmer'
  5. Choose 'AVR Dragon' instead of AVR Simulator.
  6. Choose ATXMEGA32A4 from the long list of chips.
  7. Click 'verify voltage'.  If it isn't 3.3V, make sure your board is powered up and the 6-pin cable is plugged in the right way.  Then try again.
  8. Click 'read signature' and make sure it reads a valid ID.
  9. Click 'load program' and choose the xboot-19200.hex from the list and hit program.
  10. Now, click on the Fuses tab.
  11. Go through the list and ensure that BOOTRST is selected (other option is Application Reset).  If your gadget has had a bootloader before, it should already be selected.  If you have a brand new xmega, it defaults to application reset.

Modifying the bootloader

Attached in xboot.zip is our specific configuration of the xboot bootloader .  If you have an ISP and want to modify the behavior (such as changing where the button is, serial uart, etc.) you can make the appropriate changes, recompile it, and load it on using the instructions above.

---

G2 Code Snippets

Printer-friendly versionAttached is code to run the accelerometer, the LCD, and SD card.  Note that in all cases, you'll need to integrate the provided code into your projects, either by copying and pasting appropriate sections, or by including the .h and .c files.
Attached is some SD card code, courtesy of Vikram R., a Gadgetry '10 student.  Here is his comments for it:
I've attached the code for a simple program that will create a file
"hello.txt" and write "Hello World!" to it.

The Xmega specific stuff should be taken care of. You should only need to change the pin defines in sd.h to correspond to the SPI port you are using and/or the pins you are using for card-detect.

If you aren't using card-detect, you'll need to delete references to the
sd_card_present() function, or simply set it to always return true.

Depending on which timer counters you are already using, you may need to
change the timer counters in sd.h and/or rtc.h if there is a conflict.

The rtc.c/h files are used for counting time to use for file timestamps.
Please note that the present method is not accurate. I haven't figured out how to properly configure and use the Xmega's internal 32kHz calibrated RC oscillator to count seconds. If anyone can provide code for this, I would appreciate it.

Documentation for the FAT library is here:
http://elm-chan.org/fsw/ff/00index_e.html

---

Care and Maintenance of Solidoodle Printer

Printer-friendly version

Software Packages

Design: Anything that outputs an STL file. Solidworks recommended, you can also use Trimble Sketchup though you'll need to install a plugin to allow STL output. See the following for a Sketchup tutorial: http://www.solidoodle.com/how-to-2/how-to-create-a-3d-part/
Printing: Repetier-host is recommended. See the following tutorial for configuring Repetier: http://solidoodletips.wordpress.com/2012/08/22/setting-up-repetier-host/

In the REL

  • Before you print, plug in the big Solidoodle power supply and plug the USB cable into your computer.
  • Set the heated bed temperature manually to 85C - it'll take 20 minutes to warm up, so it's useful to do this first.
  • Import your STL file into Repetier and generate G-code as documented in the Repetier tutorial.
  • Printing will take 1-4 hours (or more), and your laptop needs to stay with the printer. You can wander off, but try to check on the printer every half hour. If something goes wrong, hit the E-stop in the software and decide if you want to/can start over. Email cmugadgetry@gmail.com if the printer broke or did something naughty.
  • Once the part is complete, unplug the Solidoodle's power supply but not the USB cable. You'll need to wait for the heated bed to cool to 40C or so (wait 20 minutes); once there it will be possible to remove it just by grabbing it. If it's small, you can use pliers.

No comments:

Post a Comment