Week 8

Embedded Programming.

ASSIGNMENT:

1.) Read a microcontroller data sheet.

2.) Program your board to do something, with as many different programming languages and programming environments as possible.

This week consisted basically on learn about microcontroller programming.

It is the first time I have contact with everything related to microcontroller programming, so this assignment was very difficult for me, but I think I could understand the basics that enabled me to finish the job.

DOCUMENTATION

1.) Read a microcontroller data sheet.

ATtiny44A.

I read the datasheet of microcontroller AYtiny44A; that allows me to observe and understand the order, the role and capabilities of each pin. I could see that some pins accept analog inputs and digital outputs as well, while others only serve to digital or analogic outputs.

Given that I am new to all this, my instructor Roberto Delgado recommended me to start experimenting with Arduino to program the microcontroller. For this reason, the datasheet was helpful to observe the equivalence of ATtiny44A pins for Arduino IDE.

2.) Program your board to do something.

ARDUINO IDE.

In the assignment 4 I had used Arduino to program my FabISP, so this time I was more familiar with the Arduino IDE interface.

- Setting the arduino for the FabISP.

1.) To start we need to ensure that the section of "tools" have selected the "ATtinny44 External 20 MHz clock" card.

2.) Then we need to ensure that the programmer "USBtinyISP is selected.

Now the Arduino ISP is ready to burn codes on the "Hello World board".
- Testing different exercises in the "Hello World Board" with Arduino.
- EXERCISE 1: BLINK.

To start I only use the sample exercise "Blink" of Arduino IDE, it helped me to learn that instead declare variables and assign pins I will use later in other exercises. In this exercise, the number 8 is the corresponding green LED pin.

As you can see, the button has no function in this exercise because I have not declared at the beginning as a variable.

YOU CAN SEE THE CODE HERE.
  • void setup() {
  • pinMode(8, OUTPUT); // The 8 it's the pin number on Arduino
  • void loop() {
  • digitalWrite(8, HIGH);
  • delay(1000); // Is the time it will be on the LED
  • digitalWrite(8, LOW); // Is the time it will be off the LED
  • delay(1000);
  • }
- EXERCISE 2: ON/OFF BUTTON.

I use some Fab Academy 2015 Web pages as reference and I could write the code to burn my board, it was to basically to turn on and off the LED with the button.

This exercise take me a lot of time, because I failed over and over, but finally I can fix the mistakes and my board works as well.

YOU CAN SEE THE CODE HERE.
  • int pinLed = 8; // The 8 it's the pin number on Arduino
  • int buttonPin = 7;
  • int ledState = 0;
  • int buttonState = 0; // Is the time it will be on the LED
  • int oldButtonState = 0; // Is the time it will be off the LED
  • void setup() {
  • pinMode(pinLed, OUTPUT);
  • pinMode(buttonPin, INPUT_PULLUP);
  • }
  • void loop() {
  • int buttonState = digitalRead(7);
  • if (buttonState == 0 && oldButtonState == 1){
  • ledState = !ledState;
  • delay (30);
  • }
  • oldButtonState = buttonState;
  • if (ledState == 1){
  • digitalWrite( pinLed, 1);
  • }
  • else {
  • digitalWrite( pinLed, 0);
  • }
  • }
- EXERCISE 3: LED DIMMING SLOWLY.

In this exercise I used the "analogWrite()"" function in fading a LED off and on. AnalogWrite uses pulse width modulation (PWM), turning a digital pin on and off very quickly with different ratio between on and off, to create a fading effect.

YOU CAN SEE THE CODE HERE.
  • int pinLed = 8; // The 8 it's the pin number on Arduino
  • int brightness = 0;
  • int fadeAmount = 5;
  • void setup(){
  • pinMode(8, OUTPUT);
  • }
  • void loop() {
  • analogWrite(8, brightness);
  • brightness = brightness + fadeAmount;
  • if(brightness == 255 || brightness == 0) {
  • fadeAmount = -fadeAmount;
  • }
  • delay(30);
  • }

Arduino file: Fade_LED.ino

Arduino file: Pullup_code.ino

You can download more files here from DROPBOX.

SELF EVALUATION
WHAT WORKED:

- I could program my board with arduino IDE.

- I identify the function of the codes into a physical board.

WHAT DID NOT WORK:

- I tried to test ATMEL Studio but it did not work.

THINGS TO IMPROVE:

- Try with more options to program boards.

I'm currently taking this course in FAB LAB TECSUP, in Lima-Perú, through CIDI FADA UNA with the support of CONACYT and PARQUE TECNOLOGICO ITAIPU FOUNDATION

©DESIGNED AND BUILD BY FABIO IBARRA - FAB ACADEMY 2016

EMAIL: fabioibarrab@gmail.com