Embedded Programming

Overview

This week I worked on programing a microcontroller. I worked on two different coding languages which are TinkerCAD circuits and Arduino IDE.

What is a microcontroller?

"A microcontroller is a compact integrated circuit designed to govern a specific operation in an embedded system. A typical microcontroller includes a processor, memory and input/output (I/O) peripherals on a single chip."

graph's source

The type I am using is Arduino Nano 33 BLE Sense.

Arduino Nano 33 BLE Sense

The Arduino Nano 33 BLE looks as seen in the picture below.

pic's source

But what is Arduino? It is one of the most famous companies dealing with programming and microcontrollers.

Arduino

As the official Arduino website says:

"Arduino is an open-source electronics platform based on easy-to-use hardware and software. It's intended for anyone making interactive projects."

Datasheet and Research

The Arduino Nano 33 BLE Sense is a hardware device, which is a microcontroller used to make many different projects. It is one of the devices that the official Arduino website recognize as "Enhanced Features". It says that it is the smallest available form from Arduino’s 3.3V AI board.

Arduino Nano 33 BLE Sense has so many features, starting with its sensors:

pic's source

As seen in the graph, it has five different built-in sensors.

One impressive feature I've read about is that this microcontroller has the possibility of running Edge Computing applications "Artificial Intelligence".

Beside having many useful sensors, the Arduino Nano 33 BLE Sense also comes with Bluetooth so it can be connected to other devices wireless.

And from the name, it has BLE, which stands for Bluetooth Low Energy. It consume low energy, and has low data rate. The video explains how to use BLE.

More features as stated in Arduino Nano 33 BLE Datasheet are Flexible power management, advanced security subsystem, it has 1 MB flash and 256 kB RAM, and others.

Moving to the pinouts on the microcontroller.

  • The Vin, which is the voltage input. It is the primary voltage for the board:

  • Digital pins, which are 14 pins which work on binary states "On/Off".

  • Analog pins, which are 8 pins that read the value of the analog sensor used in the connection.

Note:

digital devices can work when connected to analog pins, while the opposite does not work.

  • GND, which is for ground, where voltage is zero.

  • To see the rest of the pinouts and their positions see the following graph:

  • The LED for turns Green when power is on:

programing

There are different software tools to program the device offline and online like Arduino IDE, Arduino CLI and tinkerCAD. I used Arduino IDE and TinkerCAD to test the difference between coding typically and coding by code blocks.

Using ARDUINO IDE

  • start with downloading the app for Arduino from their official website here.

  • The page looks like this after downloading.

  • followed this tutorial to get to know how to use Arduino and connect the device to Arduino IDE.

  • It required downloading the board to the Arduino IDE.

  • Started looking for examples that came along with Arduino IDE.

  • The example I tried is the Blink Example, which makes the programable LED light (Orange) turn on for one second and off for one second repeatedly. I found the comments in the example very helpful to understand the code.

  • I ran the Blink example on my board, which worked just by choosing its port from Tools> Port and then choose the correct port.

Note:

It seems that every time I upload the program, I need to redo the previous step again which is choosing the correct port.

  • Then I tried making the light turn on for random time, using the function random, for more info.


// 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(random(1000,5000));             // wait for random time between 1 - 4 seconds
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(3000);                       // wait for 3 seconds
}
  • Then I used this experience to make the light turn on and off as a Morse code spelling "fablab".

// 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(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a 1 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(2000);                       // wait for 2 second

  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a 1 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(2000);                       // wait for 2 second


digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a 1 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(2000);                       // wait for 2 second


  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);                       // wait for a 0.5 second
 digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a 1 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(2000);                       // wait for 2 second

digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a 1 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(2000);                       // wait for 2 second


  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);                       // wait for a 0.5 second
 digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a 1 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                       // wait for a 0.5 second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(2000);                       // wait for 2 second

}

See this video of the code running FABLAB in Morse Code:

or from this link


Downloads


Using TnkerCAD Code Blocks

Code Blocks is an easier way for coding, which uses blocks that connect together to make a code, and a live simulation could be seen.

  • Then choose the device you are working with from Components, I chose the Arduino Uno R3 because Arduino Nano 33 BLE was not available, but it was fine.

  • You can find examples just like Arduino IDE, I wanted to try doing the same work I did in Arduino IDE here, I started with the blink example.

  • Then I wanted to make it run for random time between 1 to 5 seconds. In the blocks go to Math and chose Pick Random.

  • To view if the code works, press Simulate, as seen the light turns on and off.

  • Then I downloaded the code to try it on the board from the arrow.

  • It then downloaded into a C++ code, which was pretty cool with the comments and explanations.

  • Then I wanted to redo the Morse code I did with Arduino IDE.

  • One good thing that helped me in Code Blocks is the use of the repeat block. I used it for in which I had more than one dot or dash following each others.

  • Similarly I downloaded the code and tried it on the microcontroller I have and it worked perfectly just like the code I did with Arduino IDE.


Downloads


Personal Evaluation:

  • I found Arduino IDE easy to learn from the provided examples and the references in their official website.

  • TinkerCAD Circuits is more of a fun way to code, it provides some useful Math tools and statements that can be used. A great thing is that after downloading the code you can see the comments of what each code statements do. Moreover, the live simulation gives you a pretty good view of what the code does.