Skip to content

embedded programming

Group assignments

  • demonstrate and compare the toolchains and development workflows
  • for available embedded architectures

My group assignments

west-harima week-assignments 04


Individual Assignments

  • 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

Have you answered these questions?

  • Linked to the group assignment page
  • Documented how you made the toolpath
  • Documented how you made (milled, stuffed, soldered) the board
  • Documented that your board is functional
  • Explained any problems and how you fixed them
  • Uploaded your source code
  • Included a ‘hero shot’ of your board

PC working environment

  • PC: MacBook Pro(16-inch,2019)
  • OS: Sonoma 14.7.2
  • Terminal: zsh

hero video

I built a Fab XIAO board and used the code from Adrian as a reference!

simulation

1.ESP32C3

1.0 Access WOKWI.

alt text

1.1 Select ESP32 -> XIAO ESP32-c3

1.2 Modify the circuit to the circuit you want to try.

1.3 Write the program.
This time we used the Adrian code used in 3.4. 1.4 Click on Start the simulation.
It glowed! The simulation is a success.

alt text

2.wokwi-pi-pico

wokwi-pi-pico is Raspberry Pi Pico, an RP2040 microcontroller board with dual-core ARM Cortex-M0+ processor, 264k of internal RAM, and flexible Programmable I/O (PIO) feature.

2.0 Access WOKWI

2.1 Select Pi Pico ->Blink (MicroPython Examples)

2.2 Modify the circuit to the circuit you want to try.

2.3 Write the program
This time we used the code used in 4.4.

2.4 Click on Start the simulation.
It glowed! The simulation is a success.

-Reference Links- Let's run Arduino in your browser! Part 1 What is Wokwi? (in Japanese)

3.ESP32C3

-Features-

  • Low power consumption: Energy-saving design while equipped with Wi-Fi and Bluetooth
  • RISC-V core: 32-bit RISC-V CPU (up to 160 MHz)
  • Wi-Fi & Bluetooth: Supports Wi-Fi 4 (802.11b/g/n) and Bluetooth 5 (LE)
  • Small & Low Cost: Inexpensive and compact design
  • Multi-function GPIOs: Rich interfaces including ADC, PWM, SPI, I2C, and UART
  • Program writing via USB: No additional serial converter required
  • Enhanced security: Hardware encryption and Secure Boot supported
  • Arduino & ESP-IDF support: Wide choice of development environments

-mainstream language-

  • C / C++: Ideal for development with ESP-IDF and Arduino IDE
  • MicroPython: Lightweight Python implementation for easy script development

3.0 Read the datasheet ESP32 datasheet

terminology
gpio A digital signal input/output port (I/O port).
adc A device that converts analog signals into digital signals.
Bits The smallest unit of data that a computer handles.
prog.mem Memory used to store programs, similar to how data is stored.
data mem A component that records data; when referring to memory in a computer, it typically means RAM.
ram A type of memory (storage area) that allows for random read/write (access).
cpu Central Processing Unit (the lower its performance, the slower the computer will operate).

3.1 pinout

alt text

Ardian Torres sitereference

3.2 Programming with Arduino IDE(LED flashing)

Download : Arduino IDE

alt text

3.3 environment setting

  • Search for ESP32 in the library and install Arduino_ESP32_OTA

alt text

  • Open board from tool and select XIAO_ESP32C3 from ESP32

alt text

  • Open port from tool and select /dev/cu.usmodem14101.

alt text

3.4 programming

I have tried the following code.

//ESP32 Lesson 02 LED Blink
//ESP32 Confirmation of sketch writing
//https://omoroya.com/

void setup() {
  pinMode(12, OUTPUT);    //Pin 12 is designated as Output
}

void loop() {
  digitalWrite(12, HIGH); //LED ON(12pin:HIGH)
  delay(1000);            //1 second wait
  digitalWrite(12, LOW);  //LED OFF(12pin:LOW)
  delay(1000);            //1 second wait
}

Introduction to ESP32 Lesson 02 Arduino IDE Settings and L-chicareference

I tried but the LED does not light up...。
So I tried the code from Adrian.

//Fab Academy 2023 - Fab Lab León
//Button + LED                           
//Fab-Xiao
//
//Original code:Neil Gershenfeld 12/8/19
// This work may be reproduced, modified, distributed,
// performed, and displayed for any purpose, but must
// acknowledge this project. Copyright is retained and
// must be preserved. The work is provided as is; no
// warranty is provided, and users accept all liability.
//


const int ledPin1 = D6;//first light  RP2040 pin 0 or ESP32-C3 pin D6 
const int buttonPin = D7;// button pin  RP2040 pin 1 or ESP32-C3 pin D7 
int buttonState = 0;//initial state of the button
int i = 0; //variable intensity led

void setup() { //declaration of inputs and outputs
  pinMode(ledPin1, OUTPUT);
  pinMode(buttonPin, INPUT);
}
void loop() {
  buttonState = digitalRead(buttonPin);// we read the state of the button
  if (buttonState == HIGH) { //if we press the button
  digitalWrite(ledPin1, HIGH);
  delay(500);                       
  digitalWrite(ledPin1, LOW);    
  delay(500);
  digitalWrite(ledPin1, HIGH);
  delay(500);                       
  digitalWrite(ledPin1, LOW);    
  delay(500);
  digitalWrite(ledPin1, HIGH);
  delay(2000);                        
  digitalWrite(ledPin1, LOW);    
  delay(1000);

}
  else {  //if we don't press the button
  digitalWrite(ledPin1, LOW);
  }
}

It doesn't glow either....
After consulting with the instructor, he advised me that there might be a problem with the board I used, and when I checked, the LEDs were installed in the opposite orientation.
I thought I checked it carefully and installed it... Why! I will have to be more careful next time.
Put it back on again and write the code for Adrian...
It worked!

Next, we changed the value so that it blinks every 0.2 seconds.

alt text

//Fab Academy 2023 - Fab Lab León
//Button + LED                           
//Fab-Xiao
//
//Original code:Neil Gershenfeld 12/8/19
// This work may be reproduced, modified, distributed,
// performed, and displayed for any purpose, but must
// acknowledge this project. Copyright is retained and
// must be preserved. The work is provided as is; no
// warranty is provided, and users accept all liability.
//


const int ledPin1 = D6;//first light  RP2040 pin 0 or ESP32-C3 pin D6 
const int buttonPin = D7;// button pin  RP2040 pin 1 or ESP32-C3 pin D7 
int buttonState = 0;//initial state of the button
int i = 0; //variable intensity led

void setup() { //declaration of inputs and outputs
  pinMode(ledPin1, OUTPUT);
  pinMode(buttonPin, INPUT);
}
void loop() {
  buttonState = digitalRead(buttonPin);// we read the state of the button
  if (buttonState == HIGH) { //if we press the button
  digitalWrite(ledPin1, HIGH);
  delay(200);                       
  digitalWrite(ledPin1, LOW);    
  delay(200);
  digitalWrite(ledPin1, HIGH);
  delay(200);                       
  digitalWrite(ledPin1, LOW);    
  delay(200);
  digitalWrite(ledPin1, HIGH);
  delay(200);                        
  digitalWrite(ledPin1, LOW);    
  delay(200);

}
  else {  //if we don't press the button
  digitalWrite(ledPin1, LOW);
  }
}

Success!

-Reference Links-

4.Seeed Studio XIAO RP2040

-Features-

  • Ultra-compact (20 x 17.5 mm) board with RP2040 microcontroller
  • Dual-core Cortex-M0+ (133 MHz operation)
  • 2MB Flash, 264KB SRAM
  • USB-C port (for power and writing)
  • 11 GPIOs (ADC, PWM, I²C, SPI, UART support)
  • 3.3V operation (5V not supported)
  • Arduino / MicroPython / CircuitPython compatible

-mainstream language-

  • Python (for beginners, data analysis, AI, web)
  • JavaScript (web development, front-end and back-end with Node.js)
  • C / C++ (embedded, games, system programs)

4.0 Read the datasheet Seeed Studio XIAO RP2040

4.1 pinout

alt text

4.2 Programming in Thonny Download : Thonny

alt text

Open and install the file.

alt text

4.3 environment setting
Changed to Micro Python (Raspberry Pi Pico)

alt text

alt text

4.4 Programming
After looking at several sites, I asked ChatGPT (GPT-4) the following question

Teach me the code to make the LED blink every second on the Raspberry Pi Pico.

I then used the responses.

alt text

from machine import Pin
from time import sleep

led = Pin(25, Pin.OUT) # LEDs on Pico board

while True:
    led.toggle()
    sleep(1)  # Flashes every second

4.5 Upload the codes by clicking the "Run current script" button.

alt text

When it works well, the LED light turns on and off once per second. And the increasing number of outputs is also displayed in the shell.

-Reference Links-

impressions

  • L-chica is not that difficult, so I felt it was beginner-friendly.
  • Since I did not write the program from scratch myself this time, I felt I needed to learn more.
  • For the final project, we would like to make it wireless if possible, so we thought esp32 (both wireless and wired connections are possible) would be appropriate.

L-chica is LED blink in Japanese...
Oh!my name is L-chica!!!