12. Output devices

Assignment:

  • individual assignment:
    • add an output device to a microcontroller board you’ve designed, and program it to do something
  • group assignment:
    • measure the power consumption of an output device

LED strips

(use RC circuits to control) This week I made a prototype for my final project(about FP discrption), adding input and output devices and tested it.

The lasercutter version

First I used lasercutter to make one:

I used the so called RC circuits as input to control the output - LED strips. How it works?

Then I made another version with 3D printer and deleted the breadboard:

3Dprinter version

Here is the code:

#include <CapacitiveSensor.h> 
#define threshold 6300  
#define LED 13
int flag; 

CapacitiveSensor   cs_4_7 = CapacitiveSensor(4,7);

void setup() {
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
}

void loop() {
    long total3 =  cs_4_7.capacitiveSensor(30);
    Serial.println(total3);
    if (total3 > threshold) {
      if(flag == 0){
        flag = 1;  
        digitalWrite(LED, HIGH);
      }
      else{
        flag = 0;  
        digitalWrite(LED, LOW);
      }
      delay(500);
    } 
}

Tips

To use RC circuits you must add CapacitiveSensor.h and change the threshold value

LED array

I found a very useful library to control WS2812 LED array. I tried to use a touch sensor to turn ON/OFF the leds with one touch because my final project need that function. But acturally the WS2812 LED array can control each leds and its color. Here is a very useful link for it: 8x8 RGB LED Matrix

Code:

#include <FastLED.h>
#define NUM_LEDS 16
CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<WS2812, 4, GRB>(leds, NUM_LEDS);
  for (int i=0; i<NUM_LEDS; i++) {
    leds[i] = CRGB(0, 0, 0);
  }
  FastLED.show();  
}


void loop() {
  int value;
  if(analogRead(A0)> 500){
     value = 50;
   }
    else{
      value = 0;
   }
    for (int i=0; i<NUM_LEDS; i++) {
      leds[i] = CRGB(value, value, value);
   }
    FastLED.show();
}

Tip

Because there is 44=16 leds in the array, so the power supply should be separated form the logic. I used 31.5V battery to supply more current for the leds.

Outcome:

NeoPixels tested by PCion (My own PCB)

Note

This part of the content is added later by Mid-July, because the PCino is made after the schedule.

See more info about PCino, click here.

I used the new-made PCino to test the NeoPixels. The NeoPixel is different from LED strips. Which type is called WS2812. Each LED on the strip can be controlled independently. For each LED has its own asress. I directually use the Adafruit’s labray to test the NeoPixels. Open Arduino IDE…sample…Adafruit NeoPixels…strandtest and change the pin number into D9 according to the board for my final project, and the counts of NeoPixels into 43(that is the NeoPixels’s count for one module round).

Servo


Here is a 9g servo’s 3D model you can download for 3D desig.

little project

To hold the Servo I used this 3D model and 3D printted it.

I used 3 potentiometers to control this litte device with two servos and one 88 LED array* :

Tip

To control servo with potentiometer must use map() function.
Syntax: map(value, fromLow, fromHigh, toLow, toHigh)

Code:

The bule part is for controlling servos. And the rest is the same as led array’s code.

Some problems

I found one of my servo was mad. Without touhing it, it still moved sometime.Looks like it’s nodding. Meanwhile I could still use the potentiometer to control it. Maybe it got some signal from Nano maybe the servo was something wrong.

stepper motor & DC motor

I would like to save them until the Machine design week.

Makerguides

LCD dispaly

Type:

20*4 LCD with I2C driver

Code:

Tip

If you still can’t see the image or word on the screen, maybe you can adjust the knob on the I2C driver with screwdriver.

Outcome:

OLED dispaly

Type:

I2C OLED-2864

Code:

#include "U8glib.h"

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);

void draw(void) {

  u8g.setFont(u8g_font_unifont);

  u8g.drawStr( 0, 22, "Hello World!");
}

void setup(void) {

  if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
    u8g.setColorIndex(255);
  }
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
    u8g.setColorIndex(3);
  }
  else if ( u8g.getMode() == U8G_MODE_BW ) {
    u8g.setColorIndex(1);
  }
  else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
    u8g.setHiColorByRGB(255,255,255);
  }
}

void loop(void) {

  u8g.firstPage();  
  do {
    draw();
  } while( u8g.nextPage() );

  delay(500);
}

Choose the Examples-u8glib-Hello World.
Uncomment this line to match my screen.

Some errors:

When I upload the 3D rendering rectangle rotation program, although the graphics are displayed, I feel that the graphics of the previous program still have residues.

The OLD can do a lot of things. It’s really helpful to learn it well.
u8glib note1
u8glib note2

Original files

FP stetch.ino
LED_array.ino
Servo.ino
Project.ino
HelloWorld.ino
OLED.ino
oledshow.ino