Difference: LEDAndNeopixels (1 vs. 7)

Revision 72021-03-09 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="Slides"

Start Presentation

Lecture 2: LEDs and NeoPixel

CSC 321: Embedded Sysytem

First Semester 2020/2021

Line: 199 to 199
 pwmImpl.png

Changed:
<
<

The WS2812B LED

>
>

The WS2812B LED

  A more complex LED:

  • rgb LED used in LED chains.

Revision 62021-03-05 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="Slides"

Start Presentation

Changed:
<
<

Lecture 2: LEDs and NeoPixel

CSC 321: Embedded Sysytem

First Semeter 2020/2021

>
>

Lecture 2: LEDs and NeoPixel

CSC 321: Embedded Sysytem

First Semester 2020/2021

 

The ESP32-WROVER-B MCU

Revision 52021-03-02 - IsaacArmahMensah

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="Slides"

Start Presentation

Lecture 2: LEDs and NeoPixel

CSC 321: Embedded Sysytem

First Semeter 2020/2021

 
Added:
>
>

The ESP32-WROVER-B MCU

esp32board.jpg esp32boardlab.jpeg

CPU Pinout

esp32board.png

Please note: The pin numbers IOxx on the ESP32 correspond to the GPIO pin numbers

Datasheet: https:// www.espressif.com /sites/default/files/documentation/esp32-wrover-b_datasheet_en.pdf

Meaning of pins on ESP32

pinout.jpg pinout3.png



How to program the processor

connect.png Several development tools are available:
  • ESP_IDF: The official Espressif development tool.
    Includes a gcc compiler for the ESP8266 and the ESP32

Please see:
https://docs.espressif.com/projects/esp-idf/en/latest

  • The Arduino IDE
    Needs extensions for these processors
    and the different CPU boards

see:

https://docs.espressif.com/projects/esp-idf/en/latest

  • MicroPython

see:
https://micropython-docs-esp32.readthedocs.io/en/esp32_doc

Flashing the code

esptool.png

esptool

  • esptool is called from the Makefiles in ESP-IDF
  • esptool is used when we upload code from the Arduino IDE to the processor flash
  • esptool is used with Micropython IDE on uPyCraft/Thonny

    installs Micropython onto the processor flash
In the above cases the use of esptool is hidden to us.

We can however also execute esptool directly.

How to write a Micropython program?

First we need a Micropython interpreter!

You find the sources here:

https://github.com/micropython/micropython/

In the repository you find ports for the ESP8266 and the ESP32.

In order to compile the code you need the ESP-IDF and its cross compilers

The code compiles into a binary file (firmware-combined.bin) which contains a boot loader and the interpreter.

This binary must be uploaded and flashed.

For documentation of the ESP32port of Micropython look at

http://docs.micropython.org/en/latest/esp32/tutorial/intro.html

How to communicate with the Micropython interpreter?

We use a serial connection passing through the micro USB connection.

As soon as we connect the processor card to the PC we see the serial port to connect for communication

interpret.png

What is REPL?

repl.png

The communication tools: minicom

minicom.png

You see the command prompt and you can interact with Micropython.

But … how to upload scripts?

The command line tool ampy

MPY1.png

IDE for Micropython: uPyCraft

uPyCraft.png

Thonny

thonny.png

Thonny

Thonny is a complete Integrate Development Environment (IDE)

which lets you

  • Access the REPL

  • Create directories on the Micropython file system

  • Upload scripts

  • Syntax check scripts

  • Run scripts

  • Install Micropython on your processor board

Thonny

Thonny is an IDE for Python which has provisions for Micropython.

Under Tools → Options button you can select the type of

Python interpreter you intend to use.

interpret.png

Flashing Micropython

Compiling a new version of Micropython is substantially much easier with Thonny.

You still need to install esptool first. You just select your port and firmware then install.

flashing.png

IoT Hello World program

A “Hello World” program, just printing “Hello World” on the screen

does not look very exciting.

However, this is generally used to verify that the infrastructure

Compiler, linker, downloader, flash program

are working correctly

In embedded systems printing can be quite complex

and a blinking LED is used instead.

Switching on and off a LED

The ESP32-WROVER-B have a “user LED” connected to GPIO 19.

How do we control this LED?

  • Define that the LED is connected to GPIO 19

  • Program this pin as output

  • Write a logic 1 to the pin to switch it on

  • Write a logic 0 to the pin to switch it off

  • The logic state may be inverted if the LED is active low

Micropython hardware functions

hardwareFunctions.png

The machine.Pin class

pinClass.png

Switch the LED on, version 1

ledControl1.png

Switch the LED on, version 2

ledControl2.png

The blinking LED

Now we put the code into a script and run it

blinkingLed.png

Changing the light intensity

The LED is connected to a digital line which can only be set to 0 or Vcc.

How can we change the light intensity and dim the LED?

The light intensity depends on the average current flowing through the LED.

The answer is PWM: pulse width modulation.

pwm.png

PWM in Micropython

pwm_uP.png

Our PWM implementation

pwmImpl.png

The WS2812B LED

A more complex LED:

  • rgb LED used in LED chains.

  • each ws18b12 contains the 3 colored LEDs and a controller.

  • Can be cascaded and individually addressed, depending on its position in the chain

  • Needs precise timing

  • To use it we pass through the neopixel library built into micropython

WS2812B timing

For all the details on the ws2812b look at

https://cdn-shop.adafruit.com/datasheets/WS2812B.pdf

24 bit of colour data puts 2e24 colours at your disposal

Coding of a single bit

ws2812Bits.png

The control word:

ws2812ControlWord.png

Cascading the WS2812B

ws2812Chain.png

Using the neopixel library

neopixel.png

… and our code

We have a single neopixel connected to

GPIO pin 4 (ESP8266)

or

GPIO pin 21 (ESP32)

This code works on both CPUs!

neopixelCode.png

%SLIDESHOWEND%

-- Isaac Armah-Mensah - 2021-02-28

Comments


<--/commentPlugin-->
 
META FILEATTACHMENT attachment="esp32board.png" attr="" comment="" date="1614475713" name="esp32board.png" path="esp32board.png" size="2146189" user="IsaacArmahMensah" version="1"
META FILEATTACHMENT attachment="pinout.jpg" attr="h" comment="" date="1614475813" name="pinout.jpg" path="pinout.jpg" size="134789" user="IsaacArmahMensah" version="1"
Line: 13 to 271
 
META FILEATTACHMENT attachment="connect.png" attr="h" comment="" date="1614644822" name="connect.png" path="connect.png" size="3213513" user="IsaacArmahMensah" version="1"
META FILEATTACHMENT attachment="interpretor.png" attr="h" comment="" date="1614645577" name="interpretor.png" path="interpretor.png" size="94026" user="IsaacArmahMensah" version="1"
META FILEATTACHMENT attachment="interpret.png" attr="" comment="" date="1614645765" name="interpret.png" path="interpret.png" size="107517" user="IsaacArmahMensah" version="1"
Added:
>
>
META FILEATTACHMENT attachment="MPY1.png" attr="" comment="" date="1614673213" name="MPY1.png" path="MPY1.png" size="433176" user="IsaacArmahMensah" version="1"
META FILEATTACHMENT attachment="flashing.png" attr="h" comment="" date="1614673424" name="flashing.png" path="flashing.png" size="919856" user="IsaacArmahMensah" version="1"

Revision 42021-03-02 - IsaacArmahMensah

Line: 1 to 1
 

META FILEATTACHMENT attachment="esp32board.png" attr="" comment="" date="1614475713" name="esp32board.png" path="esp32board.png" size="2146189" user="IsaacArmahMensah" version="1"
Line: 8 to 8
 
META FILEATTACHMENT attachment="esp32-pinout-chip-ESP-WROOM-32.png" attr="h" comment="" date="1614509058" name="esp32-pinout-chip-ESP-WROOM-32.png" path="esp32-pinout-chip-ESP-WROOM-32.png" size="140701" user="IsaacArmahMensah" version="1"
META FILEATTACHMENT attachment="esp32cpu.jpg" attr="h" comment="" date="1614509745" name="esp32cpu.jpg" path="esp32cpu.jpg" size="90252" user="IsaacArmahMensah" version="1"
META FILEATTACHMENT attachment="esptool.png" attr="" comment="" date="1614528073" name="esptool.png" path="esptool.png" size="394262" user="IsaacArmahMensah" version="2"
Added:
>
>
META FILEATTACHMENT attachment="esp32board.jpg" attr="" comment="" date="1614644435" name="esp32board.jpg" path="esp32board.jpg" size="286559" user="IsaacArmahMensah" version="1"
META FILEATTACHMENT attachment="esp32boardlab.jpeg" attr="h" comment="" date="1614644444" name="esp32boardlab.jpeg" path="esp32boardlab.jpeg" size="25707" user="IsaacArmahMensah" version="1"
META FILEATTACHMENT attachment="connect.png" attr="h" comment="" date="1614644822" name="connect.png" path="connect.png" size="3213513" user="IsaacArmahMensah" version="1"
META FILEATTACHMENT attachment="interpretor.png" attr="h" comment="" date="1614645577" name="interpretor.png" path="interpretor.png" size="94026" user="IsaacArmahMensah" version="1"
META FILEATTACHMENT attachment="interpret.png" attr="" comment="" date="1614645765" name="interpret.png" path="interpret.png" size="107517" user="IsaacArmahMensah" version="1"

Revision 32021-02-28 - IsaacArmahMensah

Line: 1 to 1
 

META FILEATTACHMENT attachment="esp32board.png" attr="" comment="" date="1614475713" name="esp32board.png" path="esp32board.png" size="2146189" user="IsaacArmahMensah" version="1"
Line: 7 to 7
 
META FILEATTACHMENT attachment="pinout2.jpg" attr="h" comment="" date="1614475869" name="pinout2.jpg" path="pinout2.jpg" size="145958" user="IsaacArmahMensah" version="1"
META FILEATTACHMENT attachment="esp32-pinout-chip-ESP-WROOM-32.png" attr="h" comment="" date="1614509058" name="esp32-pinout-chip-ESP-WROOM-32.png" path="esp32-pinout-chip-ESP-WROOM-32.png" size="140701" user="IsaacArmahMensah" version="1"
META FILEATTACHMENT attachment="esp32cpu.jpg" attr="h" comment="" date="1614509745" name="esp32cpu.jpg" path="esp32cpu.jpg" size="90252" user="IsaacArmahMensah" version="1"
Changed:
<
<
META FILEATTACHMENT attachment="esptool.png" attr="" comment="" date="1614511249" name="esptool.png" path="esptool.png" size="373980" user="IsaacArmahMensah" version="1"
>
>
META FILEATTACHMENT attachment="esptool.png" attr="" comment="" date="1614528073" name="esptool.png" path="esptool.png" size="394262" user="IsaacArmahMensah" version="2"

Revision 22021-02-28 - IsaacArmahMensah

Line: 1 to 1
 

META FILEATTACHMENT attachment="esp32board.png" attr="" comment="" date="1614475713" name="esp32board.png" path="esp32board.png" size="2146189" user="IsaacArmahMensah" version="1"
META FILEATTACHMENT attachment="pinout.jpg" attr="h" comment="" date="1614475813" name="pinout.jpg" path="pinout.jpg" size="134789" user="IsaacArmahMensah" version="1"
META FILEATTACHMENT attachment="pinout3.png" attr="h" comment="" date="1614475860" name="pinout3.png" path="pinout3.png" size="725586" user="IsaacArmahMensah" version="1"
META FILEATTACHMENT attachment="pinout2.jpg" attr="h" comment="" date="1614475869" name="pinout2.jpg" path="pinout2.jpg" size="145958" user="IsaacArmahMensah" version="1"
Added:
>
>
META FILEATTACHMENT attachment="esp32-pinout-chip-ESP-WROOM-32.png" attr="h" comment="" date="1614509058" name="esp32-pinout-chip-ESP-WROOM-32.png" path="esp32-pinout-chip-ESP-WROOM-32.png" size="140701" user="IsaacArmahMensah" version="1"
META FILEATTACHMENT attachment="esp32cpu.jpg" attr="h" comment="" date="1614509745" name="esp32cpu.jpg" path="esp32cpu.jpg" size="90252" user="IsaacArmahMensah" version="1"
META FILEATTACHMENT attachment="esptool.png" attr="" comment="" date="1614511249" name="esptool.png" path="esptool.png" size="373980" user="IsaacArmahMensah" version="1"

Revision 12021-02-28 - IsaacArmahMensah

Line: 1 to 1
Added:
>
>

META FILEATTACHMENT attachment="esp32board.png" attr="" comment="" date="1614475713" name="esp32board.png" path="esp32board.png" size="2146189" user="IsaacArmahMensah" version="1"
META FILEATTACHMENT attachment="pinout.jpg" attr="h" comment="" date="1614475813" name="pinout.jpg" path="pinout.jpg" size="134789" user="IsaacArmahMensah" version="1"
META FILEATTACHMENT attachment="pinout3.png" attr="h" comment="" date="1614475860" name="pinout3.png" path="pinout3.png" size="725586" user="IsaacArmahMensah" version="1"
META FILEATTACHMENT attachment="pinout2.jpg" attr="h" comment="" date="1614475869" name="pinout2.jpg" path="pinout2.jpg" size="145958" user="IsaacArmahMensah" version="1"
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback