Io IoT Device ce Ar Arch chitect ecture e and Pr Programming - - PowerPoint PPT Presentation

io iot device ce ar arch chitect ecture e and pr
SMART_READER_LITE
LIVE PREVIEW

Io IoT Device ce Ar Arch chitect ecture e and Pr Programming - - PowerPoint PPT Presentation

Io IoT Device ce Ar Arch chitect ecture e and Pr Programming 01219335 Data Acquisition and Integration Chaiporn J Chaipo n Jaik aikae aeo De Department of f Computer Engineering Kasetsart Unive versity Revised 2020-08-20 Ou


slide-1
SLIDE 1

Io IoT Device ce Ar Arch chitect ecture e and Pr Programming

Chaipo Chaiporn J n Jaik aikae aeo De Department of f Computer Engineering Kasetsart Unive versity

01219335 Data Acquisition and Integration

Revised 2020-08-20

slide-2
SLIDE 2

2

Ou Outline

  • Components of typical IoT devices
  • Hardware platforms
  • Programming methods
slide-3
SLIDE 3

3

Ma Main Co Components

Communication Module CPU Sensors/ Actuators Power Supply Memory (RAM/Flash)

Microcontroller

slide-4
SLIDE 4

4

Mi Microcontroller r Examples

  • Espressif’s ESP32
  • Dual Xtensa cores @240 MHz
  • 520 KB SRAM
  • Wi-Fi: IEEE 802.11 b/g/n
  • Bluetooth v4.2
  • Microchip’s ATSAMD21G18
  • ARM Cortex M0+ @48 MHz
  • 256 KB programmable flash
  • 32 KB SRAM

https://www.electrodragon.com/product/ esp32-wifi-bluetooth-ic-model/ http://www.jarzebski.pl/arduino/arduino-i- klony/arduino-m0-zero-pro-atsamd21g18.html

slide-5
SLIDE 5

5

Co Communication Device

  • Medium options
  • Electromagnetic, RF
  • Electromagnetic, optical
  • Ultrasound

Radio Transceiver radio wave bit stream

slide-6
SLIDE 6

6

Tr Transceiver Characteristics

  • Service to upper layers: packet, byte, bit
  • Data rate
  • Power control
  • Communication range
  • etc.
slide-7
SLIDE 7

7

Tr Transceiver States

  • Transceivers can be put into different
  • perational states, typically:
  • Transmit (Tx)
  • Receive (Rx)
  • Idle – ready to receive,

but not doing so

  • Sleep – significant parts
  • f the transceiver are

switched off

Rx Tx Idle Sleep

slide-8
SLIDE 8

8

Se Sensor

  • rs
  • Main categories
  • Passive, omnidirectional
  • Examples: light, thermometer, microphones,

hygrometer, …

  • Passive, narrow-beam
  • Example: Camera
  • Active sensors
  • Example: Radar, ultrasonic sensor
  • Important parameter: Area of coverage
  • Which region is adequately covered by a given sensor?
slide-9
SLIDE 9

9

Ener Energy S Supply upply

  • Goal: provide as much energy as possible at smallest

cost/volume/weight/recharge time/longevity

  • Depending on the application, recharging may or may not be an
  • ption
  • Options
  • Primary batteries – not rechargeable
  • Secondary batteries – rechargeable, only makes sense in

combination with some form of energy harvesting

slide-10
SLIDE 10

10

Ener Energy S Supply upply - Re Requirements

  • Low self-discharge
  • Capacity under load
  • Efficient recharging at low current
  • Voltage stability (to avoid DC-DC conversion)
slide-11
SLIDE 11

11

Ba Battery y Examples

  • Energy per volume (Joule/cc):

Primary b batteries Chemistry Zinc-air Lithium Alkaline Energy (J/cm3) 3780 2880 1200 Secondary b batteries Chemistry Lithium NiMH NiCd Energy (J/cm3) 1080 860 650

http://en.wikipedia.org/wiki/Energy_density https://en.wikipedia.org/wiki/Lithium-ion_battery http://clipart-library.com/

slide-12
SLIDE 12

12

Ex Example: ample: B Batter ery Lif Life (1) e (1)

  • Consider a device with average power consumption of

20 mA

  • If the device is powered by a 3000 mAh battery, how long

will the device last without charging?

slide-13
SLIDE 13

13

Mu Multiple P Power Con r Consump mption

  • n Mod

Modes

  • Do not run device at full operation all the time
  • If nothing to do, switch to power safe mode
  • Typical modes
  • Controller: active, idle, sleep
  • Radio mode: Turn on/off transmitter/receiver, both
  • Strongly depends on hardware
  • Questions:
  • When to throttle down?
  • How to wake up again?
slide-14
SLIDE 14

14

Ex Example: ample: B Batter ery Lif Life (2) e (2)

  • Consider a device whose components’ power consumption

characteristics are as follow:

  • What is the average power consumption of the device?

Component Power consumption Time fraction in each mode Processor Active mode: 10 mA Sleep mode: 0.01 mA 10% 90% Radio module Transmitting mode: 100 mA Receiving mode: 20 mA Idle mode: 10 mA 1% 5% 94% Sensor Active mode: 30 mA Idle mode: 0 mA 5% 95%

slide-15
SLIDE 15

15

Io IoT M Modul dule B e Boards ds

  • Designed for easy prototyping
  • Combining processor, power supply circuit, commonly-

used peripherals into a single board

https://www.electrodragon.com/product/esp32-wifi-bluetooth-ic-model/ https://github.com/LilyGO/TTGO-T8-ESP32 http://www.jarzebski.pl/arduino/arduino-i-klony/arduino-m0-zero-pro- atsamd21g18.html https://www.adafruit.com/product/2772

slide-16
SLIDE 16

16

Ar Arduino Modules

  • Various communication "shields"

https://www.arduino.cc/en/Main/Boards http://www.dragino.com/products/nb-iot/item/130-nb-iot-shield.html https://store.arduino.cc/usa/arduino-wifi-shield http://www.dragino.com/products/lora/item/102-lora-shield.html

WiFi Shield NBIoT Shield LoRa Shield

slide-17
SLIDE 17

17

BBC' BBC's s Mi Micro:bit

https://microbit.org/guide/features/

slide-18
SLIDE 18

18

Ra Raspberry y Pi

https://www.raspberrypi.org/products/

  • By Raspberry Pi Foundation
  • Controller
  • 1.4 GHz 64/32-bit quad-core ARM

Cortex-A53

  • Communication
  • Ethernet, WiFi, and Bluetooth

Raspberry Pi 3 Model B+ Raspberry Pi Zero W

slide-19
SLIDE 19

19

ES ESP32-ba based M sed Modul dules es

  • NodeMCU-32S
  • LED and switches
  • USB connector
  • TTGO T-Beam
  • LoRa + OLED + GPS modules
  • Battery charger and holder
  • USB connector
  • WEMOS D32 Pro
  • Micro SD slot
  • Battery charger
  • USB connector

https://www.shenzhen2u.com/NodeMCU-32S https://www.aliexpress.com/i/32967228739.html https://wiki.wemos.cc/products:d32:d32_pro

slide-20
SLIDE 20

20

Ki KidBri dBright Mo Modul dule

USB-C Connector ESP32 Module

  • 2 cores @240 MHz
  • 520 MB RAM
  • 4 MB Flash

External peripheral connectors Real-Time Clock Battery Light Sensor Temperature Sensor 16x8 LED Matrix Triple-Axis Accelerometer & Magnetometer Push Switches

slide-21
SLIDE 21

De Device P Programming

slide-22
SLIDE 22

22

  • Firmware flashing with an external chip programmer

Ty Typical Development Process

Source ce code (C (C/Assembly) Cross Compiler/Assembler Fi Firmware code (b (binary)

010101 011101 110110

Microcontroller Chip Programmer Uploader Software

U S B U S B

slide-23
SLIDE 23

23

  • Firmware flashing with on-chip bootstrap loader

Ty Typical Development Process

flash memory

Bootstrap Loader (BSL)

Microcontroller module Source ce code (C (C/Assembly) Cross Compiler/Assembler Fi Firmware co code (b (binary)

010101 011101 110110

Uploader Software

U S B U S B firmware code

slide-24
SLIDE 24

24

  • Script uploading with MicroPython firmware

Ty Typical Development Process

flash memory

Bootstrap Loader (BSL)

Microcontroller module Uploader Software Py Python source ce code (. (.py py) Micr croPython fi firmware (b (binary)

010101 011101 110110

uploaded

  • nly once

.py

U S B U S B

slide-25
SLIDE 25

Ba Basi sic Peri ripheral Co Control wi with Mi MicroPython

slide-26
SLIDE 26

26

Ex Example: ample: LED LED C Contro rol

  • Let's write code to control the red LED (usually used for indicating

WiFi connectivity)

slide-27
SLIDE 27

27

LED LED C Control l – Sc Schematic ic

  • Red LED is connected to IO2

KidBright's Schematic provided by INEX

slide-28
SLIDE 28

28

LED LED C Control l – Py Python Code

from machine import Pin from time import sleep # make pin 2 an OUTPUT, refer to it as 'led_wifi' led_wifi = Pin(2, Pin.OUT) while True: # set pin 2’s voltage to 3.3V led_wifi.value(1) sleep(0.5) # set pin 2’s voltage to 0V led_wifi.value(0) sleep(0.5)

slide-29
SLIDE 29

29

Ex Example: ample: Sw Switch Status

  • Let's write code to read status of a push-button
slide-30
SLIDE 30

30

Sw Switch Status – Sc Schematic ic

  • Two push-buttons are connected

to IO14 and IO16 pins

  • When a button is pushed, its status

reading is 0

  • When a button is released, its

status reading is 1

KidBright's Schematic provided by INEX

slide-31
SLIDE 31

31

Sw Switch Status – Py Python Code

from machine import Pin from time import sleep # make pin 16 an INPUT pin with pull-up activated # (i.e., give logic 1 when the pin is floating); # then refer to it as 's1' s1 = Pin(16, Pin.IN, Pin.PULL_UP) while True: # read and print out the button value print("S1 status =", s1.value()) # delay a little to slow down screen output sleep(0.1)

slide-32
SLIDE 32

32

Co Conclusi sion

  • An IoT device usually consists of a processor, power supply,

communication module, and sensors

  • There are various IoT hardware modules in the market
  • ESP32-based modules are quite popular for beginners
  • MicroPython allows controlling ESP32-based module with

Python scripts