Skip to content

4. Embedded programming

This week I worked on embedded programming and started to get familiar with Arduino IDE and Thonny

Checkout the information about the microcontrollers that we have available at my colleague Faisal’s website

Arduino IDE

This week we are dealing with embedded programming with arduino’s which requires us to download its application.
download it here

I dealt with Arduino Nano Every you can see the size of it compared to my hand

Port

More info about Arduino Nano Every or buy it if you’d like

connecting it would make the lights turn on

Connected to laptop

we turned on the option of having the verbose output during the compile and upload to make debugging an easier task

Preferences

Activate compile and upload

selecting the board name to edit its program

Select the board

If the library of the board is not already downloaded you are required to download it to be able to edit the program for it

Download the library if needed

to have an idea of how to code we opened the blink code example as shown in the picture

Opening the Blink code example

I tried to alter the default values

changing the default values

the results of 2 second lights on and half a second off

first trial

first test Code

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(2000);                       // wait for 2 seconds
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);                       // wait for half a second
}

i wanted to make something a little more complicated while the instructor was helping the other students

Additional random experimentation

this is what I came up with

additional blinking sequence trial

The instructor gave us three challenges to complete this was the easy challenge

The random challenge

The random challenge
void setup() {
 pinMode(LED_BUILTIN, OUTPUT);
}


void loop() {
  int x=random(1000,5000);
 digitalWrite(LED_BUILTIN, HIGH);
  delay(x);
  digitalWrite(LED_BUILTIN, LOW);
  delay(x);
}

I made a simple code to just display the word "Deer" so I wrote down each letter sequence based on the data sheet that was given to us

Morse challenge code

The data sheet

Morse code data sheet

The results for the word Deer

The morse challenge results

Morse challenge code

void setup() {

  pinMode(LED_BUILTIN, OUTPUT);
}


void loop() {

   delay(5000);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(3000);//D

  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(3000);//E

  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(3000);//E

  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(3000);//R


}

Micropython

Download Thonny here

Refer to Microbit as I find it very helpful in finding the needed commands

the micro-controller board we used which was the ESP32

ESP32 board

Click here to know about the ESP32

the shape of the board ports and since this is modified for kids it is made with a shell that had the port inputs and outputs written next to the port

board side

You can see what each port has as inputs and outputs

board side

that's how you set up Thonny or (Micropython) onto the board

The basic LED code

LED single blink

while true loop blink

The results of the LED blink loop

looped blinking results

This could be really helpful in some cases

while true constricted loop

traffic light code

the traffic light required a different port to be used to have each light as a different output in my case I used the port that represents output 17, 18 and 19

multi-output port

simple lights turning on and off with random

Traffic light code by my colleague (Jumaa)

from machine import Pin
import time
RLED =Pin(17,Pin.OUT)
YLED =Pin(18,Pin.OUT)
GLED =Pin(19,Pin.OUT)

while True:
    RLED.value(1)
    time.sleep(4)
    YLED.value(1)
    time.sleep(1)
    RLED.value(0)
    YLED.value(0)
    GLED.value(1)
    time.sleep(4)
    GLED.value(0)
    YLED.value(1)
    time.sleep(2)
    YLED.value(0)

Last update: September 11, 2024