Week 6: Embedded Programming


First, starting off with our group assignment in which we compared microntrollers and performed blink tests on two different boards:

Group Assignment


Binary Code

This week, I found that understanding some computer and programming fundamentals was very helpful and actually fascinating. So I went about this week in a kind of winding way, mostly focusing on reading up on the basics and later experimenting with some programming on the Seeed Studio Xiao RP2040 to produce some basic soundwaves.


Binary is a base-2 number system representing numbers using a pattern of ones and zeroes. Early computer systems had mechanical switches that turned on to represent 1, and turned off to represent 0. By using switches in series, computers could represent numbers using binary code.


Each digit in a binary number is called a bit, and each bit represents a power of 2. Binary code is the foundation of all digital technology and computing systems. In computers, binary code is used to represent data and instructions because it can be easily interpreted by electronic circuits that can distinguish between high and low voltage levels, corresponding to the binary digits 1 and 0, respectively.


HIGH = 1
LOW = 0

By arranging these binary digits in different patters, complex data such as text, images, and sound can be represented and processed by computers.


A logic gate is a device that performs a Boolean function, a logical operation performed on one or more binary inputs that produces a single binary output. The primary way of building logic gates uses diodes or transistors acting as electronic switches.


There is a world of information out there and further resources for individual study and practice. Just getting an understanding of the very basics of computers and programming was something I was needing to also "get" computer logic better and see how it's reflected in code and programming languages.


Here are some links I found helpful:

  • Binary system basics
  • Fab Lab Barcelona's code examples
  • How computers store information
  • Logic levels
  • Electronics tutorials page


  • Blink test and beyond

    This week we compared microcontrollers and performed a blink test using our Quentorres boards we milled previously, whch is equipped with the Seeed Studio Xiao RP2040. We also tested it on our Barduino boards equipped with the ESP32. You can reference the Group Assignment to find it layed out. I stuck with the Arduino UNO and made a basic synthesizer.


    Quentorres layout

    Here's the blink test code I ran first to test our board:

    
            int led = 26;
            int pushButton = 27;
            int buttonState;
            int ledState; 
    
            void setup() {
              // put your setup code here, to run once:
              pinMode(pushButton, INPUT);
              pinMode(led, OUTPUT);
            }
    
            void loop() {
            // put your main code here, to run repeatedly:
    
              buttonState = digitalRead(pushButton);
              if (buttonState == HIGH) {
              digitalWrite(led, HIGH);
              } else {
              digitalWrite(led, LOW);
              }
    
            }
    
          

    We first start with the pinout to help us identify which pin to declare in the code.

    Image Source: Lena Milly Fab Lab Barcelona

    To get the code running on the board, there are a few things you can make sure are checked and can help debug any issues:





    Code Breakdown & Explanation



    Variable Declarations:


    Setup Function:


    Loop Function:


    Uploading the Code Using Arduino IDE


    Select Board and Port



    Upload the Code:




    Code File

  • Blink Test Quentorres



  • Building a Basic Synthesizer

    Materials needed:


    Basic step by step Guide








    Code to generate soundwave using Arduino IDE:

    // Generate a square wave on pin 9
      digitalWrite(28, HIGH); // Set the pin high
      delay(1);            // Half period duration (adjust as needed)
      digitalWrite(28, LOW);  // Set the pin low
      delay(1);            // Half period duration (adjust as needed)



    In the above image, the beeping is continuous, so I added a button in order to control the sound.

    I also experimented with getting a reading on an Oscilloscope using the setup of a Fab Lab member who was working on a pre-amplifyer.

    Finally, I experimented on producing sounds with the touch sensors on the Barduino board and triggered different beeps:

    Here's the code for the Barduino touch sensor tests:

    void setup() {
      // Set pin 9 as an output
      pinMode(4, INPUT);
      pinMode(5, INPUT);
      pinMode(6, INPUT);
      pinMode(7, INPUT);
      pinMode(1, OUTPUT);
      Serial.begin(115200);
    }
    void loop() {
      int touch = touchRead(4);
      Serial.println(touch);
      delay (1);
      if (touch >=30000){ 
        digitalWrite(1, HIGH);
        delay(1);
        digitalWrite(1, LOW);
        delay(1);}
    else {
      digitalWrite(1, LOW);  // Set the pin low
      delay(1);            // Half period duration (adjust as needed)
    }
      int touch1 = touchRead(5);
      Serial.println(touch);
      delay (1);
      if (touch1 >=30000){ 
        digitalWrite(1, HIGH);
        delay(10);
        digitalWrite(1, LOW);
        delay(10);}
    else {
      digitalWrite(1, LOW);  // Set the pin low
      delay(10);            // Half period duration (adjust as needed)
    }
    
      int touch2 = touchRead(7);
      Serial.println(touch);
      delay (1);
      if (touch2 >=30000){ 
        digitalWrite(1, HIGH);
        delay(0.5);
        digitalWrite(1, LOW);
        delay(0.5);}
    else {
      digitalWrite(1, LOW);  // Set the pin low
      delay(0.5);            // Half period duration (adjust as needed)
    }
    }


    And finally, some audio clips!