Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
sjpark608 committed Aug 22, 2024
2 parents f0c6e71 + 8a30eeb commit 45b6b6d
Show file tree
Hide file tree
Showing 38 changed files with 1,233 additions and 510 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[bumpversion]
tag_name = rc/v{new_version}
current_version = 1.2.17
current_version = 1.2.21
2 changes: 1 addition & 1 deletion .github/workflows/build-and-publish-PyPI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run: |
python -m build
- name: Publish Package to PyPI
uses: pypa/gh-action-pypi-publish@v1.5.0
uses: pypa/gh-action-pypi-publish@v1.9.0
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
Expand Down
48 changes: 25 additions & 23 deletions .github/workflows/build-and-publish-TestPyPI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
run: |
python -m build
- name: Publish Distribution to TestPyPI
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@v1.9.0
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
Expand All @@ -69,26 +69,28 @@ jobs:
git config user.email ${{ env.commit_email }}
git cherry-pick ${{ env.bump_commit }}
git push origin dev
Hardware_Test:
needs: publish
name: Hardware Tests
runs-on: [self-hosted, linux, ARM64, hw-test]
strategy:
fail-fast: false
matrix:
python-version: ["3.9"]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Dependencies
run: |
python -m venv venv_hardware_test
source venv_hardware_test/bin/activate
python -m pip install --upgrade pip
python -m pip install pytest
if [ -f requirements_hw_test.txt ]; then pip install -r requirements_hw_test.txt; fi
- name: Test with pytest
run: |
source venv_hardware_test/bin/activate
python -m pytest ./tests/hardware_tests
# Hardware_Test:
# needs: publish
# name: Hardware Tests
# runs-on: [self-hosted, linux, ARM64, hw-test]
# strategy:
# fail-fast: false
# matrix:
# python-version: ["3.9"]

# steps:
# - name: Checkout
# uses: actions/checkout@v3
# - name: Install Dependencies
# run: |
# python -m venv venv_hardware_test
# source venv_hardware_test/bin/activate
# python -m pip install --upgrade pip
# python -m pip install pytest
# if [ -f requirements_hw_test.txt ]; then pip install -r requirements_hw_test.txt; fi
# - name: Test with pytest
# run: |
# source venv_hardware_test/bin/activate
# python -m pytest ./tests/hardware_tests
5 changes: 4 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ disable=logging-fstring-interpolation,
too-many-arguments,
fixme,
too-few-public-methods,
duplicate-code
duplicate-code,
no-else-return,
no-else-raise,
logging-fstring-interpolation

[LOGGING]

Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,27 @@ 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](https://github.com/EdgePi-Cloud/edgepi-python-sdk/tree/main/examples/single_din.py) | |
| Batched DIN | 0.52ms per 8 DIN | 1936 Hz | `digital_input_state_batch(...)` | [examples/batched_din.py](https://github.com/EdgePi-Cloud/edgepi-python-sdk/tree/main/examples/batched_din.py) | |
| Single ADC | 97.3 ms per 8 ADC | 10.3 Hz | `set_config(...)` <br><br> `single_sample()` | [examples/single_adc.py](https://github.com/EdgePi-Cloud/edgepi-python-sdk/tree/main/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](https://github.com/EdgePi-Cloud/edgepi-python-sdk/tree/main/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](https://github.com/EdgePi-Cloud/edgepi-python-sdk/tree/main/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](https://github.com/EdgePi-Cloud/edgepi-python-sdk/tree/main/examples/single_tc.py) | Limited by [hardware](https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31856.pdf) (see conversion mode). 100ms is needed for accurate (19 bit) readings |

# Bug Reports / Feature Requests
Use [GitHub Issues Page](https://github.com/EdgePi-Cloud/edgepi-python-sdk/issues) to report any issues or feature requests.

# Get involved
Follow [@edgepi_cloud on Twitter](https://twitter.com/edgepi_cloud/).
Read and subscribe to the [EdgePi blog](https://www.edgepi.com/blog).
See the [EdgePi wiki](https://wiki.edgepi.com/) for more information on how to get started with your EdgePi.
If you have a specific question, please check out our [discussion forums](https://www.edgepi.com/forums).

# License
Expand Down
38 changes: 38 additions & 0 deletions examples/batched_adc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Example reading from ADC using the batched function"""

import time

from edgepi.adc.edgepi_adc import EdgePiADC
from edgepi.adc.adc_constants import AnalogIn, ADC1DataRate

ITER = 50

def run_test():
"""
This test performs 400 Analog input reads, batched 8 reads at a time.
"""

edgepi_adc = EdgePiADC(enable_cache=False)

start = time.time()
result_list = []
adc_choices = [
AnalogIn.AIN1, AnalogIn.AIN2, AnalogIn.AIN3, AnalogIn.AIN4,
AnalogIn.AIN5, AnalogIn.AIN6, AnalogIn.AIN7, AnalogIn.AIN8,
]

for _ in range(ITER):
tmp = edgepi_adc.read_samples_adc1_batch(
data_rate=ADC1DataRate.SPS_38400,
analog_in_list=adc_choices,
)
result_list += [tmp]

elapsed = time.time() - start

print(result_list[24])
print(f"Time elapsed {elapsed/ITER:.6f} s")
print(f"Frequency {ITER/elapsed:.4f} hz")

if __name__ == "__main__":
run_test()
44 changes: 44 additions & 0 deletions examples/batched_adc_diff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Example reading from from individual ADC pins"""

import time

from edgepi.adc.edgepi_adc import EdgePiADC
from edgepi.adc.adc_constants import AnalogIn, ADC1DataRate, DiffMode

ITER = 50

def run_test():
"""
This test performs 300 analog input reads, with 50 for each of 4 analog pins, and
50 for each of 2 differential analog pairs.
"""

edgepi_adc = EdgePiADC(enable_cache=False)

start = time.time()
result_list = []
adc_choices = [
AnalogIn.AIN1, AnalogIn.AIN2,
AnalogIn.AIN5, AnalogIn.AIN6,
]
differential_pairs = [
DiffMode.DIFF_2,
DiffMode.DIFF_4,
]

for _ in range(ITER):
tmp = edgepi_adc.read_samples_adc1_batch(
ADC1DataRate.SPS_38400,
adc_choices,
differential_pairs,
)
result_list += [tmp]

elapsed = time.time() - start

print(result_list[24])
print(f"Time elapsed {elapsed/ITER:.6f} s")
print(f"Frequency {ITER/elapsed:.4f} hz")

if __name__ == "__main__":
run_test()
34 changes: 34 additions & 0 deletions examples/batched_din.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Example reading from DIN using the batched function"""

import time

from edgepi.digital_input.digital_input_constants import DinPins
from edgepi.digital_input.edgepi_digital_input import EdgePiDigitalInput

ITER = 250

def run_test():
"""
This test performs 2000 Digital input reads, batched 8 reads at a time.
"""
digital_input = EdgePiDigitalInput()

state_list = []
choices = [
DinPins.DIN1, DinPins.DIN2, DinPins.DIN3, DinPins.DIN4,
DinPins.DIN5, DinPins.DIN6, DinPins.DIN7, DinPins.DIN8,
]

start = time.time()
for _ in range(ITER):
pin_states = digital_input.digital_input_state_batch(choices)
state_list += [pin_states]

elapsed = time.time() - start

print(f"DIN Pins: {state_list[217]}")
print(f"Time elapsed {elapsed/ITER:.6f} s")
print(f"Frequency {ITER/elapsed:.4f} hz")

if __name__ == "__main__":
run_test()
44 changes: 44 additions & 0 deletions examples/single_adc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Example reading from individual ADC pins"""

import time

from edgepi.adc.edgepi_adc import EdgePiADC
from edgepi.adc.adc_constants import AnalogIn, ADC1DataRate, ConvMode

ITER = 50

def run_test():
"""
This test performs 400 analog input reads, with a total of 50 per ADC pin.
"""
edgepi_adc = EdgePiADC(enable_cache=False)

start = time.time()
result_list = []
adc_choices = [
AnalogIn.AIN1, AnalogIn.AIN2, AnalogIn.AIN3, AnalogIn.AIN4,
AnalogIn.AIN5, AnalogIn.AIN6, AnalogIn.AIN7, AnalogIn.AIN8,
]

for _ in range(ITER):
tmp_list = []
for ain in adc_choices:
edgepi_adc.set_config(
adc_1_analog_in=ain,
conversion_mode=ConvMode.PULSE,
adc_1_data_rate=ADC1DataRate.SPS_38400
)

voltage = edgepi_adc.single_sample()
tmp_list += [voltage]

result_list += [tmp_list]

elapsed = time.time() - start

print(result_list[24])
print(f"Time elapsed {elapsed/ITER:.6f} s")
print(f"Frequency {ITER/elapsed:.4f} hz")

if __name__ == "__main__":
run_test()
35 changes: 35 additions & 0 deletions examples/single_din.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Example reading from individual DIN pins"""

import time

from edgepi.digital_input.digital_input_constants import DinPins
from edgepi.digital_input.edgepi_digital_input import EdgePiDigitalInput

ITER = 250

def run_test():
"""
This test performs 2000 Digital input reads, with a total of 250 per DIN pin.
"""
digital_input = EdgePiDigitalInput()

state_list = []
choices = [
DinPins.DIN1, DinPins.DIN2, DinPins.DIN3, DinPins.DIN4,
DinPins.DIN5, DinPins.DIN6, DinPins.DIN7, DinPins.DIN8,
]

start = time.time()
for _ in range(ITER):
for din in choices:
pin_state = digital_input.digital_input_state(din)
state_list += [pin_state]

elapsed = time.time() - start

print(f"DIN Pins: {state_list[-9:-1]}")
print(f"Time elapsed {elapsed/ITER:.6f} s")
print(f"Frequency {ITER/elapsed:.4f} hz")

if __name__ == "__main__":
run_test()
41 changes: 41 additions & 0 deletions examples/single_tc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Example reading from the thermocouple (tc)"""

import time

from edgepi.tc.edgepi_tc import EdgePiTC
from edgepi.tc.tc_constants import ConvMode

ITER = 25

def run_test():
"""
This test
"""
edgepi_tc = EdgePiTC()
edgepi_tc.set_config(conversion_mode=ConvMode.AUTO)

cj_temperatures = []
lin_temperatures = []

start = time.time()
for _ in range(ITER):
iter_start = time.time()

# make a single temperature measurement
cold_junction, linearized = edgepi_tc.read_temperatures()
cj_temperatures += [cold_junction]
lin_temperatures += [linearized]

# It doesn't make sense to read thermocoupler values faster than 10hz as they
# won't be updated. You can try it here if you'd like!
sleep_time = 0.1 - (time.time() - iter_start)
time.sleep(0.0 if sleep_time < 0.0 else sleep_time)

elapsed = time.time() - start

print(f"TC Reads: {lin_temperatures}")
print(f"Time elapsed {elapsed/ITER:.6f} s")
print(f"Frequency {ITER/elapsed:.4f} hz")

if __name__ == "__main__":
run_test()
26 changes: 0 additions & 26 deletions requirements_build.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1 @@
bleach==5.0.0
build==0.7.0
certifi==2021.10.8
charset-normalizer==2.0.12
colorama==0.4.4
commonmark==0.9.1
docutils==0.18.1
idna==3.3
importlib-metadata==4.11.3
keyring==23.5.0
packaging==21.3
pep517==0.12.0
pkginfo==1.8.2
Pygments==2.12.0
pyparsing==3.0.9
pywin32-ctypes==0.2.0
readme-renderer==35.0
requests==2.27.1
requests-toolbelt==0.9.1
rfc3986==2.0.0
rich==12.4.1
six==1.16.0
tomli==2.0.1
twine==4.0.0
urllib3==1.26.9
webencodings==0.5.1
zipp==3.8.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setuptools.setup(
name="edgepi-python-sdk",
version="1.2.17",
version="1.2.21",
author="S.Park",
author_email="[email protected]",
description="EdgePi Python SDK package",
Expand Down
Loading

0 comments on commit 45b6b6d

Please sign in to comment.