• Stars
    star
    117
  • Rank 300,685 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created over 11 years ago
  • Updated almost 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Firmata based framework for interacting with Arduinos over serial.

BreakfastSerial

A Firmata based framework for interacting with Arduinos over serial.

Arduino Setup

In order to use BreakfastSerial, you need to have an arduino running the standard firmata.

  1. Download the Arduino IDE from the arduino website
  1. Plug in your Arduino or Arduino compatible microcontroller via USB
  2. Open the Arduino IDE, select: File > Examples > Firmata > StandardFirmata
  3. Click the "Upload" button.

Installation

Using PyPi

pip install BreakfastSerial

From Source

git clone git://github.com/theycallmeswift/BreakfastSerial.git && cd BreakfastSerial

python setup.py install

Getting Started

The BreakfastSerial library provides a simple abstraction for a number of common components. Make sure your arduino is plugged in and is running firmata.

Arduino

If you create a Arduino object without any parameters, it will attempt to auto discover the serial port that the Arduino is attached to and connect automatically. Optionally, you can supply the path to a serial port (Ex. "/dev/tty.usbmodem4111").

from BreakfastSerial import Arduino
board = Arduino() # This will autodiscover the device

Blink an LED

To use the led object, import Led from BreakfastSerial. The constructor takes an Arduino object and a pin number as its arguments.

from BreakfastSerial import Arduino, Led
from time import sleep

board = Arduino()
pin = 13
led = Led(board, pin)

led.on()
sleep(2)
led.off()

You can also use the blink method and pass it a number of milliseconds to automate the blinking process

millis = 200
led.blink(millis)

Push a button

The Button component has a number of helper methods that make it easy to work with buttons. The constructor takes an Arduino object and a pin number as its arguments.

from BreakfastSerial import Button, Arduino

board = Arduino()
button = Button(board, 8)

def down_cb():
  print "button down"

def up_cb():
  print "button up"

def hold_cb():
  print "button held"

button.down(down_cb)
button.up(up_cb)
button.hold(hold_cb)

The down and up functions are just nice wrappers around the underlying event emitter. The Button component emits the following events:

  • change - The button value changed
  • down - The button is pressed
  • up - The button is not being pressed
  • hold - The button was held for at least 1 second

Use an RGB Led

The RGBLed component lets us change the colors of an RGB Led without having to interact with the three underlying leds.

from BreakfastSerial import Arduino, RGBLed
from time import sleep

board = Arduino()
led = RGBLed(board, { "red": 10, "green": 9, "blue": 8 })

led.red()
sleep(1)

led.green()
sleep(1)

led.blue()
sleep(1)

led.yellow()
sleep(1)

led.cyan()
sleep(1)

led.purple()
sleep(1)

led.white()
sleep(1)

led.off()

LED Brightness

You can set the brightness of an LED with the brightness function. The LED must be on a PWM capable pin or it will throw and error. Brightness is measured on a scale of 0% to 100%.

from BreakfastSerial import Arduino, Led
from time import sleep

board = Arduino()
pin = 9
led = Led(board, pin)

for x in range(0, 100):
  led.brightness(x)
  sleep(0.01)

Read a sensor

The Sensor component lets us read in data from a sensor (analog or digital). The constructor takes in an Arduino object and a pin number.

from BreakfastSerial import Arduino, Sensor

board = Arduino()
sensor = Sensor(board, "A0")

def print_value():
  print sensor.value

sensor.change(print_value)

The Sensor object has the following properties:

  • threshold - the amount value must change by to trigger a change event (Default: 0.01)
  • value - the value of the underlying pin

The change function is just a nice wrapper around the underlying event emitter. The Sensor component emits the following events:

  • change - The sensor value change by at least the amount of threshold

Control a servo

The Servo component let's us control a servo. The constructor takes in an Arduino object and a pin number.

from BreakfastSerial import Arduino, Servo
from time import sleep

board = Arduino()
servo = Servo(board, "10")

servo.set_position(180)
sleep(2)
servo.move(-135)
sleep(2)
servo.center()
sleep(2)
servo.reset()

The value property of a Servo object is the current position of the servo in degrees

Control a DC Motor

The Motor component let's us control a DC Motor. The constructor takes in an Arduino object and a pin number. The motor must be on a PWM capable pin.

from BreakfastSerial import Arduino, Motor
from time import sleep

board = Arduino()
motor = Motor(board, 9)

motor.start(80)
sleep(2)
motor.speed = 50
sleep(2)
motor.stop()

The speed property is represented in a percentage of max speed. So, speed = 80 is setting the motor to 80% speed. Setting speed equal to 0 is the same as calling stop().

Moar!

There are a bunch of examples in the examples/ folder. Additional components will be added over time, so be sure to check back regularly.

githalytics.com alpha

More Repositories

1

node-mongodb-s3-backup

A node.js package that makes syncing a MongoDB database to S3 simple.
JavaScript
112
star
2

quill

Quill is a simple blog engine inspired by Jekyll. Quill runs on node and has an easy command line interface. Themeing is as simple as editing a single html page.
JavaScript
51
star
3

arduino-101-workshop

A basic arduino workshop with Node.js
Arduino
14
star
4

Direct-Mapped-Cache-Simulation

This is a C implementation of a direct mapped cache (simulation)
C
14
star
5

grooveshark

A node.js package for grooveshark
CoffeeScript
11
star
6

SendGrid-Markdown-Demo

This is a demo using Node.js and websockets to send markdown formatted emails powered by SendGrid
JavaScript
10
star
7

playlist.sendgriddemos.com

A social playlist that's entirely powered by email using SendGrid's parse API and Rdio
JavaScript
10
star
8

forgery

A simple library for creating mock API data for testing
CoffeeScript
8
star
9

heroku-unicorn-scheduler

An email scheduler that you can run for FREE on heroku using unicorn
Ruby
4
star
10

iFridge

Totally awesome RFID integrated, Arduino powered fridge. Nuff said.
JavaScript
4
star
11

testuino

A simple build status notifier powered by arduino. [WIP]
JavaScript
3
star
12

TwilioEstevez.com

An API for Emilio Estevez jokes [Comedy Hack Day]
JavaScript
3
star
13

declaration-of-twitter-independence

The Declaration of Independence for Twitter Developers
JavaScript
3
star
14

Colloqueasy

Social network for CS336 written in PHP
PHP
3
star
15

Basic-C-Desktop-Search

Basic desktop search implemented in C. Takes advantage of basic data structures and software cacheing.
C
2
star
16

node-drone-virus

JavaScript
2
star
17

Twaiku

Twilio / Twitter powered Haikus
CoffeeScript
2
star
18

hackshots.com

An HTTPS wrapper for PinkyUrl.com
JavaScript
2
star
19

theycallmeswift.github.com

My personal blog, portfolio, and resume.
HTML
2
star
20

DiffChat

Real time code review and collaboration
JavaScript
1
star
21

jobs.theycallmeswift.com

The theycallmeswift.com jobs site
CSS
1
star
22

ChartBuildr

A web interface for designing and saving beautiful charts
JavaScript
1
star
23

full-stack-testing-with-node

Slides and sample code from my Codemash 2013 session
JavaScript
1
star
24

Frontend-JS-Demo

JavaScript
1
star
25

Class-Notes

CoffeeScript
1
star
26

Spine-Boilerplate

A basic boilerplate for a spine app with jasmine for unit testing and cucumber for integrations
CoffeeScript
1
star
27

shin-ny-wrapper

A RESTful wrapper for the SHIN-NY API so you don't have to SOAP around all day
JavaScript
1
star
28

1-through-9

Using the numbers 1 through 9, without changing the order insert a "+", "*", or nothing between each number to get an expression that evaluates to 2002.
Ruby
1
star