Skip to main content

Extensive Arduino abstraction

Project description

pyduin

A Pyhton wrapper for Arduino and other IOT devices such as ESP. It aims to support everything, that platformio supports. It consists of two parts

  • A python library
  • A firmware to be loaded onto the device

[[TOC]]

What for?

To interact seamless with an Arduino or other IOT device from within Python. Once a device has the correct firmware applied, one can set pin modes, pin states, pwm values and more.

This makes it easy to wire a sensor to an IOT device, connect it to a computer and start working with the sensor values in Python. The library supports:

  • Analog read and write
  • Digital read and write
  • OneWire
  • DHT Sensors
  • ...

Installation

pyduin module

Only pip installs are available.

pip install pyduin

Dependency socat

To make meaningful use of the CLI features, the installation and usage of soact is recommendet. To activate usage, edit ~/.pyduin.yml and set use_socat to yes (default).

serial:
  use_socat: yes

If socat is installed, a proxy will be started for every device that connections are made to. The pins get set up accordint to the pinfile and the inital modes get set on first conect. The following connections will not reset the arduino. The proxy will stop safely on device disconnect. The proxy will also be stopped for flashing.

Usage

As python module

After installation the pyduin module can be imported.

from pyduin import arduino

Arduino = arduino.Arduino(model='nano', tty='/dev/ttyUSB0', pinfile='~/.pyduin/pinfiles/nano.yml', baudrate=115200)
firmware_version = Arduino.get_firmware_version()
Arduino.Pins[13].set_mode('OUTPUT')
Arduino.Pins[13].high()
free_mem = Arduino.get_free_memory()

CLI

The following command turns on the onboard LED on an Arduino Nano

pyduin -t /dev/ttyUSB0 --board nanoatmega328 pin 13 high 

To connect to a device, it is necessary to specify the baudrate, tty and model(board) arguments. Since there are some defaults set (see: pyduin --help), only differing arguments need to be specified. The following call shows the default values for baudrate and tty ommited, but pinfile and model present. This means that implicitly /dev/ttyUSB0 will be used and the connection speed will be 115200 baud.

The buddy list

The buddy-list feature allows one to define buddies. Here the same defaults apply as when invoked from command line. Thus only differences need to be specified.

buddies:
  uber:
    board: nanoatmega328 # as in platformio
    tty: /dev/uber
    pinfile: ~/nanoatmega328_pins_dev.yml # optional 
    ino: ~/arduino-sketchbook/uber/uber.ino # optional
pyduin -B uber pin 13 high

Flashing firmware to the arduino

Then the buddies can be addressed with the -B option. The following example would build the .ino file from the example above and flash it to the arduino.

pyduin -B uber flash

It can also be done without the buddy list.

pyduin --board nanoatmega328 --tty=/dev/mytty flash

If the --firmware option is ommitted, then the project firmware gets applied.

Control the arduinos pins

Opening a serial connection resets most arduinos. pyduin circumvents this drawback with a socat proxy. Also another variant (hupcl:off) is in the pipeline. The difference is, that socat will set all pin modes on startup while the hupcl approach will require the user to set the pin mode manually. The big plus of the hupcl approach independence of third party applications.

pyduin --buddy uber pin 4 {high|low}

Also the pin mode can be set

pyduin -B uber pin 4 mode {input|ouput|input_pullup,pwm}

Get firmware version from the arduino

pyduin --buddy uber firmware

Get free memory from the arduino

pyduin --buddy uber --action free

Contribute

mkdir pyduindev && cd !$
git git@github.com:SteffenKockel/pyduin.git
virtualenv .
. bin/activate
pip install -e .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyduin-0.6.1.tar.gz (31.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyduin-0.6.1-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

Details for the file pyduin-0.6.1.tar.gz.

File metadata

  • Download URL: pyduin-0.6.1.tar.gz
  • Upload date:
  • Size: 31.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for pyduin-0.6.1.tar.gz
Algorithm Hash digest
SHA256 057de46562a9ad156582915496d0ceb2d43b6b6bb3ca93e96272dde5de38aaa7
MD5 62d10e8a2e7a3fdbdcda3690d22c93b4
BLAKE2b-256 b0ed5f0de181afdc686e9d79739e8a3f2b10c1d804285e5a3f369ddd8125414f

See more details on using hashes here.

File details

Details for the file pyduin-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: pyduin-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 28.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for pyduin-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1fdeb8ec426e77dfdf89d532d6c1c24adc1e17342323aa73c67299abb08ec968
MD5 bfd9d1ec293aa611b1ae9e36da74d675
BLAKE2b-256 b9a9b457fbe4ac46c9c74ad1c435796c279fdbbb8ca6bec9021d5b3b1d703c7f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page