Embedded Programming


Group assignment

Individual assignment

Learning outcomes:

Have you:

Week workflow


Tools used


Software Used


Group Assignment

Go to for the group assignment page

Introduction

Read the Datasheet

A few thoughts about it:

One a more serious note, I really think this assignment is one of the hardest I m stuck because of this datasheet.

Will jump to programing and use it to consult only. While I do will detach important sections bellow:

ATTINY44A pin configurations


Programing

Because I was a bit confuse on how to do it I decided to list all steps in detail and have some sort of template for my next projects. With what is applicable I fill the gaps after each step and do while documenting it, and that is what follows bellow:

  1. Burn bootloader

    1. identify programer
    2. - avrdude or Atmel Studio 7 (windows only)

    3. identify bootloader and makefile
    4. - for that I start by pointing I want to program a ATTINY44A

      - Download makefile

      - Bootloader is not going to be used here since there is no USB

    5. download bootloader
    6. - not applicable

    7. identify commands to burn bootloader
    8. - nope

    9. burn bootloader
    10. - nope


  2. Burn firmware

    1. identify example code:
    2. - There is this code from Prof. Neil

    3. identify commands to compile and burn firmware
    4. - with all files prior downloaded on one directory, in linux I rename the file to makefile and run the script to create the firmware (this step I will repeat every time I want to modify the code:

      mv hello.ftdi.44.echo.c.make makefile
      make

      renaming to makefile and compiling

    5. compile source code
    6. - done in previous step

    7. Adapting makefile to work with my programer
    8. I had to edit the makefile file to work with my programmer. That was done by replacing the entry usbtiny with USBasp 2 times, one when burning the firmware the other when burning the fuses

    9. burn firmware
    10. run:

      make program-usbtiny

      renaming to makefile and compiling

    11. identify what fuses to burn
    12. - that was done already in the makefile

    13. burn fuses
    14. run:

      make program-usbasp-fuses

      burning fuses


Programing with Arduino IDE

I decided to try Arduino IDE as well to program my board.

In order to do it there are a few steps that should work regardless of the os

  1. Add additional board to the boards manager:
  2. Paste the following into (Preferences)-(Additional Boards Manage URLs:)

    https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json

  3. Chose your new added board, in my case ATtiny44
  4. Chose your processor, same as before
  5. select clock, because I am using an external 20Mhz oscillator, I chose "External 20 MHZ"
  6. Because I want to do some serial monitoring on this board I chose the best mach for my FTDI wich is "/dev/cu.usbserial-A7032T9C
  7. The last step before compiling and burning was to select the programmer, in my case "USBasp"

First test

Burning Neil's code "hello.ftdi.44.echo.c"

Here instead of using terminal and avrdude, I used the Arduino IDE as it has a built-in serial monitor.

The results are as follows in the video


Program something else

Now I will try to program it to blink as I press the button.

  1. determine the pin where switch is connected
  2. after looking into the PCB schematics I determined the button is connected to pin 10

  3. determine the pin where LED is connected
  4. after looking into the PCB schematics I determined the LED is connected to pin 6

  5. Code
  6. In human language I want something like this:

    1. wait for button
    2. if button pressed blink LED 3 times
    3. if not go back to beginning

the problem is I never really coded from scratch only changed code, so that will be a challenge...


1st iteration

how did I do it

I Tried first to customize the Blink code from Arduino IDE with my pin numbers, That did not work

code without comments bellow:

void setup() {

  pinMode(LED_BUILTIN, OUTPUT);
  
}

void loop() {

  digitalWrite(LED_BUILTIN, HIGH);   
  delay(1000);                       
  digitalWrite(LED_BUILTIN, LOW);    
  delay(1000); 
  
}

The reason the first code did not work is because I was using a code built in for the Arduino platform but building my own board. Arduino board usually have a built in LED connected to pin 13, not my board! The constant for the arduino platform to deal with the builtin LED is:

LED_BUILTIN 

In the first code I tried to use that constant and failed. In the second code I found enpirically by setting a number instead of the constant would make the LED on.

The right code for the Attiny44 would need to have the pin declared in the begining with the following code:

const int ledPin =  07;

I realize that after trial and error. Now I understand it different that the pin number on the data sheet does not correspond to the arduino pin number that is not the same as in the arduino platform constant. Of course after all this is a customized board but thats the price you pay for being a noob!

So after empirically finding the right pin number I programmed the board and got it to blink!

Here is the customized code without comments:

const int ledPin =  07;

void setup()    {

  pinMode(ledPin, OUTPUT);
  
}

void loop()     {

  digitalWrite(ledPin, HIGH);
  delay(1000);
  digitalWrite(ledPin, LOW);
  delay(1000);

}
        

No more empirically finding pins. Here is the ATtiny44 Arduino pinout diagram

In order to have the button recognized by the board I needed to initialize it too with the following code in the beginning of the sketch:

const int buttonPin = "the pin number here"

Next I had to set the state of the pin with the following code:

int buttonState = 0; 

The <0> in the above code could also be defined as <LOW> another constant in Arduino programing. Arduino website on constants.

After searching for attiny44 Arduino pin. With the right pin number in hand I replaced the pins in the code and it worked! Here is the code.

const int buttonPin = 3;
const int ledPin =  7;

int buttonState = 0; 

void setup() {

  pinMode(ledPin, OUTPUT);

  pinMode(buttonPin, INPUT);
}

void loop() {

  buttonState = digitalRead(buttonPin);

  if (buttonState, LOW) {

  digitalWrite(ledPin, HIGH);
  else {

    digitalWrite(ledPin, LOW);
     }
     }
}
Schema

Because I lost this board many years ago I can only show how to connect the programmer on a similar board. Just like I did in Electronic Design week.

Programmer FabISP and USBisp

Here I show how I used the programmers on Output devices, for Another method without the Arduino IDE check Embedded Programing

USBasp

Programming an attiny44 board with arduino using a FabTinyISP or USBtinyISP that I made.

FabISP

In order to change the behavior of the button I simply replaced the constant <HIGH> for the constant <LOW> here:

if (buttonState == LOW) {

This way the logic of the code is inverted meaning that when the button is depressed the LED is off.

now I inverted when the LED turns on and off. Here is the code without comments:

const int buttonPin = 3;
const int ledPin =  7;

int buttonState = 0;

void setup() {

  pinMode(ledPin, OUTPUT);

  pinMode(buttonPin, INPUT);
}

void loop() {

  buttonState = digitalRead(buttonPin);

  if (buttonState == LOW) {

    digitalWrite(ledPin, HIGH);   
  }else {

    digitalWrite(ledPin, LOW);
    }
    }

Let's see some proof...


Blink 3 times

With a simple addition to the code I changed the behaviour so it blinks 3 times.

donload the code


Hacking the board

I was a bit annoyed my board would not advise me when powered so I decide to solder a red LED and a 22 Ohms resistor and a resistor so if I got the connections wrong I would know and switch it.

Thats the before and after

Before

After

After