Skip to content

c64emulator/py-arduino

 
 

Repository files navigation

py-arduino

py-arduino is a Python tool/library to communicate with Arduino through USB (serial port), plus a web application on top of it.

The low level tool is simple to use and extend, only requires pyserial. Many scripts are included to let you quickly start using it (see py_arduino.cli.*).

The web application allows read and write to pins from a web page, easily implement background tasks, manages the concurrent access to the Arduino (from the web interface, background tasks, cron, command line, etc.), and more... It uses Django, PyRO and uWSGI.

The project has some testing utilities, and an emulator, to allow make some test without actually having an Arduino connected.

Other characteristics

  • Python methods named around Arduino's methods
  • Handles connections timeouts
  • Can recover after timeouts and connection's troubles - see: validateConnection()
  • Easy to extend
  • Easy to debug (with --arduino-debug, which dumps all the data transmitted to/from Arduino)
  • Growing documentation

Implemented methods

The basic methods of Arduino are implemented. The following actions can be done from Python:

  • pinMode()
  • digitalRead()
  • digitalWrite()
  • analogRead()
  • analogWrite()
  • millis(), micro()
  • delay(), delayMicroseconds()`
  • shiftOut()

There are other extra methods:

  • ping() to check communication with Arduino
  • getFreeMemory() returns free Arduino memory
  • autoconnect() to automatically connect to any available serial port
  • validateConnection() to recover after communications problems
  • watchInterrupt(), getInterruptMark() to work with interrupts (Prototype/Work In Progress)
  • enableDebug(), disableDebug(), enableDebugToLcd() to show debug messages
  • getAvrCpuType(), getArduinoTypeStruct() to get information about the Arduino
  • streamingAnalogRead(), streamingDigitalRead() eficientlly receive much values (Prototype/Work In Progress)

And support for:

  • lcdMessage(), lcdWrite(), lcdClear() show messages on LCDs, based on the Hitachi HD44780 (or a compatible) chipset
  • dht11_read() read temperature and humidity with DHT11 sensor
  • ds18x20_read() read temperature with DS18x20 sensor

Quick installation instructions (low level tool/library)

Quick instructions (see full install instructions and other documentation here)

$ git clone https://github.com/hgdeoro/py-arduino.git
$ cd py-arduino
$ virtualenv -p python2.7 virtualenv
$ . virtualenv/bin/activate
$ pip install -r requirements.txt

Then upload the sketch from sketches/py_arduino, and test:

$ python -m py_arduino.cli.ping /dev/ttyACM0

Installation (web application)

To install the web application, follow the steps on Installation (low level tool/library), and then:

$ pip install -r requirements-web.txt
$ python -m py_arduino_web.dj.manage syncdb --noinput --migrate

(that will create a Sqlite3 database at ~/py_arduino.sqlite).

To launch the web server, run:

$ ./bin/run_uwsgi.sh

connect your Arduino, go to http://localhost:8080/, insert the serial device (something like /dev/ttyACM0) and clic 'Connect'.

To use the Django Admin (to modify pin labels, etc.), you'll need to create an user:

$ python -m py_arduino_web.dj.manage createsuperuser

TODOs

  • Add INPUT_PULLUP to pinMode()
  • Add missing basic functions: tone(), analogReference()
  • Add support to use analog pins as digital pins
  • Better streaming support
  • Multi-read (read multiple pins in a single operation)
  • Finish support for interrupt
  • Make hardware-specific functionality optional (LCD, DHT11, etc.)

License y copyright

py-arduino - Access your Arduino from Python
Copyright (C) 2011-2013 - Horacio Guillermo de Oro <hgdeoro@gmail.com>

py-arduino is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2.

py-arduino is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License version 2 for more details.

About

Communicate with Arduino from Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • CSS 36.5%
  • Python 24.1%
  • JavaScript 22.5%
  • C++ 8.6%
  • C 2.9%
  • PHP 2.8%
  • Other 2.6%