LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms &...

30
LEGO MINDSTORMS & ARDUINO PRACTICAL SESSION 1 Part of SmartProducts

Transcript of LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms &...

Page 1: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

LEGO MINDSTORMS & ARDUINOPRACTICAL SESSION 1

Part of SmartProducts

Page 2: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

▪ Goal: Become familiar with Lego Mindstorms &

Arduino

▪ 3 sessions: Apr. 25th, May 1 & 4th, 13:45-17:30h

▪ Introduction to Arduino powered Lego robots

▪ Mandatory assignment

PRACTICAL SESSION 1Fjodor van Slooten

W241 (Horst-wing West)

[email protected]

LEGO MINDSTORMS & ARDUINO

4/26/2018AppDev 2slides @ vanslooten.com/appdev

Page 3: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

4/26/2018AppDev 3

WHAT IS LEGO MINDSTORMS?

Lego Technic + “Computer” + Sensors + Actuators

Page 4: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

4/26/2018AppDev 4

MINDSTORMS GENERATIONS

Mindstorms NXT 1.0, 2.0, EV3

We use 2.0 and EV3 version

Page 5: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

4/26/2018AppDev 5

SENSORS

Light sensor

Reads light intensity

and reflected light

from infrared led

Ultrasonic sensor*

Measures distance

to objects

(using ultra sound)

Sound sensor*

Read sound level

(not a microphone)

Touch sensor

Responds to

press, release,

touch

EV3:

NXT:

* does not work with EVShield

We’ve added some extra sensors

more on those next week

/ Color

Page 6: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

4/26/2018AppDev 6

SERVO MOTORS

Page 7: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

4/26/2018AppDev 7

ARDUINO POWERED ROBOTS

▪ Arduino hardware

▪ Arduino programming

▪ Language, IDE, Upload,

Serial Monitor, Libraries etc.

Page 8: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

4/26/2018AppDev 8

ARDUINO UNOPROGRAMMABLE CIRCUIT BOARD (AKA MICROCONTROLLER)

Arduino Nano:

learn.sparkfun.com/tutorials/what-is-an-arduino

Page 9: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

▪ Arduino program also called: sketch

▪ Language: C++ (similar to Java)

4/26/2018AppDev 9

ARDUINO PROGRAMMING

setup(): start of

program, runs once

loop(): runs continuously

after setup()

Page 10: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

4/26/2018AppDev 10

ARDUINO PROGRAMMINGLEARN BY EXAMPLES

loop(): turn LED on and

off

LED_BUILTIN is the LED on the board

Page 11: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

4/26/2018AppDev 11

RUN A PROGRAM

Select Board and Port

Click Upload

Connect USB

cable first

Page 12: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

▪ Connect (almost) all Lego motor’s and sensors

▪ What not?:

▪ NXT Ultrasonic Sensor (EV3 version works)

▪ Sound Sensor

4/26/2018AppDev 12

EVSHIELDINTERFACE BETWEEN ARDUINO AND LEGO MINDSTORMS

attachments for Lego axles

3 RGB LED’s built-in

4 buttons

4 motor

connectors

4 sensor

connectors

power connector

dual-use servo header

Arduino headers accessible

Page 13: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

4/26/2018AppDev 13

EVSHIELDPINS USED

Red pins can not be

used ‘normally’ but

can be used for i2c-

connections

Page 14: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

4/26/2018AppDev 14

MOUNT ARDUINO + SHIELD + BATTERY HOLDER

Guide: vanslooten.com/2018/04/03/lego-evshield-battery-pack

Page 15: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

▪ Libraries come

with examples

4/26/2018AppDev 15

EXAMPLES

Page 16: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

▪ View results of

test

4/26/2018AppDev 16

EXAMPLES

Serial Monitor

Close after

disconnecting USB

cable

To wait for a press of the touch

sensor, you may use:

while (!myTouch.isPressed()) ;

Page 17: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

▪ vanslooten.com/appdev

4/26/2018AppDev 17

EVSHIELD DOCUMENTATION

Page 18: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

4/26/2018AppDev 18

EXAMPLES: DRIVING ROBOTS

Castor Bot

nxtprograms.com

Support wheel

Two separately

driven wheels

Easy to extend

with extra’s, eg.

sensors

These are using NXT, but

can be easily adapted to

Arduino + EVShield!

Page 19: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

4/26/2018AppDev 19

EXAMPLES: DRIVING ROBOTS

TriBot

Building guide in folder “info\Lego\building_guides”

Responds to voice

commands

Grippers can hold small

objects

Touch sensor detects if it is

holding an object

Locate objects with

ultrasonic sensor

Light-sensor: stay

within area

These are using NXT, but

can be easily adapted to

Arduino + EVShield!

Page 20: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

4/26/2018AppDev 20

EXAMPLES: GRIP AND MOVE

Robot Arm

nxtprograms.com

These are using NXT, but

can be easily adapted to

Arduino + EVShield!

Page 21: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

4/26/2018AppDev 21

EXAMPLES: GRIP AND MOVE

RoboArm T-56

Building guide in folder “info\Lego\building_guides”

Light sensor

detects color of

object in gripper

Gripper can open

and closeRotates around

axis

Retractable arm

moves up and down

Touch sensor

detects if object in

gripper

These are using NXT, but

can be easily adapted to

Arduino + EVShield!

Page 22: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

4/26/2018AppDev 22

SLINGSHOT

Catapult

nxtprograms.com

These are using NXT, but

can be easily adapted to

Arduino + EVShield!

Page 23: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

4/26/2018AppDev 23

OPEN, CLOSE, LOCK

nxtprograms.com

Combination Lock Box

LockedUnlocked

These are using NXT, but

can be easily adapted to

Arduino + EVShield!

Page 24: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

4/26/2018AppDev 24

ROTATE & CONNECT

Joining beams

Conical gear connection

‘free’: without friction ‘stiff’: some friction ‘sturdy’: rigid connection

Page 25: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

4/26/2018AppDev 25

ROTATE

Reverse turning direction

Simple gearbox

Page 26: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

4/26/2018AppDev 26

BUILDING GUIDES

differences

in colors!

Length = 5 holes

Length = 15 holes

Required

parts

Page 27: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

▪ All project groups get a Mindstorms kit on loan for entire module

▪ Handle with care

▪ Lock when stored, leave them in corner of lecture room

▪ To open, remove entire cover (do not leave clips locked on one side,

this will break the cover!)

4/26/2018AppDev 27

HANDOUT MINDSTORMS BOXES

Remove all 4 clips!

→ to be returned July 4th

Page 28: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

4/26/2018AppDev 28

POWER & BATTERY

▪ EVShield can be powered via attached USB

cable or via (9V) battery pack

▪ If powered via USB, might not supply sufficient

power to outputs!

▪ Re-connecting circuits? First, disconnect power

▪ Always remove one battery from battery pack

after use

Page 29: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

▪ Do assignment in groups of 4!

▪ → 2 persons of project-group join other couple: ‘ad-hoc groups’

▪ Project group: get Mindstorms Box + 3 EL kits*

▪ ‘ad-hoc’ groups get 2 EV3 boxes (Core set + expansion set)

▪ All groups: get 1 Arduino kit** + 6 AA batteries

4/26/2018AppDev 29

ASSIGNMENT: GET MATERIALS

slides @ vanslooten.com/appdev

* contains breadboard, wires, Arduino Nano, basic components + Multimeter

** contains EVShield, Arduino Uno, battery holder etc

→ return everything at end of afternoon

→ project group stores 3 EL kits + 1 Arduino kit in the box

Page 30: LEGO MINDSTORMS & ARDUINO - Universiteit Twente · Goal: Become familiar with Lego Mindstorms & Arduino 3 sessions: Apr. 25 th, May 1 & 4 , 13:45-17:30h Introduction to Arduino powered

▪ If your kit is missing pieces: ask

teacher/assistant for spare parts

▪ Divide tasks!

▪ Tutorial for this assignment:

vanslooten.com > “Lego: Build Spike

with Arduino brain”

4/26/2018AppDev 30

DO ASSIGNMENT: BUILD SPIKESPIKE IS A SCORPION THAT HAS A NASTY STING

slides @ vanslooten.com/appdev

This assignment is a mandatory part of Application Development.

Show results at the end to receive ‘pass’.

Only students actually participating will receive a 'pass'.