29
Microcontrollers and Interfacing Week 01 Introduction and course overview College of Information Science and Engineering Ritsumeikan University 1

Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

  • Upload
    phamdan

  • View
    219

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

Microcontrollers and Interfacing

Week 01

Introduction and course overview

College of Information Science and Engineering

Ritsumeikan University1

Page 2: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

useful information

Course title: Topics in IT 4 — Microcontrollers andEmbedded System Interfacing for the IoT

Course language: EnglishCourse web site: www.ritsumei.ac.jp/~piumarta/topics4

Instructor’s name: (Prof. | Dr.) PIUMARTA (ピュマータ)Instructor’s e-mail: [email protected]

Instructor’s office: CC301Office hours:

Friday 13:00–14:00others send e-mail

2

Page 3: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

course relevance: 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

3

Page 4: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

course relevance: the Internet of Things

4

Page 5: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

course objectives

understand the architecture of microcontrollers and embedded systems

learn how to interface these devices to the physical world

• software techiques

• 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!

5

Page 6: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

this week

a brief history of microcontrollers: where they came from

software environment

• booting the laptop

• shutting down the OS

the Arduino development environment

• anatomy of arduino programs

• some simple programming exercises

• using the serial monitor

hardware environment

• digital output

6

Page 7: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

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)

7

Page 8: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

some history

8

Page 9: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

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!

9

Page 10: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

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)

10

Page 11: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

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) chip11

Page 12: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

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 Arduino12

Page 13: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

architecture

memory

31 8-bit registers

16-bit addresses

• three index registers

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

13

Page 14: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

tethered development environment

‘sketches’ written in simplified C++

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

14

Page 15: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

expansion

stackable ‘shields’over 500 available:

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

15

Page 16: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

shields: connectivity

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

16

Page 17: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

shields: interfaces

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

17

Page 18: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

shields: robotics

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

18

Page 19: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

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!19

Page 20: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

environment

programming the microcontroller requires an IDE

• header files and libraries

• compiler and linker

• binary uploader– transfers the compiled program to the microcontroller

it is highly recommended that you

• install the IDE on your own laptop– it runs on Mac, Windows and Linux– download from: http://www.arduino.org

• remember to bring your laptop to this class every week

• make copies or back ups of your work frequently

if you do not want to do this, you can use a lab laptop...

20

Page 21: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

environment

your hardware kit includes a bootable USB flash memory stick

• Linux operating system

• Arduino Integrated Developement Environment (IDE)

to boot from USB:

• insert the USB memory stick into a USB port

• turn the laptop on

• repeatedly press the F12 key until the machine beeps

• wait for the boot menu to appear

• use the cursor keys to select the third entry, something like3. USB media USB 3.0

• press Enter

• wait for the boot loader menu

• press Enter

• wait (about 30 seconds) for the Linux desktop to appear21

Page 22: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

the IDE

double-click on the icon:

a window should appear:

22

Page 23: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

the IDE buttons and panes

23

Page 24: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

the hardware

in your hardware kit you should find

• an arduino board

• a USB cable

connect the board to the computer with the cable

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

• Arduino Uno on /dev/tty/ACM0

(or something similar)

24

Page 25: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

first programming example: blinking LED

edit the initial (empty) sketch as follows:

void setup(){

// your configuration code goes here}

void loop(){

// your application code goes here}

useful functions:

pinMode(n, OUTPUT); // configure pin n as an outputdigitalWrite(n, LOW); // set pin n to 0 (low voltage)digitalWrite(n, HIGH); // set pin n to 1 (high voltage)delay(n); // pause execution for n milliseconds

when entered, select ‘upload’ from the ‘Sketch’ menu

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

25

Page 26: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

first programming exercise: blinking LED

we will learn what the various functions do next week

in the meantime, try this:

• modify the constant values (change the ‘200’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

26

Page 27: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

shutting down the computer

never remove the USB stick while the computer is running!

• doing so may destroy your work

to turn off the computer:

• click this button in the top-right corner of the screen

• a window will open: confirm that you want to shut down the machine

• wait 20 seconds for the machine to shut down before removing the USB stick

27

Page 28: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

about your hardware kits

each hardware kit has a number printed on the side of the box

• make a note of your kit’s number

• use the same kit every week

this is important for several reasons, including:

1. data (such as your sketches) are saved permanently on the USB stick

2. you might need to save your hardware ciruit for the following week

28

Page 29: Microcontrollers and Interfacing - 立命館大学piumarta/topics4/arduino-01.pdf · some simple programming exercises using the serial monitor ... parallel I/O, serial I/O (UART)

about the software environment

the Arduino IDE is free and runs on Linux, Mac and Windows:

http://www.arduino.org

the USB memory sticks we are using boot into a ‘portable’ version of the Linux OS

• ‘portable’ means that no changes are made to the host computer

• you can put the USB stick into almost any PC or Mac and boot into Linux

• your Linux files and other data will be preserved on the USB stick

so if you are

• new to Linux and want to practice with it, or

• in need of a persistent Linux OS that you can carry in your pocket

then you might like to install the same environment on your own USB stick:

http://www.porteus.org

29