3 TcHxW6S6 k3B8VuouvuA Mod2 Devices QC Whiteoutsremoved Mar 2021
3 TcHxW6S6 k3B8VuouvuA Mod2 Devices QC Whiteoutsremoved Mar 2021
Module 2: Devices
UNIVERSITY OF ILLINOIS AT URBANA-CHAMPAIGN
You Need to Build…
• Flyover drone to analyze crops
• Intelligent smartwatch
• This lecture: What You Need to Know to Build IoT Hardware Systems
• Electricity Fundamentals, IoT Circuits, Microcontroller Platforms
Background: Atoms
• Made of protons,
neutrons, and
electrons
• In materials, nucleus +
n
held in fixed position -
n
+ + n -
• Some electrons are +
also fixed
• But some electrons
may be free to
“move”
Background: Electrical Current
• Usually free electrons hop around randomly
• However, outside forces can encourage them to flow in a particular direction
• Magnetic field, charge differential this is called current
• We can vary properties of current to transmit information (via waves, like dominos, as
electron drift velocities are very slow)
_ +
Voltage (V)
Water
Pump Pressure
Resistor
Resistance Constriction Resistance
(R) (R)
Water Analogy: Capacitance
Flow Rate (I) Current (I)
Pipe
Voltage (V)
Expansion
Water
Pump Bladder
Pressure Capacitance
Capacitance
(C) (C)
Capacitor
Electrical Components
Photocell Crystal
Oscillator
Light-Emitting DC Fan Speaker
Diode (LED)
Electric
Resistor M
Motor
Capacitor Speaker
Voltage
Diode
Source
Transistor Switch
Electrical
Oscillator
Ground
• Indicator/status signals
• User interfaces and displays
• Illumination sources
• Light effects
Components that make light
Optical Audio
LED (green) TFT Display Transmitter
7-Segment
Display Laser Diode Light to
Red/Green TFT Display
Frequency
Bi-color LED Light Pipe Converter
LED Sequin
Infrared LED
4-Digit
Infrared 7-Segment LED Dot Matrix Optical Audio
Phototransistor Display Display Backlight Module LED Strip LCD Display Transmitter
Suppose you want to build…
something that needs electricity
• Operate for long periods of time without
management
• Move around without being plugged in
• Collect energy from environment
• Supply electricity to other devices
• Change voltage from one level to
another
• Protect against voltage spikes, electronic
noise, and static electricity
Electrical power sources
Energy Harvesting
Batteries
AA battery
AA battery holder Motor/Generator Piezoelectric
[motion] generator
[vibration]
C battery
9V battery snap 9VDC 2.1mm wall
USB to TTL serial cable
adapter
Antenna/
Thermoelectric
Rectenna
generator
[radio waves]
[heat]
9V battery
9V battery holder
Ball generator
1.5V
1800 mAh
Circuit
(Ball Consumer)
1.5V
1800 mAh
Components that change voltage levels
Orange 3 x1K
Useful for:
• Temporarily holding some
–––– charge (like a tiny battery)
++++
Capacitor • Smoothing out voltage
spikes
• Measurement (humidity,
Example Circuit: Storing Charge in a Capacitor
pressure, touch sensors)
Capacitors Key metrics:
• Capacitance: how much charge it can
store (farads)
• Tolerance: how accurate their
plates capacitance rating is (%)
+ -
+ - • Maximum voltage: how much voltage
+ - they can handle (before they short out or
+ - burn up)
• Leakage current: amount of current that
leaks through dielectric
dielectric
Motor
Flyback
D1
Useful for:
R1
Diode
CONTROL Q1 • Reverse current protection
• “Rectifying” signals
Example Circuit: Preventing Current
(pulling out positive parts)
“Kickback” with a Flyback Diode • Converting AC to DC
• Measurement
(temperature, radiation)
Diode
Key metrics:
• Maximum forward current: how
Forward
Current much current can go through in the
forward direction (amps)
Current
Audio recording
Microphone
Converts sound into electrical signal Speech recognition/Wake phrase
(sound)
Echolocation
Presence/arrival detection
Weight measurement
Load Cell Measures force/weight Impact measurement
Mechanical strain detection
Sensors
Picture Sensor name What it detects Example Applications
Industrial process monitoring
Measure flow rate (and thereby volume) Farming (eg. water/pesticide applications)
Flow Sensor
of gas or fluids Water/gas meters
“Green building” resource usage
• Next, we will go through some that are helpful to know for IoT
projects
• Build intuition, use these when you need them
Six Useful Circuits to Know About
Widely used, demonstrate useful concepts:
1. Current-Limiting Resistor
2. Voltage Shifter
3. Filter Capacitor
4. Pull-Down Resistor
5. Signal Amplifier
6. Transistor Switch
1. Protecting against Current Overload
(Resistors)
Current 100
Forward
If - Forward current - mA
Current
80
R1
60 Vs
Breakdown
Voltage 40 Vf
Voltage
Forward
Voltage
20 LED
VI VO Vout
0.33µF 0.1 µF
GND
5
U1
C C
10 10
GND
Switch
Vout
Logic Gate
Vout (buffer)
Ground
R1 5.6kΩ C1
Vin
5V pin 22 pF 3.3V pin
Vout
R1
1 kΩ
R2
R2
2 kΩ
V2
Rf Rin Rf
Rin
Vout Rf Vout Rf Rf Rf Rf Rf
A= = A= = 1+ Vout = (V2 – V1) Vout = — V1 + V2 + V3
Vin Rin Vin Rin Rin Rin R2 R3
4 7 Si 3 2
2
6 4
5
3
Si
Si Si
Undoped Semiconductors
Are Insulators B
Si Si P
Si
Si Si Si Si Si
Si Si Si Si Si
Si Si Si Si Si
Doping with Boron
B
Si Si P
Si
Si Si Si B Si
Si B Si Si Si
Si Si B Si B
Doping with Phosphorus
B
Si Si P
Si
Si Si P P Si
Si P Si Si Si
P Si P Si P
How to “Print” Components
base +
Glass
Mask
emitter base collector emitter base collector
Photoresist
Silicon dioxide
n+ n+ p+ p+
P-type silicon n-well
CMOS (technology)
Integrated Circuit Packaging
Small-Outline IC (SOIC)
SN74S08N (DIP)
Pinouts
Logic Diagram
Schematic (each AND gate)
• Datasheet: https://www.ti.com/lit/ds/symlink/sn74ls08.pdf
• Google “SN74S08N datasheet”
• Price: $1.61 for one, $0.65 each for 5000 (Digikey.com, January 2019)
Popular IC Types
IC Alternatives/
Type Pinout Logic diagram What it does
family Variants
Accepts input voltage within a certain range and 78xxSR, 78xxC, 78xxS, 79xx,
Voltage produces a constant output voltage. xx represents LM317, LM2575T-ADJ
78xx
Regulator voltage regulated by chip (e.g., 7805 produces a (output adjustable 1.23V to
5-volt output) 37V), MC34063A, XL6009
MCP23017, MCP
I/O Change one serial input to 8 pins of parallel
MCP23008 23016 (16-bit),
Expander output. Adds 8 pins to your microcontroller.
SX1509, TCA9535
0V
Cycle 1 2 3 4 5 6 7 8 9 10 11 12 13
Data
Wait a bit for the bit to arrive, Hold line high long enough
then send clock pulse to distinguish it from noise
Data
Clock
Sender Receiver
clock clock
Phase Locked Loop
It’s a 1
Undetermined
It’s a 0
It’s a 1
Undetermined
It’s a 0
Data
Clock
Sender Receiver
clock clock
Phase Locked Loop
0V
idle start stop idle
0V
idle start stop idle
0101110010100000000000000000000000000001110101100110
What if we disallow 0000?
0101 1100 1010 0000 0000 0000 0000 0000 0000 0001 1101 0110 0110
01011 11001 10101 00001 00001 00001 00001 00001 00001 00011 11011 01101 01101
01011110011010100001000010000100001000010000100011110110110101101
• Codewords
• At most one leading 0, at most two trailing 0s
• Never more than three consecutive 0s
• Transmit with NRZI
Better Approach: 4B/5B
(Choose Codewords Smarter)
• 16 of 32 possible codes used for data, others used for
command characters
• Ensures at least two transitions for each code
• Variants
• 8B/10B (used in digital audio – compact discs, DAT tapes,
etc.)
• 64B/66B (used in 10Gig Ethernet)
• 128B/130B, 128B/132B (used in PCI Express 3.0 and USB 3.1)
4B/5B Encoding Table At most two trailing zeros
• Between chips on a PCB you care more about low power and
cost
• Simpler techniques, easier to run shared clock lines everywhere
• See more asynchronous, clocked encodings, etc.
Connecting ICs with the I2C Protocol
Vcc
SDA
SCL
• Easy to use, very expandable, serial bus widely used to connect ICs
• Reduces pinouts, transfers data/commands
• Address-oriented scheme, where addresses are part of packets that you send
• Handles many devices; each device has an address (can solder jumpers to change address)
• Message-based communication (unlimited length), 0.1-5Mbps, synchronous
• Multi-master/Multi-slave architecture: master generates clock, initiates
communications
Other Kinds of Buses
• Serial Peripheral Interface (SPI)
• Max # devices very limited (chip-select for each chip on the bus)
• Significantly faster than I2C (25Mbps), works over longer cable runs
• Used for, eg. Connecting microcontroller to SD/microSD card
• UART (RS-232/422/485/etc., aka Serial Port)
• Asynchronous (no shared clock)
• Parameters: baudRate, parity, stopBits, dataBits (e.g., 115200, none, 1, 8)
• Max speed 8Mbps
• GPIO
• Not really a protocol – turning pins on and off, defines threshold voltages
• Used for switches, buttons, motion detectors, LEDs, turning on/off appliances
• Max speed 1kHz
Example Breakout Boards
Internal Other boards in this
Type Name Picture What it does
Components category
Takes in logic input and uses that to control a higher-
Allegro amp input for driving a stepper motor. Includes
A4988 current limiting, short-circuit/over-current/over- Clock generators, Audio FX
Actuator Stepper temperature protection. Operates from 8-35V and A4988 IC sound boards,
Motor supports up to 1A without cooling (2A with sufficient storage/microSD, NVRAM
Driver additional cooling). Five different resolutions (full, half,
quarter, 1/8, 1/16).
Nokia 6100 color LCD,
SparkFun
Uses logic input to write graphics onto and control Philips PCF8833 LED matrix backpacks, LED
Color LCD
Display backlight of color LCD display. Display is 132x132 graphics controller, strip controllers, LCD displays,
Breakout
pixels @12 bit color, same display from cell phones. status LEDs, two touchscreen controllers
Board
pushbuttons.
Other types of USB (microB,
SparkFun Splits out female USB type A connector’s VCC, D-, D+,
C, etc), audio connectors,
USB Type A and GND pins to a standard 0.1”-width header. Good USB Type A female
Connector HDMI/DVI coders, USB
Female if you need USB but don’t want to deal with soldering connector
mouse/keyboard controller
Breakout tiny connectors.
Wireless 802.11/LoRA/etc.
Adafruit
MEMS sensor breakout to monitor levels of various Sensors for Oxygen, CO2,
MiCS5524
sorts of gases. Useful for indoor carbon monoxide methane, PM2.5/PM10,
CO, Alcohol SGX NICS-5524 gas
Sensor and natural gas leakage, alcohol breath checker, early humidity, barometric/altitude,
and VOC sensor
fire detection. Sensitive to 1-1000ppm. Can’t tell you windspeed, temperature,
Gas Sensor
which gas it has detected. human breath analysis
Breakout
What if we want to build something
flexible?
• Circuits are good for very specific, single-purpose
functions
• Increase voltage from 3.3V to 5V, drive a motor, etc.
I3
I2
I0
I1
I4
I7
I5
I6
Please become a Pins
C0
circuit that raises C1 Amplify
Add pinspin
1-47,
Raise/lower pin 5
and lowers pin 5 C2 send to
and a5-8
20x pin 4
second
twenty times a C3
second
O3
O2
O0
O1
O4
O7
O5
O6
Please become a
circuit that amplifies Output Pins
the signal on pin 7
1101
and sends it to pin 4
VCC
CPU
D0
D1
D2
a
D3 a e
D4 b f
f b
D5 c g g
d dp
D6
D7
Gnd e c Vcc
D8 d
dp
D9
D10
D11
D13
D13
GND
VCC
CPU
D0
D1
D2
a
Program Counter 1. Write D, 00000000 D3 a e
2. Write D, 01101110 D4 b f
f b
3. Write D, 10011110 D5 c g g
d dp
4. Write D, 10001100 D6
D7
Gnd e c Vcc
5. Write D, 01101110
D8 d
6. Write D, 11111100
dp
D9
7. Write D, 00000000
D10
D11
D13
OSC1 D13
GND
Opcode [Operand] Instruction Memory
0001 [address] add Instruction memory
0010 [address] subtract Address Value
2. Consolidated design
• Memory, oscillator, I/O controllers,
watchdog timers, are within chipset
3. Special on-chip functions
(peripherals)
(b) Microcontroller
• Package availability
• Wafer-level CSP package that’s 2x2mm? Larger DIP package?
How to Choose a Microcontroller
• Peripherals: multiple interrupt channels, DMA, internal clocks,
power configuration control options, etc.
• Development experience:
• What kinds of IDEs/SDKs/compilers/emulators/dev boards/debuggers
are available? How much do they cost? Are they cross-platform?
MICROCHIP PIC
• RISC design. 4T machine - 4 cycles fetch (plus 4 cycles execute)
• Strengths: many peripherals, historically very popular
• Downsides: only one register, no stack, lower-end chips have no on-
chip debugging support, slow flash-load times. Falling out of favor for
Microchip PIC16 Microchip PIC24 students/hobbyists.
(lower-end) (higher-end) • PIC32 uses 3rd party core (MIPS M4K)
• Example chips: PIC10, PIC12, PIC16, PIC18, PIC24, PIC32
Popular Microcontroller Cores
ARM Cortex-M0
• 32-bit RISC. Entry level to ARM architecture. Rapidly gaining market
share in <$1 market
• Strengths: 32 interrupt vectors, 4 interrupt priorities, full support for
runtime exceptions. 13 registers.
• Downsides: low code density, lack of compatibility across vendor
peripherals, complex peripherals, slow (12 cycle) interrupt latency
ATMEL SAM D10 Infineon XMC
• Example chips: Infineon XMC-1100, Cypress PSOC 4000S
INTEL 8051
• Variable-length CISC instruction set, 32 registers, 2 interrupt
priorities, 64KB program/RAM addressability. Widely-cloned architecture.
• Strengths: fast interrupts (good for real-time eg USB webcams and audio
DSPs), fast clock speeds, historicallyextremely popular
• Downsides: only 8-bits, hard to compete with cheap 32-bit controllers.
Simplicity can be a detriment with modern compilers. Falling out of favor.
Nuvoton 8051 Infineon XC8XX • PIC32 uses 3rd party core (MIPS M4K)
• Example chips: STCmicro STC8, Silicon Labs EFM8, Nuvoton N76
Other Kinds of Programmable Circuits
• Non-graphics applications
• Applications that can be parallelized work well: processing hashes
(bitcoin mining), matrix operations, audio processing, machine learning
• SoC=system on chip
CPUs
Nike Hyperadapt LG E8 Amazon Echo Show Moverio BT-300
(smart speaker with screen) Fitbit Ionic
(self-lacing bluetooth shoes) (55-65” OLED TV) (smart glasses)
ARM Cortex A8 CPU (GPS smartwatch)
ARM Cortex M4 CPU LG α9 CPU Intel Atom x5 CPU
ARM Cortex A8 CPU
Microcontrollers
HTC Vive Parrot AR.Drone 2.0 Honeywell Water Alarm Pleo Smart Dinosaur Amazon Fire TV
(VR Goggles) (Drone) (Freeze/Leak detector) (AI Toy) (digital media player)
ARM Cortex M0 Microchip PIC24 Microchip PIC12 Toshiba TMP86FH47 8-bit TI MSP430F5435A
Memory/Storage
• No “universal memory” (yet)
• So best way to build something is use a mix of technologies
DC Power Jack
Diode (protects
Power against reverse
Communication polarity on DC Power Source Analog Pins
Compute input)
I2C Communication
In-Circuit Serial Analog Reference
Programming Header Voltage Digital Pins
For ATmega16 Ground
Serial Communications
Reset Button
DC Power Jack
Diode (protects
Power against reverse
Communication polarity on DC
Compute Power Source Analog Pins
input)
Power
Debugging/
Emulation
Timing
Computation
(CPU/Core)
Memory
I/O and
Communication
Official Arduino Boards
Arduino Uno Rev3 Arduino Uno Wi-Fi Rev2 Arduino Nano Arduino Mega
(most popular Arduino board) (Similar to Uno, but has Wi-Fi) (smaller Arduino board) (larger Arduino board)
Ardusat
Elegoo Uno Adafruit Trinket FlyDuino KISS FC (domain-specific Arduino)
(lower-cost Arduino) (small Arduino) (domain-specific Arduino)
Nanosatellite based on CubeSat standard
Fully compatible; uses faster control Small (1.2”x0.6”), light (1.85 grams). Arduino-compatible board designed for
processor (ATMega16U2) Good for wearables (e.g., necklaces), dog autonomous navigation and auto- Public allowed to use platform via
tracking, covert computing, etc. piloting of aircraft. ArduSatSDK while in space
Other boards exist at <$3
Attiny85@16MHz, 8KB Flash, 512bytes Flight control firmware monitors and Includes a 3-axis magnetometer, a 3-axis
SRAM, 512bytes EEPROM performs telemetry of motor speed gyroscope, a 3-axis accelerometer, an
(ESCs). Stabilizes flight and automates infrared temperature sensor, four
movement and tracking. temperature sensors, two luminosity
sensors (infrared and vis light), two
Geiger counters, one optical spectrometer
one 1.3MP camera
Arduino Shields
• Measure pulses
• Measure how long user holds down a button, how
long car was blocking highway laser sensor
• Generate tones
• Alarm sounds when burglar steps on smart floor,
make music play when you walk into a room
Digital Streaming I/O Functions
• Functions for shifting data in/out:
Diagram Function name(s) What it does Notes
tone(pin, frequency, Generates a square wave of the Also see: noTone(pin) – stops
Frequency
[duration]) specified frequency in Hz (with generation of square wave on
50% duty cycle). Can connect to specified pin.
Example: piezo buzzer or speaker to play
tone(8,500) tones.
pulseIn(pin, value, [timeout]) Measures duration of next received Returns 0 if no complete pulse was
pulse. E.g. If value is HIGH, received before timeout. Works on
Example: pulseIn() waits for pin to transition pulses from 10µs → 3 minutes.
unsigned long duration = LOWHIGH, starts timer, and ends
Times To pulseIn(3,HIGH) on transition HIGHLOW.
from here here
byte incoming = Shifts a byte of data in from data Also see: shiftOut(dataPin,
Data shiftIn(dataPin, clockPin, pin, with values read on rising clockPin, bitOrder, value) – shifts
bitOrder) edges of clock pin. out the byte value, driving both
data and clock pins appropriately.
Example:
Clock byte value =
shiftIn(6,7,MSBFIRST)