31
PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti [email protected] @elpaso Davide Corio [email protected] @davidecorio EuroPython 2012 - Florence License: Creative Commons Attribution - Share Alike 3.0

PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti [email protected] @elpaso Davide Corio [email protected]

  • Upload
    others

  • View
    13

  • Download
    0

Embed Size (px)

Citation preview

Page 1: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS

Alessandro [email protected]@elpaso

Davide [email protected]@davidecorio

EuroPython 2012 - Florence

License: Creative Commons Attribution - Share Alike 3.0

Page 2: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

Introduction

whowhywhat

Page 3: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

In the beginning

In the beginning was the abacus...Technology started on real things you could touch

Page 4: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

Being digital

From Big-Blue to Micro-Soft

Page 5: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

Touching the Sky

Alice in Metaphorsland: desktops, trash-bins and wizards

Page 6: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

Leaving Earth

Abstraction can be addictive

Page 7: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

Unusable interfaces

Page 8: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

It's all about Interactivity

Page 9: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

Sniffing the stacktrace

Page 10: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

Being real

Physical computing: low cost MCU's and electronic components

Page 11: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

Here comes the King

Arduino's revolution

minimaleasy to usecheapfrom artistsMade in Italyopen hardware

Page 12: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

What's inside?

hw: device: electronic prototyping boardsw: bootloadersw: librariessw: IDEcommunitylot of manualslot of examples

Page 13: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

The board

Arduino UNO

Page 14: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

MCU

Atmega 328

RAM 2 KBROM 32 KBEEPROM 1 KB14 digital pins6 PWM capable6 analog inputsUp to 16 MHzavr-gcc

Page 15: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

Power to the people!

1982 – IBM 80286

Page 16: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

Splitting the byte

Atmega 328 Registers and ports

Page 17: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

Pins

Digital IOPWM (digital)

Analog inputs

Page 18: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

PWM (pulse width modulation)

Logical 0

Logical 1

255 levels

Page 19: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

C programming

Page 20: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

Programming

setuploopblink!

Page 21: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

King's audience

Arduino talks and listens

serialsensorsRFethernet

Page 22: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

At the king's court

shieldsclones

Page 23: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

DIY Arduino

< 10 €

Page 24: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

Snake's attack

ASCII messagescompact protocols

>>> import pyfirmata

>>> print "yeah, it works!! :-D

"

Page 25: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

ASCII snake

>>> import serial>>> ser = serial.Serial('/dev/ttyACM0', 9600)>>> while 1:... ser.readline()'1 Hello world!\r\n''2 Hello world!\r\n''3 Hello world!\r\n'

>>> import serial>>> ser = serial.Serial('/dev/ttyACM0', 9600)>>> ser.write('5')

Page 26: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

The firmata protocol

http://firmata.org/wiki/Main_Page

pyfirmata to the rescue

https://bitbucket.org/tino/pyfirmata/src

Page 27: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

PyFirmata example

Page 28: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

Embedded snakes

Python on a chip

http://code.google.com/p/python-on-a-chip/

Page 29: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

Other projects

Python Arduino Prototyping APIhttps://github.com/HashNuke/Python-Arduino-Prototyping-API

Python 2B (ASCII protocol)http://arduino.cc/playground/Code/2B

Page 30: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

OpenERP arduino controller

Demo

https://github.com/elpaso/arduinocontrollerhttp://www.youtube.com/watch?feature=player_embedded&v=MkxK9bHPZxQ

Page 31: PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS · PYTHON AND ARDUINO: A TALE OF SNAKES AND KINGS Alessandro Pasotti a.pasotti@itopen.it @elpaso Davide Corio davide.corio@domsense.com

THANKS!

Alessandro [email protected]@elpaso

Davide [email protected]@davidecorio

License: Creative Commons Attribution - Share Alike 3.0