Thursday, February 28, 2013

USBtiny

Ever since I first heard about bitbanged USB I knew I wanted to test it.
"USBtiny is a software implementation of the USB low-speed protocol for the Atmel ATtiny microcontrollers." - http://dicks.home.xs4all.nl/avr/usbtiny/

Ladyada has the USBtinyISP based on USBtiny and I decided to hook one up myself. I already got a programmer (sparkfun AVR pocket programmer), but I consider it fun to make my own tools.

It is a great thing LadyAda does by providing schematics and files, so you really should go buy their kit for the programmer instead of doing what I do!

The ATtiny2313 on a breadboard
The first thing I did was to put the ATtiny2313 on a breadboard and write the firmware to it using my existing programmer.

The datasheet for ATtiny2313

avrdude help http://www.ladyada.net/make/usbtinyisp/avrdude.html

The avrdude commands from the Makefile modified to my avrdude.conf location
I just moved to my avrdude folder (D:\daniel\programmering\arduino-1.0.3\hardware\tools\avr\bin) using cmd.exe and ran the command for setting the fuses.

avrdude -c usbtiny -pt2313 -C D:\daniel\programmering\arduino-1.0.3\hardware\tools\avr\etc\avrdude.conf   -U hfuse:w:0xdf:m -U lfuse:w:0xef:m
Where D:\daniel\programmering\arduino-1.0.3\hardware\tools\avr\etc\ is where I have my avrdude.conf.

After setting the fuses its time to write the hex file to the chip:
avrdude -c usbtiny -pt2313 -C D:\daniel\programmering\arduino-1.0.3\hardware\tools\avr\etc\avrdude.conf  -B 1 -U flash:w:main.hex
I actually moved to main.hex file from the  \usbtinyisp\spi folder to the avrdude folder in order for the avrdude to find it.

Then I wired the connections to the USB and tried power it by usb. The LED lights up! Showing us we have USB connection

I use the sparkfun USB pinout

The Ladyada schematics includes a levelconverter that I decided to skip until this circuit gets soldered... Datasheet for the 74HC125. The idea for the level-converter is that the programmer can be powered by usb and the circuit being programmed can be programmed at another voltage level. The level-converter stops the target circuit from being fried.

http://www.ladyada.net/make/usbtinyisp/parts.html

I decided to hook up the attiny8 circuit directly instead.

To the left the ATtiny85V , middle ATtiny2313 and to the right USB level conversions.


In order to know if it works I ran

avrdude -c usbtiny -C D:\daniel\programmering\arduino-1.0.3\hardware\tools\avr\etc\avrdude.conf -p m8
And got:
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.03s
avrdude: Device signature = 0x1e930b
avrdude: Expected signature for ATMEGA8 is 1E 93 07
         Double check chip, or use -F to override this check.
avrdude done.  Thank you.

...in response! success!

Now I need the board description for the Arduino IDE.

From http://hlt.media.mit.edu/?p=1695 I got the link to
https://github.com/damellis/attiny/archive/master.zip

That I downloaded and copied into the hardware folder. Restarted Arduino IDE and found the ATtiny85 board under boards.

I modified the blink sketch to use pin 2 instead of 13
int led = 2;
Then I uploaded it using programmer (CTRL+SHIFT+U)
Blink sketch on ATtiny85
Very satisfied!!!

I think I will wait until I get a ZIF socket to solder this one up... or at least part of it...




Wednesday, February 27, 2013

Soldered one of three

Three wires connect to the Arduino, GND, +5V and Signal to Analog 0

Introduction

One out of three microphones with amplifiers has been soldered. These microphones are included in the Robot Mapping project and are part of the "radio beacons".


The Electret Microphone and LM386 Amplifier (200x)
I did not really plan the layout of the components, I just added one component after another. Maybe I will use Fritzing for the next one. I really must learn on how to work more professional!

Soldering went ok, design was ad-hoc
For once the soldering worked out ok, these prototype-boards are very cheap and low-quality.

The microphone next to one on a breadboard, only difference is the resistor that got replaced with a trimpot.

The initial test seemed ok.

Tuesday, February 26, 2013

New parts ordered

Introduction

I just placed an order for new parts, here are the notes so I do not forget why I ordered them...

For the microphone circuit

The MCP3008-I at electrokit

I ordered a Analog to digital Converter, this is because I want to try if I can get a higher sampling rate with it than with the built in ADC of the ATmega328 Arduino.

I also ordered a EEPROM memory circuit to test dumping the memory, the ATmega only has 2Kb of SRAM so in order to sample a bigger number of samples I want to try to move the samples to the 64Kb  eeprom.

For USB-bitbanging experiments

I´m kind of curious on various bit-banging circuits. I think I´m going to build a USBtinyISP that you can find here: http://www.ladyada.net/make/usbtinyisp/
I got most of the parts and are going to wire the circuit myself but I need the Chrystal and USB mini as well as the level conversion parts.
A 12.000Mhz chrystal from electrokit

Level conversion IC 74HC125N DIP
Zener diods (for level conversions) BZX55C3V6 DO-35 3.6V
A simple to wire USB USB mini-B monterad på kort

I also intend to test the V-USB and perhaps build my own USB to serial as can be found here: http://www.recursion.jp/avrcdc/

For that I need some diods and another USB:

Monday, February 25, 2013

ATtiny13V


Introduction

I bought some AVR microcontrollers a while ago, and while I still had the programmer out of its box since burning the ATmega328PUs I wanted to try to program the ATtiny13V. 

ATtiny13V

The ATtiny13V has:
"– Up to 20 MIPS Througput at 20 MHz
...
High Endurance Non-volatile Memory segments
– 1K Bytes of In-System Self-programmable Flash program memory
– 64 Bytes EEPROM
– 64 Bytes Internal SRAM
...
– On-chip Analog Comparator
...
• Operating Voltage:
– 1.8 - 5.5V for ATtiny13V" -
datasheet
So as you realize this microcontroller has very little memory and only 1KB of flash memory for your programs... I just got it because its cheap

First thing is to put it on a breadboard, since all my good ones are used in the trilateration project I use this one without any power rails.

ATtiny13V on breadboard
In order to connect it properly I need the datasheet. From that I can see the pinout enabling me to connect it to the programmer.

From the datasheet
So the programming adapter has these nice clearly labeled pinout. So this makes it easy to connect.

Sparkfun programming adapter pinout

To use the Arduino IDE to program the microcontroller we need an Arduino core for it.

A fast googleing lead me here: http://sourceforge.net/projects/ard-core13/

I downloaded the core13_017.zip unzipped it and placed it in "arduino-1.0.3\hardware\arduino\cores" restarted the IDE. Hm nothing I guess that is since it is not in the "arduino-1.0.3\hardware\arduino\boards.txt"

A little more googleing I find this http://arduino.cc/forum/index.php/topic,89781.0.html with some instructions and the thing to add to boards.txt
attiny13.name=Attiny 13A standalone
attiny13.upload.using=arduino:arduinoisp
attiny13.upload.maximum_size=1024
attiny13.upload.speed=19200
attiny13.bootloader.low_fuses=0x7B
attiny13.bootloader.high_fuses=0xFF
attiny13.bootloader.path=empty
attiny13.bootloader.file=empty
attiny13.bootloader.unlock_bits=0xFF
attiny13.bootloader.lock_bits=0xFF
attiny13.build.mcu=attiny13a
attiny13.build.f_cpu=128000
attiny13.build.core=core13
I restart the IDE again and now there is a "Attiny 13A standalone" under Tools/Board/

I tried to compile but get error messages that it does not find Arduino.h...

Changed the path of the core to arduino-1.0.3\hardware\arduino\cores\core13

Now I can compile, and changed the blink sketch so that pin 2 is the led pin...

The following taken from http://elabz.com/site/ shows the pins arduino names...

// ATMEL ATTINY13 / ARDUINO
//
//                         +-\/-+
// ADC0 (D 5) PB5 1| |8 Vcc
// ADC3 (D 3) PB3 2| |7 PB2 (D 2) ADC1
// ADC2 (D 4) PB4 3| |6 PB1 (D 1) PWM1
//                  GND 4| |5 PB0 (D 0) PWM0
//                         +----+

 When I try to upload to the controller I get the following error

avrdude: AVR Part "attiny13a" not found.
I changed in the boards.txt to
attiny13.build.mcu=attiny13
And restarted the IDE once more... and now I can compile and upload!

And behold!

Its looking like the timer is a bit wrong...



More bootloader burning

Burning bootloaders...


I got two ATmega328-PU from my brother that he could not burn using his Uno. Well now they are burned and ready to be put into use.

Sunday, February 24, 2013

Measuring the distance from speaker to microphone

Introduction

I have worked for a while on a way of telling the distance from a speaker to a microphone. I want to use a number of microphones to localize a sound-source using trilateration.

After a number of failing attempts of using Arduino libraries for FFT and specialized IC´s that can lock on to a specific frequency. I decided to just think over the problem myself and try to do what I can...

Method

The speed of sound is 340 meters per second at sea level 343.2 at 20 degrees Celsius  The aimed distance is 2 meter. The time for the sound to travel the distance I want to cover is 2 /340 = 0,00583 seconds. 

I´d like to take as many samples during that time as possible, after that view the results on the 5150 LCD and identify the incoming sound wave visually and try to just write code that can find the first wave front.


The radio receiver and speaker.
The speaker and microphone is synchronized using 433 Mhz radio. The speaker has a radio receiver and I use the Virtual Wire library.

The code for the speaker:
#include <VirtualWire.h>
int rxpin = 2;
int speakerpin = 8;

void setup() {
  vw_set_rx_pin(rxpin);
  vw_set_ptt_inverted(true);
  vw_setup(2000);
  vw_rx_start();
}
void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    if (vw_get_message(buf, &buflen)) // Non-blocking
    {
      delay(10);
      sound();
    }
}
void sound() {
    tone(speakerpin, 4800);
    delay(150);
    noTone(speakerpin);
}

The code for the microphone to synchronize
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
delay(10);
After that I sample as fast as I can. 

for (int i = 0; i< BUFFERWIDTH; i++) {
    buffer[i] = analogRead(analogPin);
}

In order to sample faster I set the prescale to 16

And I render the result to the LCD
No signal, the sine wave is noise (from the USB connection to the computer I think)

A signal, line is the first wave. identified and the distance is calculated.
In order to distinguish between the signal and the no signal I first identify the valleys.
I do that by comparing a sample with a few of its neighbors.
The code is pretty nasty, but you can see the results as small dots in the lower end of the screen.
   boolean isValley(int index, int numAround) const {
        int valueIndex = getAt(index);
        int totalDiff = 0;
        for (int i = 0; i < numAround; i++) {
          int at = index + i - numAround / 2;
         
          if (at < 0) { //make sure we do not step outside the buffer
            at = 0;
          } else if (at > BUFFERWIDTH) {
            at = BUFFERWIDTH;
          }
          int valueAt = getAt(at);
          int diff = valueAt - valueIndex;
          if (diff < 0) {
            diff = -1;
          } else {
            diff = 1;
          }
          totalDiff += diff;
        }
        return (numAround + totalDiff < 4);
    }
If those valleys exists at the rate of the sound then we have a sound. And I try to identify the first valley of the incoming series...
Test setup, speaker to the left and microphone to the right.

I take a number of samples at different ranges. 50, 75 and 100 cm

Result

I can now measure the distance!
Red line is actual distance, blue is measured, the samples have been ordered . The median errors for all three distances looks similar...


The error is a bit large, but the distance of one wave at 4800 Hz is 7 cm so that was expected... The median error is around +14.8 cm. It sounds reasonable to me that the synchronization takes a little bit of time. And I catch the first valley so we probably have an entire wave before that.

In order to get a proper reading I probably have to make a few different readings and use the median and subtract 14.8,

Future work.¨

I need to clean up the code a bit, experiment with different sampling rates and distances. 

Perhaps I should solder up another microphone circuit and see if I can measure using two microphones next!

But for now I'm really happy, I worked hard on this...  and now I need to spend some time with the family.




Saturday, February 23, 2013

Hoping för Communications...

Getting a little desperate after all failing tests. I tested two ultrasonic sensors.The ordinary distance measuring works of cause...

 The idea was that one of them sends a beam and the other one to receive it. It turns out that you need to trigger the beam of the one that listens to receive another beam.




More failing attempts to measure the distance

Introduction

My goal is to use a number of microphones to pinpoint the location of a sound-source. In my case I´d like that sound-source to be a robot and the microphone array helps it to locate itself.

The microphone is synchronized with the robot using 433Mhz radio, I did some attempts using a wire but get signals passing through it.
The sound source(Robot) with 433Mhz radio and speaker

Method 1. The Goertzel Library

I have used this library to detect a specific frequency. The library detect the frequency but I get both false positives and false negatives at such error rate that it becomes unusable.
It does not seem very good with low amplitudes.

Method 2. FFT

I have successfully used FFT to isolate and identify the specific frequency the robot emits. The problem is that the FFT takes a long time to sample(256 samples) and to process.
That means that I can detect that the sound but not the exact timing the sound arrives at. There are also some issues with measureing time when the library shuts down timers and interrups...

Method 3. XR2567CP Tone Decoder (today)

The third attempt uses a tone decoder IC to identify the frequency. The datasheet was a pretty bad scan, but eventually I managed to get it correctly setup.

The receiver microphone in the center, the amplifier and XR2567 in the middle and 433Mhz radio to the right.
The circuit sends a radio pulse to the "Robot" and the Robot transmits a short sound of 4670Mhz. The pulse is picked up and time is measured.

Unfortunatly the XR2567 takes a "long" time to lock itself to the frequency and with different delay each time. The datasheet actually specified this in a graph.

Conclusion

Fail on all three methods, so what is next? 

I believe I will try with ultrasound!





Friday, February 22, 2013

First attempts to get a distance, failed

The current setup, the breadboards with microphone and the robot with speaker
Last night I did a first attempt to measure the distance between the robot-Arduino and the other Arduino board.

Method

The robot first sends a synchronization through a wire (fatal mistake) and after a specific time interval the robot outputs a sound signal through its speaker. 
On the receiving Arduino I wait for the signal  through the wire and starts a timer when it is received and when the microphone picks up a sound the timer is stopped.
The time difference is multiplied with the speed of sound 340 m/s to get a distance reading.

Results

The issue was that the speaker produces A LOT of disturbance that passes directly through the wire. This is picked up by the sensitive microphone amplifier unit and since it contains the correct frequency it is identified as the right signal. 

Conclusion

Do not connect sensitive amplifying circuits to speakers (or motors).

I could have guess this would happen and kind of expected it, so hopefully I get some quality time tonight using 433Mhz radio for synchronization tonight.


Oh and I received my order , I look forward to test the Dual Monolithic Tone Decoder and compare it to the fft-results

New parts recieved, mostly capacitors and some IC´s 

Wednesday, February 20, 2013

Fast Fourier Transforms FFT


Introduction

I have had a hard time trying to isolate the audio frequency sent out by my robot. Fortunately Mike Barela pointed me in the direction of FFT. FFT is Fast Fourier Transforms and are used to find out what combination of frequencies that make up a sound (among other things).

"If a function x(t) contains no frequencies higher than B hertz, it is completely determined by giving its ordinates at a series of points spaced 1/(2B) seconds apart." -Nyquist–Shannon sampling theorem


Mike pointed me to this awesome project:
http://coolarduino.wordpress.com/2012/10/01/sound-localization/

That was really inspirational, and made me think that I still might have a chance to do this!

There are a lot of who have done this before...
http://www.arduinoos.com/2010/10/fast-fourier-transform-fft-cont/

The 15ms beeps (1 per second) results in an update of the LCD.

Now using a library I can get a boolean result when a sound of the correct frequency is received. It feels like a step forward towards calculating the distance between the robot and the microphone. Next step synchronize the sender and receiver! Looking forward to it!

Libraries:

I found a few libraries and this was the one I tried first:
http://wiki.openmusiclabs.com/wiki/ArduinoFFT

They also have this that might be even faster
" As a result, the FHT uses half as much processing power, and half as much memory. You can have your cake and eat it too!" - http://wiki.openmusiclabs.com/wiki/ArduinoFHT
Here is another library to try...
http://code.google.com/p/makefurt/source/browse/trunk/arduino-libraries/?r=11#arduino-libraries%2FPlainFFT


Tuesday, February 19, 2013

Sound frequency detection and new order for parts

Introduction

This is part of my trilateration project.

I have spent a few days working with the electret microphone circuit connected to an Arduino to be able to listen to a specific frequency. In my code I count the number of times the input wave crosses over the zero line. This way I can identify that a specific frequency is played from the robot but there is still a long way from reliable results. With current circuit and code it takes too long to detect. Every millisecond gives a large error in distance.

Other issues is that sound waves are really long if you do not go to high frequencies.
"The wavelengths of sound frequencies audible to the human ear (20 Hz–20 kHz) are thus between approximately 17 m and 17 mm" - http://en.wikipedia.org/wiki/Wavelength
This means if I use 20KHz I can theoretical get a distance precision of one single wave detection of 1.7cm. That also means I have to detect the time of the first wave that hits the microphone. In my experiments really load noises like clapping or whistling close to the microphone gives really large outputs that can be easily detected but the tone of a buzzer a few meters away is way harder to detect.

The sampling frequency I get is around 10Khz. I have seen others get higher frequencies by neat tricks. Another thing to consider is that it looks like the tone library´s limit is around 30Khz .

10KHz sampling rate showing the tone wave from the robot.
The plan is to test a few more software libraries and then move over to hardware devices like the XR-2567 that can handle higher frequencies.

The Goertzel Library

The Goertzel Library is the thing that looks most promising
https://github.com/jacobrosenthal/Goertzel
it is based on the Goertzel algorithm and can detect frequencies.
http://en.wikipedia.org/wiki/Goertzel_algorithm

The XR-2567 dual monolithic tone decoder

The 2567 IC also looks most interesting and is made to detect specific frequencies and outputs an logic output. so I will order myself one of those. This might enable me to go to much higher frequencies than the Arduino can handle by itself. 

The 2567 Datasheet, I hate those bad scans!
http://www.electrokit.com/productFile/download/918

Here is a similar circuit showing a similar IC to get a feel for typical values for the capacitors and resistors.

New Order 

I decided to order some parts from electrokit .
  1. Various Capacitors and Resistors for the audio detection circuits
  2. 10K Trimpot for the audio detection circuits
  3. XR2567CP-DIP 16 Dual tone decoder
  4. ATTiny13V and ATTiny25 just for fun. I have not tried the ATTiny13V before.
  5. A couple of zener diods to be able to do some experiments on voltage regulation
  6. Digital potentiometer 256 steps also for experiments
But tonight I hope to get some coding done...

Sunday, February 17, 2013

First steps toward trilateration

Introduction

One of my goals is to be able to locate the robot using trilateration. I plan to do this using a few stationary microphones and speaker and radio transceivers. The Raspberry Pi with Arduino will send out a  radio signal to the robot which outputs a sound. The sound is collected using a number of stationary microphone. Difference in sound arrival time can then be used to calculate a relative position of the robot.
CC Wikipedia Trilateration
Well, that is the plan, in reality I´m not quite close to that yet. Right now I can sample at 3K Hz and output the result to the Nokia 5110 screen as below. I can see the tone of that the robot sends out but the input is very noisy.


3K Hz sampling of sound
Next step is to output a specific frequency from the Robot that the receiver can detect. I have been reading this instructable and tried the code but do not get very good results from it.
The robot beeps using Arduino tone command.
The robot now outputs a tone of 1Khz this is how it looks on the 5110
1Khz from robot buzzer, really close to the microphone.

The wave looks 55 pixels wide. The screen show 84 pixels of the 255 samples taken
4600 Microseconds for 255 samples.
0.0046s / 255 = 1.8e-5 s for one sample
9,9e-4 s for 55 samples = 1010 Hz!

So we can sample the robots wave, even if it does look a bit chopped up compared to when I whistle (sin wave). I guess that is since it is generated as a square wave using the tone command.
The tone command:
"Generates a square wave of the specified frequency" - Arduino Tone
ok next step is to detect the frequency by code. Judging from the look of the wave I think I will try to sample hills somehow...

Nokia 5110 LCD


Nokia 5110 LCD https://www.sparkfun.com/products/10168

Introduction

I started tinkering with sound the other day and one thing that I lack is some easy way to visualize the input from the microphone. Sure, I use processing but that implies serial communication that I believe takes a little time from the sampling. So I ordered myself an LCD screen the cheapest I could get my hands on. The Nokia 5110 Monochrome LCD display.

The datasheet says that:
"The PCD8544 is a low power CMOS LCD controller/driver,designed to drive a graphic display of 48 rows and84 columns. All necessary functions for the display areprovided in a single chip, including on-chip generation ofLCD supply and bias voltages, resulting in a minimum ofexternal components and low power consumption." - datasheet
Sounds great!

Implementation

I followed this Adafruit tutorial to wire things up. The only problem with this tutorial is that I got a LCD from Sparkfun and the tutorial show the Adafruit LCD and they differ slightly in pinout.
Adafruit pinout.
Sparkfun pinout
If you look closely you can see that they also use slightly different names. If you check the datasheet there are another set of names. So here is the conversion table:

Adafruit - Sparkfun -    Datasheet -                           (Pin on 4050)
1 GND -   2 GND -         VSS - Negative Power supply - (GND)
2 VCC -    1 VCC -          VDD - Positive Power Supply - (3.3V)
3 CLK -    7 SCLK-         SCLK: Serial Clock Line -          (12)
4 DIN -    6 DN(MOSI) - SDIN: Serial Data Line -           (15)
5 D/C -     5 D/C -           D/C: Mode Select -                   (6)
6 CS -      3 SCE -           SCE: Chip Enable -                   (4)
7 RST -    4 RST -           RES: Reset -                            (2)
8 LED -    8 LED -           VLCD1 LCD Power Supply      (3.3V)

In this tutorial Adafruit uses a "4050" chip as "level shifter". I bought the CD4050B from electrokit to use as level converters.


"The CD4049UB and CD4050B devices are inverting andnon-inverting hex buffers, respectively, and feature logiclevelconversion using only one supply voltage (VCC). Theinput-signal high level (VIH) can exceed the VCC supplyvoltage when these devices are used for logic-levelconversions." - cd4050b datasheet



CD4050B pinout from datasheet
CD4050B  from the datasheet



Code

https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library
https://github.com/adafruit/Adafruit-GFX-Library

I tested the same sketch as in the tutorial, and behold, it worked flawlessly

Running the Adafruit example demo
Next step is to connect this one to the circuit that measure sound and do some coding to visualize the sampling! But now it is time for breakfast!


Friday, February 15, 2013

Electret microphone

LM386 and electret circuit.
Tonight's project was to try out the LM386 together with the electret microphones I intend to use in my radio-beacon project. The microphones are intended to listen to a specific signal and provide the time difference between a radio signal and sound to give me a distance between the sender and the radio-beacon.

I had some issues getting this circuit to work. After much work I realized the electret microphone was not attached all the way into the breadboard. After that it worked as intended. But even with this success I have some doubts that the intended use will work. Well next time I will attach the speaker to another Arduino and see if I can receive the sound and perhaps measure the time it traveled.

Links to circuit´s:

Hardware:


Code:

Thursday, February 14, 2013

Bootloading the ATMEGA 328-PU

Since I had my programmer out and breadboard setup for burning I also wanted to burn a bootloader to the ATmega328-PU chip I got today.
Note that it is not the same chip as ATmega328P-PU that is normally included with an Arduino.
I buy these since they are much cheaper and you can use them as the ATMEGA328P-PU chip. They lack the "pico-power" power saving mode but otherwise they are pretty much the same.

Select Arduino Uno board
But if you try to burn the bootloader directly to the 328-PU you will get the following error

avrdude: Device signature = 0x1e9514
avrdude: Expected signature for ATMEGA328P is 1E 95 0F
         Double check chip, or use -F to override this check.
avrdude done.  Thank you.


We have a ATMEGA328-PU and it is not a ATMEGA328P-PU!

To remedy this we trick the AVRDUDE into thinking it is working with a ATMEGA328P chip. This is done by modifying the file "avrdude.conf". You find it in the arduino folder under "hardware\tools\avr\etc".

We trick the Avrdude into thinking its dealing with another chip.
First take a backup of the file... 

Under the 
#------------------------------------------------------------
# ATmega328P
#------------------------------------------------------------
Replace the line 
signature = 0x1e 0x95 0x0F; 

With
#signature for 328P
#signature = 0x1e 0x95 0x0F;
#signature for 328-PU
signature = 0x1e 0x95 0x14;
Then you can burn the bootloader.

But when you are done, change back the signature to 0x1e 0x95 0x0F; otherwise you will get the following message when you try to upload sketches:
avrdude: Device signature = 0x1e950f
avrdude: Expected signature for ATMEGA328P is 1E 95 14
So after the bootloading with the replaced signature the bootloader identifies itself to the avrdude when programming the chip as a true ATMEGA328p!

So change the line avrdude.conf back to
#signature for 328P
signature = 0x1e 0x95 0x0F;
#signature for 328-PU
#signature = 0x1e 0x95 0x14; 
and you can program the chip as any other ATmega328p




Bootloading the ATMEGA8

So lets burn a bootloader on those ATMEGA8 chips I bought on dx. For that we need the pinout of the chip.

If you intend to do this, please follow the excellent tutorial where I learnt everything from
http://itp.nyu.edu/physcomp/Tutorials/ArduinoBreadboard


By FDominec (Own work) [CC-BY-SA-3.0], via Wikimedia Commons
The first thing I do is to put it on a breadboard and wire up the 2xGND to GND and VCC, AVCC and AREF to +5V. Put a 10KOhm pullup resistor to RESET (Pin 1) so that the chip do not reset by itself. If we want to reset it we connect the RESET pin to GND, preferably through a button.

All IC create noise so to smooth things out i put a 104 Capacitor between VCC and GND.
minimum setup

Next I put the 16Mhz resonator between XTAL1 and XTAL2. This way we can run the chip in 16Mhz instead of the internal 8Mhz resonator. You can also use a crystal here but I wanted to try the resonator this time around.

Next I put a LED and a 220Ohm resistor in series on PB5 (Arduino PIN 16).
Its time to include the programmer.



AVR Pocket programmer
AVR programming adapter
I use the AVR pocket programmer and the AVR adapter that you can find here:



The programmer is attached
The programming adapter has clearly marked out pin-out and you connect it like this:

  • GND to GND rail on breadboard
  • 5V to 5V rail on breadboard
  • MISO to PB4 (MISO, Arduino pin 12)
  • SCK to PB5 (SCK, Arduino pin 13)
  • RESET to RESET pin 1
  • MOSI to PB3 (Arduino pin 11)

Now lets connect the programmer to the computer and start Arduino IDE.

Select USBTinyISP programmer


Select a ATmega8 board

To test programming the chip you can try to upload the Blink sketch using the programmer. For this you do not need a bootloader. Please note that if you have a bootloader on the chip it gets replaced.

upload a sketch using the programmer


If you see your PB5 (Arduino pin 13) LED blink you can proceed to burning the bootloader. Under Tools you find "Burn Bootloader". It takes a while and after you should see the pin 13 LED blink very fast if you reset the chip.

Burning the bootloader

Next step is to program the chip serially for that I moved the chip to my home built Arduino board. I could have created a header on the breadboard, but its getting late here.
I removed the Amega328 carefully with the help of a flat screwdriver and inserted the Amege8 chip

And now I can upload the Blink sketch using normal serial upload...