Skip to content

Commit d43bbd4

Browse files
committed
Merge branch 'staging'
2 parents cf93a59 + cd7f7e0 commit d43bbd4

File tree

145 files changed

+7053
-2106
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+7053
-2106
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[bumpversion]
22
tag_name = rc/v{new_version}
3-
current_version = 1.1.17
3+
current_version = 1.2.1

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@ $ python3 -m pip install edgepi-python-sdk
1919
## Example Code
2020
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:
2121

22-
```
23-
from edgepi.adc.edgepi_adc import EdgePiADC
24-
from edgepi.adc.adc_constants import ADCChannel, ConvMode, ADCNum
22+
```python
23+
from edgepi.dac.edgepi_adc import EdgePiADC
24+
from edgepi.adc.adc_constants import ADCChannel, ConvMode
2525

2626
# initialize ADC
2727
edgepi_adc = EdgePiADC()
2828

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

32-
# send command to start continuous conversions
33-
edgepi_adc.start_conversions(ADCNum.ADC_1)
32+
# send command to start automatic conversions
33+
edgepi_adc.start_conversions()
3434

3535
# perform 10 voltage reads
3636
for _ in range(10):
37-
out = edgepi_adc.read_voltage(ADCNum.ADC_1)
37+
out = edgepi_adc.read_voltage()
3838
print(out)
3939

40-
# stop continuous conversions
41-
edgepi_adc.stop_conversions(ADCNum.ADC_1)
40+
# stop automatic conversions
41+
edgepi_adc.stop_conversions()
4242
```
4343
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.
4444
# Implemented Modules

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[pytest]
22
; faulthandler_timeout=5
3-
; log_cli=TRUE
3+
log_cli=False
44
log_level=INFO
55
log_format=%(asctime)s %(levelname)s [%(filename)s:%(lineno)d] %(message)s
66
# **********************

requirements_test.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ tomli==2.0.1
1212
bitstring==3.1.9
1313
pytest-mock==3.7.0
1414
pytest-cov==3.0.0
15-
protobuf==3.20.3
15+
protobuf==4.21.12

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setuptools.setup(
99
name="edgepi-python-sdk",
10-
version="1.1.17",
10+
version="1.2.1",
1111
author="S.Park",
1212
author_email="spark@osensa.com",
1313
description="EdgePi Python SDK package",
@@ -25,5 +25,5 @@
2525
packages=setuptools.find_packages(where="src", exclude=["test_edgepi"]),
2626
package_dir={"": "src"},
2727
python_requires=">=3.6",
28-
install_requires=["python-periphery >= 2.3.0", "bitstring >= 3.1.9", "protobuf==3.20.*"],
28+
install_requires=["python-periphery >= 2.3.0", "bitstring >= 3.1.9", "protobuf>=3.20"],
2929
)

src/edgepi/adc/README.md

Lines changed: 86 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ Note, the EdgePi ADC can be used with two different sampling modes: pulse conver
66

77
### Reading Voltage from Analog Input Pin: Pulse Conversion Mode
88
In pulse conversion mode, a sampling event must be manually triggered. This can be achieved as follows.
9-
```
10-
from edgepi.dac.edgepi_adc import EdgePiADC
11-
from edgepi.adc.adc_constants import ADCChannel, ConvMode
9+
```python
10+
from edgepi.adc.edgepi_adc import EdgePiADC
11+
from edgepi.adc.adc_constants import AnalogIn, ConvMode, ADC1DataRate
1212

1313
# initialize ADC
1414
edgepi_adc = EdgePiADC()
1515

16-
# configure ADC to sample input pin 4 (the input pins are 0-indexed)
17-
edgepi_adc.set_config(adc_1_analog_in=ADCChannel.AIN3, conversion_mode=ConvMode.PULSE)
16+
# configure ADC to sample A-IN 1 (Refer to the EdgePi label for details)
17+
edgepi_adc.set_config(adc_1_analog_in=AnalogIn.AIN1, conversion_mode=ConvMode.PULSE, adc_1_data_rate=ADC1DataRate.SPS_38400)
1818

1919
# trigger sampling event
2020
out = edgepi_adc.single_sample()
@@ -25,28 +25,102 @@ print(out)
2525
In continuous conversion mode, sampling events occur automatically. However, after configuring the ADC
2626
to perform continuous conversion, the user must send a command to start the conversions, and
2727
sampling data must also be manually by the user.
28+
```python
29+
from edgepi.adc.edgepi_adc import EdgePiADC
30+
from edgepi.adc.adc_constants import AnalogIn, ConvMode, ADCNum, ADC1DataRate
31+
32+
# initialize ADC
33+
edgepi_adc = EdgePiADC()
34+
35+
# configure ADC to sample A-IN 1 (Refer to the EdgePi label for details)
36+
edgepi_adc.set_config(adc_1_analog_in=AnalogIn.AIN1, conversion_mode=ConvMode.CONTINUOUS, adc_1_data_rate=ADC1DataRate.SPS_38400)
37+
38+
# send command to start automatic conversions
39+
edgepi_adc.start_conversions(ADCNum.ADC_1)
40+
41+
# perform 10 voltage reads
42+
for _ in range(10):
43+
out = edgepi_adc.read_voltage(ADCNum.ADC_1)
44+
print(out)
45+
46+
# stop automatic conversions
47+
edgepi_adc.stop_conversions(ADCNum.ADC_1)
2848
```
29-
from edgepi.dac.edgepi_adc import EdgePiADC
30-
from edgepi.adc.adc_constants import ADCChannel, ConvMode
49+
### Reading Voltage from Analog Input Pin: Continuous Conversion Mode and Differential
50+
```python
51+
from edgepi.adc.edgepi_adc import EdgePiADC
52+
from edgepi.adc.adc_constants import AnalogIn, ConvMode, ADCNum, ADC1DataRate, DiffMode
3153

3254
# initialize ADC
3355
edgepi_adc = EdgePiADC()
3456

35-
# configure ADC to sample input pin 4 (the input pins are 0-indexed)
36-
edgepi_adc.set_config(adc_1_analog_in=ADCChannel.AIN3, conversion_mode=ConvMode.CONTINUOUS)
57+
# configure ADC to sample A-IN 1 (Refer to the EdgePi label for details)
58+
edgepi_adc.set_config(adc_1_analog_in=AnalogIn.AIN1, conversion_mode=ConvMode.CONTINUOUS, adc_1_data_rate=ADC1DataRate.SPS_38400)
59+
# Configure inputs to differential between A/DIN5 and A/DIN6
60+
edgepi_adc.select_differential(ADCNum.ADC_1,DiffMode.DIFF_3)
3761

3862
# send command to start automatic conversions
39-
edgepi_adc.start_conversions()
63+
edgepi_adc.start_conversions(ADCNum.ADC_1)
4064

4165
# perform 10 voltage reads
4266
for _ in range(10):
43-
out = edgepi_adc.read_voltage()
67+
out = edgepi_adc.read_voltage(ADCNum.ADC_1)
4468
print(out)
4569

4670
# stop automatic conversions
47-
edgepi_adc.stop_conversions()
71+
edgepi_adc.stop_conversions(ADCNum.ADC_1)
4872
```
4973
___
74+
75+
### Reading RTD Measurements: Pulse Conversion Mode
76+
Input 4-8 can be configured to read three-leaded RTD sensor.
77+
```python
78+
from edgepi.adc.edgepi_adc import EdgePiADC
79+
from edgepi.adc.adc_constants import AnalogIn, ConvMode, ADCNum
80+
81+
# initialize ADC
82+
edgepi_adc = EdgePiADC()
83+
84+
edgepi_adc.set_config(conversion_mode=ConvMode.PULSE)
85+
# Both ADC_1 and ADC_2 are available but only one of them is used at a time. It uses ADC_2 by default
86+
edgepi_adc.set_rtd(True, ADCNum.ADC_2)
87+
88+
# trigger sampling event
89+
edgepi_adc.single_sample_rtd()
90+
91+
# Disable RTD
92+
edgepi_adc.set_rtd(False, ADCNum.ADC_2)
93+
94+
```
95+
### Reading RTD Measurements: Continuous Conversion Mode
96+
Input 4-8 can be configured to read three-leaded RTD sensor.
97+
```python
98+
from edgepi.adc.edgepi_adc import EdgePiADC
99+
from edgepi.adc.adc_constants import AnalogIn, ConvMode, ADCNum
100+
101+
# initialize ADC
102+
edgepi_adc = EdgePiADC()
103+
104+
edgepi_adc.set_config(conversion_mode=ConvMode.CONTINUOUS)
105+
# Both ADC_1 and ADC_2 are available but only one of them is used at a time
106+
edgepi_adc.set_rtd(True, ADCNum.ADC_2)
107+
108+
# send command to start automatic conversions
109+
edgepi_adc.start_conversions(ADCNum.ADC_2)
110+
111+
# perform 10 voltage reads
112+
for _ in range(10):
113+
out = edgepi_adc.read_rtd_temperature()
114+
print(out)
115+
116+
# stop automatic conversions
117+
edgepi_adc.stop_conversions(ADCNum.ADC_2)
118+
# Disable RTD
119+
edgepi_adc.set_rtd(False, ADCNum.ADC_2)
120+
121+
```
122+
___
123+
50124
## Using ADC Module
51125
This section introduces ADC functionality available to users.
52126

src/edgepi/adc/adc_commands.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def read_register_command(self, address: int, num: int):
2020
"""Trigger ADC register read"""
2121
self.check_for_int([address, num])
2222
command = [ADCComs.COM_RREG.value + address, num - 1]
23-
_logger.debug("RREG command to send is %s", (command + [255] * num))
2423
return command + [255] * num
2524

2625
def write_register_command(self, address, values):
@@ -29,7 +28,6 @@ def write_register_command(self, address, values):
2928
all(self.check_range(value, 0, 255) for value in values)
3029
self.check_for_int(values)
3130
command = [ADCComs.COM_WREG.value + address, len(values) - 1]
32-
_logger.debug("WREG Command to send is %s", (command + values))
3331
return command + values
3432

3533
def start_adc(self, adc_num: ADCNum):

src/edgepi/adc/adc_constants.py

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ class ADCReg(Enum):
6565
REG_ADC2FSC0 = 0x19
6666
REG_ADC2FSC1 = 0x1A
6767

68+
@unique
69+
class AnalogIn(Enum):
70+
"""EdgePi Analog Input Number"""
71+
72+
AIN1 = 0
73+
AIN2 = 1
74+
AIN3 = 2
75+
AIN4 = 3
76+
AIN5 = 4
77+
AIN6 = 5
78+
AIN7 = 6
79+
AIN8 = 7
80+
AINCOM = 10
81+
FLOAT = 0xF
6882

6983
@unique
7084
class ADCChannel(Enum):
@@ -313,30 +327,59 @@ class REFMUX(Enum):
313327
NEG_REF_EXT_AIN5 = OpCode(0x3, ADCReg.REG_REFMUX.value, ADCMasks.RMUXN_BITS.value)
314328
NEG_REF_INT_VAVSS = OpCode(0x4, ADCReg.REG_REFMUX.value, ADCMasks.RMUXN_BITS.value)
315329

330+
class ADC2REFMUX(Enum):
331+
"""Settings for ADC2 REFMUX register (ADC2 Configuration register 5:3 bits)"""
332+
INTERNAL_2P5 = OpCode(0x00, ADCReg.REG_ADC2CFG.value, ADCMasks.RMUXP_BITS.value)
333+
AIN0_AIN1 = OpCode(0x08, ADCReg.REG_ADC2CFG.value, ADCMasks.RMUXP_BITS.value)
334+
AIN2_AIN3 = OpCode(0x10, ADCReg.REG_ADC2CFG.value, ADCMasks.RMUXP_BITS.value)
335+
AIN4_AIN5 = OpCode(0x18, ADCReg.REG_ADC2CFG.value, ADCMasks.RMUXP_BITS.value )
336+
INT_VAVDD_VAVSS = OpCode(0x20, ADCReg.REG_ADC2CFG.value, ADCMasks.RMUXP_BITS.value )
316337

317338
class RTDModes(Enum):
318339
"ADC.__config args for for turning RTD mode on/off"
319340
RTD_ON = {
320-
"adc_1_analog_in": ADCChannel.AIN5,
321-
"adc_1_mux_n": ADCChannel.AIN6,
322341
"idac_1_mux": IDACMUX.IDAC1_AIN8,
323342
"idac_2_mux": IDACMUX.IDAC2_AIN9,
324343
"idac_1_mag": IDACMAG.IDAC1_500,
325344
"idac_2_mag": IDACMAG.IDAC2_500,
326-
"pos_ref_inp": REFMUX.POS_REF_EXT_AIN4,
327-
"neg_ref_inp": REFMUX.NEG_REF_INT_VAVSS,
328345
}
329346
RTD_OFF = {
330-
"adc_1_analog_in": ADCChannel.FLOAT,
331-
"adc_1_mux_n": ADCChannel.AINCOM,
332347
"idac_1_mux": IDACMUX.IDAC1_NO_CONNECT,
333348
"idac_2_mux": IDACMUX.IDAC2_NO_CONNECT,
334349
"idac_1_mag": IDACMAG.IDAC1_OFF,
335350
"idac_2_mag": IDACMAG.IDAC2_OFF,
336351
"pos_ref_inp": REFMUX.POS_REF_INT_2P5,
337352
"neg_ref_inp": REFMUX.NEG_REF_INT_2P5,
353+
"adc2_ref_inp": ADC2REFMUX.INTERNAL_2P5,
338354
}
339355

356+
class ADC1RtdConfig(Enum):
357+
"ADC1.__config args for for turning RTD mode on/off"
358+
ON = {
359+
"adc_1_ch": ADCChannel.AIN7,
360+
"adc_1_mux_n": ADCChannel.AIN6,
361+
"pos_ref_inp": REFMUX.POS_REF_EXT_AIN4,
362+
"neg_ref_inp": REFMUX.NEG_REF_EXT_AIN5,
363+
}
364+
OFF = {
365+
"adc_1_ch": ADCChannel.FLOAT,
366+
"adc_1_mux_n": ADCChannel.AINCOM,
367+
"pos_ref_inp": REFMUX.POS_REF_INT_2P5,
368+
"neg_ref_inp": REFMUX.NEG_REF_INT_2P5,
369+
}
370+
371+
class ADC2RtdConfig(Enum):
372+
"ADC2.__config args for for turning RTD mode on/off"
373+
ON = {
374+
"adc_2_ch": ADCChannel.AIN7,
375+
"adc_2_mux_n": ADCChannel.AIN6,
376+
"adc2_ref_inp": ADC2REFMUX.AIN4_AIN5,
377+
}
378+
OFF = {
379+
"adc_2_ch": ADCChannel.FLOAT,
380+
"adc_2_mux_n": ADCChannel.AINCOM,
381+
"adc2_ref_inp": ADC2REFMUX.INTERNAL_2P5,
382+
}
340383

341384
class AllowedChannels(Enum):
342385
"""Available channels for reading depend on whether RTD is enabled or not"""
@@ -346,7 +389,6 @@ class AllowedChannels(Enum):
346389
ADCChannel.AIN1,
347390
ADCChannel.AIN2,
348391
ADCChannel.AIN3,
349-
ADCChannel.AIN7,
350392
ADCChannel.AINCOM,
351393
ADCChannel.FLOAT,
352394
]

src/edgepi/adc/adc_conv_time.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,21 @@
183183
}
184184

185185

186-
# continuous conversion delay times for ADC2 (ADC2 only uses continuous mode)
187-
ADC2_DELAYS = {
186+
# initial conversion delay times for ADC2 (ADC2 only uses initial mode)
187+
ADC2_INITIAL_DELAYS = {
188188
DR2.SPS_10.value.op_code: 121,
189189
DR2.SPS_100.value.op_code: 31.2,
190190
DR2.SPS_400.value.op_code: 8.71,
191191
DR2.SPS_800.value.op_code: 4.97,
192192
}
193193

194+
ADC2_CONT_DELAYS = {
195+
DR2.SPS_10.value.op_code: 100,
196+
DR2.SPS_100.value.op_code: 10,
197+
DR2.SPS_400.value.op_code: 2.5,
198+
DR2.SPS_800.value.op_code: 1.25,
199+
}
200+
194201

195202
def expected_initial_time_delay(adc_num: ADCNum, data_rate: int, filter_mode: int):
196203
"""
@@ -213,7 +220,8 @@ def expected_initial_time_delay(adc_num: ADCNum, data_rate: int, filter_mode: in
213220

214221
# no initial figures given in documentation, but estimate initial delay
215222
# is 3 times longer than subsequent conversion delays
216-
return ADC2_DELAYS[data_rate] * 3
223+
return ADC2_INITIAL_DELAYS[data_rate]
224+
217225

218226

219227
def expected_continuous_time_delay(adc_num: ADCNum, data_rate: int):
@@ -232,4 +240,4 @@ def expected_continuous_time_delay(adc_num: ADCNum, data_rate: int):
232240
if adc_num == ADCNum.ADC_1:
233241
return ADC1_CONT_DELAYS[data_rate]
234242

235-
return ADC2_DELAYS[data_rate]
243+
return ADC2_CONT_DELAYS[data_rate]

0 commit comments

Comments
 (0)