Embedded Programming


Assignment
   read a microcontroller data sheet
   program your board to do something, with as many different programming languages and programming environments as possible



Arduino: Program Button + LED Board

The first thing I did was download the Arduino software (version 1.0.4) to edit the firmware and upload it to the Button + Led Board. This board I made during the Electronics Design.

Here are the Arduino installation instructions.

I need to Install the Attiny.zip extra support in Arduino. Steps to configure this:




ATtiny 44A Microcontroller Pin-Out

The first problem I found was that I didn't know identify from the Arduino software the pin number to edit the mode of config, input,output,pwm,analog,etc. The pin numbers of the microcontroller are labeled in the Arduino code.



ATtiny 44A vs. Arduino Pin-Out Numbering

ATtiny 44A 
Pin Number
Corresponding Arduino 
Pin Number
Details
1 No number, no access? VCC (+)
2 Pin 10  
3 Pin 9  
4 No number, no access? Reset
5 Pin 8 PWM
6 Pin 7 PWM, Analog Input 7
7 Pin 6 MOSI, PWM, Analog Input 6
8 Pin 5 Analog Input 5, PWM, MISO
9 Pin 4 Analog Input 4, SCK
10 Pin 3 Analog Input 3
11 Pin 2 Analog Input 2
12 Pin 1 Analog Input 1
13 Pin 0 Analog Input 0, AREF
14 No number, no access? GND (-)


Here is the link to the full ATtiny 44A datasheet


I need a programmer
to upload the firmware to the Button+Led Board, the FabISP ,we made in last class.

Fab ISP

Power and Connect the Boards

select board

select board


Program the ATtiny




Code Example

Here is a code example with lots of comments for explanation of what is happening in the code. Download the code example. (or just cut and paste the code below)
  /*

 // Change de LED state each new pulsation of pushbutton
 
 The circuit:
 * LED attached from pin 7 to VCC
 * Pushbutton attached to pin 8 from +5V
 
 Created 2013
 By Rubén Saguar
 
 */

// constants won't change. 
// They're used here to set pin numbers:
const int buttonPin = 8;     // the number of the pushbutton pin
const int ledPin =  7;      // the number of the LED pin

// initialize variables:
int buttonState = 0;         // variable for reading the pushbutton status
int oldbuttonState = 0;      // last read pushbutton status
unsigned char ledState = HIGH;  // LED state ( ON -> LOW , OFF -> HIGH )

void setup() 
{
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);    
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);    
  digitalWrite(ledPin, ledState);  // turn LED off
}

void loop()
{
  // read pushbutton
  buttonState = digitalRead(buttonPin);
  
  // Change de LED state each new pulsation
  if ((oldbuttonState == 0) && (buttonState==1))
  { 
     digitalWrite(ledPin, ledState);
     ledState = !ledState;
  }
  // save old buttonState
  oldbuttonState = buttonState;
}

Initially the LED is off. When I press the button , the LED turn on. Pressing the button a second time, the LED turn off.

 



Supported Arduino Commands / Limitations

Due to the memory limitations of this microcontroller, not all of the Arduino commands are supported.

The following Arduino commands are supported:


Program using AVRDUDE

AVRDUDE is a very popular command-line program for programming AVR chips. Avrdude 5.5 explicitly supports USBtinyISP! Look below for instructions for windows and mac on how to install the correct version of avrdude!

For a tutorial on how to use AVRDUDE and how to program AVRs, check out this tutorial (which is still in progress)

To test that avrdude is working properly open a command line and run the command avrdude -c usbtiny -p m8 while the device is plugged in (the green LED is lit)

You should get that response, which means that it communicated with the programmer but failed to find a connected chip.

If the programmer is not found, you will get this response:

You can try unplugging and replugging it (a reset may help) or check if the driver is installed, etc.

If you connect the programmer to a target (say an attiny2313 target board) and run avrdude -c usbtiny -p t2313 you should get the following which indicates it communicated properly with the chip.

Using it is simple, just indicate usbtiny as the programmer type. The port option is ignored as it always uses USB.

You can use the -B option to specify the ISP speed. By default the value is 10 which means 100KHz clock, this is good for target clock speeds > 500KHz. If you want the high speed clockrate (400KHz) for target frequencies > 4MHz you can use "-B 1" to speed up programming
To calculate the SPI frequency from the delay value, use this formula:

SPI clock frequency in KHz = 1000/(1.5+B) where B is the delay value

In general, the clock frequency should be at least 4 times larger than the target clock frequency. Try "-B 32" if you're having clocking issues, that should handle even 128khz clocks.

Can't get it working? Dont worry, help is available in the forums!


For Windows

For a tutorial on how to install WinAVR, check out this page which has step by step instructions. Make sure you get the Dec 20. 2007 release or newer. That one has avrdude 5.5 with usbtiny support!

Don't forget to install the driver too (and check the driver page for more info)


For Mac OS X

For a tutorial on how to set up your Mac for AVR programming and development, check out this page which has step by step instructions.

If you install the AvrMacPack, it comes with Avrdude 5.5 and usbtiny is supported out of the box!

otherwise, If you installed OSX-AVR, finish with these steps.

Grab the avrdude zip file from the download page

Replace avrdude and avrdude.conf wherever you have them installed, probably /usr/local/bin and /usr/local/etc but not necessarily depending on your development system!

To find where avrdude was installed type which avrdude into a Terminal window and the directory will pop up. To move the files, type mv ~/usbtiny-avrdude/avrdude <directory> assuming the new avrdude binary is in a folder called usbtiny-avrdude in your home directory.
To find out where the conf file is type avrdude -v into a Terminal window. Do the same thing for avrdude.conf

(Make backups of the old version of course.)

Close the terminal and open a new one. If you type in avrdude -c usbtiny -p t2313 (without the usbtinyisp plugged in) it should say Could not find USB device 0x1781/0xc9f If not, check to make sure properly replaced avrdude and avrdude.conf

Now read about how to use avrdude here!

If that still doesnt work, you should compile it from the source code which is guaranteed to work


For Linux

For a tutorial on how to set up your Linux machine for AVR programming and development, check out this page which has step by step instructions. Make sure you get avrdude 5.5 version or later!

If you get this response, its a permissions problem with USB. You can run as root or....

Thanks to a friendly user, there is a quick fix so you dont have to run it as root:

A udev rule, placed in a new rule file (named whatever you'd like) in /etc/udev/rules.d/ (or wherever you distro will expect it) will set the permissions for the USBtinyISP correctly.

SUBSYSTEM=="usb", SYSFS{idVendor}=="1781", SYSFS{idProduct}=="0c9f", GROUP="users", MODE="0666"
or maybe
SUBSYSTEM=="usb", SYSFS{idVendor}=="1781", SYSFS{idProduct}=="0c9f", GROUP="adm", MODE="0666"
depending on your distro

(one line!) should do the trick. Sane does something very similar to
allow regular users to access a scanner.

Another user suggests:

The udev examples given don't work on some systems as the SYSFS parameter is deprecated. The following rule works on recent Ubuntu systems and should probably work on other newer Linux systems:

SUBSYSTEM=="usb", ATTR{product}=="USBtiny", ATTR{idProduct}=="0c9f", ATTRS{idVendor}=="1781", MODE="0660", GROUP="dialout"