header
// 1-Principles and proyect management   // 2-Computer-aided design // 3-computer-controlled cutting
// 4-electronics production // 5-3D scanning and printing // 6-electronics design // 7-molding and casting
// 8-embedded programming // 9-computer-controlled machining // 10-input devices // 11-composites  
// 12-interface & application programming // 13-output devices // 14-networking & communications
// 15-mechanical design, machine design // 16-appplications and implications
// 17-invention, intellectual property and income // 18-project development
// FinalProject // 

Week8: Embedded Programing
Here comes the programming week. I want to learn several programming enviroments, so i will try as much as i can. Lets start coding...

Reading Datasheet

After reading the datasheet of the Attiny44 microcontroller, i can make little chart to show the components of the micro. In red is the pin of the led and in green is the pin of the button:
resume attiny44
Components needed

To do this week assignement, we need several things:
components needed embedded programming
connections


Build an FTDI cable.

To get an FTDI cable, there are some USB cables from Nokia Mobile Phones that can be converted into a FTDI cable. This USB cable has inside the C-42 chipset. You can search in eBay this kind of cable, and check this website to know how to do it (in spanish):

http://txapuzas.blogspot.com.es/2010/07/cable-de-programacion-para-arduino-ftdi.html


Installing Arduino

First of all we need a IDE to program the chipsets. The most versatil IDE to program is the Arduino. Its very portable (can run in Linux, Mac and Windows) and is very escalable. A big community is working with it, so lets take a look.


UBUNTU

First of all we need to know wich version of Ubuntu we are running, 32 or 64 bit.

$ uname -a

in the result of this command, if you see a text with "x86_64" you are running a 64bit system. Else (ixxx or x86 only) you are running a 32 bits.

Now lets install Java in Ubuntu. Open the Software Center in Ubuntu (main menu) and search for the word "Java". Generally the first result is the better or the most official.

install java in ubuntu

This is the ONLY package you need to install Java.

If you have a lower version of Ubuntu than 12.04 Try with these command:

$ sudo apt-get install sun-java6-jdk sun-java6-jre sun-java6-plugin sun-java6-fonts


After this we download the Arduino in his version 1.0.3 from here: http://arduino.cc/en/main/software

Put it at the Desktop, and descompress it:

$ tar xvzf arduino-1.0.3-linux32.tgz

Move to the extracted directory

$ cd arduino-1.0.3

Run the shell script in that directory

$ ./arduino

If you want to start Arduino from terminal in anywhere of the system, you must add the Path of the Arduino directory to the system PATH:

Open the file .bashrc from your personal folder:

$ sudo nano ~/.bashrc

And add at the botton of the file this line:

PATH=$PATH:~/Desktop/arduino-1.0.3

or the directory where you had uncompress the Arduino.

Now lets add the hardware list to Arduino. Download this file: http://www.as220.org/fabacademy/tutorials/Downloads/attiny.zip

And then uncompress inside the "hardware" folder in the Arduino folder.


Install FTDI drivers. 

If you had a Linux with a kernel 3.0.0-19 or better, dont need to install it. Else, you can download and install from the official site:

http://www.ftdichip.com/Drivers/VCP.htm

If you are running Ubuntu 12.04, AVRdude needs sudo access to the program. So lets do this:


$ sudo apt-get install uisp


After this, we need a config file.Download the config file here.

Copy this file in /etc/udev/rules.d with this command

$ sudo mv 10-usbtinyisp.rules /etc/udev/rules.d


Now lets restart the uisp server:

$ sudo service udev restart



WINDOWS


In my case i installed it on a Windows 7 64 bits. From a 32 bits and a 64 bits there arent a lot of differences, only the FDTI drivers are different.

1) Ok,  first thing we need is Arduino files for Windows. You can download it from here


http://arduino.cc/en/Main/Software


Search the 1.0.4 version for windows (no matter 64 or 32 bits). After download just have to uncompress it where you want to have it. Dont need to install, just unzip.

Now go inside the folder and doble click in the "arduino.exe" file ....does it open a green windows? ok, thats all, you can go to the next point.


Arduino dont open? maybe you need to install the Java on your machine. You can download from here:

http://www.java.com/es/download/

after download, double click on it and follow the instructions. After install, try to open now the "arduino" executable, and now the green window must appear.


2) Now we need the Hardware database (the same in all operative system):

http://www.as220.org/fabacademy/tutorials/Downloads/attiny.zip

After download, unzip it and move the attiny folder into the Hardware folder of the arduino. Thats it.


3)And now we need the FTDI software for windows. You need to go to this page and download the 32 or 64bits format, depending of your SO:


http://www.ftdichip.com/Drivers/VCP.htm


Its a executable file, just need to press "next" every time and finally you have the drivers installed.



MACINTOSH

Its the easier way to install arduino.


1) Download Arduino from the official web site: http://arduino.cc/en/Main/Software

After download, just unzip it. Now you will have just one file, named arduino. Double click on it to open Arduino. This file is the whole program, so no matter where you store it.


2) Now we need the hardware list for Arduino. You can download from here:

http://www.as220.org/fabacademy/tutorials/Downloads/attiny.zip

Now unzip and put it on the hardware folder. Commonly it will be on <USER>/DOCUMENTS/ARDUINO, but if you want to know exactly where it is, open Arduino and, in the up menu, go to ARDUINO->PREFERENCES. There you will have the place of the Sketchbook path.


folder for arduino

3) Install the FTDI drivers: Download from here http://www.ftdichip.com/Drivers/VCP.htm

After , doble click on it and slide the FTDI icon as usual on MAC.



CONFIGURING ARDUINO TO WORK WITH ATTINY44


There area  a few things to tweak in Arduino to work it properly with Attiny44:

1º Define the model of the Tiny

define the model of the tiny

2º Change the programmer type

chaage to fabisp

3º If this is the first time you plug the board and need to load with the bootloader, you can do in.

charge the bootloader


Now we can load the button example of the Arduino to check that the board are working good. Go to FILE -> EXAMPLES -> DIGITAL ->BUTTON. Now we must change some parameters in this example. The line with this text:


const int buttonPin = 2;    

const int ledPin =  13;     


Must be changed with the pin of your component . In my case i had the led in PA7 and the button in PA3. Now we go to the datasheet (at the top of the site) and check which pins are this in Arduino. We check that the led is in pin 7 and button is in the pin 3.


const int buttonPin = 3;    

const int ledPin =  7;     


After we change this, plug all your cables and go to compile and download the program to the board.

eureka