Skip to content

8. Embedded Programming

This week I learn how to program the board and upload to the board. I am interested in this and program several simple code to run. The board use ATtiny 44 as the microcontroller, its arduino pin is shown in the picture below ( brown color).

Programming the Arduino board by Arduino software

As my first hello world board only work for several hours and then couldn’t program, so I use arduino board to test my code before I solder another hello world board.

Reference

https://www.arduino.cc/reference/en/language/functions

https://otasurvivalschool.com/signalling/learn-the-morse-code/

Steps

  • Connect the Arduino board to the computer by USB wire.

  • Click Tools-Board-Arduino AVR Boards-Arduino Uno .

  • Follow the blink example to test the board.

  • Use if function sentence to control LED and upload the program.

  • Add serial function sentence to the first program.

  • Program with Morse Code.

Morse code is made up of “.” and “-“. I use 0.3 s light represent “.”, 9 s light represent “-“, there’s also 0.9 second off meaning the one morse code ends. 1.5 seconds off means the whole code ends.

Programming the hello world board by Arduino software

Steps

  • Use Fab ISP to upload the code to my hello world, and use the FTDI to support 5 V power for the board.

  • Open File-Example-01 Basic-Blind, program and upload to the board.

Upload coding to Hello World Board by Arduino software

I use one button as the digital input connecting to Arduino pin 3, use one LED as the digital ouput connecting to Arduino board pin 7..

-As long as I press the button, the LED light will light.

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 == HIGH) {
    digitalWrite(ledPin, HIGH);
  } else {
        digitalWrite(ledPin, LOW);
  }
}
  • I upload the blink code to my hello world board.
void setup() {
   pinMode(7, OUTPUT);
}
void loop() {
  digitalWrite(7, HIGH);   )
  delay(1000);                      
  digitalWrite(7, LOW);   
  delay(1000);                   
}

Delay(1000) means delay 1 second, however the LED in hello world board is on for 8 seconds and off for 8 seconds iwhen it run the blink code . As we use the make program-usbtiny-fuses code to make the firmware for the hello world board with ATtiny 44 , we also need use Tool- Burn Bootloader to correct the timer in ATtiny 44, then upload the program again. In the second trial the LED is on for 1 second and off for 1 second.

  • I upload the Moser code to the hello world board. For the hello world board, the button connects with Pin 3, and yellow LED connects with Pin 7.

The Moser code is same with the one programming for Arduino board, only changing the pin number.

Problems & Error

  • My hello world board only worked for seconds then the LED didn’t light and the programming couldn’t upload to the board. We will work on the board in the next few weeks.

  • Test the board. Run Makefile, input ‘make program-usbtiny-fuses’ in Git Bash, it shows the connection failed.

  • The hello world board didn’t work at first.
  • We use the Multimeter to find whether the components or lines are connected well or not. It tooks hours to find the first problems that the micro- controller and ISP didn’t connect well. And we re-soldered them.
  • In addition,we changed the computers, different FabISP & connection lines and tried to found the problems. And we found the FabISP is something wrong.
  • There may be something wrong with resonator l as the connection goes well after I soldered a new resonator and changed a new FabISP. Finally, the hello world board works.
  • Try ‘Burn Booloader’ and failed. I misunderstood the meaning. ‘Burn Booloader’ is used for the new board to set the frame before programming. Each new board only use the function once, and the Arduino board has burn booloader in the factory. So it couldn’t upload successfully.

Files

simple_button_code.ino blink_code.ino Alisa-Moser code.ino

Datasheet

There are many types of controllers,such as AVR controller( ATtiny 44 &45), Xtensa, NVIDIA, and so on. The microcontroller we use in O shanghai Fablab is ATtiny 44, so I read the datasheet of the AVR 8bits (ATtiny24/44/84) microcontroller.

The normal pins that I normally use are VCC, GND and PA ( signal pins). In the circuit, ATtiny 44 always connect to 0.1 uF capacitor to keep the voltage stable and connect the RESET pin. Reset pin is one input pin. A low level on this pin for longer than the minimum pulse length will generate a reset, even if the clock is not running and provided the reset pin has not been disabled. Shorter pulses are not guaranteed to generate a reset. The reset pin can also be used as a (weak) I/O pin. The pinout ATtiny 24/44/84 is

The block diagram is

Research

Features

  • Microcontroller receives and sends the message by digital signals with sepecial areas input(A/D) & output (timer/counter/PWM).
  • High Features, Low Power AVR 8-Bit Microcontroller.
  • Clock : 2MHz-ATtiny44, 1MHz-ATtiny45
  • One 8-bit and one 16-bite timer/Counter with two PWM channels
  • Operating Voltage: 2.7~5.5 V for ATtiny 24/44/84.
  • Speed Grade for ATtiny 24/44/84 : 0-20 MHz @ 4.5~5.5 V.
  • Industrial Temperature Range: -40 degree to +85 degree.
  • Non-voltatile program and data memories:
  • The ATtiny24/44/84 contains 2/4/8K byte On-chip In-System Reprogrammable Flash memory for program storage. The Flash memory has an endurance of at least 10,000 write/erase cycles.
  • 128/256/512 Bytes of in-syatem programmable EEPROM, with endurance jis 100,1000 write/erase cycles.

This is my first time to read a datasheet of microcontroller, there’re lots of new knowledge for me. I will read the datasheet carefully and upload the information & knowledge that I learn from it.


Last update: June 23, 2021