Skip to content

10-Output devices

Assignments

Group assignment:

  • Measure the power consumption of an output device.
  • Document your work on the group work page and reflect on your individual page what you learned.

Individual assignment:

  • Add an output device to a microcontroller board you’ve designed and program it to do something.

Learning outcomes - Demonstrate workflows used in controlling an output

The road map i made for this week can be accesed here

Group Assignment

You can access our group assignment here

Reflection

Individual Assignments

step1

This was the Scematic for my first board

Oled

While working with the oled, since I needed to use the esp32 library for the xaio board, heres how I downloaded it.

Firstly, go to tools- boards- Board manager

step

It should bring you too this. Then type esp32 and install it

install

Once it is installed, to access it you need to go back to tools- boards- esp32. Then look for the esp32 microcontroller you’ll be using.

xaio

This is the code I used while testing it with an an arduino and the xaio

/*
 Light meter
 Oled interfacing with Seeeduino XIAO
 Download Libraries:
 https://www.electroniclinic.com/arduino-libraries-download-and-projects-they-are-used-in-project-codes/

 */
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);


// int LDR = A0; 
// int LDR_DATA; 

// int F_value; // LDR sensor final value

void setup() {

  Serial.begin(57600);
  // pinMode(LDR, INPUT); 
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  delay(2000);
  display.clearDisplay();
  display.setTextColor(WHITE);

}

void loop() {


//  F_value = readSensor();

  display.clearDisplay();

  // display R G B Values
  display.setTextSize(2);
  display.setCursor(0,0);
  display.print("L Meter:");


  // display.setTextSize(3);
  // display.setCursor(0, 28);
  // display.print(F_value);

  display.setTextSize(1);
  display.setCursor(0, 56);
  display.print("www.electroniclinic.com");

display.display(); 
}

// int readSensor()
// {
//   LDR_DATA = analogRead(LDR);
//   LDR_DATA = map(LDR_DATA,0,1023,0,100);
//   return(LDR_DATA);
//   delay(1000);  
// }

code uploaded

Afterwards, It worked with bothe the arduino and xaio, but it didnt work with my microcontroller, so I decided to make it again

working

Matrix Display 8 by 8

  • Blinking heart
#include <LedControl.h>

// Pin configuration for the MAX7219
#define DATA_IN    11
#define CLK         13
#define LOAD        10
#define MAX_DEVICES 1  // Set this to the number of 8x8 matrices you're using

// Create an instance of the LedControl class
LedControl lc = LedControl(DATA_IN, CLK, LOAD, MAX_DEVICES);

void setup() {
  // Initialize all MAX7219 devices
  for (int i = 0; i < MAX_DEVICES; i++) {
    lc.shutdown(i, false);  // Wake up the display
    lc.setIntensity(i, 8);   // Set brightness (0-15)
    lc.clearDisplay(i);      // Clear display
  }
}

void loop() {
  // Apple shape pattern (8x8 matrix representation)
  byte apple[8] = {
    B00000000, // ....#### 
    B01100110, // ...#....#
    B11100111, // ...#..#.# 
    B11111111, // ...#####.
    B01111110, // ...#####.
    B01111110, // ...#....#
    B00111100, // ....#### 
    B00011000, // ......... (empty row for bottom)
  };

  // Display the apple pattern on the matrix
  for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, apple[row]);  // Update row on the matrix
  }

  delay(1000);  // Wait for a second

  // Clear the display after the pattern is shown
  lc.clearDisplay(0);  // Clear the display
  delay(1000);  // Wait for a second
}

Matrix Display Test

The first component I’ll be needing for my project id the matrix display so for the eyes of the bot. While testing and learning about this component, I was able to change up and make a few different animations!

heart

eye

The code for the blinking eye is from chatgpt.

#include <LedControl.h>

// DIN = 12, CLK = 11, CS = 10
LedControl lc = LedControl(12, 11, 10, 1);
byte eyeOpen[8] = {
  B01111110,
  B10000001,
  B10000001,
  B10111101,
  B10111101,
  B10000001,
  B10000001,
  B01111110
};

// Half-closed eye (top lid coming down) (vertical flipped)
byte eyeHalfClosed1[8] = {
 B00001110,
  B00110010,
  B01000010,
  B01111110,
  B01111110,
  B01000010,
  B00110010,
  B00001110
};

// Closed eye (vertical flipped)
byte eyeClosed[8] = {
  B00011000,
  B00011000,
  B00011000,
  B00011000,
  B00011000,
  B00011000,
  B00011000,
  B00011000
};

// Half-closed eye (bottom lid going up) (vertical flipped)
byte eyeHalfClosed2[8] = {
  B00001110,
  B00110010,
  B01000010,
  B01111110,
  B01111110,
  B01000010,
  B00110010,
  B00001110
};
void setup() {
  lc.shutdown(0, false);       
  lc.setIntensity(0, 8);       
  lc.clearDisplay(0);          
}

void loop() {
  displayFrame(eyeOpen);
  delay(6000);

  displayFrame(eyeHalfClosed1);
  delay(500);

  displayFrame(eyeClosed);
  delay(1000);

  displayFrame(eyeHalfClosed2);
  delay(500);
}

void displayFrame(byte frame[8]) {
  for (int i = 0; i < 8; i++) {
    lc.setRow(0, i, frame[i]);
  }
}

Errors

1- The first error I faced was checking the power with a multimeter. The first few times the connection wa sjust not done right, but afterwards, even if i got the connection correct, it turned out that it just short circuited, so i needed to make a new microcontroller.

connection

2- During the connection process, i also, like i mentioned made quite a few wrong connections, so i burned up the oled.It didn’t exactly burn, it just heated up but i felt liek i should mention it in my errors.

3-


Last update: May 16, 2025