Output Devices

The assignments for this week:

About Output devices

Output devices are the important part of any electronic device. Output devices can be used in different applications to help users interact with digital information in a more meaningful way.
An output device is a hardware component that translates processed data into a form that can be understood byus or used by other devices. In this context, output is the final result that users can see, hear, or physically interact with. Outputs can be viewed on a screen, printed, played as audio, or sent to another device.

How Output Devices Work

The exact way a specific output device works will vary depending on the type of output it produces, but the general process works something like this:
  • The computer sends binary data or computer-readable code to the output device.
  • The output device converts the digital data it receives into a form that can be understood by humans or used by other devices.
  • The converted data is then presented to the user or sent to another device.
  • I planned to add two output devices, a speaker and a neopixel. The components needed for this:

  • Microcontroller: Like the SAMD11C.To connect a speaker to a SAMD11 microcontroller and produce sound using PWM (Pulse Width Modulation) output,you need to choose a pin on the SAMD11 microcontroller that supports PWM output. In the datasheet or the microcontroller's pinout diagram, PWM-capable pins are PA04, PA05, PA08, PA09, PA14, PA15, PA28, PA30.




  • Speaker Device: Such as a buzzer, piezo buzzer, or alarm module.
  • Transistor: To amplify the current from the microcontroller to drive the speaker device.


  • Neo Pixel
  • NeoPixels can draw a significant amount of current when changing colors or brightness levels rapidly. This rapid change in current can lead to voltage spikes in the power supply, which may damage the NeoPixels or cause erratic behavior. A capacitor placed near the NeoPixels acts as a buffer, absorbing these voltage spikes and protecting the NeoPixels from potential damage.
    Using a capacitor can also help improve the overall performance of the NeoPixels by reducing noise in the power supply and minimizing voltage fluctuations. This can lead to smoother color transitions and more reliable operation.


  • Power Supply: To power the microcontroller, the speaker and neopixel.

  • In this schematic:
  • Connect one terminal of the speaker to the collector of the transistor.
  • Connect the other terminal of the speaker device to the positive terminal of the power supply.
  • Connect the base of the transistor to a GPIO pin of the microcontroller via a resistor (usually 1kΩ).
  • Connect the emitter of the transistor to the ground (GND).
  • Connect the positive terminal of the power supply to the positive rail of the circuit.
  • Connect the negative terminal of the power supply to the ground (GND) rail of the circuit.
  • Here is the schematic of the circuit:


    This is how it works:
  • GPIO Pin Control: The microcontroller controls the speaker by toggling the GPIO pin (in this case, PA05) high and low. This GPIO pin can be configured as an output pin by the microcontroller's firmware.
  • High State (GPIO Pin set to High): When the GPIO pin is set high, it means that it provides a positive voltage (usually the same as the supply voltage) to the speaker. This allows current to flow from the power supply through the speaker, causing it to produce sound. The voltage supplied by the GPIO pin activates the speaker and generates sound waves.
  • Low State (GPIO Pin set to Low): When the GPIO pin is set low, it means that it doesn't provide any voltage to the speaker. Consequently, current flow to the speaker stops, deactivating the speaker. With no voltage applied, the speaker remains silent as there's no electrical signal to generate sound waves.
  • Speaker Operation: The speaker operates by converting electrical signals (voltage variations) into sound waves. When current flows through the speaker coil, it creates a magnetic field that interacts with a permanent magnet attached to the speaker cone. This interaction causes the cone to move, generating sound waves that we can hear.
  • No Need for a Transistor (For Simple Applications): If you're using a simple speaker that operates within the voltage and current limits of the microcontroller's GPIO pins, a transistor might not be required. The GPIO pin can directly drive the speaker without additional components. However, it's essential to ensure that the speaker's specifications (voltage and current ratings) are compatible with the GPIO pin's output capabilities to prevent damage to either the microcontroller or the speaker.Here, I have used a transistor.






  • Run the Design Rule Check (DRC) to ensure that the PCB layout meets manufacturing requirements and constraints.
  • Run the Electrical Rule Check (ERC) to verify the electrical connectivity and integrity of the circuit.


  • Run the footprint assignment test to ensure all the symbols have footprints.


  • To open the pcb in the editor.


  • KiCad Editor

    Once it is imported to KiCad editor, the components need to be arranged such that the connections don't cross each other.

    We need to edit the settings for routing.





    Once, it is arranged, we can get the fabrication outputs from here:

    The path to save the traces are here:


    We can convert the gerber files to png from this site: Gerber Viewer Drag and drop the files and generate the top trace and top cut as shown:








    PCB milling

    Using the traces mentioned above, I milled the PCB in the Modela using the same procedures mentioned in Week 4 - Electronics Production week

    Soldering

    I collected the required components from the fablab inventory.

    Here again, soldering was done using the same procedures followed in Week 4 - Electronics Production week

    Connecting the two boards







    Neopixel as an Output device

    NeoPixels are special LEDs - they're not just one light but three! Each NeoPixel contains tiny red, green, and blue lights all in one package.
  • Control with SAMD11C14C: The SAMD11C14C microcontroller can control the NeoPixel. By connecting the NeoPixel to one of the microcontroller's pins, we can tell it what to do.
  • Powering Up: To get the NeoPixel shining, we need to feed it some power. It requires electricity to glow, so I planned to connect to a power source, like the microcontroller's power output. However, I missed out that the board I made last week converts the 5V to 3.3V and I hadnt given provision for 5V, so I soldered a pin to the power source and used a jumper wire to power the new pcb.
  • Color Control: Inside the NeoPixel, there's a chip that understands commands and adjusts the intensity of the red, green, and blue lights to create any color.
  • To light up the Neopixel

          #include < Adafruit_NeoPixel.h>
    
            #define LED_PIN   5  // Define the pin connected to the NeoPixel
            #define LED_COUNT 1  // Define the number of NeoPixels in the chain
            
            Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
            
            void setup() {
              // Initialize NeoPixel strip
              strip.begin();
              strip.show();  // Initialize all pixels to 'off'
            }
            
            void loop() {
              // Set NeoPixel color to green
              strip.setPixelColor(0, 0, 255, 0);  // Green color (R=0, G=255, B=0)
              strip.show();  // Update the NeoPixel strip with the new color
            }
    
    


    Changing this command, I got red colour. strip.setPixelColor(0, 255, 0, 0);

    Changing this command again, I got blue colour. strip.setPixelColor(0, 0, 0, 255);

    To colour cycle the neopixel

    #include < Adafruit_NeoPixel.h>
    
      #define LED_PIN     5   // Define the pin connected to the NeoPixel
      #define LED_COUNT   1   // Define the number of NeoPixels in the chain
      
      Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
      
      void setup() {
        // Initialize NeoPixel strip
        strip.begin();
        strip.show();  // Initialize all pixels to 'off'
      }
      
      void loop() {
        colorCycle(10);  // Speed of color cycling (adjust as needed)
      }
      
      // Function to cycle through colors
      void colorCycle(uint8_t wait) {
        uint16_t i;
        
        for(i = 0; i < 256; i++) {
          // Set NeoPixel color
          strip.setPixelColor(0, Wheel((i) & 255));
          strip.show();
          delay(wait);  // Wait between colors
        }
      }
      
      // Input a value 0 to 255 to get a color value
      // The colors are a transition r - g - b - back to r
      uint32_t Wheel(byte WheelPos) {
        if(WheelPos < 85) {
          return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
        } else if(WheelPos < 170) {
          WheelPos -= 85;
          return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
        } else {
          WheelPos -= 170;
          return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
        }
      }
    

    Speaker as an output device

    Since I was planning to use a speaker ,it is required to use a trasistor. I used MOSFET (Metal-Oxide-Semiconductor Field-Effect Transistor). It is a type of transistor commonly used in electronic circuits for switching and amplifying electronic signals. When using a MOSFET with a speaker, it's typically employed as a switch to control the flow of current through the speaker.

    This code of the nursery rhythm, Twinkle Twinkle.
          #define led 2  // led pin
    
          #define speakerPin  5
          
          int length = 28;  // the number of notes
          char notes[] = "CCGGAAG FFEEDDC GGFFEED GGFFEED CCGGAAG FFEEDDC "; // Twinkle, Twinkle, Little Star
          int beats[] = { 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2 }; // Corresponding beats
          int tempo = 150;
          
          
          void playTone(int tone, int duration) {
            for (long i = 0; i < duration * 1000L; i += tone * 2) {
              digitalWrite(speakerPin, HIGH);
              delayMicroseconds(tone);
              digitalWrite(speakerPin, LOW);
              delayMicroseconds(tone);
            }
          }
          void playNote(char note, int duration) {
            char names[] = { 'C', 'D', 'E', 'F', 'G', 'A', 'B', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'x', 'y' };
            int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 834, 765, 593, 468, 346, 224, 655, 715 };
            int SPEE = 5;  // play the tone corresponding to the note name
            for (int i = 0; i < 17; i++) {
              if (names[i] == note) {
                int newduration = duration / SPEE;
                playTone(tones[i], newduration);
              }
            }
          }
          
          void setup() {
          
            pinMode(speakerPin, OUTPUT);  //buzzer
            pinMode(led, OUTPUT);
            digitalWrite(led, HIGH);
            delay(1000);
            digitalWrite(led, LOW);
          }
          void loop() {
             for (int i = 0; i < length; i++) {
              if (notes[i] == ' ') {
                delay(beats[i] * tempo);  // rest
              } else {
                playNote(notes[i], beats[i] * tempo);
              }
              // pause between notes
              delay(tempo);
            }
            delay(100);
          }
          
    
    
        

    Problems Encountered

  • The speaker needs a 5V to power it and since I hadn't given a pin for this, I soldered a pin directly to the Proshplay board.
  • I tried using a Piezoelectric as an output device but the sound was very faint. Maybe I should make a casing for it
  • This code of Happy birthday is from Alfia's documentation. The link is here.
        #define led 2  // led pin
    
        #define speakerPin  5
        
        int length = 28;  // the number of notes
        char notes[] = "GGAGcB GGAGdc GGxecBA yyecdc";
        int beats[] = { 2, 2, 8, 8, 8, 16, 1, 2, 2, 8, 8, 8, 16, 1, 2, 2, 8, 8, 8, 8, 16, 1, 2, 2, 8, 8, 8, 16 };
        int tempo = 150;
        
        
        void playTone(int tone, int duration) {
          for (long i = 0; i < duration * 1000L; i += tone * 2) {
            digitalWrite(speakerPin, HIGH);
            delayMicroseconds(tone);
            digitalWrite(speakerPin, LOW);
            delayMicroseconds(tone);
          }
        }
        void playNote(char note, int duration) {
          char names[] = { 'C', 'D', 'E', 'F', 'G', 'A', 'B', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'x', 'y' };
          int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 834, 765, 593, 468, 346, 224, 655, 715 };
          int SPEE = 5;  // play the tone corresponding to the note name
          for (int i = 0; i < 17; i++) {
            if (names[i] == note) {
              int newduration = duration / SPEE;
              playTone(tones[i], newduration);
            }
          }
        }
        
        void setup() {
        
          pinMode(speakerPin, OUTPUT);  //buzzer
          pinMode(led, OUTPUT);
          digitalWrite(led, HIGH);
          delay(1000);
          digitalWrite(led, LOW);
        }
        void loop() {
           for (int i = 0; i < length; i++) {
            if (notes[i] == ' ') {
              delay(beats[i] * tempo);  // rest
            } else {
              playNote(notes[i], beats[i] * tempo);
            }
            // pause between notes
            delay(tempo);
          }
          delay(100);
        }
      
    It was our friend, Kalyani's birthday today and we had a surprise for her and we played the song.

    Group assignment:

    Power consumption of an output device



    Power, measured in watts (W), is the rate at which energy is transferred or consumed in a circuit. It is a key factor in determining the performance and efficiency of electronic devices. Power can be calculated using two different formulas: Power (P)=Voltage (V)×Current (I) This formula states that power (measured in watts) is the product of voltage (measured in volts) and current (measured in amperes). or P = I^2 * R (using current and resistance).

    By understanding the relationship between power, voltage, current, and resistance, we can optimize circuit designs and select components that meet specific power requirements. It is important to note that power dissipation and energy efficiency are crucial considerations in electronic systems, as excessive power consumption can lead to inefficiencies, heat generation, and reduced lifespan of components.
    To measure the power consumption of an output device,we need to measure both the current and the voltage, since direct measurement of power is not straightforward. A multimeter can be used to measure both voltage and current. For determining the power consumption of an output device:
  • Measure Voltage: Use a multimeter to measure the voltage across the device.
  • Measure Current: Measure the current flowing through the device using the multimeter.
  • Calculate Power: Multiply the measured voltage by the measured current using the formula above.
  • For example, if a motor operates at 12 volts and draws 2 amperes of current, the power consumption is:
    12V×2A=24W
    This indicates that the motor consumes 24 watts of power.

    Design files

    KiCad for schematic with Samd11
    Border for the pcb
    Program- Neopixel_green colour
    Program-Neopixel_colour cycling