Reflashing+the+AQE+Shield

=**Reflashing The Air Quality Egg Sensor Interface Shield Microcontroller**=

The AQE Sensor Shield features an ATTiny microcontroller which handles all I2C bus communication (through a mux), as well as all sensor metadata and interpretation calculations for both the CO and NO2 sensors which are part of the shield. Version 1.5+ uses an ATTiny88, previous versions have an ATTiny48. To store the sensor interpolation data, we are using EEPROM, which is flashed in Step 6 of this tutorial. As we have iterated the shield, the code has also been updated to output the most accurate readings possible, and support for various features. This tutorial is slightly advanced, however I'll try to be as thorough as possible so even someone with minimal experience will be able to follow. To program the ATTiny using ICSP, you will need either an AVR ISP Programmer (such as the AVRISP mkII) or alternatively, you can use an Arduino Board (Uno or Duemilanove). This tutorial will cover both. You'll also need a computer.

> code avrdude code
 * 1. Install AVRDUDE**
 * Regardless of what AVR ISP programmer you are using, you will need to install AVRDUDE on your computer. AVRDUDE is a popular command-line program for programming AVR chips.
 * Ladyada has a fantastic tutorial for installing AVRDUDE on Mac, Windows, and Linux here. As she suggests, for Mac users, the easiest is to install the CrossPack from Obdev. This tutorial will use OSX, however the commands should be identical for all OS's. Vic might have specific suggestions for installing on Linux.
 * Once installed, open the Terminal app and simply execute
 * you should see a list of options printed out, and the final line should contain the version number of avrdude installed (in my case 5.11.1)


 * 2. Download .hex and .eep Program Files**
 * All AQE Sensor Inteface Shield source and compiled .hex files can be found on GitHub here.
 * Either fork the repository, or simply download locally by clicking on the ZIP button and unpacking on your computer.
 * For testing purposes, also download the railroad.hex file here:




 * 3. Connect the ISP Programmer to the AQE Sensor Interface Shield**


 * //-- using an AVR Programmer --//**
 * Very straightforward. Connect the female programmer cable to the 6-pin ICSP header on the shield.
 * Note: Make sure to orient the cable such that the red line is on the same side of the screen-printed white line (below "J2") on the shield's PCB. Check the following images:
 * //-- using Arduino as ISP --//**
 * This requires a little more legwork, however is very doable. You will need 6 female-male jumper wires and an Arduino or Duemilanove. If using an Arduino Uno, you will also need a 10uF capacitor.
 * Another note from Toby, an AQE community member, who is on Windows7, using a seeeduino (Arduino clone):I had to put a resistor (120R) between 5v & reset. Otherwise avrdude compained "avrdude: stk500_getsync: not in sync: resp=0x15". see [] for more.
 * Now, connect the Arduino to your computer and program it to behave like an ISP Programmer.
 * Navigate to File > Examples > ArduinoISP
 * Upload this sketch to the Arduino
 * Quit the Arduino app and unplug the USB cable.
 * Connect digital pins 10-13 on the Arduino to the 6-pin ICSP header, one by one.
 * digital pin 10 is RESET and is blue
 * digital pin 11 is MOSI and is red
 * digital pin 12 is MISO and is green
 * digital pin 13 is SCK and is yellow
 * GND is black
 * 5v is striped red
 * Moving counter-clockwise, starting from the pin closest to the white stripe marker on the PCB, pins are MISO (green), SCK (yellow), RESET (blue), GND (black), MOSI (red), 5v (striped red). Check the images to see which pin is which by following the colors.
 * **Note**: Since I am using an Arduino Uno, you'll see a 10uF capacitor is needed -- cathode to GND, anode to the RESET pin of the Arduino. I believe this is not needed with a Duemilanove.
 * **Note**: Since I am using an Arduino Uno, you'll see a 10uF capacitor is needed -- cathode to GND, anode to the RESET pin of the Arduino. I believe this is not needed with a Duemilanove.






 * 4. Power the Circuit**
 * If using an AVR programmer, connect the shield to the regulated power supply (7.5 - 12v DC) and then connect the AVR programmer to your computer with a USB cable. On an mkII, the indicator LED should turn green.
 * If using an Arduino as ISP, simply connect the Arduino to your computer using a USB cable.
 * YOU ARE READY TO PROGRAM


 * 5. Program the Shield**
 * Open the Terminal App.
 * Navigate to the folder of the railroad.hex file you downloaded during step 2.


 * -- if using AVR Programmer --**

code avrdude -p t88 -c avrisp2 -e -P usb -U flash:w:railroad.hex
 * Execute the following command:

code
 * Note: if you're shield is v1.4, it contains an ATTiny48, so replace "t88" with "t48"
 * The Red and Green LEDs on the shield should begin flashing in a quick, alternating fashion. Terminal output should look like the following:

avrdude -p t88 -c avrisp2 -e -P usb -U flash:w:aqe_sensor_interface_shield.hex code
 * Once that has been successfully programmed, repeat step 5, but first navigating to the folder containing "aqe_sensor_interface_shield.hex" (downloaded in step 2), and using the following command:
 * code
 * YOU HAVE SUCCESSFULLY PROGRAMMED YOUR SHIELD


 * -- if using Arduino as ISP --**


 * Execute the following command:

code avrdude -c arduino -p t88 -P COMPORT -b 19200 -U flash:w:railroad.hex code

> code avrdude -c arduino -p t88 -P COMPORT -b 19200 -U flash:w:aqe_sensor_interface_shield.hex code
 * Replace "COMPORT" with the serial port which your Arduino is connected. In OSX this is something like "/dev/tty.usbmodem####"
 * To find the port address of your Arduino, open the Arduino app and navigate to "Tools > Serial Port".
 * Note: if you're shield is v1.4, it contains an ATTiny48, so replace "t88" with "t48"
 * After executing, Red and Green LEDs should begin flashing quickly and alternating. Terminal log should look like:
 * Once that has been successfully programmed, repeat these steps, but first navigating to the folder containing "aqe_sensor_interface_shield.hex", and using the following command:
 * YOU HAVE SUCCESSFULLY PROGRAMMED YOUR SHIELD


 * 6. Flash the EEPROM**

Once your shield is programmed it is ready to communicate using the EggBus library to any I2C device attached to the shield. However, before it can accurately interpret values from the CO and NO2 sensors on board, the EEPROM on the shield must be flashed with the correct look-up tables.

avrdude -c avrisp2 -p t88 -e -P usb -U eeprom:w:aqe_sensor_interface_shield.eep code
 * -- using an AVR programmer --**
 * Navigate to the folder which contains the "aqe_sensor_interface_shield.eep" file.
 * Execute the following command:
 * Note in some cases you may need to remove the -e from this command line to install the eeprom file. This may depends on your programmer as to how it functions. If after flashing the eep file your sensor does not report in simply reflash the Hex file as above and use the code line without the -e command.
 * code

avrdude -c arduino -p t88 -P COMPORT -b 19200 -U eeprom:w:aqe_sensor_interface_shield.eep code You can use a standard Arduino (or Nanode), not configured as an ISP, to flash the EEPROM. If you have an FTDI cable handy, you can simply use the Nanode that came with your Egg. Otherwise you can remove the shield and put it on a standard Arduino board.
 * -- using an Arduino as ISP --- **
 * Navigate to the folder which contains the "aqe_sensor_interface_shield.eep" file.
 * Execute the following command:
 * code
 * -- Alternatively --**
 * Upload the PollEggBus_WriteTest.ino file to the Arduino.
 * After programming wait at least 5 seconds before disconnecting the shield

YOU ARE NOW READY TO ROCK AND ROLL