Little Python

Making things go beep and boop.

Created by Mark Cotton / @mcotton

Who am I?

I am Mark Cotton. I am a big nerd. I do programmer-y stuff. Eagle Eye Networks gives me money to programmer-y stuff.

What am I doing here?

Embedded microprocessors are cool but not normally programmed with Python.

Python

Is awesome...

  • Dynamic
  • Powerful
  • Fun
  • Great Community
  • Batteries included
  • Rapid interations

Sensors

Are awesome...

  • Buttons
  • LEDs
  • Motors
  • Temperature
  • Sonar
  • Distance
  • RFID

A Little History

Motorola dev board

  • C/C++ with customer compiler
  • $5000+
  • Required NDAs and Electrical Engineering Degree
  • Purchased: 2000

Not practical to interface with Python.

NetBurner

  • C/C++ with customer compiler
  • $300
  • Ethernet and Serial
  • Purchased: 2004

Inexpensive enough to talk over network/serial to Python

Phidgets

  • USB sensors to any machine, Python
  • $100
  • Easiest way to add sensors to a project
  • Purchased: 2008

Connect via USB, Python SDK

Synapse-Wireless

  • Python-esque implementation in SoC
  • $200
  • Wireless mesh networking, low power
  • Purchased: 2010

Run a limited version of Python directly.

Arduino

  • Sketch or C/C++
  • $30
  • Amazing Community, Documentation
  • Purchased: 2012

Control Android via firmata, allows usage of Android ecosystem.

Raspberry Pi

  • Complete linux distro, Python
  • $35
  • Awesome little computer, extremely powerful
  • Purchased: 2013

SparkCore

  • SoC with WiFi, cloud based API
  • $200
  • Just as easy as any REST API
  • Purchased: 2014

Access sensor data via URL GET /v1/devices/{DEVICE_ID}/{VARIABLE}

Phidgets Example


from Phidgets.PhidgetException import *
from Phidgets.Events.Events import *
from Phidgets.Devices.InterfaceKit import *

device.setOnSensorChangeHandler(sensorChanged)

def sensorChanged(e):
   if e.value > 0 and e.value < 301:
     device.setOutputState(0, 1)
     device.setOutputState(1, 0)
     device.setOutputState(2, 0)
   if e.value > 300 and e.value < 601:
     device.setOutputState(0, 0)
     device.setOutputState(1, 1)
     device.setOutputState(2, 0)
   if e.value > 601 and e.value < 999:
     device.setOutputState(0, 0)
     device.setOutputState(1, 0)
     device.setOutputState(2, 1)

					

Arduino Firmata Example


import pyfirmata

PIN = 12 # Pin 12 is used
DELAY = 2 # A 2 seconds delay

PORT = '/dev/ttyACM0'

# Creates a new board
board = pyfirmata.Arduino(PORT)

# Loop for blinking the led
while True:
    board.digital[PIN].write(1) # Set the LED pin to 1 (HIGH)
    board.pass_time(DELAY)
    board.digital[PIN].write(0) # Set the LED pin to 0 (LOW)
    board.pass_time(DELAY)

Synapse-wireless Example



from synapse.evalBase import *
from synapse.pinWakeup import *
from synapse.switchboard import *
from synapse.platforms import *
from synapse.hexSupport import *

...

def beep(length,Tone):
    x = 0
    setPinDir(GPIO_6,True)
    while x < length:
        x = x+1
        pulsePin(GPIO_6,Tone,True)
    setPinDir(GPIO_6,False)

Spark-core Example



/* FIRMWARE */
int temperature = 0;

void setup()
{
  Spark.variable("temperature", &temperature, INT);
  pinMode(A0, INPUT);
}

void loop()
{
  temperature = analogRead(A0);
}

curl "https://api.spark.io/v1/devices/device/temperature?access_token=token"

Front Door Twitter



import twitter

twit = twitter.Api(username=, password=)


def interfaceKitInputChanged(e):
    print "Input %i: %s" % (e.index, e.state)

    if e.index == 4:
        if interfaceKit.getInputState(e.index):
            status = twit.PostUpdate('Front Door contact was open and now its closed')
        else:
            status = twit.PostUpdate('Front Door contact was closed and now its open')



http://www.instructables.com/id/Combining-security-system-with-phidges-and-twitter/

THE END

Mark Cotton / @mcotton