Week 04

This is my 4th week in the Fabacademy and this week we have learnt about embedded programming. The assignment this week also consisted of a group plus an individiual assignment, more specifically we need to:

group assignment: demonstrate and compare the toolchains and development workflows for available embedded architectures individual assignment: browse through the data sheet for your microcontroller write a program for a microcontroller, and simulate its operation, to interact (with local input &/or output devices) and communicate (with remote wired or wireless connections) extra credit: test it on a development board extra credit: try different languages &/or development environments

Group Assignment

Regarding the comparison of embedded architectures, in the Fab we analyzed the architecture and capabilities of five microcontrollers. You can find the details of our work in a separate webpage: https://fabacademy.org/2025/labs/aindustriosa/week04.html

Individual Assignment

Regarding the individual assignment, this week I was working with the Arduino UNO which is a open source microcontroller board with 14 digital input/output interfaces (6 of them can be used as pulse wave modulation), 6 analog inputs, one USC interface, one power interface, reset button and different LEDs for tracking turn on, 13th in built LED and LEDs for tracing data transfer (through the digital TXD and RXD ports). Prior to designing and simulating different programs I get installed and get used to using the Arduino Integrated Development Environment, which can be freely downloaded here (https://www.arduino.cc/en/software). In my case, I installed the Arduino IDE 2.3.4 Windows version. I have never got my hands in electronics before, so I made an exercise of programing and phyisically simulating the circuits in a development board.

First, I just opened a blinck example available in the Arduino IDE. The example consists of a flashing LED with the code:

void setup() { 
 // put your setup code here, to run once:
 pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
 // put your main code here, to run repeatedly:
     digitalWrite(LED_BUILTIN, HIGH);
     delay(1000);
     digitalWrite(LED_BUILTIN, LOW);
      delay(1000);
 }
}

Then I saved and compilled the code through a USB interface and tested it in the development board putting, appart from the LED, a protection resistance:

Next I defined different variables for installing two leds and flashing them. The program consisted of


int led = 12;       // red led to pin 12 
//int ledA = 10;        // yellow led to pin 10 
void setup() { 
pinMode(ledA, OUTPUT); 
pinMode(ledV, OUTPUT);
}
void loop() {
digitalWrite(ledR, HIGH); 
digitalWrite(ledA, LOW); 
delay(1000);                  
digitalWrite(ledR, LOW);
digitalWrite(ledA, HIGH);
delay(1000);                  
}

Latter I tested it in the development board

After that, I added a button to switch on and switch off the light. To achieve that I defined a new two variables (button and state) and used the if function. The code consisted of:

int led = 12;        
int pulsador = 2; 
int estado = 0; 
void setup() {`\ 
  pinMode(led, OUTPUT); 
}`\ 
void loop() {`\ 
estado = digitalRead(pulsador) ; 
if (estado == 1) {  
  digitalWrite(led, HIGH);  // envia 5V a led rojo 
 }else{ 
    digitalWrite(led,LOW); 
}
} 

See a picture of the pulsator running in the development board

Once, I started to understand the matter and went to Wokwi (https://wokwi.com/) which is a simulation platform in which different circuits can be programmed and simulated withouth the need of a development board. I used this simulation platform to construct my program, which consisted of creating a series of 5 lights that flash in a row on an infinite loop and the counting of the loop is being displayed in an OLED screen.

In the following I share the code epxlaining the steps followed as well as the pictures of the simulation. It is worth mentioning that before coding is necessary to install several libraries in Wokwi in the library manager option, otherwise the libraries necessary for running the OLED screed do not work.

Here you can see the libraries I installed:

And now my first program:

#include <SPI.h>	// libraries necessary for running 
#include <Wire.h> 
#include <Adafruit_GFX.h> 
#include <Adafruit_SSD1306.h> 

#define SCREEN_WIDTH 128 // wide of screen OLED 
#define SCREEN_HEIGHT 64  // height OLED
#define OLED_RESET -1  // Reset pin (not used in arduino uno) 
#define SCREEN_ADDRESS 0x3C  // Standar I2C direction for OLED

// Create an object with oled display 
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

int time = 100;

void setup() {
    Serial.begin(9600);  // begin serial
    
    // Connections necessary for arduino uno: 
    // SDA -> A4
    // SCL -> A5
    // VCC -> 5V 
    // GND -> GND
    
    // starto OLED diplay 
    if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { // Dirección I2C 0x3C 
        Serial.println(F("Error at starting")); 
        for (;;); 
    } 
    display.clearDisplay(); 
    display.setTextSize(2); 
    display.setTextColor(SSD1306_WHITE);
    
    for (int n = 9; n <= 13; n++) {  // Repeat from 9 to 13 
        pinMode(n, OUTPUT);  // Configure leds as output 
    }
}

void loop() { 
    static int contador = 0;
    
    for (int n = 9; n <= 13; n++) { 
        digitalWrite(n, HIGH); 
        delay(time); 
        digitalWrite(n, LOW); 
        delay(time); 
    }
    
    // Show the counter in the OLED 
    display.clearDisplay(); 
    display.setCursor(10, 25); 
    display.print("Counting: "); 
    display.print(contador); 
    display.display(); 
    
    contador++; 
}

Here you can see an illustration of the result in the simulation of Wokwi:

Here the ino file if you wanna test it: Arduino file