Peranti dan Pengaturcaraan IoT
Peranti dan Pengaturcaraan IoT MAHDZIR BIN JAMIAAN (Che Det) Asmayuzie Binti Ahmad (Kak Ayu) Electrical Engineering Department Tuanku Sultanah Bahiyah Polytechnic Kulim Hi-Tech, KEDAH
I'm an Electrical and Computer Engineer. I've been teaching Electrical and Computer Engineering at Malaysia Polytechnic for over than 19 years now. “I love hardware, software and teaching” P. Tech Husaini Aza Mohd Adam , Head of Electrical Engineering Department Tuanku Sultanah Bahiyah Polytechnic Kulim Hi-Tech, KEDAH
What is ? Arduino is a hardware and software open-source prototyping platform for building electronic microcontroller-based project. • A microcontroller board, contains on-board power supply, USB port to communicate with PC, and an Atmel microcontroller chip. • It simplify the process of creating any control system by providing the standard board that can be programmed and connected to the system without the need to any sophisticated PCB design and implementation. • It is an open source hardware, any one can get the details of its design and modify it or make his own one himself.
``Physical Computing is about prototyping with electronics, turning sensors, actuators and microcontrollers into materials for designers and artists.’’ ``It involves the design of interactive objects that can communicate with humans using sensors and actuators controlled by a behaviour implemented as software running inside a microcontroller.’’ Massimo Banzi CTO of Tinker.it Co-Founder of ARDUINO platform Massimo Banzi is the co-founder of the Arduino project. He is an Interaction Designer, Educator and Open Source Hardware advocate. He has worked as a consultant for clients such as: Prada, Artemide, Persol, Whirlpool, V&A Museum and Adidas. Arduino project started, the five co-founders (myself, David Cuartielles, David Mellis, Tom Igoe, and Gianluca Martino) Arduino was created in Ivrea, Italy in 2005 by Massimo Banzi & David Cuartielles
“… Current prototyping tools for electronics and programming are mostly targeted to engineering, robotics and technical audiences. They are hard to learn, and the programming languages are far from useful in contexts outside a specific technology …” “… It can also be used to teach and learn computer programming and prototyping with electronics…” “Wiring builds on Processing…” Massimo Banzi and Casey Reas create Processing https://arduinohistory.github.io/ “ The objective was to make it easy for artists and designers to work with electronics, by abstracting away the often complicated details of electronics so they can focus on their own objectives” H. Barragan create Wiring
why Arduino? • Open source hardware (100%) • Resources from large community. • Wiki, forums, tutorials • Prototyping is like fastfood. • Devive hacking and reuse
why choose Arduino? The Hardware • Cheap • Board variation • USB connection The community • Arduino.cc • Forum • Tutorials The Development environment • Free download • Serial Monitor • Example
Microcontrollers Which µC to choose? ✔PIC from Microchip - http://www.microchip.com ✔ Atmel AVR - http://www.atmel.com ✔Intel 8051 and variants ( - http://www.8052.com ) ✔Freescale (Motorola) -http://www.freescale.com ✔Texas Instrument MSP430 ✔ARM microcontrollers – http://www.arm.com ✔Picaxe ✔Cypress PSOC ✔Renesas (Hitachi) H8, M6
Arduino boards specs
Arduino Retired Boards specs
Arduino Board UNO (2010) ATmega328P MEGA LILYPAD NANO (2008) ATmega328/168 MINI PRO
Arduino NEW Board Arduino Zero (2014) ARDUINO 101 (2015) MKR1000 (2016) Arduino Uno WIFI (2018) ATMEGA4809 NINA-W132 Wi-Fi module from ublox, ECC608 crypto device MKR Vidor 4000 (2018) First-ever Arduino based on an FPGA chip, equipped with a SAM D21 microcontroller, a u-blox Nina W102 WiFi module, and an ECC508 crypto chip for secure connection to local networks and the Internet MKR wifi 1010 MKR NB 1500 (2018)
ESP 8266 Shanghai-based Chinese manufacturer Espressif Systems
ESP8266 – AI Thinker ESP-01 ESP-02 ESP-03 ESP-04 ESP-05 ESP-06 ESP-07 ESP-08 ESP-09 ESP-10 ESP-11 ESP-12
NodeMCU – (ESP12/12E) There currently are three primary producers: Amica (see ‘NodeMCU and Amica‘ below), DOIT/SmartArduino, and LoLin/WeMos. 2nd generation v1.0 / V2 1st generation v0.9 / V1 ESP-12 ESP-12E V3 – by LoLin
ESP8266 – SUMMARY TABLE ESP-02 ESP-03 ESP-04
ESP32 – Dual Core • ESP32 which is the ESP8266 successor. • combines Wi-Fi and Bluetooth (BLE) wireless capabilities • comes with the ESP-WROOM-32 chip • All pin supported PWM & I2C pin current 6-12mA
NANO ESP32 – Dual Core • ESP32 which is the ESP8266 successor. • combines Wi-Fi and Bluetooth (BLE) wireless capabilities • comes with the ESP-WROOM-32 chip • All pin supported PWM & I2C pin current 6-12mA
NANO
Single board Computer/System-on-a-chip (SOC) Raspberry Pi Olimex A13 OLinuXino ODROID-X2 ODROID-U2 BeagleBone Cubieboard Gooseberry Board
Single board Computer Hackberry Board Chumby Hacker Board v1.0 FOXG20 Banana Pi Pro pcDUINO
SESSION 2 ESP32
ARDUINO HARDWARE ESP32
ESP32 - HARDWARE
ESP32 - HARDWARE Bukan semua GPIO boleh dicapai dalam semua pembangunan projek ini. Ianya bergantung kepada apa fungsi yang kita gunakan. The ESP32 peripherals include: • 18 Analog-to-Digital Converter (ADC) channels • 3 SPI interfaces • 3 UART interfaces • 2 I2C interfaces • 16 PWM output channels • 2 Digital-to-Analog Converters (DAC) • 2 I2S interfaces
ESP32 – PIN LAYOUT Note: • ADC2 pins cannot be used when Wi-Fi is used. • All pins that can act as outputs can be used as PWM pins (GPIOs 34 to 39 can’t generate PWM). • All GPIOs can be configured as interrupts.
ARDUINO NANO HARDWARE Understanding Arduino Nano Pin There are totally three ways to power up your Nano. • USB Jack, Vin Pin, +5V Pin Input/output: • There are totally 14 digital Pins and 8 Analog pins These pins apart from serving their purpose can also be used for special purposes which are discussed below: • Serial Pins 0 (Rx) and 1 (Tx): Rx and Tx pins are used to receive and transmit TTL serial data • External Interrupt Pins 2 and 3 • PWM Pins 3, 5, 6, 9 and 11.(8-bit PWM) • SPI communication Pins 10 (SS), 11 (MOSI), 12 (MISO) and 13 (SCK): In-built LED Pin 13: • I2C A4 (SDA) and A5 (SCA) (IIC communication) • AREF: Used to provide reference voltage for analog inputs • Reset Pin: Making this pin LOW, resets the microcontroller.
ARDUINO SOFTWARE
ARDUINO SOFTWARE https://www.youtube.com/watch?v=YDkdVZ7e3O Y
INSTALL THE ARDUINO SOFTWARE (IDE) ❑ Download the Arduino IDE ❑ When the download finishes, proceed with the installation ❑ Installing Drivers in Windows • please allow the driver installation process when you get a warning from the operating system.
INSTALL Windows Driver for ARDUINO BOARD (none Official FTDI driver) Installing CP210x USB UART Driver • Extract the zip file and install https://www.silabs.com/products/develo pment-tools/software/usb-to-uart-bridgevcp-drivers http://www.wch.cn/download/CH341SER_EXE.html Installing CH340 serial-USB communication Driver
SESSION 3 Programming & Interfacing
PREPARE YOUR ARDUINO Installing Drivers in Windows
INTRODUCTION TO ARDUINO IDE
INTRODUCTION TO ARDUINO IDE
INTRODUCTION TO ARDUINO IDE Verify button: This checks through the sketch to ensure that it is written in a way that the Arduino can understand – a process called “compiling”. If the sketch compiles correctly, you’ll see a message “Done Compiling” in the message area. If not, you’ll see a list of errors that the compiler has picked up – these are there to help you correct your sketch, although they can sometimes be a little cryptic. Upload button: This button uploads the sketch to your Arduino. The board must of course be connected with a USB cable. Before uploading, the IDE compiles the sketch and will only upload the sketch if there are no errors. New button: This creates a new, empty sketch. Open & Save buttons: These either open an existing sketch, or save the current one. Sketches are saved in a “Sketchbook” – you can see all sketches in your sketchbook from the File-Sketchbook menu. Serial Monitor button: This is a way to communicate with your sketch while it’s running on the Arduino, via the USB port. It’s very useful, and we’ll work with it in later chapters. http://www.crash-bang.com/arduino-tutorial/chapter-2-5/
Arduino Integrated Development Environment (IDE) Two required functions / methods / routines: void setup() { // runs once } void loop() { // repeats } error & status messages
ARDUINO SKETCH byte pinLed = 13; void setup() { pinMode(pinLed, OUTPUT); } void loop() { digitalWrite(pinLed, HIGH); delay(1000); digitalWrite(pinLed, LOW); delay(1000); } http://www.crash-bang.com/arduino-tutorial/chapter-2-5/ Type the Sketch Compile the Sketch
ARDUINO SKETCH http://www.crash-bang.com/arduino-tutorial/chapter-2-5/ Connect your Arduino Select the Arduino Board: • Click on the Tools menu, then Board, then select the Arduino board you’re using from the list. Tools Board menu.
ARDUINO SKETCH http://www.crash-bang.com/arduino-tutorial/chapter-2-5/ Select the Serial Port Select the Serial Port: Next, choose the serial port that your board is connected to by clicking on the Tools, Serial Port menu option. Your computer communicates to the Arduino microcontroller via a serial port through a USBSerial adapter. (make sure that the drivers are properly installed)
ARDUINO SKETCH http://www.crash-bang.com/arduino-tutorial/chapter-2-5/ Upload the Sketch Upload the Sketch Now it’s time to upload the sketch to the board. Click on the Upload button on the toolbar, and watch the lights on your Arduino. First, the IDE should compile the sketch, then start uploading. As it uploads you should see your LED and some lights on the Arduino flash rapidly – these lights are the Tx and Rx (transmit and receive) which show the Arduino and the PC are communicating. After a while the lights will stop.
DIGITAL OUTPUT
LESSON 1- BASIC I/O (Input & Output) Task 1 : Working with multiple LED – simple OUTPUT Task 2 : Working with Buzzer (Piezo) - digital OUTPUT
Thinking of ARDUINO…. • Arduino is an example of Embedded system • Hardware & Software • About to control and manipulate INPUT and OUTPUT
Referenced from the perspective of the microcontroller (electrical board). Inputsis a signal / information going into the board. Examples: Buttons Switches, Light Sensors, Flex Sensors, Humidity Sensors, Temperature Sensors… Output is any signal exiting the board. Examples: LEDs, DC motor, servo motor, a piezo buzzer, relay, an RGB LED CONCEPST - INPUT & OUTPUT
Inputs (Sensors) DIGITAL & ANALOG Output DIGITAL & Pulse (PWM) CONCEPST - INPUT & OUTPUT Microcontrollers are digital devices – (1 or 0), (ON or OFF), (HIGH or LOW). Also called – discrete. Analog signals are anything that can be a full range of values. Pulse Width Modulation, or PWM, is a technique for getting analogue results with digital means. Digital control is used to create a square wave, a signal switched between on and off. This on-off pattern can simulate voltages in between full on (5 Volts) and off (0 Volts) by changing the portion of the time the signal spends on versus the time that the signal spends off.