<!DOCTYPE html> <html lang="en-us"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="generator" content="GitLab Pages"> <meta name="description" content="Fab Academy documentation site for Charlotte Fab-C"> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> <link rel="stylesheet" href="../assets/css/main.css" /> <title>Charlotte Fab-C - Fab Academy</title> </head> <body class="is-preload"> <!-- Wrapper --> <div id="wrapper"> <!-- Main --> <div id="main"> <div class="inner"> <!-- Header --> <header id="header"> <a href="../index.html" class="logo"><strong>Charlotte - FabLab de Charleroi</strong> Fab Academy website</a> <ul class="icons"> <li><a href="https://www.facebook.com/littlebelge" class="icon brands fa-facebook-f" target="_blank"><span class="label">Facebook</span></a></li> <li><a href="https://www.instagram.com/little.belge/" class="icon brands fa-instagram" target="_blank"><span class="label">Instagram</span></a></li> <li><a href="https://gitlab.fabcloud.org/charlotte-vandenbulcke" class="icon brands fa-gitlab" target="_blank"><span class="label">Gitlab</span></a></li> </ul> </header> <!-- Section --> <section id="banner"> <div class="content"> <header class="main"> <h2>6. Embedded Programming</h2> </header> <section> <p>This week we programmed the Quentorres, tried another programming language and browsed through a data sheet.</p> </section> <hr> <section> <h3>Group assignment</h3> <p>Browsing through a data sheet and comparing the performance and development workflows for other architectures were on our to-do list.</p> <h4>Seeed Studio XIAO RP2040</h4> <span class="image object"> <img src="../images/xinfront.jpg" alt="..." /> </span> <h5>Features</h5> <p> <ul> <li>Powerful MCU: Dual-core ARM Cortex M0+ processor, flexible clock running up to 133 MHz</li> <li>Rich on-chip resources: 264KB of SRAM, and 2MB of on-board Flash memory</li> <li>Flexible compatibility: Support Micropython/Arduino/CircuitPython</li> <li>Easy project operation: Breadboard-friendly & SMD design, no components on the back</li> <li>Small size: As small as a thumb(20x17.5mm) for wearable devices and small projects.</li> <li>Multiple interfaces: 11 digital pins, 4 analog pins, 11 PWM Pins,1 I2C interface, 1 UART interface, 1 SPI interface, 1 SWD Bonding pad interface.</li> </ul> </p> <span class="image object"> <img src="../images/xinpin.jpg" alt="..." /> </span> <h5> Specifications </h5> <table> <thead> <tr> <th scope="col">Item</th> <th scope="col">Value</th> </tr> </thead> <tbody> <tr> <th scope="row">CPU</th> <td>Dual-core ARM Cortex M0+ processor up to 133MHz</td> </tr> <tr> <th scope="row">Flash Memory</th> <td>2MB</td> </tr> <tr> <th scope="row">SRAM</th> <td>264KB</td> </tr> <tr> <th scope="row">Digital I/O Pins</th> <td>11</td> </tr> <tr> <th scope="row">Analog I/O Pins</th> <td>4</td> </tr> <tr> <th scope="row">PWM Pins</th> <td>11</td> </tr> <tr> <th scope="row">I2C interface</th> <td>1</td> </tr> <tr> <th scope="row">SPI interface</th> <td>1</td> </tr> <tr> <th scope="row">UART interface</th> <td>1</td> </tr> <tr> <th scope="row">Power supply and downloading interface</th> <td>Type-C</td> </tr> <tr> <th scope="row">Power</th> <td>3.3V/5V DC</td> </tr> <tr> <th scope="row">Dimensions</th> <td>20×17.5×3.5mm</td> </tr> </tbody> </table> <p>In this state, the Seeed Studio has 11 pins free to be used and an in- and/or output.</p> <p>When we use it in the Quentorres, only 4 pins are left available and the in- and/or output.</p> <p>Link to our <a href="https://fabacademy.org/2024/labs/fabc/group-assignment/week006/" target="_blank">Group page</a></p> </section> <hr> <section> <h3>Individual assignment</h3> <h4>Quentorres programming</h4> <p>We've already programmed the led to blink by pushing the button on the Quentorres on week04.</p> <span class="image object"> <img src="../images/quentorres-programming.jpg" alt="..." /> </span> <p>This week we went a little further !</p> <p>First we programmed the 3 leds to blink all at ones every second with Arduino.</p> <pre> <code> //read leds on pin 26, 0 and 1(correspondance seeed studio component) const int ledPin0 = 26; const int ledPin1 = 0; const int ledPin2 = 1; // the setup function runs once when you press reset or power the board void setup() { // initialize digital pins as an output. pinMode(ledPin0, OUTPUT); pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(ledPin0, HIGH); // turn the LEDs on (HIGH is the voltage level) digitalWrite(ledPin1, HIGH); digitalWrite(ledPin2, HIGH); delay(1000); // wait for a second digitalWrite(ledPin0, LOW); // turn the LEDs off (LOW is the voltage level) digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); delay(1000); // wait for a second } </code> </pre> <span class="object"> <video width="600" height="300" controls> <source src="../images/3LEDs-blinking.mp4" type="video/mp4"> </video> </span> <br> <p>The next step was to use the button again and turn the 3 leds on all at ones by pushing it.</p> <pre> <code> // Defining the pins const int boutonPin = 27; const int ledPin0 = 26; const int ledPin1 = 0; const int ledPin2 = 1; void setup() { // Configure the button as INPUT pinMode(boutonPin, INPUT); // Configure the LEDs as OUTPUT pinMode(ledPin0, OUTPUT); pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); // Starting with the LEDs turned off digitalWrite(ledPin0, LOW); digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); } void loop() { // Reading the button's state int etatBouton = digitalRead(boutonPin); // If the button is pushed if (etatBouton == HIGH) { // Turn on the LEDs digitalWrite(ledPin0, HIGH); digitalWrite(ledPin1, HIGH); digitalWrite(ledPin2, HIGH); } else { // Turn off the LEDs digitalWrite(ledPin0, LOW); digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); } } </code> </pre> <span class="object"> <video width="600" height="300" controls> <source src="../images/3LEDs-blink-button2.mp4" type="video/mp4"> </video> </span> <br> <p>Last step, I used the Arduino Serial Monitor to turn on and off the LEDs separately.</p> <p>For this program, I asked <a href="https://gemini.google.com/app/" target="_blank">Gemini</a> (Google's ChatGPT) for some help (because I'm no good at programming!) and it gave me this code :</p> <pre> <code> // Defining LEDs pins #define LED_26 26 #define LED_1 1 #define LED_0 0 void setup() { // Initialize LEDs pins as OUTPUT pinMode(LED_26, OUTPUT); pinMode(LED_1, OUTPUT); pinMode(LED_0, OUTPUT); // Starting Serial Monitor Serial.begin(9600); } void loop() { // Declaring the variable that will stock the received character char c; // Waiting to receive the character while (!Serial.available()); // Reading the received character c = Serial.read(); // The LED that corresponds to the received character lights up switch (c) { case '1': digitalWrite(LED_26, HIGH); digitalWrite(LED_1, LOW); digitalWrite(LED_0, LOW); break; case '2': digitalWrite(LED_26, LOW); digitalWrite(LED_1, HIGH); digitalWrite(LED_0, LOW); break; case '3': digitalWrite(LED_26, LOW); digitalWrite(LED_1, LOW); digitalWrite(LED_0, HIGH); break; case '0': digitalWrite(LED_26, LOW); digitalWrite(LED_1, LOW); digitalWrite(LED_0, LOW); break; } } </code> </pre> <p>It results on : <ul> <li>turning on LED 26 by writing "1" in the serial monitor,</li> <li>turning on LED 1 by writing "2" in the serial monitor,</li> <li>turning on LED 0 by writing "3" in the serial monitor,</li> <li>turning all LEDs off by writing "0" in the serial monitor.</li> </ul> </p> <p>Here is the prompt I used in Gemini to get the code : <blockquote> code arduino serial monitor seeed rp2040 led pin 26, led pin1 and led pin0. When "1" is written in the serial monitor, led pin 26 lights up. When "2" is written in the serial monitor, led pin 1 lights up. When "3" is written in the serial monitor, led pin 0 lights up. When "0" is written in the serial monitor, all 3 leds go out. </blockquote> </p> <span class="image object"> <img src="../images/gemini-prog-test.jpg" alt="..." /> </span> <br> <span class="object"> <video width="600" height="300" controls> <source src="../images/LED-change-serial-monitor.mp4" type="video/mp4"> </video> </span> <br> <p>As little extra, I installed and tried out <a href="https://thonny.org/" target="_blank">Thonny</a> to code in MicroPython.</p> <p>For that, I followed all the steps of the <a href="https://wiki.seeedstudio.com/XIAO-RP2040-with-MicroPython/" target="_blank">Seeed Studio wiki page MicroPython language</a> to get the RGB LED to blink in "Beautiful colors".</p> <p>So, after installing the Thonny Editor and connecting the Seeed Studio, it is asked to download the <a href="../files/ws2812.py" target="_blank">ws2812.py</a> library, open it in the Editor and save it on the "Raspberry Pi Pico".</p> <p>Here is the ws2812.py library content :</p> <pre> <code> import array, time from machine import Pin import rp2 # Configure the number of WS2812 LEDs. #brightness = 0.2 @rp2.asm_pio(sideset_init=rp2.PIO.OUT_LOW, out_shiftdir=rp2.PIO.SHIFT_LEFT, autopull=True,pull_thresh=24) def ws2812(): T1 = 2 T2 = 5 T3 = 3 wrap_target() label("bitloop") out(x, 1) .side(0) [T3 - 1] jmp(not_x, "do_zero") .side(1) [T1 - 1] jmp("bitloop") .side(1) [T2 - 1] label("do_zero") nop() .side(0) [T2 - 1] wrap() class WS2812(): def __init__(self, pin_num, led_count, brightness = 0.5): self.Pin = Pin self.led_count = led_count self.brightness = brightness self.sm = rp2.StateMachine(0, ws2812, freq=8_000_000, sideset_base=Pin(pin_num)) self.sm.active(1) self.ar = array.array("I", [0 for _ in range(led_count)]) def pixels_show(self): dimmer_ar = array.array("I", [0 for _ in range(self.led_count)]) for i,c in enumerate(self.ar): r = int(((c >> 8) & 0xFF) * self.brightness) g = int(((c >> 16) & 0xFF) * self.brightness) b = int((c & 0xFF) * self.brightness) dimmer_ar[i] = (g<<16) + (r<<8) + b self.sm.put(dimmer_ar, 8) time.sleep_ms(10) def pixels_set(self, i, color): self.ar[i] = (color[1]<<16) + (color[0]<<8) + color[2] def pixels_fill(self, color): for i in range(len(self.ar)): self.pixels_set(i, color) def color_chase(self,color, wait): for i in range(self.led_count): self.pixels_set(i, color) time.sleep(wait) self.pixels_show() time.sleep(0.2) def wheel(self, pos): # Input a value 0 to 255 to get a color value. # The colours are a transition r - g - b - back to r. if pos < 0 or pos > 255: return (0, 0, 0) if pos < 85: return (255 - pos * 3, pos * 3, 0) if pos < 170: pos -= 85 return (0, 255 - pos * 3, pos * 3) pos -= 170 return (pos * 3, 0, 255 - pos * 3) def rainbow_cycle(self, wait): for j in range(255): for i in range(self.led_count): rc_index = (i * 256 // self.led_count) + j self.pixels_set(i, self.wheel(rc_index & 255)) self.pixels_show() time.sleep(wait) </code> </pre> <p>Then I had to open a new file and paste this code in it :</p> <pre> <code> from ws2812 import WS2812 import utime import machine power = machine.Pin(11,machine.Pin.OUT) power.value(1) BLACK = (0, 0, 0) RED = (255, 0, 0) YELLOW = (255, 150, 0) GREEN = (0, 255, 0) CYAN = (0, 255, 255) BLUE = (0, 0, 255) PURPLE = (180, 0, 255) WHITE = (255, 255, 255) COLORS = (BLACK, RED, YELLOW, GREEN, CYAN, BLUE, PURPLE, WHITE) led = WS2812(12,1)#WS2812(pin_num,led_count) while True: print("Beautiful color") for color in COLORS: led.pixels_fill(color) led.pixels_show() utime.sleep(0.2) </code> </pre> <p>Finally, this code has to be uploaded by clicking the "Run current script" button. The location where it will be saved is not important. Both locations are fine.</p> <p>If it works well, you will see the RGB LED light convert and flash the lights. And the output of the text "Beautiful Color" will as well be displayed in the Shell.</p> <span class="object"> <video width="600" height="300" controls> <source src="../images/beautiful-color-microPython.mp4" type="video/mp4"> </video> </span> </section> <hr> <section> <h3>My journey</h3> <p></p> <span class="image object"> <img src="../images/...jpg" alt="..." /> </span> </section> <hr> <section> <h3>Files and resources</h3> <p><strong>My files</strong></p> <ul> <li><a href="../files/Blink-3-leds.ino" target="_blank">Arduino file 3 leds blinking</a></li> <li><a href="../files/blink-button-3-leds.ino" target="_blank">Arduino file 3 leds blinking with button pushed</a></li> <li><a href="../files/3_leds_changing_serial_monitor.ino" target="_blank">Arduino file leds on/off with serial monitor</a></li> <li><a href="../files/ws2812.py" target="_blank">ws2812.py library for Thonny Editor</a></li> </ul> <p><strong>Resources</strong></p> <ul> <li><a href="https://wiki.seeedstudio.com" target="_blank">Seeed Studio wiki page</a></li> <li><a href="https://gemini.google.com/app/" target="_blank">Gemini website</a></li> <li><a href="https://thonny.org/" target="_blank">Thonny Editor Website</a></li> <li><a href="https://fabacademy.org/2024/labs/fabc/" target="_blank">Our group page</a></li> </ul> </section> </div> </section> </div> </div> <!-- Sidebar --> <div id="sidebar"> <div class="inner"> <!-- Menu --> <nav id="menu"> <header class="major"> <h2>Menu</h2> </header> <ul> <li><a href="../index.html">Homepage</a></li> <li><a href="../assignments.html">Assignments</a></li> <li> <span class="opener">Week per week</span> <ul> <li><a href="../assignments/week01.html">1. Project Management</a></li> <li><a href="../assignments/week02.html">2. Computer Aided Design</a></li> <li><a href="../assignments/week03.html">3. Computer Controlled Cutting</a></li> <li><a href="../assignments/week04.html">4. Electronics Production</a></li> <li><a href="../assignments/week05.html">5. 3D Scanning And Printing</a></li> <li><a href="../assignments/week06.html">6. Embedded Programming</a></li> <li><a href="../assignments/week07.html">7. Computer Controlled Machining</a></li> <li><a href="../assignments/week08.html">8. Electronics Design</a></li> <li><a href="../assignments/week09.html">9. Output Devices</a></li> <li><a href="../assignments/week10.html">10. Mechanical Design And Machine Design</a></li> <li><a href="../assignments/week11.html">11. Input Devices</a></li> <li><a href="../assignments/week12.html">12. Molding and Casting</a></li> <li><a href="../assignments/week13.html">13. Networking And Communications</a></li> <li><a href="../assignments/week14.html">14. Interface And Application Programming</a></li> <li><a href="../assignments/week15.html">15. Wildcard Week</a></li> <li><a href="../assignments/week16.html">16. Applications And Implications</a></li> <li><a href="../assignments/week17.html">17. Invention, Intellectual Property And Income</a></li> <li><a href="../assignments/week18.html">18. Project Development</a></li> </ul> </li> <li><a href="../final-project.html">Final Project</a></li> <li><a href="../about.html">About Me</a></li> </nav> <!-- Footer --> <footer id="footer"> <p class="copyright">© Charlotte - FabLab de Charleroi. Fab Academy 2024. All rights reserved. Design: <a href="https://html5up.net">HTML5 UP</a>.</p> </footer> </div> </div> </div> <!-- Scripts --> <script src="../assets/js/jquery.min.js"></script> <script src="../assets/js/browser.min.js"></script> <script src="../assets/js/breakpoints.min.js"></script> <script src="../assets/js/util.js"></script> <script src="../assets/js/main.js"></script> </body> </html>