Group Assignment on Embedded programming
Group members
- Stanley Amaechi
- Lauri Hallman
- Shahmeer Adnan Rana
Week 4 - Embedded Programming (group work)
We kickstarted the week with Toni our instructor, giving us a rundown recap of the different microcontrollers used in the lab. For this week’s group assignment we have to demonstrate and compare the toolchains and development workflows for available embedded architectures.
Group Work: Checking the Toolchain
As a group, we tested the toolchain for three boards and languages: - Arduino Nano with Arduino IDE - ESP32 in Arduino IDE - ESP32 with MicroPython
The basic program structure of all C++ based Arduino programs looks like this:
void setup() {
// Initialization code
// Runs once at startup
}
void loop() {
// Main program code
// Runs repeatedly
}
For Python programs the basic stucture is:
# Initialization code, runs once at startup
import time # import what you need
while True:
# Main program code
# Runs repeatedly
Programming the microcontroller varies slightly depending on the microcontroller type, as explained below.
Arduino Nano with Arduino IDE
The Arduino Nano is a compact, complete, and breadboard-friendly development board based on the ATmega328. It can be programmed using the Arduino IDE. To configure the board in Arduino IDE, we followed these steps: - In Tools → Board, we chose Arduino Nano. - We set the correct COM Port by first unplugging the board from USB, then reopening Tools → Port to see which port disappeared and reappeared. In this case, it was COM8. - We entered the code provided by Toni into Arduino IDE and uploaded it to the board.
Below is the code we entered into Arduino IDE and uploaded to the board.
#define LED 13
void setup() {
pinMode(LED, OUTPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(LED, HIGH);
Serial.println("HIGH");
delay(2000);
digitalWrite(LED, LOW);
Serial.println("LOW");
delay(2000);
}
Pressing the Verify button (shown in the next image) compiles the code. The compiled code is then uploaded to the Arduino Nano via the bootloader, which is pre-installed on the board.
We opened the Serial Monitor from the Tools menu, which is useful for debugging. For example, the code includes the line:
Serial.println("HIGH");
This prints the word "HIGH" in the Serial Monitor window, as shown in the following video. Once the code is working properly, these Serial.println statements can be commented out or removed to improve performance.
ESP32 in Arduino IDE
Hardware requirements
- ESP32S Development Board
- Micro USB cable
- Computer with Arduino IDE installed
Arduino IDE Configuration
- Open Arduino IDE
- See below the default screen or sketch you would see on Arduino IDE
- then go to File > Preferences:
- Add ESP32 board URL in the “Additional boards manager URLs” (you can obtain the url, by searching on Arduino page for the github link): https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
- Install ESP32 board support via Tools > Board > Boards Manager
- Select "ESP32 Dev Module" from Tools > Board
Common Issues and Solutions
Upload Fails
- Hold BOOT button while uploading
- Check USB cable connection
- Verify correct board selection
Wi-Fi Connection Issues
- Check credentials
- Monitor signal strength
- Implement reconnection logic
Memory Leaks
- Use heap monitoring tools
- Implement proper cleanup
- Watch for fragmentation
ESP32 with MicroPython
The application that we used for this was Thonny which was downloaded from the web. First Micropython was installed onto the esp32 board by going into the configure interpreter and selecting install or update Micropython. Then Micropython (Esp32) was selected as the interpreter. In the port selection, COM3 was selected automatically as the esp32 was plugged into the computer.
Then the following code was run on the esp32
from machine import Pin
import time
for i in range(3):
led =Pin(2,Pin.OUT)
led.value(1)
print(led.value())
time.sleep(2)
led.value(0)
print(led.value())
time.sleep(2)
which showed the following output on the editor
Notes
- This particular esp32 board didn’t have any other led on it other than the power led therefore there was no blinking
- For some reason there was an issue with the ssl certificate and after looking up the issue on Arduino forums, we installed something that verified the ssl certificates and issue was solved allowing micropython to be installed onto the esp32 board