Python and Arduino





Álvaro Justen aka Turicas

EuroSciPy 2012
Lightning Talks
26/08/2012

Rio de Janeiro, Brazil

Álvaro Justen,

nice to meet you!

{twitter.com, github.com, youtube.com }/turicas
turicas.info
alvaro@CursoDeArduino.com.br

www.CursoDeArduino.com.br


emap.fgv.br

Arduino!

A little computer














arduino.cc

Technical specifications

Talk is cheap, show me the code!
Linus Torvalds

Arduino Hello World

Blink

#define LED 13

void setup() {
    pinMode(LED, OUTPUT);
}

void loop() {
    digitalWrite(LED, HIGH); //on
    delay(1000); //1000 ms = 1s
    digitalWrite(LED, LOW); //off
    delay(1000); //1000 ms = 1s
}



Controlling a LED with Python (Arduino code)

#define LED 13

void setup() {
    pinMode(LED, OUTPUT);
    Serial.begin(9600);
}

void loop() {
    if (Serial.available()) {
        char c = Serial.read();
        if (c == 'H') {
            digitalWrite(LED, HIGH);
        }
        else if (c == 'L') {
            digitalWrite(LED, LOW);
        }
    }
}

Controlling a LED with Python (Python code)

#!/usr/bin/env python

import serial
import time

# /dev/ttyACM0 = Arduino Uno on Linux
arduino = serial.Serial('/dev/ttyACM0', 9600)
time.sleep(2) #waiting the initialization...

arduino.write('H') #turns LED *on*
time.sleep(3) #zzz

arduino.write('L') #turns LED *off*
time.sleep(3) #zzz

arduino.close() #let's say goodbye

Example Project














Traffic light for lightning talks and coding dojos

Wi-Fi-controlled car

Collecting data from sensors

#define SENSOR A0 //analog pin 0
#define INTERVAL 100 //ms between measures

void setup() {
    Serial.begin(9600);
}

void loop() {
    int measure = analogRead(SENSOR);
    Serial.println(measure);
    delay(INTERVAL);
}

Arduino Bluetooth Shield

pybluez

Arduino Ethernet Shield

Wi-Fi-controlled RGB lamp

Yes, we can run Python on Android



github.com/turicas/luminaria-rgb
Python Brasil 2012


?

I'll be @ PyPLN's poster

{twitter.com, github.com, bitbucket.org, youtube.com }/turicas turicas.info
alvaro@CursoDeArduino.com.br
www.CursoDeArduino.com.br