Skip to main content

EdgePi Python SDK package

Project description

Image

EdgePi is a DIN rail-mounted, Raspberry Pi 4 industrial PC with the features of a Programmable Logic Controller (PLC), and Internet of Things (IoT) cloud edge device. Visit edgepi.com for more information.

License

EdgePi SDK

Use our user-friendly Python SDK to control the EdgePi hardware with just a few lines of simple Python Code. Image

How to Use EdgePi SDK

How to Install

The latest stable release of the EdgePi SDK will be available to be installed via The Python Package Index (PyPi). To install the EdgePi SDK from PyPi via pip, you may use the following command from terminal:

$ python3 -m pip install edgepi-python-sdk

Example Code

The EdgePi SDK provides a wide range of functionality to users, allowing interaction with the many modules onboard the EdgePi. One such module, the ADC, can be used to read voltage continuously from any of the eight EdgePi analog input pins:

from edgepi.dac.edgepi_adc import EdgePiADC
from edgepi.adc.adc_constants import ADCChannel, ConvMode

# initialize ADC
edgepi_adc = EdgePiADC()

# configure ADC to sample input pin 4 (the input pins are 0-indexed)
edgepi_adc.set_config(adc_1_analog_in=ADCChannel.AIN3, conversion_mode=ConvMode.CONTINUOUS)

# send command to start automatic conversions
edgepi_adc.start_conversions()

# perform 10 voltage reads
for _ in range(10):
  out = edgepi_adc.read_voltage()
  print(out)
  
# stop automatic conversions
edgepi_adc.stop_conversions()

For further details on this and other modules, please refer to each module's documentation by following the links provided in the Implemented Modules section below.

Implemented Modules

The EdgePi SDK contains modules intended to represent each connected peripheral device onboard the EdgePi. Below is a directory of the currently available modules.

Development

Active development SDK versions can be accessed from the following resources:

Installing from TestPyPi

To install the most recent active development SDK version via TestPyPi:


$ python3 -m pip install -i https://test.pypi.org/simple/edgepi-python-sdk

Previous development SDK versions can also be installed by specifiying the version number:

$ python3 -m pip install -i https://test.pypi.org/simple/edgepi-python-sdk==<version-number>

Please refer to TestPyPi for available SDK versions.

Installing from GitHub

To install the SDK via HTTPS from GitHub:

$ python3 -m pip install git+https://github.com/EdgePi-Cloud/edgepi-python-sdk.git@<branch-name>

Packaging

To build and publish a new SDK version as a package, a build virtual environment is required. This may be configured as follows:

$ cd edgepi-python-sdk

$ python3 -m venv venv_build

$ source venv_build/bin/activate 

$ python3 -m pip install -r requirements_build.txt

With the build environment configured and activated, a new distribution can be built as follows:

$ python3 -m build

Note, when the package structure changes, such as after renaming the src module or other folders, delete the .egg-info file from /src and rebuild. This will ensure the file names in the compiled package are updated. Also note that changes in file/folder name capitalization are recognized by git. To disable this:

git config --global core.ignorecase false

With the new disbtribution created, you may publish to the official Python package repositories:

To publish to TestPyPi:

$ python3 -m twine upload --repository testpypi dist/* --verbose

To publish to PyPi:

$ python3 -m twine upload dist/* --verbose

Both TestPyPi and PyPi will prompt you for authentication. For best practices, use a corresponding TestPyPi or PyPi token to authenticate as follows:

name: __token__
password: <token-value>

Make sure to include the pypi- prefix for your token value.

Performance

The following benchmarks were measured on the Rasberry Pi 4, with all edgepi daemons disabled. They're also the slowest average of 3 runs.

The Performance column represents how long it takes to call one function, while the Max Read Frequency column represents how many times that function could be called every second.

Feature Performance Max Read Frequency Function Example Description
Single DIN 0.85ms per 8 DIN 1171 Hz digital_input_state(...) examples/single_din.py
Batched DIN 0.52ms per 8 DIN 1936 Hz digital_input_state_batch(...) examples/batched_din.py
Single ADC 97.3 ms per 8 ADC 10.3 Hz set_config(...)

single_sample()
examples/single_adc.py Reads from ADC1 only
Batched ADC 6.49 ms per 8 ADC 154 Hz read_samples_adc1_batch(...) examples/batched_adc.py Reads from ADC1 only
Batched ADC/Diff 5.467 ms per 4 ADC, 2 Diff 183 Hz read_samples_adc1_batch(...) examples/batched_adc_diff.py Differential ADC inputs each use two pins. Reads from ADC1 only
Thermocouple (TC) 100.2ms 9.98 hz read_temperatures() examples/single_tc.py Limited by hardware (see conversion mode). 100ms is needed for accurate (19 bit) readings

Bug Reports / Feature Requests

Use GitHub Issues Page to report any issues or feature requests.

Get involved

Follow @edgepi_cloud on Twitter. See the EdgePi wiki for more information on how to get started with your EdgePi. If you have a specific question, please check out our discussion forums.

License

EdgePi SDK is distributed under MIT License.

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

edgepi_python_sdk-1.2.21.tar.gz (140.7 kB view details)

Uploaded Source

Built Distribution

edgepi_python_sdk-1.2.21-py3-none-any.whl (101.1 kB view details)

Uploaded Python 3

File details

Details for the file edgepi_python_sdk-1.2.21.tar.gz.

File metadata

  • Download URL: edgepi_python_sdk-1.2.21.tar.gz
  • Upload date:
  • Size: 140.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for edgepi_python_sdk-1.2.21.tar.gz
Algorithm Hash digest
SHA256 e5af0a7706ec6d037a1e203c36c5d4378ee4bee68e9e52aa22a1349c4c75010c
MD5 b1a97c1f1df22e67b5b5f6a2b5100bd6
BLAKE2b-256 c0fdefc541f216e1fb7019550938f68810da4d73715c8501d39c0793084cb98a

See more details on using hashes here.

File details

Details for the file edgepi_python_sdk-1.2.21-py3-none-any.whl.

File metadata

File hashes

Hashes for edgepi_python_sdk-1.2.21-py3-none-any.whl
Algorithm Hash digest
SHA256 33faa49dcef9255793b0384747996fe381449915244ea57a1b5041d689b12326
MD5 25d3a895460cb88e3499bb6671780b02
BLAKE2b-256 3e8a746c34c31a0e571b52fe48abbd7fa0720e393384e33a999371ee8649d48c

See more details on using hashes here.

Supported by

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