Week9. Output Devices

Assignments


Hero Shot


Group Assignment

Measuring Power Consumption of LED

Measuring power consumption is a crucial aspect of assessing the energy efficiency and performance of electrical or electronic devices. Power consumption refers to the rate at which energy is used by a device and is typically measured in watts (W) or milliwatts (mW).When we try to measure the power consumption of a device, we need to prepare the corresponding equipment and calculate it by the following formula:

Power (P) = Voltage (V) × Current (I)

Knowing the gear of multimeter

I prepared a fuse, resistor, 9V battery, 100uf capacitor, respectively, to test each gear, observe the multimeter reading. During use, it is necessary to determine the content of the measurement and dial the rotary button to the correct position. Specific measurements can be observed as shown in the following figure:

Measuring Video

Circuits requiring measurement of power consumption

By measuring the voltage and current of the blinking LED lamp in the lit state using a multimeter, respectively, it can be calculated from the power calculation formula: P=U*I=2.08*0.0415=0.08632w.The measured voltage and current values are limited to the values in the current circuit, which are related to the resistance of the connection, but basically correspond to the actual values of the current circuit.

After you measure the voltage and current of the LED, you can calculate according to the formula to get the value of the LED. Since manual measurements affect the accuracy of voltage and current, you can average repeated measurements as much as possible to make the measured power consumption as close as possible to the actual power consumption.


Individual Assignments

Grove-OLED Display 0.96" (SSD1315)

Description

The Grove - OLED Display 0.96" (SSD1315) is a monochrome(white) 128×64 pixels passive display matrix module with Grove I2C Interface.As for software compatibility, this Grove-OLED Display supports the U8g2 monochrome displays library written by Olikraus. This library is so convenient and well-compatible that it can support not only this display based on SSD1315 but also displays equipped with SSD1306 or many other chips.

Features

I2C

Here,I will use IIC to connect Seeed Studio XIAO RP2040 with Grove-OLED Display 0.96" (SSD1315) and display"Hello world."

Step 1. Open the Arduino IDE and navigate to Sketch > Include Library > Manage Libraries... Search the library.

Search for the keyword "U8G2" in Arduino Library Manager and install the latest version.

Write the code and upload it to the control board.

          
              #include 
              #include 
               
              #ifdef U8X8_HAVE_HW_SPI
              #include 
              #endif
              #ifdef U8X8_HAVE_HW_I2C
              #include 
              #endif
              
              U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);
               
              void setup(void) {
                u8g2.begin();
              }
               
              void loop(void) {
                u8g2.clearBuffer();                   // clear the internal memory
                u8g2.setFont(u8g2_font_ncenB08_tr);   // choose a suitable font
                u8g2.drawStr(0,10,"Hello Wrold!");    // write something to the internal memory
                u8g2.drawStr(0,30,"Hello Werold!"); 
                u8g2.drawStr(0,50,"Hello Wrrrold!"); 
                u8g2.sendBuffer();                    // transfer internal memory to the display
                delay(1000);  
              }
          
        

SPI

Change IIC function to SPI function

Step 1. Open the Arduino IDE and navigate to Sketch > Include Library > Manage Libraries... Search the library.

Search for the keyword "Adafruit_GFX" in the Arduino Library Manager and install the latest version.

Search for the keyword "Adafruit_SSD1306" in the Arduino Library Manager and install the latest version.

Write the code and upload it to the control board.

          
              #include 
              #include 
              #include 
              #include 
              
              #define SCREEN_WIDTH 128 // OLED display width, in pixels
              #define SCREEN_HEIGHT 64 // OLED display height, in pixels
              
              // Declaration for SSD1306 display connected using software SPI (default case):
              #define OLED_MOSI  MOSI   //Connect SSD1315 D1
              #define OLED_CLK  SCK     //Connect SSD1315 D0
              #define OLED_DC  D4      //Connect SSD1315 D/C
              #define OLED_CS  SS      //Connect SSD1315 CS
              #define OLED_RESET  D5   //Connect SSD1315 RES
              Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
                OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
              
              void setup() {
                Serial.begin(9600);
                if(!display.begin(SSD1306_SWITCHCAPVCC)) {
                  Serial.println(F("SSD1306 allocation failed"));
                  for(;;); // Don't proceed, loop forever
                }
              }
              
              void loop() {
                display.clearDisplay();
                display.setTextSize(1);             // Normal 1:1 pixel scale
                display.setTextColor(SSD1306_WHITE);        // Draw white text
                display.setCursor(0,3);             // Start at top-left corner
                display.println(F("Hello"));
                display.setTextSize(2); 
                display.setCursor(0,16);  
                display.println(F("Hello"));
                display.setTextSize(3); 
                display.setCursor(0,38);  
                display.println(F("Hello"));
                display.display();
                delay(2000);
              }
          
        

Different displays need to load different library files when controlling. In this week's exercise, I learned about two communication control methods, IIC and SPI. When using module control, you need to determine the type of module first, download and install the library file supporting programming control, and then carry out programming control.Secondly, when displaying content, it is necessary to clarify the size of the screen and the number of displayed content, usually with the vertex of the screen as the display origin, pixel values as the coordinate values for display, and can control the size of the displayed content.

Useful links