Arduino: Controlling the Wild RGB LED Strips! Slides and Programs: - - PowerPoint PPT Presentation

arduino controlling the wild rgb led strips
SMART_READER_LITE
LIVE PREVIEW

Arduino: Controlling the Wild RGB LED Strips! Slides and Programs: - - PowerPoint PPT Presentation

Arduino: Controlling the Wild RGB LED Strips! Slides and Programs: http://pamplin.com/dms/ Brady Pamplin DMS: @bpamplin DMS SSID: DMS Member Password: dms--109238 Agenda Physical Computing Microcontrollers,


slide-1
SLIDE 1

Arduino: Controlling the Wild RGB LED Strips!

Slides and Programs: http://pamplin.com/dms/ Brady Pamplin DMS: @bpamplin

DMS SSID: “DMS Member” Password: dms--109238

slide-2
SLIDE 2

Agenda

  • Physical Computing
  • Microcontrollers, Arduino, Wemos
  • Is Raspberry Pi a microcontroller?
  • Parts Kit and the Breadboard
  • Arduino IDE – Portable and Standard
  • Map of files for this class
  • CH340 Driver
  • IDE Installation and Verification– Lab time
  • WS1812B RGB LED Strips Definition
  • Options and Safety
  • Strips Programs
  • Lab time

2 Arduino: Controlling the Wild LED Strips!

slide-3
SLIDE 3

Physical Computing

Physical computing [systems] are interactive systems that can sense and respond to the world around them.

https://en.wikipedia.org/wiki/Physical_computing

Common inexpensive hobby sensors and components include:

3 Arduino: Controlling the Wild LED Strips!

LEDs LCD Display RGB LED Strips Ultrasonic Distance Sensor Temperature Sensor Light Sensor Relay Flame Sensor Module Metal Touch Module Sound Module Laser Emit Module Water Lever Sensor IR Receiver Module IR Emission Module Tilt Switch Module Button Module Buzzer Module Photo-resistor Module Photo-interrupter Module Tap Module Membrane Switch Module Shake Module

slide-4
SLIDE 4

Terminology

Microprocessor – CPU for servers, PCs, laptops

  • Requires external memory and IO controllers
  • All pins dedicated for specific purposes
  • A primary goal is speed

Microcontroller, MCU - embedded computer - pins available for

sensors and actuators

  • Chip includes limited size CPU, flash memory, IO capabilities
  • Great for Physical Computing
  • 50 in typical car - 100 or more in top end luxury cars
  • ATmega328 used in Arduino Uno, Nano
  • ESP8266 used in Wemos

System on Chip, SoC

  • Integrates all components of a computer or other electronic system
  • Digital, analog, mixed-signal, radio frequency
  • Raspberry Pi, cell phones

4 Arduino: Controlling the Wild LED Strips!

slide-5
SLIDE 5

Terminology (Cont’d)

Microcontroller boards - microcontroller and support

components

  • Arduino Uno, Nano,… - ATmega328
  • Wemos D1 Mini - ESP8266

Arduino IDE – Integrated Development environment

  • GUI based software to manage all steps from program

development to downloading software into microcontrollers

  • Started with Arduino boards and others were added

5 Arduino: Controlling the Wild LED Strips!

slide-6
SLIDE 6

6

How much code is in my car?

“On top of all the hardware components, today’s cars are running an enormous amount of software. Mainstream cars may have up to 10 million lines of code and high-end luxury sedans can have nearly 100 million—that’s about 14 times more than even a Boeing 787 Dreamliner jet.” https://www.usatoday.com/story/tech/c

  • lumnist/2016/06/28/your-average-car-

lot-more-code-driven-than-you- think/86437052/

Arduino: Controlling the Wild LED Strips!

slide-7
SLIDE 7

Microcontrollers and Raspberry Pi Comparison

aaa

7

Arduino Nano/UNO Lolin/Wemos D1 Mini RPi 3B+ Category Microcontroller Microcontroller Computer system Chip ATmega328 ESP8266 Broadcom BCM2837B0 Flash 32K – 2K bootloader 4M Add in >= 8G SRAM 2K 80K 1 GB WiFi No Yes Yes Voltage 5 3.3 3.3 Digital I/O Pins 14 11 24 Analog Input Pins 6 1 Active programs 1 1 Dozens Clock speed 16 MHz 80 MHz 1.4 GHz USB Cable Nano – Mini Uno - B Micro Micro

Arduino: Controlling the Wild LED Strips!

slide-8
SLIDE 8

Arduino Nano Close-up

slide-9
SLIDE 9

If the 5V, 3V3 or output data pins are shorted directly to ground, there is a danger of damaging the microcontroller or USB port. These circuits use five volts and less so there is no danger to a person. USB ports provide a limited amount

  • f power. LED strips demand a lot
  • f power. Be careful if you increase

power.

9 Arduino: Controlling the Wild LED Strips!

slide-10
SLIDE 10

Parts Kit

  • Arduino Nano
  • Breadboard
  • WS2812B RBG LED Strip
  • 10k Linear Potentiometer
  • LEDs and 330 Ω Resistors
  • USB mini cable
  • Jumper wires

10 Arduino: Controlling the Wild LED Strips!

slide-11
SLIDE 11

Breadboards and Jumpers

11 Arduino: Controlling the Wild LED Strips!

slide-12
SLIDE 12

Install CH340 Driver for Arduino Clones

English language site

  • https://sparks.gogo.co.nz/ch340.html

Chip manufacturer site – Chinese

  • http://www.wch.cn/download/CH341SER_EXE.html
  • Windows zip

http://www.wch.cn/downloads/file/5.html

  • Linux zip

http://www.wch.cn/downloads/file/177.html

  • Mac zip

http://www.wch.cn/downloads/file/178.html

12 Arduino Install Information

slide-13
SLIDE 13

Characteristics of Standard Arduino IDE

  • Programs in protected area –
  • Users / (ID) / Program Files / Arduino
  • Sketches and libraries in user area –
  • Users / (ID) / My Documents/Arduino
  • Supported for Windows, Apple, Linux

13 Arduino Install Information

slide-14
SLIDE 14

Why Use Portable Arduino IDE?

  • All files in single user area – often the Desktop
  • Easy to deploy in class and use at home
  • Easy to run from USB memory stick
  • All programs will be installed in

(root)\portable\sketchbook

  • Libraries will install in

(root)\portable\sketchbook\libraries

  • Avoids conflict with existing installation
  • Supported for Windows and Linux only

https://www.arduino.cc/en/Guide/PortableIDE

14 Arduino Install Information

slide-15
SLIDE 15

USB Flash Files for Class

Windows users need only copy first directory structure to the Desktop. Apple and Linux users need the last to do a normal installation plus the last two files. arduino-1.8.10_a Full Portable Arduino IDE with programs, libraries and slides for Windows only.

  • (root)\arduino.exe
  • (root)\portable\sketchbook - programs
  • (root)\portable\sketchbook_slides - slides
  • (root)\portable\sketchbook\libraries – user libraries

progs_nov19.zip Program files slides__nov19.zip Class slides

15 Arduino: Controlling the Wild LED Strips!

slide-16
SLIDE 16

Install Portable Arduino IDE

Windows Only

Copy arduino-1.8.10_a from USB drive to Desktop This contains the IDE files, sketchbook programs for this class and a set of libraries used in DMS classes Remove USB Drive Open the new folder and double click arduino.exe or arduino application

16 Arduino: Controlling the Wild LED Strips!

slide-17
SLIDE 17

Install Standard Arduino IDE

Install Arduino IDE: https://www.arduino.cc/en/Main/Software Unzip and copy program files into Arduino folder Install FastLED library:

  • Tools / Library Manager…
  • Search for FastLED by Daniel Garcia
  • Install

For Apple see also: https://www.youtube.com/watch?v=4tOAwJ8Rn9c

17 Arduino: Controlling the Wild LED Strips!

slide-18
SLIDE 18

Arduino IDE Control Panel

18 Arduino Install Information

slide-19
SLIDE 19

Configure Tools Tab

19 Arduino Install Information

Tools / Board: Arduino Nano Tools / Processor: ATmega 328 or ATmega 328P (Old Bootloader) Tools / Port: Port with Arduino

slide-20
SLIDE 20

Select Program From Sketchbook

20 Arduino Install Information

slide-21
SLIDE 21

Verify with Blink Example

21

File / Examples / 01.Basics / Blink Select the Upload Button Watch for LED to blink slowly Change delay times Upload again

Arduino: Controlling the Wild LED Strips!

slide-22
SLIDE 22

Blink - Everyone’s first program

void setup() { pinMode(LED_BUILTIN, OUTPUT); } void loop() { digitalWrite(LED_BUILTIN, HIGH); delay(1000); digitalWrite(LED_BUILTIN, LOW); delay(1000); }

Program: File / Examples / 01.Digital / Blink

22

slide-23
SLIDE 23

Blink an LED

23

Add an LED, resistor and two wires to light LED when D13 is high. Anode to the left. Run Blink.

Arduino: Controlling the Wild LED Strips!

slide-24
SLIDE 24

Light Two LEDs Alternately

24

Add an LED, resistor and two wires to light LED when D13 is high. Anode to the left. Run Blink.

Arduino: Controlling the Wild LED Strips!

Add a second LED, resistor and two wires to light second LED when D13 is low. Anode to the right. Run Blink.

slide-25
SLIDE 25

Short Lab Time for Installation and Verification

25 Arduino: Controlling the Wild LED Strips!

NTP clock to be used in Arduino: Using I2C LCD Displays class.

slide-26
SLIDE 26

Can You Fade an LED?

26

File/ Examples / 02.Analog / Fading Using the previous circuit, move the jumper from D13 to D9. This uses Pulse Width Modulation (PWM) to make the LED appear to dim. Only pins 3, 5, 6, 9, 10 and 11 will do PWM. Program: File / Examples / 03.Analog / Fading

https://www.arduino.cc/en/Tutorial/PWM

Arduino: Controlling the Wild LED Strips!

slide-27
SLIDE 27

WS2812B RGB LED Strips

27

This class uses WS2812B aka Adafruit Neopixels Options:

  • LEDs/meter: 30, 60, 144
  • Background: black, white
  • Length: 1 meter (39 inches),

5 meters (16 feet)

  • Waterproof: Silicon coating,

Silicon tube, none

  • Voltage: 5 volts

Arduino: Controlling the Wild LED Strips!

slide-28
SLIDE 28

WS2812B 5050 RGB LED Strips

28 Arduino: Controlling the Wild LED Strips!

slide-29
SLIDE 29

Walk on the Safe Side

They say that LEDs use very little power. While that is true, these are very bright and the USB can supply a limited amount

  • f current. One of these on maximum white brightness (255)

needs 60mA (0.06 amp). Ten require 600mA (0.6 amp) which exceeds available power on many USB ports. Example programs are set to a brightness level of 10. It is safe to increase this to 50. 36 white LEDs at brightness 50 require less than 500mA which is safe. You are on your own to increase power beyond 50. My parts are not at risk. Your USB ports may be. USB ports have a “self resettable” fuse but I do not care to test it.

29 Arduino: Controlling the Wild LED Strips!

slide-30
SLIDE 30

Dim - Dull - Boring

Example programs are configured to be unexciting so that you can Crank It Up! Increase NUM_LEDS up to 36. Increase brightness value to 50. Speed it up! Reduce delay () times to speed things up of some programs.

30 Arduino: Controlling the Wild LED Strips!

slide-31
SLIDE 31

Example Code : Simple (1/2)

#define NUM_LEDS 5 int brightness = 5; int delay_time = 500; #include <FastLED.h> #define DATA_PIN 3 // Arduino pin D3 CRGB leds[NUM_LEDS]; void setup() { FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); LEDS.setBrightness(brightness); }

31 Arduino: Controlling the Wild LED Strips!

slide-32
SLIDE 32

Example Code : Simple (2/2)

void loop() { for (int i=0; i <NUM_LEDS; i++) { leds[i] = CRGB::Green; FastLED.show(); delay(delay_time); } for (int i=NUM_LEDS-1; i!= -1; i--) { leds[i] = CRGB::Black; FastLED.show(); delay(delay_time); } }

32 Arduino: Controlling the Wild LED Strips!

slide-33
SLIDE 33

Colors

http://fastled.io/docs/3.1/group___pixeltypes.html

AliceBlue =0xF0F8FF, Amethyst =0x9966CC, AntiqueWhite =0xFAEBD7, Aqua =0x00FFFF, Aquamarine =0x7FFFD4, Azure =0xF0FFFF, Beige =0xF5F5DC, Bisque =0xFFE4C4, Black =0x000000, BlanchedAlmond =0xFFEBCD, Blue =0x0000FF, BlueViolet =0x8A2BE2, Brown =0xA52A2A, BurlyWood =0xDEB887, CadetBlue =0x5F9EA0, Chartreuse =0x7FFF00, Chocolate =0xD2691E, Coral =0xFF7F50, CornflowerBlue =0x6495ED, Cornsilk =0xFFF8DC, Crimson =0xDC143C, Cyan =0x00FFFF, DarkBlue =0x00008B, DarkCyan =0x008B8B, DarkGoldenrod =0xB8860B, DarkGray =0xA9A9A9, DarkGrey =0xA9A9A9, DarkGreen =0x006400, DarkKhaki =0xBDB76B, DarkMagenta =0x8B008B, DarkOliveGreen =0x556B2F, DarkOrange =0xFF8C00, DarkOrchid =0x9932CC, DarkRed =0x8B0000, DarkSalmon =0xE9967A, DarkSeaGreen =0x8FBC8F, DarkSlateBlue =0x483D8B, DarkSlateGray =0x2F4F4F, DarkSlateGrey =0x2F4F4F, DarkTurquoise =0x00CED1, DarkViolet =0x9400D3, DeepPink =0xFF1493, DeepSkyBlue =0x00BFFF, DimGrey =0x696969, DodgerBlue =0x1E90FF, FireBrick =0xB22222, FloralWhite =0xFFFAF0, ForestGreen =0x228B22, Fuchsia =0xFF00FF, Gainsboro =0xDCDCDC, GhostWhite =0xF8F8FF, Gold =0xFFD700, Goldenrod =0xDAA520, Gray =0x808080, Green =0x008000, GreenYellow =0xADFF2F, Honeydew =0xF0FFF0, HotPink =0xFF69B4,

33 Arduino: Controlling the Wild LED Strips!

slide-34
SLIDE 34

What is a Potentiometer, a.k.a. pot?

A potentiometer is a three- terminal resistor with a sliding or rotating contact that forms an adjustable voltage divider.

34

slide-35
SLIDE 35

Potentiometer (Pot) Program

void loop() { sensorValue = analogRead(sensorPin); newLED = map(sensorValue,0, 1023, 0, NUM_LEDS-1); if (newLED != oldLED) { leds[oldLED] = CRGB::Black; FastLED.show(); leds[newLED] = CRGB::Red; FastLED.show(); Serial.println();

  • ldLED = newLED;

} } Connect a pot with the center pin to A4 and outer pins to 5V and GND. Turn knob to control LEDs.

35 Arduino: Controlling the Wild LED Strips!

slide-36
SLIDE 36

Wire Up the Strips

36

  • 1. Connect +5V to 5V on Nano
  • 2. Connect Din to D3 on Nano
  • 3. Connect GND to GND on Nano

Arduino: Controlling the Wild LED Strips!

slide-37
SLIDE 37

Run example programs in File / Sketchbook / class_strips

  • Simple_2
  • Pot
  • test_rgb_color
  • TheatreChase
  • RGBSetDemo
  • Blink
  • Ceylon
  • ColorTemperature
  • DemoReel100
  • Fire2012WithPalette
  • Sunflower

37 Arduino: Controlling the Wild LED Strips!

slide-38
SLIDE 38

Other Example Programs

38 Arduino: Controlling the Wild LED Strips!

Other example programs are available on the web and at the following location but be careful. Many USB ports can

  • nly supply 500mA (0.5A) and can be damaged by too

much load. Most such programs assume you are using a power supply. File / Examples / FastLED / … For example, ten LEDs on full brightness White requires 600mA (0.6) which exceeds specifications for some USB ports. Each “LED” of the strip actually includes an LED for each of the three colors and requires 60mA for max White. To be safe, calculate current required and use an appropriate power supply.

slide-39
SLIDE 39

Resources

External Power Supply Connection

39 Arduino: Controlling the Wild LED Strips!

slide-40
SLIDE 40

Resources

  • What if red and green are reversed?

https://forum.arduino.cc/index.php?topic=511446.msg348 7058#msg3487058

  • Build a Times Square sign

https://wp.josh.com/2016/05/20/huge-scrolling-arduino- led-sign/

  • http://www.pamplin.com/sign/

Contact me for updates if interested: @bpamplin

  • Andreas Spiess - guy with Swiss accent

https://www.youtube.com/channel/UCu7_D0o48KbfhpEo hoP7YSQ/videos

40 Arduino: Controlling the Wild LED Strips!

slide-41
SLIDE 41

End of Class Material

41 Arduino: Controlling the Wild LED Strips!