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.

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
    avrdude
  • 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:
2012-12-29 08.50.52_800.jpg
Note the orientation of the red stripe of the programmer's cable
2012-12-29 08.51.12_800.jpg

-- 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 http://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection 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.

2012-12-29 08.04.44_1000.jpg
Arduino Digital Pins 10,11,12,13 connected to the RESET (blue), MOSI (red), MISO (green), and SCK (yellow) pins on the shield

2012-12-29 08.06.46_800.jpg
with 5V (striped red) and GROUND (black) connected

2012-12-29 08.02.13_1000.jpg
10uF capacitor between RESET and GND on the Arduino


2012-12-29 08.02.00_1000.jpg
All Arduino Connections

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 --

  • Execute the following command:
avrdude -p t88 -c avrisp2 -e -P usb -U flash:w:railroad.hex
 
  • 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:

Screen Shot 2012-12-28 at 8.29.25 PM.png


  • 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:
  • avrdude -p t88 -c avrisp2 -e -P usb -U flash:w:aqe_sensor_interface_shield.hex
  • YOU HAVE SUCCESSFULLY PROGRAMMED YOUR SHIELD

-- if using Arduino as ISP --

  • Execute the following command:

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

  • 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:
Screen Shot 2012-12-28 at 8.48.26 PM.png
  • 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:
    avrdude -c arduino -p t88 -P COMPORT -b 19200 -U flash:w:aqe_sensor_interface_shield.hex
  • 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.

-- 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.
  • avrdude -c avrisp2 -p t88 -e -P usb -U eeprom:w:aqe_sensor_interface_shield.eep



-- using an Arduino as ISP ---
  • Navigate to the folder which contains the "aqe_sensor_interface_shield.eep" file.
  • Execute the following command:
  • avrdude -c arduino -p t88 -P COMPORT -b 19200 -U eeprom:w:aqe_sensor_interface_shield.eep
-- Alternatively --
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.
  • 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