Introduction to Design (2) Microcontrollers and Interfacing Introduction to Design (2)...

Preview:

Citation preview

Introduction to Design (2)

Microcontrollers and Interfacing

Week 01Introduction and course overview

Department of Mechanical and Electrical System Engineering

useful information

Course title: Introduction to Design (2) —Microcontrollers and Interfacing

Course web site: https://kuas.org/~piumarta/id2

Instructor’s name: (Prof. | Dr.) PIUMARTA (ピュマータ)Instructor’s e-mail: ian.piumarta@kuas.ac.jp

Instructor’s office: S401Office hours: via e-mail or Teams/Zoom meeting

2

microcontrollers, devices, IoTonline video:

ID2-01-1

3

microcontrollers, devices, IoT

4

microcontrollers, devices, IoT

5

microcontrollers, devices, IoT

6

the Internet of Things

academic challenges and opportunities:embedded languages & group distributed big HCI autonomous on-demand physicalhardware middleware communication algorithms data models collaboration manufacturing design

7

the Internet of Things

8

course objectives

understand the architecture of microcontrollers and embedded systems

learn how to interface these devices to the physical world

• software techniques

• several different types of hardware device

review some basic electronics techniques relevant to interfacing

• voltage, current, resistance, Ohm’s law

• simple use of transistors and op-amps

have some fun!

9

this week

tools for programming a microcontroller

• the integrated development environment

a brief history of microcontrollers: where they came from

installing and using the Arduino development environment

• anatomy of Arduino programs

• a simple program

first look at the hardware environment

• simple digital output

10

some history

late 1970’s, early 1980’s

• 4- and then 8- bit microprocessors become popular and cheap

• complete system contains many discrete components:– microprocessor– memory: ROM and RAM– input/output: counter-timer, parallel I/O, serial I/O (UART)

11

some history

12

evolution: 1980s

single-board embedded systems rapidly outnumber desktop systems

• industrial control

• telephone switches

• household appliances

microcomputer systems evolve in several directions

• more powerful CPUs, for high performance– leading to Phenom II, Core i7, etc.

• more efficient CPUs, for low power– leading to ARM, Geode, etc.

• integration onto one die, for small footprint– serial/parallel input-output, RAM, ROM, timers, CPU– leading to microcontrollers and system-on-a-chip (SoC)– embedded/control systems can contain one chip + power!

13

modern microcontroller: AVR (ATmega)

• 8-bit RISC CPU, 16 MIPS

• 2k RAM

• 32k ROM (flash)

• 8- and 16-bit timer/counters

• 32 parallel/serial I/O lines

• eight 10-bit analogue inputs

• PWM analogue outputs

(red lines show functions inherited from1980s single-board microcomputers)

14

result of integration

architecture similar to 1980s, but very large scale integration (VLSI). . .

300×250 mm (12×10 in) board −→ 12×12 mm (0.5×0.5 in) chip15

popular AVR implementation: Arduino

open-source hardware and software

more than 500,000 sold, less than $30 (2500 JPY)

many add-on products available

Google’s ‘Android Open Accessories’ standard uses Arduino16

architecture

memory

31 8-bit registers

16-bit addresses

• three index registers

• pairs of 8-bit registers: r26:r27, r28:r29, r30:r31

17

tethered development environment

‘sketches’ written in simplified C++

libraries provide functions for configuring and reading/writing I/O pins

18

expansion

stackable ‘shields’over 500 available:

audiospeechcameravideodisplay (LED, LCD)SD cardjoystickaccelerometertemperature, pressureradiationinfrared I/OEthernetWiFiBluetoothRFIDFM radiocompass, GPSGSM, cellular modemetc...

19

shields: connectivity

Ethernet ($55), SD card ($20), proto board ($12), LED array ($25)

20

shields: interfaces

simple LCD ($20), colour touchscreen ($60)

21

shields: robotics

stepper motor ($30), robot ($120), chassis ($50, $60)

22

course overview

Arduino software and hardware environments

input and output (digital and analogue)

pulse-width modulation

amplifying input and output signals

digital-to-analogue and analogue-to-digital conversion

transducers for voltage, sound, visible and IR light, temperature, etc.

advanced hardware topics:

• asynchronous activities

• memory-mapped registers, timers, counters, interrupts

advanced software topics:

• serial communication, UART

• I2C and SPI busses: using a “real” D-to-A converter

project!23

environmentonline video:

ID2-01-2

programming the microcontroller requires an IDE

• install the IDE on the laptop/computer you will use for development– it runs on Mac, Windows and Linux– download from: http://www.arduino.cc

in your hardware kit you should find

• an Arduino board

• a USB cable

connect the board to the computer with the cable

24

environmentonline video:

ID2-01-3

double-click on the icon:

a window should appear:

verify that the hardware status at the bottom of the IDE window shows

• Windows: Arduino Uno on COM1

• MacOS: Arduino Uno on /dev/cu.usbmodemFB0001

• Linux: Arduino Uno on /dev/tty/ACM0

(or something similar; use the ‘Tools > Port’ menu to adjust, if needed)

25

the IDE buttons and panes

26

first programming example: blinking LED

the initial (empty) sketch looks like this:

void setup(){

// your configuration code goes here (run once at startup)}

void loop(){

// your application code goes here (run repeatedly in a loop)}

an LED on the Arduino board is already connected to pin 13

to make it blink we have to

• configure pin 13 as an OUTPUT

• repeatedly run application code in a loop that– turns the LED on (HIGH voltage)– waits some number of milliseconds– turns the LED off (LOW voltage)– waits some number of milliseconds

27

first programming example: blinking LED

the ‘blink’ sketch looks like this:

void setup(){

// your configuration code goes here (run once at startup)pinMode(13, OUTPUT); // configure pin 13 as an output

}

void loop(){

// your application code goes here (run repeatedly in a loop)digitalWrite(13, HIGH); // turn LED on (high voltage)delay(500); // pause execution for 500 millisecondsdigitalWrite(13, LOW); // turn LED off (low voltage)delay(500); // pause execution for 500 milliseconds

}

after entering it, press the ‘upload’ button:

• (‘upload’ will first compile the sketch, then upload the binary to the hardware)

If you see red error messages, look carefully for typing mistakes and fix them

28

next steps

try this:

• modify the constant values (change the ‘500’s to something else)

• upload your sketch again and observe the behaviour

• try different constant values– large and small– either two of the same value, or two different values

more experiments can be found in this week’s lab worksheet

complete those experiments now

(review this week’s material again online, if you want to)

29

next week: analogue input and displaying information

homework: complete week 1 experimental lab work before Monday

• if you have difficulty, e-mail the instructors!

(all materials for week 2 will be posted online before Monday)

homework: before next week’s class, starting Monday at the latest

• watch the online videos that present week 2 background material

• download week 2 lab experiment worksheet

• try to complete week 2 experiments before the class next Friday

during week 2 class periods we will have an interactive ‘clinic’ for

• Q&A about anything in the background material that was not clear

• Q&A about anything related to experimental lab work

30