Blinkentree DE
Prometheus (Talk | contribs) |
Prometheus (Talk | contribs) |
||
Line 7: | Line 7: | ||
|contact=Slopjong, prometheus | |contact=Slopjong, prometheus | ||
}} | }} | ||
+ | |||
+ | == Introduction == | ||
+ | |||
Um was geht es nun eigentlich bei diesem grünen blinkenden Tannenbaum? | Um was geht es nun eigentlich bei diesem grünen blinkenden Tannenbaum? | ||
Als kreative Hacker dachten wir uns, dass wir uns für den Weihnachtsmark der Gemeinde etwas besonderes ausdenken werden. Resultat? Der BlinkenTree. Wie sich erkennen lässt, repräsentiert der BlinkenTree einen Tannanebaum und die Weinachstbeleuchtung wird mit Hilfe von blinkenden LEDs realisiert. | Als kreative Hacker dachten wir uns, dass wir uns für den Weihnachtsmark der Gemeinde etwas besonderes ausdenken werden. Resultat? Der BlinkenTree. Wie sich erkennen lässt, repräsentiert der BlinkenTree einen Tannanebaum und die Weinachstbeleuchtung wird mit Hilfe von blinkenden LEDs realisiert. | ||
− | As hackerspaces are places with creative hackers, we thought it would be necessary to support the Christmas market of the commune of Strassen with something tiny, but creative. Result? The Blinkentree. Obviously it represents a green fir tree that is dorned with flashing LEDs which should represent the baubles of a 'real' tree. | + | As hackerspaces are places with creative hackers, we thought it would be necessary to support the Christmas market of the commune of Strassen with something tiny, but creative. Result? The Blinkentree. Obviously it represents a green fir tree that is dorned with flashing LEDs which should represent the baubles of a 'real' tree.'''''UNDER CONSTRUCTION''''' |
'''A big thanks to all of you folks who purchsed a Blinkentree and thus supporting syn2cat Hackerspace.''' | '''A big thanks to all of you folks who purchsed a Blinkentree and thus supporting syn2cat Hackerspace.''' | ||
− | + | '''Hacky Christmas!''' | |
− | == How to | + | == Assembling the kit == |
+ | |||
+ | If you purchased a non-assembled kit you have to put the devices on the board as on the picture. | ||
+ | |||
+ | [[File:Front.png]] | ||
+ | |||
+ | == How to program it on your own? == | ||
We designed our Blinkentree in a way you can customize it by yourself. You can define your own flashing patterns using the C language that you can transfer to your chip using the USBasp programmer. | We designed our Blinkentree in a way you can customize it by yourself. You can define your own flashing patterns using the C language that you can transfer to your chip using the USBasp programmer. | ||
Line 24: | Line 33: | ||
=== Installing and confguring the tools === | === Installing and confguring the tools === | ||
− | This section describes what you need to program the chip. First you need the toolchain with the compiler which translates your program text into bits and bytes that the controller can execute. We are using the GCC compiler which is part of the WinAVR (Windows) and CrossPack (Mac). | + | This section describes what you need to program the chip. First you need the toolchain with the compiler which translates your program text into bits and bytes that the controller can execute. We are using the GCC compiler which is part of the [http://winavr.sourceforge.net WinAVR] (Windows) and [http://www.obdev.at/products/crosspack/index-de.html CrossPack-AVR] (Mac). |
− | If you use Windows download [http://sourceforge.net/projects/winavr/files/WinAVR/20100110/WinAVR-20100110-install.exe/download WinAVR] and follow the installtion guide. When the | + | If you use Windows download [http://sourceforge.net/projects/winavr/files/WinAVR/20100110/WinAVR-20100110-install.exe/download WinAVR] and follow the installtion guide. When the installer asks to make an entry in the PATH variable be sure this is checked. |
+ | |||
+ | For a mac you have to download [http://www.obdev.at/downloads/crosspack/CrossPack-AVR-20100115.dmg CrossPack AVR]. The toolchain is installed into /usr/local/CrossPack-AVR <ref>/usr/local/CrossPack-AVR is just a symbolic link to /usr/local/CrossPack-AVR-20100115 or something like that.</ref>. Have a look if the installer did add an entry to the PATH variable by typing the following line in your shell (Terminal): | ||
+ | |||
+ | <pre>echo $PATH</pre> | ||
+ | |||
+ | If it doesn't contain ''/usr/local/CrossPack-AVR/bin'', execute this in your shell: | ||
+ | <pre>echo -e " \n \n export PATH=/usr/local/CrossPack-AVR/bin:$PATH" >> ~/.profile</pre> | ||
− | |||
<!-- | <!-- | ||
Line 35: | Line 50: | ||
--> | --> | ||
+ | For both '''Windows''' and '''Mac''' chose a good editor like [http://notepad-plus-plus.org/ Notepad++] or [http://www.pnotepad.org/ Programmers Notepad] for Windows and [http://www.barebones.com/products/textwrangler/ TextWrangler] for Mac. | ||
=== Coding === | === Coding === | ||
+ | Programming new flashing patterns for your Blinkentree is very easy. Here is a sample code: | ||
− | < | + | <syntaxhighlight lang="C" line="GESHI_NORMAL_LINE_NUMBERS"> |
− | #include | + | #include <avr/io.h> |
− | #include | + | #include <util/delay.h> |
int main(void) { | int main(void) { | ||
// configure the ports as outputs | // configure the ports as outputs | ||
− | DDRD = | + | DDRD = 0b11111111; |
− | DDRB = | + | DDRB = 0b11111111; |
while(1) | while(1) | ||
Line 62: | Line 79: | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
+ | |||
+ | Save this code in the file main.c because this filename will be used in next sections. | ||
+ | |||
+ | In the first two lines you include one library for input/output (I/O) operations and one library for delay operations. In line 4 you define the main function that the Blinkentree jumps to when you switch it on. The ''DDRD'' and ''DDRB'' functions are used to configure the ports D and B. They're set to 0b11111111 which are binary numbers where each 1 stands for one pin of the port which has 8 pins. 1 means that the pin is set as an output wheras a 0 would be used to configure the pin as an input. | ||
+ | |||
+ | By setting the port B to ''high'' (255 = 0b11111111) in line 12 we turn on all the LEDs of that port. If you want to turn on only certain LEDs you have to set other values from the range 0 to 255 (0b00000000 to 0b11111111). You can use the [http://acc6.its.brooklyn.cuny.edu/~gurwitz/core5/nav2tool.html decimal-binary converter] to convert decimal numbers in binary numbers. | ||
+ | |||
+ | The while loop is used to execute the flashing pattern repeatedly. Otherwise the microcontroller would stop at the end of the main function. In other words the flashing pattern would be executed only one time. | ||
+ | |||
+ | On [https://iamsuhasm.wordpress.com/tutsproj/avr-gcc-tutorial/ Suhas's blog] you find more information about the I/O operations. If we have some time we will update this site to provide you with a mini coding tutorial for AVR microcontrollers. | ||
=== Compiling and linking === | === Compiling and linking === | ||
− | After you're done with the programming, the code must be translated into machine code that can be executed by the microcontroller. | + | After you're done with the programming, the code must be translated into machine code that can be executed by the microcontroller. Open your command line and change into the directory where your code file is. |
+ | |||
+ | There you you type in: | ||
<pre> | <pre> | ||
− | avr-gcc -Wall -Os -std=c99 -DF_CPU=1000000 -mmcu=attiny2313 -c main.c -o main.o avr-gcc -Wall -Os -std=c99 -DF_CPU=1000000 -mmcu=attiny2313 -o main.elf main.o avr-objcopy -O ihex -R .eeprom main.elf main.hex | + | avr-gcc -Wall -Os -std=c99 -DF_CPU=1000000 -mmcu=attiny2313 -c main.c -o main.o |
+ | avr-gcc -Wall -Os -std=c99 -DF_CPU=1000000 -mmcu=attiny2313 -o main.elf main.o | ||
+ | avr-objcopy -O ihex -R .eeprom main.elf main.hex | ||
</pre> | </pre> | ||
− | + | These commands are the same for Mac and Windows. | |
− | + | After that you have main.hex which is the translated code that will be loaded into the chip later. | |
− | + | === Flashing the microcontroller === | |
+ | To flash the controller you need a programmer like the [http://www.fischl.de/usbasp/ USBasp]. On that homepage you find all information you need to build your own programmer but I'd recommend to come tu auer hackerspace in Strassen where you get help and support. We have the equipment like an etching machine to make electronic stuff in a professional way. If you have questions about our space just write an email to electronics[at]hackerspace.lu (please replace [at] by @). | ||
+ | TODO: Driver installation for f***ing Windoze. | ||
+ | |||
+ | With the programmer you are able to flash your controller. On Windows you execute | ||
<pre> | <pre> | ||
− | + | avrdude -c USBasp -p t2313 -U flash:w:main.hex -v -F | |
</pre> | </pre> | ||
− | + | and on Mac | |
− | + | ||
− | + | ||
<pre> | <pre> | ||
sudo avrdude -c USBasp -p t2313 -U flash:w:main.hex -v -F | sudo avrdude -c USBasp -p t2313 -U flash:w:main.hex -v -F | ||
</pre> | </pre> | ||
+ | |||
+ | '''Note''' | ||
+ | |||
+ | If you replaced the chip by a new one you have to configure it first before you can flash with the last command. | ||
+ | |||
+ | <!-- | ||
+ | After you built or got such a programmer you are able to get bits and bytes written into the microcontroller memory. Before you can load the actual compiled code into the microcontroller, it has to be configured first. This is done by setting the fuse bits. Thus you execute the following line: | ||
+ | --> | ||
+ | |||
+ | Then you have to execute | ||
+ | <pre> | ||
+ | avrdude -cUSBasp -p t2313 -U lfuse:w:0x64:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m | ||
+ | </pre> | ||
+ | |||
+ | on Windoze | ||
+ | |||
+ | and | ||
+ | |||
+ | <pre> | ||
+ | sudo avrdude -cUSBasp -p t2313 -U lfuse:w:0x64:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m | ||
+ | </pre> | ||
+ | |||
+ | on a Mac. | ||
+ | |||
+ | <!-- | ||
+ | There are three fuse bytes ( = 24 bits in total). collection of bits stands for a base or a module configuration (Fuse Bits, page 160). Use the fusecalc to be sure to have the right ones. | ||
+ | --> | ||
== References == | == References == | ||
− | + | == Footnotes == | |
+ | <references /> |
Revision as of 13:10, 9 December 2010
Blinkentree DE | |
---|---|
BlinkenTree stellt eine der Weihnachtsaktivtäten des syn2cat Hackerspace dar. | |
Meetings: | none |
Type: | hardware
|
Status: | running |
Members: | |
Contact Person: | Slopjong (mail), prometheus (mail) |
Tools | |
QrCode: |
Contents |
Introduction
Um was geht es nun eigentlich bei diesem grünen blinkenden Tannenbaum?
Als kreative Hacker dachten wir uns, dass wir uns für den Weihnachtsmark der Gemeinde etwas besonderes ausdenken werden. Resultat? Der BlinkenTree. Wie sich erkennen lässt, repräsentiert der BlinkenTree einen Tannanebaum und die Weinachstbeleuchtung wird mit Hilfe von blinkenden LEDs realisiert.
As hackerspaces are places with creative hackers, we thought it would be necessary to support the Christmas market of the commune of Strassen with something tiny, but creative. Result? The Blinkentree. Obviously it represents a green fir tree that is dorned with flashing LEDs which should represent the baubles of a 'real' tree.UNDER CONSTRUCTION
A big thanks to all of you folks who purchsed a Blinkentree and thus supporting syn2cat Hackerspace.
Hacky Christmas!
Assembling the kit
If you purchased a non-assembled kit you have to put the devices on the board as on the picture.
How to program it on your own?
We designed our Blinkentree in a way you can customize it by yourself. You can define your own flashing patterns using the C language that you can transfer to your chip using the USBasp programmer.
Installing and confguring the tools
This section describes what you need to program the chip. First you need the toolchain with the compiler which translates your program text into bits and bytes that the controller can execute. We are using the GCC compiler which is part of the WinAVR (Windows) and CrossPack-AVR (Mac).
If you use Windows download WinAVR and follow the installtion guide. When the installer asks to make an entry in the PATH variable be sure this is checked.
For a mac you have to download CrossPack AVR. The toolchain is installed into /usr/local/CrossPack-AVR [1]. Have a look if the installer did add an entry to the PATH variable by typing the following line in your shell (Terminal):
echo $PATH
If it doesn't contain /usr/local/CrossPack-AVR/bin, execute this in your shell:
echo -e " \n \n export PATH=/usr/local/CrossPack-AVR/bin:$PATH" >> ~/.profile
For both Windows and Mac chose a good editor like Notepad++ or Programmers Notepad for Windows and TextWrangler for Mac.
Coding
Programming new flashing patterns for your Blinkentree is very easy. Here is a sample code:
#include <avr/io.h>
#include <util/delay.h>
int main(void) {
// configure the ports as outputs
DDRD = 0b11111111;
DDRB = 0b11111111;
while(1)
{
PORTB = 255;
PORTD = 0;
_delay_ms(400);
PORTB = 0;
PORTD = 255;
_delay_ms(400);
}
}
Save this code in the file main.c because this filename will be used in next sections.
In the first two lines you include one library for input/output (I/O) operations and one library for delay operations. In line 4 you define the main function that the Blinkentree jumps to when you switch it on. The DDRD and DDRB functions are used to configure the ports D and B. They're set to 0b11111111 which are binary numbers where each 1 stands for one pin of the port which has 8 pins. 1 means that the pin is set as an output wheras a 0 would be used to configure the pin as an input.
By setting the port B to high (255 = 0b11111111) in line 12 we turn on all the LEDs of that port. If you want to turn on only certain LEDs you have to set other values from the range 0 to 255 (0b00000000 to 0b11111111). You can use the decimal-binary converter to convert decimal numbers in binary numbers.
The while loop is used to execute the flashing pattern repeatedly. Otherwise the microcontroller would stop at the end of the main function. In other words the flashing pattern would be executed only one time.
On Suhas's blog you find more information about the I/O operations. If we have some time we will update this site to provide you with a mini coding tutorial for AVR microcontrollers.
Compiling and linking
After you're done with the programming, the code must be translated into machine code that can be executed by the microcontroller. Open your command line and change into the directory where your code file is.
There you you type in:
avr-gcc -Wall -Os -std=c99 -DF_CPU=1000000 -mmcu=attiny2313 -c main.c -o main.o avr-gcc -Wall -Os -std=c99 -DF_CPU=1000000 -mmcu=attiny2313 -o main.elf main.o avr-objcopy -O ihex -R .eeprom main.elf main.hex
These commands are the same for Mac and Windows.
After that you have main.hex which is the translated code that will be loaded into the chip later.
Flashing the microcontroller
To flash the controller you need a programmer like the USBasp. On that homepage you find all information you need to build your own programmer but I'd recommend to come tu auer hackerspace in Strassen where you get help and support. We have the equipment like an etching machine to make electronic stuff in a professional way. If you have questions about our space just write an email to electronics[at]hackerspace.lu (please replace [at] by @).
TODO: Driver installation for f***ing Windoze.
With the programmer you are able to flash your controller. On Windows you execute
avrdude -c USBasp -p t2313 -U flash:w:main.hex -v -F
and on Mac
sudo avrdude -c USBasp -p t2313 -U flash:w:main.hex -v -F
Note
If you replaced the chip by a new one you have to configure it first before you can flash with the last command.
Then you have to execute
avrdude -cUSBasp -p t2313 -U lfuse:w:0x64:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m
on Windoze
and
sudo avrdude -cUSBasp -p t2313 -U lfuse:w:0x64:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m
on a Mac.
References
Footnotes
- ↑ /usr/local/CrossPack-AVR is just a symbolic link to /usr/local/CrossPack-AVR-20100115 or something like that.