|
1 | | -# edgepi-python-sdk |
| 1 | + |
2 | 2 |
|
3 | | -## Develop Environment Setup |
4 | | -Two separate virtual environment is needed. |
5 | | -1. venv_build: building environement where the package is compiled and published. import requirements_build.txt for pip dependencies. |
6 | | -2. venv_test |
7 | | - - TDD environment where the package source tree can be tested as bug fix / new features are implemented.The `testPyPi` tries to install the dependency in `testPyPi` instead of actual `PyPi`. Therefore, the `install_requires` option fails to install the required package. |
8 | | - - This environment is also used to test the package after it is published. Install the package using `pip` and run test scripts inside `test` folder. This will import the installed package, not the modules in the `src` directory. |
| 3 | +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](https://www.edgepi.com) for more information. |
9 | 4 |
|
10 | | -## SDK packaging |
| 5 | + |
| 6 | + |
| 7 | +[](https://github.com/EdgePi-Cloud/edgepi-python-sdk/blob/main/LICENSE) |
| 8 | +--- |
| 9 | +# EdgePi SDK |
| 10 | +Use our user-friendly Python SDK to control the EdgePi hardware with just a few lines of simple Python Code. |
| 11 | + |
| 12 | +# How to Use EdgePi SDK |
| 13 | +## How to Install |
| 14 | +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: |
11 | 15 |
|
12 | | -- Use setup.py file to edit meta-data when building/created new package |
13 | | -- run ```python -m build``` command in root directory of the SDK create distribution |
14 | | -- run ```py -m twine upload --repository testpypi dist/* --verbose``` command to upload the distribution to TestPyPi |
| 16 | +``` |
| 17 | +$ python3 -m pip install edgepi-python-sdk |
| 18 | +``` |
| 19 | +## Example Code |
| 20 | +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: |
| 21 | + |
| 22 | +``` |
| 23 | +from edgepi.adc.edgepi_adc import EdgePiADC |
| 24 | +from edgepi.adc.adc_constants import ADCChannel, ConvMode, ADCNum |
| 25 | +
|
| 26 | +# initialize ADC |
| 27 | +edgepi_adc = EdgePiADC() |
| 28 | +
|
| 29 | +# configure ADC to sample analog input pin AIN3 |
| 30 | +edgepi_adc.set_config(adc_1_analog_in=ADCChannel.AIN3, conversion_mode=ConvMode.CONTINUOUS) |
| 31 | +
|
| 32 | +# send command to start continuous conversions |
| 33 | +edgepi_adc.start_conversions(ADCNum.ADC_1) |
| 34 | +
|
| 35 | +# perform 10 voltage reads |
| 36 | +for _ in range(10): |
| 37 | + out = edgepi_adc.read_voltage(ADCNum.ADC_1) |
| 38 | + print(out) |
| 39 | + |
| 40 | +# stop continuous conversions |
| 41 | +edgepi_adc.stop_conversions(ADCNum.ADC_1) |
| 42 | +``` |
| 43 | +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. |
| 44 | +# Implemented Modules |
| 45 | +The EdgePi SDK contains modules intended to represent each connected peripheral device onboard the EdgePi. Below is a directory of the currently available modules. |
| 46 | +* [Thermocouple](src/edgepi/tc) |
| 47 | +* [Digital to Analog Converter (DAC)](src/edgepi/dac) |
| 48 | +* [Analog to Digital Converter (ADC)](src/edgepi/adc) |
| 49 | +* [LED Array](src/edgepi/led) |
| 50 | +* [Digital In (DIN)](src/edgepi/din) |
| 51 | +* [Digital Out (DOUT)](src/edgepi/dout) |
| 52 | +# Development |
| 53 | +Active development SDK versions can be accessed from the following resources: |
| 54 | +## Installing from TestPyPi |
| 55 | +To install the most recent active development SDK version via [TestPyPi](https://test.pypi.org/project/edgepi-python-sdk/): |
| 56 | +``` |
| 57 | +$ python3 -m pip install -i https://test.pypi.org/simple/ edgepi-python-sdk |
| 58 | +``` |
| 59 | +Previous development SDK versions can also be installed by specifiying the version number: |
| 60 | +``` |
| 61 | +$ python3 -m pip install -i https://test.pypi.org/simple/ edgepi-python-sdk==<version-number> |
| 62 | +``` |
| 63 | +Please refer to [TestPyPi](https://test.pypi.org/project/edgepi-python-sdk/) for available SDK versions. |
| 64 | +## Installing from GitHub |
| 65 | +To install the SDK via HTTPS from GitHub: |
| 66 | +``` |
| 67 | +$ python3 -m pip install git+https://github.com/EdgePi-Cloud/edgepi-python-sdk.git@<branch-name> |
| 68 | +``` |
| 69 | + |
| 70 | +# Packaging |
| 71 | +To build and publish a new SDK version as a package, a build virtual environment is required. This may be configured as follows: |
| 72 | +``` |
| 73 | +$ cd edgepi-python-sdk |
| 74 | +
|
| 75 | +$ python3 -m venv venv_build |
15 | 76 |
|
16 | | -__NOTE__ when package structure name, such as folder or module src file name, changes, delete '.egg-info' file and rebuild. This will ensure the file name in compiled package is changed. |
| 77 | +$ source venv_build/bin/activate |
17 | 78 |
|
18 | | -Change in capitalization in file/folder names are recognized by git |
| 79 | +$ python3 -m pip install -r requirements_build.txt |
| 80 | +``` |
| 81 | +With the build environment configured and activated, a new distribution can be built as follows: |
| 82 | +``` |
| 83 | +$ python3 -m build |
| 84 | +``` |
| 85 | +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: |
19 | 86 | ``` |
20 | 87 | git config --global core.ignorecase false |
21 | 88 | ``` |
22 | 89 |
|
23 | | -## SDK Structure |
24 | | -``` |
25 | | -EDGEPI-PYTHON-SDK |
26 | | -├── src |
27 | | -│ └── edgepi |
28 | | -│ ├── __init__.py |
29 | | -│ ├── dac |
30 | | -│ │ ├── __init__.py |
31 | | -│ │ └── ...submodules |
32 | | -│ ├── peripherals |
33 | | -│ │ ├── __init__.py |
34 | | -│ │ └── ...submodules |
35 | | -│ ├── ...subpackages |
36 | | -│ ├── edgepi_dac.py |
37 | | -│ ├── edgepi_adc.py |
38 | | -│ ├── edgepi_tc.py |
39 | | -│ └── ...modules |
40 | | -│ └── test_edgepi |
41 | | -│ ├── __init__.py |
42 | | -│ ├── test_dac |
43 | | -│ │ ├── __init__.py |
44 | | -│ │ └── ...submodules |
45 | | -│ ├── test_peripherals |
46 | | -│ │ ├── __init__.py |
47 | | -│ │ └── ...submodules |
48 | | -│ ├── ...test_subpackages |
49 | | -├── tests |
50 | | -│ ├── test_dac.py |
51 | | -│ ├── test_tc.py |
52 | | -│ └── ...each subpackages |
53 | | -├── readme.md |
54 | | -├── setup.py |
55 | | -└── requirements.txt |
56 | | -``` |
| 90 | +With the new disbtribution created, you may publish to the official Python package repositories: |
| 91 | + |
| 92 | +To publish to TestPyPi: |
| 93 | +``` |
| 94 | +$ python3 -m twine upload --repository testpypi dist/* --verbose |
| 95 | +``` |
| 96 | +To publish to PyPi: |
| 97 | +``` |
| 98 | +$ python3 -m twine upload dist/* --verbose |
| 99 | +``` |
| 100 | + |
| 101 | +Both TestPyPi and PyPi will prompt you for authentication. For best practices, use a corresponding TestPyPi or PyPi token to authenticate as follows: |
| 102 | +``` |
| 103 | +name: __token__ |
| 104 | +password: <token-value> |
| 105 | +``` |
| 106 | +Make sure to include the `pypi-` prefix for your token value. |
| 107 | + |
| 108 | +# Bug Reports / Feature Requests |
| 109 | +Use [GitHub Issues Page](https://github.com/EdgePi-Cloud/edgepi-python-sdk/issues) to report any issues or feature requests. |
| 110 | + |
| 111 | +# Get involved |
| 112 | +Follow [@edgepi_cloud on Twitter](https://twitter.com/edgepi_cloud/). |
| 113 | +Read and subscribe to the [EdgePi blog](https://www.edgepi.com/blog). |
| 114 | +If you have a specific question, please check out our [discussion forums](https://www.edgepi.com/forums). |
| 115 | + |
| 116 | +# License |
| 117 | +EdgePi SDK is distributed under [MIT License](https://github.com/EdgePi-Cloud/edgepi-python-sdk/blob/main/LICENSE). |
0 commit comments