Skip to content

Interface and Application Programming

This week I will learn about interface and application programming. This will include:

Unit Description

Group assignment:

  • Compare as many tool options as possible.
  • Document your work on the group work page and reflect on your individual page what you learned.

Individual assignment:

  • Write an application that interfaces a user with input and/or output device(s) on a board that you made.

Learning outcomes

  • Implement a Graphical User Interface (GUI) using programming and explore protocols to communicate with an MCU board.

Checklist

Linked to the group assignment page:

  • Linked to the group assignment page:

  • There are two types of assignments, one group and one individual, since I am alone in my personal Fab Lab I will do both. All of my work will be documented here, so there won’t be a group assignment page.

  • Compare as many tool options as possible.

Tools:

Devices: Seeed Studio XIAO RP2040, nRF52840, ESP32C3

Editor: Arduino IDE, Thonny (MicroPython), MuEditor (CircuitPython)

Languages: C++, .NET, C#, Python, Arduino, MicroPython, CircuitPython

Device Interfaces: SerialPort, I2C, FTDI, USB, UART, SPI

Experience in Learning:

Device: Seeed Studio XIAO RP2040 Interfaces: I2C, UART, SPI, USB Type-C, Boot, Reset, 14 castellated mounting holes, 3-in-one user LED (r,g,b), Power LED, Full-Color RGB LED PC Connection: Step 1. Press and hold the BOOT button and then connect the Seeed Studio XIAO RP2040 to the PCs USB port. Step 2. If the “RPI-RP2” disk is shown on the PC and the Power LED on the Seeed Studio XIAO RP2040 is turned on, the connection is complete. Step 3. Press and release Reset button. IDE: Arduino 2.1.0 IDE Board Manager: “Raspberry Pi Pico/RP2040” Selection: Board: “Seeed Studio XIAO RP2040”, Port: COM7 Programming: Open the Blink example by navigating “File –> Examples —>01.Basics –> Blink” Upload: Click the Upload button to upload the Blink example code to the board. Compiling…Done Compiling. Uploading…”RPI-RP2” disk is shown on the PC…Flashing E: (RPI-RP2) Wrote 138752 bytes to E:/NEW.UF2…Done Uploading. Language: Arduino Discovery: digitalWrite(LED_BUILTIN, HIGH) turns off the Red User LED (GPIO Arduino 17); GPIO Arduino 16: Green LED; GPIO Arduino 25: Blue LED. Thank you, Adrian!

Digital Interface Example: Connect a pushbutton to Pin D0 and an LED to Pin 25. Uploaded the following code to control the ON/OFF of LED using the pushbutton. Improved interface of the interface :) Adding modules is getting easier.

//https://wiki.seeedstudio.com/XIAO-RP2040-with-Arduino

const int buttonPin = D0;     // the number of the pushbutton pin
const int ledPin =  25;      // the number of the LED pin

int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED off:
    digitalWrite(ledPin, HIGH);
  } else {
    // turn LED on:
    digitalWrite(ledPin, LOW);
  }
}

Analog Interface Example: Connect a potentiometer to Pin A0 and an LED to Pin 25. Then upload the following code to control the blinking interval of the LED by rotating the potentiometer knob. Printed a few more mini-pegs.

//https://wiki.seeedstudio.com/XIAO-RP2040-with-Arduino

const int sensorPin = A0;
const int ledPin =  25; 
void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(sensorPin, INPUT);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // read the value from the sensor:
int sensorValue = analogRead(sensorPin);
  // turn the ledPin on
  digitalWrite(ledPin, HIGH);
  // stop the program for <sensorValue> milliseconds:
  delay(sensorValue);
  // turn the ledPin off:
  digitalWrite(ledPin, LOW);
  // stop the program for for <sensorValue> milliseconds:
  delay(sensorValue);
}

RGB LED Interface Example: Pin 11 is the enable pin of RGB LED. You can light up the RGB LED by setting the Pin 11 high. Here we are going to make it go flash. This example uses the “Adafruit_NeoPixel” library. The RGB LED displays a rainbow color. Very Bright!

#include <Adafruit_NeoPixel.h>

int Power = 11;
int PIN  = 12;
#define NUMPIXELS 1

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pixels.begin();
  pinMode(Power,OUTPUT);
  digitalWrite(Power, HIGH);

}

void loop() { 
  pixels.clear();
  pixels.setPixelColor(0, pixels.Color(15, 25, 205));
  delay(400);
  pixels.show();
  pixels.clear();
  pixels.setPixelColor(0, pixels.Color(103, 25, 205));
  delay(400);
  pixels.show();
  pixels.clear();
  pixels.setPixelColor(0, pixels.Color(233, 242, 205));
  delay(400);
  pixels.show();
  pixels.clear();
  pixels.setPixelColor(0, pixels.Color(233, 23, 23));
  delay(400);
  pixels.show();
  pixels.clear();
  pixels.setPixelColor(0, pixels.Color(12, 66, 101));
  delay(400);
  pixels.show();
  delay(500);

}

I2C Interface Example: Connected the Seeed Studio XIAO RP2040 with Grove - OLED Display 0.96” (SSD1315) through IIC and display “Hello world”.