Di Digi gital and Analog
- g Si
Sign gnals
Chaipo Chaiporn J n Jaik aikae aeo De Department of f Computer Engineering Ka Kasetsart Unive versity
01219335 Data Acquisition and Integration
Revised 2020-08-26
Di Digi gital and Analog og Si Sign gnals 01219335 Data - - PowerPoint PPT Presentation
Di Digi gital and Analog og Si Sign gnals 01219335 Data Acquisition and Integration Chaipo Chaiporn J n Jaik aikae aeo De Department of f Computer Engineering Ka Kasetsart Unive versity Revised 2020-08-26 Ou Outline Digital
Revised 2020-08-26
2
3
Cliparts are taken from http://openclipart.org and http://clipart-library.com
4
value time value time
5
sound wave electrical signal electrical signal sound wave
6
7
Microcontroller 3.3V
Microcontroller
Microcontroller 3.3V
input
8
https://www.makerlab-electronics.com
9
Microcontroller 3.3V
Microcontroller
Turning on LED by setting the pin’s logic to 1 Turning on LED by setting the pin’s logic to 0 Pin’s output logic Pin’s voltage 0V 1 3.3V
10
KidBright's Schematic provided by INEX
11
from machine import Pin # make pin 2 and 12 OUTPUT, # refer to them as 'led_red' and 'led_green' led_red = Pin(2, Pin.OUT) led_green = Pin(12, Pin.OUT) # set pin 2’s voltage to 0V (Red LED on) led_red.value(0) # set pin 12’s voltage to 0V (Green LED on) led_green.value(0)
12
Pin’s voltage Pin’s input logic Switch is released 3.3V 1 Switch is pressed 0V
3.3V internal pull-up resistor
13
KidBright's Schematic provided by INEX
14
from machine import Pin from time import sleep # make pin 16 an INPUT pin with pull-up enabled; # refer to it as 'sw1' sw1 = Pin(16, Pin.IN, Pin.PULL_UP) while True: # read and print out the switch value print("S1 value =", sw1.value()) # delay a little to slow down screen output sleep(0.1)
15
(Image by Hebi B. from Pixabay)
16
(Image by Francis Ray from Pixabay)
17
1 15
0V 3.3V
0V 3.3V 1
18
3-bit resolution (8 levels) 4-bit resolution (16 levels) 8-bit resolution (256 levels)
19
https://randomnerdtutorials.com/esp32-pinout-reference-gpios/
20
from machine import Pin, ADC from time import sleep ain = ADC(Pin(34)) while True: print(ain.read()) sleep(0.1)
21
22
KidBright's Schematic provided by INEX
23
24
Light-Dependent Resistor (LDR)
R1 VA
! = 3.3×
25
26
DAC pin PWM pin
27
Analog data PWM output 25% duty cycle 50% duty cycle 75% duty cycle
https://en.wikipedia.org/wiki/Pulse-width_modulation
28
KidBright's Schematic provided by INEX
29
from machine import Pin, PWM from time import sleep led_red = PWM(Pin(2),freq=5000) while True: for d in range(0,1024): led_red.duty(d) sleep(0.001) for d in range(1023,-1,-1): led_red.duty(d) sleep(0.001)
30
(Images from http://clipart-library.com )
31