Atmega8 + Bluetooth HC05

 This project consists on having a breadboard, the processor Atmega8 without any board, and in the act of programming it and permeating it with bluetooth communication for your personal projects.

 

 

So, in this image we can see the entire hardware used: 

1 x USB ISP programmer (usbasp)

1 x atmega8

1 x itead bluetooth shield from arduino (containing the HC05 BT shield)

2 x ceramic capacitators

1 x external quartz oscilator of 16MHz

1 x led (color of your choosing)

 - x wires

 

I am not covering here how to program the microcontroller with the ISP, but I'm leaving here the schematics with the pin layouts you need to do so, as well as all the command lines I needed to program it:

 

 

 

Here are the command lines:

 

# ping the chip, and all its information (to see whether it's properly connected)
avrdude -c usbasp -p atmega8 -P usb -v

# make the bit fuse. DO NOT TOUCH THIS UNLESS YOU'RE CERTAIN.
avrdude -c usbasp -p m8 -U lfuse:w:0b11111111:m -U hfuse:w:0b11001001:m

# Compilar um programa (the included path is from the OSX. Figure out where are the needed files in your PC)
avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega8 -DF_CPU=16000000L  -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/standard program.cpp -o program.cpp.o

avr-gcc -w -Os -Wl,--gc-sections -mmcu=atmega8 -o program.cpp.elf program.cpp.o /var/folders/rn/szrph81d41g26wn1xd61tf5h0000gn/T/build4757347194695071985.tmp/core.a -L/var/folders/rn/szrph81d41g26wn1xd61tf5h0000gn/T/build4757347194695071985.tmp -lm

avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 program.cpp.elf program.cpp.eep

avr-objcopy -O ihex -R .eeprom program.cpp.elf program.cpp.hex

# erase the chip, before flashing with the .hex file created
avrdude -c usbasp -p atmega8 -P usb -e

# flashing the atmega8
avrdude -C avrdude.conf -v -p m8 -c usbasp -P usb -b 115200 -D -Uflash:w:program.cpp.hex:i

 

An example of a batch file is made available at the end, as a makefile, to automatize the entire process.

 The first image shows that my connections are already made. A special note to the necessity to use an external clock, because the one provided inside the uController does not have the resolution required to support the programming. Hence, a couple of .22 pF ceramic capacitators are needed, and linked to both the ground and the oscilator. From the oscilator, you link each of its "feet" to the XTAL 1 and 2 from the scheme above.

Next image shows the connections of the oscilator in a better way, as well as the led turned off.

 

 

The led will blink whenever it receives bluetooth communication:

 

Now, I connected my phone to it. the uController scans all the communications, and when the received communication is (in this case) a given character (in this case, the caracter 'x'), it will reply with an "ok" message:

 

 

 Batch makefile:  flashuC.sh   dependencies.zip  (dependency libraries and configuration files to use this makefile)

Published by fxsf às 15:47