Skip to content

13. Output Devices

Here is an updated version, I am going to use XIAO RP2040 and Grove - LCD RGB Backlight to make a new project for my Output Devices week.

alt text

alt text

Schemetic Design:

alt text alt text

Generate Gerber files

alt text

Convert Gerber to PNG

alt text

PNG to G-code

Top-trace:
alt text Top-outline:
alt text

PCB Milling

alt text

Soldering and short circuit testing

alt text alt text

Embedded Programming

Add Grove-LCD RGB Backlight Library

Step 1. Download the Grove-LCD RGB Backlight Library from Github.

Step 2. Refer How to install library to install library for Arduino.

alt text alt text

Select the board and upload the code

alt text

Upload the code

I read the original ‘Hello world’ example, then I wrote a ‘hello world’ program that can switch the LCD backlight color.

#include <Wire.h>
#include "rgb_lcd.h"

rgb_lcd lcd;

const int colorR = 255;
const int colorG = 255;
const int colorB = 0;

void setup()
{
    // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);

    // Print a message to the LCD.
    lcd.print("hello, world!");

    delay(1000);
}

void loop()
{
    // set the cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0):
    lcd.setCursor(0, 2);
    // print the number of seconds since reset:
    // lcd.print(millis()/1000);

    // delay(100);
    lcd.print("by Dion");
    // lcd.setRGB(colorR, colorG, colorB);
    lcd.setRGB(255, 0, 0); // Red
    delay(1000);
    lcd.setRGB(0, 255, 0); // Green
    delay(1000);
    lcd.setRGB(0, 0, 255); // Blue
    delay(1000);
}

This program is an Arduino sketch designed to control an RGB backlit LCD display. It initializes the LCD, displays a message, and cycles through different backlight colors.

lcd.setCursor(0, 2); This line attempts to set the cursor to the first column of the second row. Note that this is incorrect because the second row should be indexed by 1, not 2.

rgb_lcd lcd; This line creates an rgb_lcd object named lcd to interact with the RGB backlit LCD.

Set Cursor Position:

lcd.setCursor(0, 2); This line attempts to set the cursor to the first column of the second row. Note that this is incorrect because the second row should be indexed by 1, not 2.

In total, This Arduino sketch initializes an RGB backlit LCD display, prints “hello, world!” followed by “by Dion”, and cycles through red, green, and blue backlight colors. The cursor positioning to 0, 2 is incorrect and should be 0, 1 for the second row on a 16x2 display.

Heroshot/ Demo video


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.

Group Assignment

Click here to group work.

Step-by-Step Guide

Turn Off the Power: Before making any changes to your circuit, ensure the power is turned off to avoid any electrical hazards.

Disconnect the LED Strip: Identify the connection where the power supply connects to the LED strip. You will need to open this connection to insert the multimeter.

Set the Multimeter: Set your multimeter to the appropriate current measurement mode. For most LED strips, a DC current measurement is required, so set your multimeter to the DC current (A or mA) setting. (Try start with A setting first)

Connect the Multimeter in Series:

Red Probe (Positive Lead): Connect the red probe of the multimeter to the positive side of the open circuit. This can be the wire from the power supply that was originally connected to the LED strip’s VCC. Black Probe (Negative Lead): Connect the black probe of the multimeter to the VCC pin of the LED strip where the power supply was originally connected.

Turn On the Power: With the multimeter connected in series with the LED strip, turn on the power supply.

Read the Current: The multimeter will now display the current flowing through the LED strip. This is the amount of current being drawn by the LED strip from the power supply.

alt text alt text

Calculating Power Consumption:

INFO
Once I have the current (in amperes) and the voltage (in volts), I can calculate the power consumption using the formula:

Power (Watts) = Voltage (Volts) x Current (Amperes)

My LED Current(Amperes) : 325.6 mA, i.e, 0.3256 A My LED Voltage :4.97 v;

Then my LED strip power consumption is: 1.618 watts.

For more details , check the bottom of documentation of this week.

Individual Assignment

From week8, I finish my-designed PCB. And in this week, I am going to add an LED-strip to my board and program it to flash the led lights.

Embedded Program

Diagrams and Designs

Hardware overview - Pinout diagram alt text

Schematic Diagram: alt text

PCB Design:
alt text

My Test - Flash LED Strip

I want to blink my LED Strip, maybe make it rainbow colorful , or change into flashing gradiant color to it. To realize , I am going to useAdafruit NeoPixel library, make sure you’ve added this library, so that you can use examples code of it.

To add library:

alt text alt text

To use examples:

alt text

alt text alt text

Edit Examples Code:

I am going to use RGBWstrandtest.ino, according to my-designed PCB, I need to change the LED-PIN into D1: alt text

Select Board & Port

alt text

Upload the code to XIAO

alt text

What if I Fail to upload code to XIAO

alt text

In this case, try hold on the ‘Boot’ button on XIAO and press ‘Reset’ button meanwhile when you’re uploading the program to XIAO.

alt text

// It keeps fail to uploading… alt text

So I close Arduino IDE, and I reconnect my board to my laptop, after this trial, I upload again,and it success!!!!

alt text

However , the LED Strip not turning on. Even though I try press ‘Reset’ button, there’s no response.

alt text

Flash Led Strip Project - Use Multimeter to address the Issue

To address the issue, I use multimeter to test if there’s any short circuit. And after my checking, I found out it’s the copper layer of GND line not working well ,a connector issue.

So I re-solder it to make up the cooper.

alt text

Finally !!!!

Result /Hero Shot

alt text

Source-Code

// NeoPixel test program showing use of the WHITE channel for RGBW
// pixels only (won't look correct on regular RGB NeoPixel strips).

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
 #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN     D1  // in my case, it's D1 Pin

// How many NeoPixels are attached to the Arduino?
#define LED_COUNT  30

// NeoPixel brightness, 0 (min) to 255 (max)
#define BRIGHTNESS 50 // Set BRIGHTNESS to about 1/5 (max = 255)

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)

void setup() {
  // These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
  // Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  clock_prescale_set(clock_div_1);
#endif
  // END of Trinket-specific code.

  strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  strip.show();            // Turn OFF all pixels ASAP
  strip.setBrightness(BRIGHTNESS);
}

void loop() {
  // Fill along the length of the strip in various colors...
  colorWipe(strip.Color(255,   0,   0)     , 50); // Red
  colorWipe(strip.Color(  0, 255,   0)     , 50); // Green
  colorWipe(strip.Color(  0,   0, 255)     , 50); // Blue
  colorWipe(strip.Color(  0,   0,   0, 255), 50); // True white (not RGB white)

  whiteOverRainbow(75, 5);

  pulseWhite(5);

  rainbowFade2White(3, 3, 1);
}

// Fill strip pixels one after another with a color. Strip is NOT cleared
// first; anything there will be covered pixel by pixel. Pass in color
// (as a single 'packed' 32-bit value, which you can get by calling
// strip.Color(red, green, blue) as shown in the loop() function above),
// and a delay time (in milliseconds) between pixels.
void colorWipe(uint32_t color, int wait) {
  for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
    strip.setPixelColor(i, color);         //  Set pixel's color (in RAM)
    strip.show();                          //  Update strip to match
    delay(wait);                           //  Pause for a moment
  }
}

void whiteOverRainbow(int whiteSpeed, int whiteLength) {

  if(whiteLength >= strip.numPixels()) whiteLength = strip.numPixels() - 1;

  int      head          = whiteLength - 1;
  int      tail          = 0;
  int      loops         = 3;
  int      loopNum       = 0;
  uint32_t lastTime      = millis();
  uint32_t firstPixelHue = 0;

  for(;;) { // Repeat forever (or until a 'break' or 'return')
    for(int i=0; i<strip.numPixels(); i++) {  // For each pixel in strip...
      if(((i >= tail) && (i <= head)) ||      //  If between head & tail...
         ((tail > head) && ((i >= tail) || (i <= head)))) {
        strip.setPixelColor(i, strip.Color(0, 0, 0, 255)); // Set white
      } else {                                             // else set rainbow
        int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
        strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
      }
    }

    strip.show(); // Update strip with new contents
    // There's no delay here, it just runs full-tilt until the timer and
    // counter combination below runs out.

    firstPixelHue += 40; // Advance just a little along the color wheel

    if((millis() - lastTime) > whiteSpeed) { // Time to update head/tail?
      if(++head >= strip.numPixels()) {      // Advance head, wrap around
        head = 0;
        if(++loopNum >= loops) return;
      }
      if(++tail >= strip.numPixels()) {      // Advance tail, wrap around
        tail = 0;
      }
      lastTime = millis();                   // Save time of last movement
    }
  }
}

void pulseWhite(uint8_t wait) {
  for(int j=0; j<256; j++) { // Ramp up from 0 to 255
    // Fill entire strip with white at gamma-corrected brightness level 'j':
    strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
    strip.show();
    delay(wait);
  }

  for(int j=255; j>=0; j--) { // Ramp down from 255 to 0
    strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
    strip.show();
    delay(wait);
  }
}

void rainbowFade2White(int wait, int rainbowLoops, int whiteLoops) {
  int fadeVal=0, fadeMax=100;

  // Hue of first pixel runs 'rainbowLoops' complete loops through the color
  // wheel. Color wheel has a range of 65536 but it's OK if we roll over, so
  // just count from 0 to rainbowLoops*65536, using steps of 256 so we
  // advance around the wheel at a decent clip.
  for(uint32_t firstPixelHue = 0; firstPixelHue < rainbowLoops*65536;
    firstPixelHue += 256) {

    for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...

      // Offset pixel hue by an amount to make one full revolution of the
      // color wheel (range of 65536) along the length of the strip
      // (strip.numPixels() steps):
      uint32_t pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());

      // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
      // optionally add saturation and value (brightness) (each 0 to 255).
      // Here we're using just the three-argument variant, though the
      // second value (saturation) is a constant 255.
      strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue, 255,
        255 * fadeVal / fadeMax)));
    }

    strip.show();
    delay(wait);

    if(firstPixelHue < 65536) {                              // First loop,
      if(fadeVal < fadeMax) fadeVal++;                       // fade in
    } else if(firstPixelHue >= ((rainbowLoops-1) * 65536)) { // Last loop,
      if(fadeVal > 0) fadeVal--;                             // fade out
    } else {
      fadeVal = fadeMax; // Interim loop, make sure fade is at max
    }
  }

  for(int k=0; k<whiteLoops; k++) {
    for(int j=0; j<256; j++) { // Ramp up 0 to 255
      // Fill entire strip with white at gamma-corrected brightness level 'j':
      strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
      strip.show();
    }
    delay(1000); // Pause 1 second
    for(int j=255; j>=0; j--) { // Ramp down 255 to 0
      strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
      strip.show();
    }
  }

  delay(500); // Pause 1/2 second
}

Measure the power consumption of an output device

Step-by-Step Guide

Turn Off the Power: Before making any changes to your circuit, ensure the power is turned off to avoid any electrical hazards.

Disconnect the LED Strip: Identify the connection where the power supply connects to the LED strip. You will need to open this connection to insert the multimeter.

Set the Multimeter: Set your multimeter to the appropriate current measurement mode. For most LED strips, a DC current measurement is required, so set your multimeter to the DC current (A or mA) setting. (Try start with A setting first)

Connect the Multimeter in Series:

Red Probe (Positive Lead): Connect the red probe of the multimeter to the positive side of the open circuit. This can be the wire from the power supply that was originally connected to the LED strip’s VCC. Black Probe (Negative Lead): Connect the black probe of the multimeter to the VCC pin of the LED strip where the power supply was originally connected.

Turn On the Power: With the multimeter connected in series with the LED strip, turn on the power supply.

Read the Current: The multimeter will now display the current flowing through the LED strip. This is the amount of current being drawn by the LED strip from the power supply.

Measure Current of the LED strip
  • Multimeter Setting : Use the A and connect the Red cable to 10A pin:

alt text

  • Multimeter connected in series with the LED strip Any of the VCC or GND will fine, as it’s measure current flowing in between gnd and vcc.

In my case, the Green wire connects to VCC; white wire connects to GND;
alt text

I will connect the Multimeter in series with the Green wire:
alt text

Like this :

alt text

The max current shows measured as : 0.21 A; alt text

And current flow will be changing as components are working;

Measure Voltage of the LED strip

Put the red cable to right corner port mentioned on the above image and change the dial to dc voltage symbol

And in pcb, put the black cable to the ground of pcb and red to the led vcc pin.

alt text

INFO
Once I have the current (in amperes) and the voltage (in volts), I can calculate the power consumption using the formula:

Power (Watts) = Voltage (Volts) x Current (Amperes)

My LED Current(Amperes) : 0.21 A My LED Voltage :5.05 v; Then my LED strip power consumption is: 1.06 watts.