GP8XXX-IIC 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,181 @@
1
+ from abc import ABC
2
+ from smbus2 import SMBus
3
+
4
+ # i2c address
5
+ GP8XXX_I2C_DEVICE_ADDR = 0x58
6
+
7
+
8
+ class GP8XXX(ABC):
9
+ # Select DAC output voltage of 0-5V
10
+ OUTPUT_RANGE_2_5V = 0
11
+ # Select DAC output voltage of 0-5V
12
+ OUTPUT_RANGE_5V = 1
13
+ # Select DAC output voltage of 0-10V
14
+ OUTPUT_RANGE_10V = 2
15
+ # Select DAC output voltage of 0-VCC
16
+ OUTPUT_RANGE_VCC = 3
17
+ RESOLUTION_12_BIT = 0x0FFF
18
+ RESOLUTION_15_BIT = 0x7FFF
19
+
20
+ def __init__(self):
21
+ pass
22
+
23
+ def begin(self):
24
+ pass
25
+
26
+ def set_dac_out_voltage(self, voltage, channel):
27
+ pass
28
+
29
+ class GP8XXX_IIC(GP8XXX):
30
+ """
31
+ I2C class initialization
32
+ - param resolution: the resolution of the chip
33
+ - param bus: the i2c bus number
34
+ - param device_addr: the I2C device address
35
+ - param auto_range: automatically selects the correct output range
36
+ """
37
+ GP8XXX_CONFIG_REG = 0x02
38
+
39
+ def __init__(self, resolution, bus=1, device_addr=GP8XXX_I2C_DEVICE_ADDR, auto_range=True):
40
+ self._resolution = resolution
41
+ self._bus = bus
42
+ self._device_addr = device_addr
43
+ self._auto_range = auto_range
44
+
45
+ self._i2c = SMBus(self._bus)
46
+
47
+ self._dac_voltage = None
48
+
49
+ def begin(self):
50
+ """
51
+ Initialize the function returns true for success
52
+ """
53
+ return not self._i2c.read_byte(self._device_addr) != 0
54
+
55
+ def set_dac_outrange(self, output_range: int = GP8XXX.OUTPUT_RANGE_10V):
56
+ """
57
+ Set the DAC output range
58
+ - param output_range [int]: DAC output range
59
+ """
60
+ if output_range == self.OUTPUT_RANGE_5V:
61
+ self._dac_voltage = 5000
62
+ self._i2c.write_byte_data(
63
+ self._device_addr, self.GP8XXX_CONFIG_REG >> 1, 0x00)
64
+ elif output_range == self.OUTPUT_RANGE_10V:
65
+ self._dac_voltage = 10000
66
+ self._i2c.write_byte_data(
67
+ self._device_addr, self.GP8XXX_CONFIG_REG >> 1, 0x11)
68
+
69
+ def set_dac_out_voltage(self, voltage: float, channel: int = 0):
70
+ """
71
+ Set different channel output DAC values
72
+ - param voltage [int]: value corresponding to the output voltage value (e.g. 4.321V is 4321)
73
+ - param channel [int]: integer representing the output channel
74
+ - 0: Channel 0
75
+ - 1: Channel 1
76
+ - 2: All channels
77
+ """
78
+ voltage = float(voltage)
79
+
80
+ if self._auto_range and 0 <= voltage <= 5000:
81
+ self.set_dac_outrange(self.OUTPUT_RANGE_5V)
82
+ elif self._auto_range and 5000 <= voltage <= 10000:
83
+ self.set_dac_outrange(self.OUTPUT_RANGE_10V)
84
+
85
+ output_value = (voltage / self._dac_voltage) * self._resolution
86
+
87
+ if self._resolution == self.RESOLUTION_12_BIT:
88
+ output_value = int(output_value) << 4
89
+ elif self._resolution == self.RESOLUTION_15_BIT:
90
+ output_value = int(output_value) << 1
91
+
92
+ if channel == 0:
93
+ self._i2c.write_word_data(
94
+ self._device_addr, self.GP8XXX_CONFIG_REG, output_value)
95
+ elif channel == 1:
96
+ self._i2c.write_word_data(
97
+ self._device_addr, self.GP8XXX_CONFIG_REG << 1, output_value)
98
+ elif channel == 2:
99
+ self._i2c.write_word_data(
100
+ self._device_addr, self.GP8XXX_CONFIG_REG, output_value)
101
+ self._i2c.write_word_data(
102
+ self._device_addr, self.GP8XXX_CONFIG_REG << 1, output_value)
103
+
104
+ def store(self):
105
+ """
106
+ FIXME: Unfortunately, I can't get the chip to store the values
107
+ """
108
+ raise NotImplementedError
109
+
110
+ class GP8503(GP8XXX_IIC):
111
+ """
112
+ 12bit DAC Dual Channel I2C to 0-2.5V/0-VCC
113
+ - param bus: the i2c bus number
114
+ """
115
+
116
+ def __init__(self, bus=1):
117
+ super().__init__(bus=bus, resolution=self.RESOLUTION_12_BIT, auto_range=False)
118
+ self.voltage = 2500
119
+
120
+ class GP8211S(GP8XXX_IIC):
121
+ """
122
+ 15 bit DAC I2C to 0-5V/0-10V
123
+ - param bus: the i2c bus number
124
+ - param auto_range: automatically selects the correct output range
125
+ """
126
+
127
+ def __init__(self, bus=1, auto_range=True):
128
+ super().__init__(bus=bus, resolution=self.RESOLUTION_15_BIT, auto_range=auto_range)
129
+
130
+ class GP8512(GP8XXX_IIC):
131
+ """
132
+ 15bit DAC I2C to 0-2.5V/0-VCC
133
+ - param bus: the i2c bus number
134
+ """
135
+
136
+ def __init__(self, bus=1):
137
+ super().__init__(bus=bus, resolution=self.RESOLUTION_15_BIT, auto_range=False)
138
+ self.dac_voltage = 2500
139
+
140
+ class GP8413(GP8XXX_IIC):
141
+ """
142
+ 15bit DAC Dual Channel I2C to 0-10V
143
+ - param bus: the i2c bus number
144
+ - param i2c_addr: the I2C device address
145
+ """
146
+
147
+ def __init__(self, bus=1, i2c_addr=0x58):
148
+ super().__init__(bus=bus, resolution=self.RESOLUTION_15_BIT,
149
+ device_addr=i2c_addr, auto_range=False)
150
+ self.set_dac_outrange(self.OUTPUT_RANGE_10V)
151
+
152
+ class GP8403(GP8XXX_IIC):
153
+ """
154
+ 12bit DAC Dual Channel I2C to 0-5V/0-10V
155
+ - param bus: the i2c bus number
156
+ - param i2c_addr: the I2C device address
157
+ - param auto_range: automatically selects the correct output range
158
+ """
159
+
160
+ def __init__(self, bus=1, i2c_addr=0x58, auto_range=True):
161
+ super().__init__(bus=bus, resolution=self.RESOLUTION_12_BIT,
162
+ device_addr=i2c_addr, auto_range=auto_range)
163
+
164
+ class GP8302(GP8XXX_IIC):
165
+ """
166
+ 12bit DAC Dual Channel I2C to 0-5V/0-10V
167
+ - param bus: the i2c bus number
168
+ - param i2c_addr: the I2C device address
169
+ - param auto_range: automatically selects the correct output range
170
+ """
171
+
172
+ def __init__(self, bus=1, i2c_addr=0x58, auto_range=True):
173
+ super().__init__(bus=bus, resolution=self.RESOLUTION_12_BIT,
174
+ device_addr=i2c_addr, auto_range=auto_range)
175
+
176
+ def set_dac_out_electric_current(self, current):
177
+ """
178
+ Set different channel output DAC values
179
+ - param current [int]: value corresponding to the output current value (e.g. 1.321A is 1321)
180
+ """
181
+ return self.set_dac_out_voltage(current)
@@ -0,0 +1,79 @@
1
+ Metadata-Version: 2.1
2
+ Name: GP8XXX-IIC
3
+ Version: 0.0.1
4
+ Summary: The GP8XXX Python module offers an intuitive interface for controlling DAC (Digital to Analog Converter) devices via the I2C protocol. With support for various DAC models.
5
+ Home-page: https://github.com/joe2824/GP8XXX_IIC/
6
+ Author: Joel Klein
7
+ License: UNKNOWN
8
+ Project-URL: Bug Tracker, https://github.com/joe2824/GP8XXX_IIC/issues
9
+ Project-URL: Github, https://github.com/joe2824/GP8XXX_IIC/
10
+ Description: # GP8XXX-IIC
11
+
12
+ The GP8XXX-IIC module provides an interface for controlling DAC (Digital to Analog Converter) devices over the I2C protocol. This module supports various DAC models with different resolutions and output voltage ranges.
13
+
14
+ ## Features
15
+
16
+ - **I2C Communication**: Utilizes the smbus2 library for communicating with DAC devices over the I2C bus.
17
+ - **Output Ranges**: Supports different output voltage ranges including 0-5V, 0-10V.
18
+ - **Support Multiple DAC Models**:
19
+ - GP8503: 12-bit DAC Dual Channel I2C to 0-2.5V/0-VCC
20
+ - GP8211S: 15-bit DAC I2C to 0-5V/0-10V
21
+ - GP8512: 15-bit DAC I2C to 0-2.5V/0-VCC
22
+ - GP8413: 15-bit DAC Dual Channel I2C to 0-10V
23
+ - GP8403: 12-bit DAC Dual Channel I2C to 0-5V/0-10V
24
+ - GP8302: 12-bit DAC Dual Channel I2C to 0-5V/0-10V
25
+
26
+ ## Installation
27
+ You can install the GP8XXX module from PyPI using pip:
28
+
29
+ ```bash
30
+ pip install GP8XXX-IIC
31
+ ```
32
+
33
+ ## Example
34
+ ```python
35
+ import time
36
+ from GP8XXX_IIC import GP8403
37
+
38
+ GP8403 = GP8403(i2c_addr=0x5F, auto_range=True)
39
+
40
+ while GP8403.begin():
41
+ print("init error")
42
+ time.sleep(1)
43
+
44
+ # Optional because GP8403 support auto_range
45
+ # GP8403.set_dac_outrange(GP8403.OUTPUT_RANGE_10V)
46
+
47
+ # Chanel 1: 6.721V ≙ 6721
48
+ GP8403.set_dac_out_voltage(voltage=6721, channel=0)
49
+
50
+ time.sleep(3)
51
+
52
+ # Chanel 2: 2.774V ≙ 2774
53
+ GP8403.set_dac_out_voltage(voltage=2774, channel=1)
54
+
55
+ time.sleep(3)
56
+
57
+ # Chanel 1 & 2: 1.253V ≙ 1253
58
+ GP8403.set_dac_out_voltage(voltage=1253, channel=2)
59
+ ```
60
+
61
+ ## Tested devices
62
+
63
+ | DAC Module | Tested |
64
+ |------------|--------|
65
+ |GP8503 | ❌ |
66
+ |GP8211S | ❌ |
67
+ |GP8512 | ❌ |
68
+ |GP8512 | ❌ |
69
+ |GP8413 | ❌ |
70
+ |GP8403 | ✅ |
71
+ |GP8302 | ❌ |
72
+ Keywords: Raspberry Pi,Raspi,GP8403,GP8503,GP8211S,GP8512,GP8413,GP8302,DAC
73
+ Platform: UNKNOWN
74
+ Classifier: Development Status :: 5 - Production/Stable
75
+ Classifier: Programming Language :: Python :: 3
76
+ Classifier: License :: OSI Approved :: MIT License
77
+ Classifier: Operating System :: POSIX :: Linux
78
+ Requires-Python: >=3
79
+ Description-Content-Type: text/markdown
@@ -0,0 +1,9 @@
1
+ README.md
2
+ pyproject.toml
3
+ setup.py
4
+ GP8XXX_IIC/__init__.py
5
+ GP8XXX_IIC.egg-info/PKG-INFO
6
+ GP8XXX_IIC.egg-info/SOURCES.txt
7
+ GP8XXX_IIC.egg-info/dependency_links.txt
8
+ GP8XXX_IIC.egg-info/requires.txt
9
+ GP8XXX_IIC.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ smbus2
@@ -0,0 +1 @@
1
+ GP8XXX_IIC
@@ -0,0 +1,79 @@
1
+ Metadata-Version: 2.1
2
+ Name: GP8XXX_IIC
3
+ Version: 0.0.1
4
+ Summary: The GP8XXX Python module offers an intuitive interface for controlling DAC (Digital to Analog Converter) devices via the I2C protocol. With support for various DAC models.
5
+ Home-page: https://github.com/joe2824/GP8XXX_IIC/
6
+ Author: Joel Klein
7
+ License: UNKNOWN
8
+ Project-URL: Bug Tracker, https://github.com/joe2824/GP8XXX_IIC/issues
9
+ Project-URL: Github, https://github.com/joe2824/GP8XXX_IIC/
10
+ Description: # GP8XXX-IIC
11
+
12
+ The GP8XXX-IIC module provides an interface for controlling DAC (Digital to Analog Converter) devices over the I2C protocol. This module supports various DAC models with different resolutions and output voltage ranges.
13
+
14
+ ## Features
15
+
16
+ - **I2C Communication**: Utilizes the smbus2 library for communicating with DAC devices over the I2C bus.
17
+ - **Output Ranges**: Supports different output voltage ranges including 0-5V, 0-10V.
18
+ - **Support Multiple DAC Models**:
19
+ - GP8503: 12-bit DAC Dual Channel I2C to 0-2.5V/0-VCC
20
+ - GP8211S: 15-bit DAC I2C to 0-5V/0-10V
21
+ - GP8512: 15-bit DAC I2C to 0-2.5V/0-VCC
22
+ - GP8413: 15-bit DAC Dual Channel I2C to 0-10V
23
+ - GP8403: 12-bit DAC Dual Channel I2C to 0-5V/0-10V
24
+ - GP8302: 12-bit DAC Dual Channel I2C to 0-5V/0-10V
25
+
26
+ ## Installation
27
+ You can install the GP8XXX module from PyPI using pip:
28
+
29
+ ```bash
30
+ pip install GP8XXX-IIC
31
+ ```
32
+
33
+ ## Example
34
+ ```python
35
+ import time
36
+ from GP8XXX_IIC import GP8403
37
+
38
+ GP8403 = GP8403(i2c_addr=0x5F, auto_range=True)
39
+
40
+ while GP8403.begin():
41
+ print("init error")
42
+ time.sleep(1)
43
+
44
+ # Optional because GP8403 support auto_range
45
+ # GP8403.set_dac_outrange(GP8403.OUTPUT_RANGE_10V)
46
+
47
+ # Chanel 1: 6.721V ≙ 6721
48
+ GP8403.set_dac_out_voltage(voltage=6721, channel=0)
49
+
50
+ time.sleep(3)
51
+
52
+ # Chanel 2: 2.774V ≙ 2774
53
+ GP8403.set_dac_out_voltage(voltage=2774, channel=1)
54
+
55
+ time.sleep(3)
56
+
57
+ # Chanel 1 & 2: 1.253V ≙ 1253
58
+ GP8403.set_dac_out_voltage(voltage=1253, channel=2)
59
+ ```
60
+
61
+ ## Tested devices
62
+
63
+ | DAC Module | Tested |
64
+ |------------|--------|
65
+ |GP8503 | ❌ |
66
+ |GP8211S | ❌ |
67
+ |GP8512 | ❌ |
68
+ |GP8512 | ❌ |
69
+ |GP8413 | ❌ |
70
+ |GP8403 | ✅ |
71
+ |GP8302 | ❌ |
72
+ Keywords: Raspberry Pi,Raspi,GP8403,GP8503,GP8211S,GP8512,GP8413,GP8302,DAC
73
+ Platform: UNKNOWN
74
+ Classifier: Development Status :: 5 - Production/Stable
75
+ Classifier: Programming Language :: Python :: 3
76
+ Classifier: License :: OSI Approved :: MIT License
77
+ Classifier: Operating System :: POSIX :: Linux
78
+ Requires-Python: >=3
79
+ Description-Content-Type: text/markdown
@@ -0,0 +1,62 @@
1
+ # GP8XXX-IIC
2
+
3
+ The GP8XXX-IIC module provides an interface for controlling DAC (Digital to Analog Converter) devices over the I2C protocol. This module supports various DAC models with different resolutions and output voltage ranges.
4
+
5
+ ## Features
6
+
7
+ - **I2C Communication**: Utilizes the smbus2 library for communicating with DAC devices over the I2C bus.
8
+ - **Output Ranges**: Supports different output voltage ranges including 0-5V, 0-10V.
9
+ - **Support Multiple DAC Models**:
10
+ - GP8503: 12-bit DAC Dual Channel I2C to 0-2.5V/0-VCC
11
+ - GP8211S: 15-bit DAC I2C to 0-5V/0-10V
12
+ - GP8512: 15-bit DAC I2C to 0-2.5V/0-VCC
13
+ - GP8413: 15-bit DAC Dual Channel I2C to 0-10V
14
+ - GP8403: 12-bit DAC Dual Channel I2C to 0-5V/0-10V
15
+ - GP8302: 12-bit DAC Dual Channel I2C to 0-5V/0-10V
16
+
17
+ ## Installation
18
+ You can install the GP8XXX module from PyPI using pip:
19
+
20
+ ```bash
21
+ pip install GP8XXX-IIC
22
+ ```
23
+
24
+ ## Example
25
+ ```python
26
+ import time
27
+ from GP8XXX_IIC import GP8403
28
+
29
+ GP8403 = GP8403(i2c_addr=0x5F, auto_range=True)
30
+
31
+ while GP8403.begin():
32
+ print("init error")
33
+ time.sleep(1)
34
+
35
+ # Optional because GP8403 support auto_range
36
+ # GP8403.set_dac_outrange(GP8403.OUTPUT_RANGE_10V)
37
+
38
+ # Chanel 1: 6.721V ≙ 6721
39
+ GP8403.set_dac_out_voltage(voltage=6721, channel=0)
40
+
41
+ time.sleep(3)
42
+
43
+ # Chanel 2: 2.774V ≙ 2774
44
+ GP8403.set_dac_out_voltage(voltage=2774, channel=1)
45
+
46
+ time.sleep(3)
47
+
48
+ # Chanel 1 & 2: 1.253V ≙ 1253
49
+ GP8403.set_dac_out_voltage(voltage=1253, channel=2)
50
+ ```
51
+
52
+ ## Tested devices
53
+
54
+ | DAC Module | Tested |
55
+ |------------|--------|
56
+ |GP8503 | ❌ |
57
+ |GP8211S | ❌ |
58
+ |GP8512 | ❌ |
59
+ |GP8512 | ❌ |
60
+ |GP8413 | ❌ |
61
+ |GP8403 | ✅ |
62
+ |GP8302 | ❌ |
@@ -0,0 +1,7 @@
1
+ [build-system]
2
+ requires = [
3
+ "setuptools>=42",
4
+ "wheel"
5
+
6
+ ]
7
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,30 @@
1
+ from setuptools import setup
2
+
3
+ with open("README.md", "r", encoding="utf-8") as fh:
4
+ long_description = fh.read()
5
+
6
+ setup(
7
+ name="GP8XXX_IIC",
8
+ keywords = 'Raspberry Pi, Raspi, GP8403, GP8503, GP8211S, GP8512, GP8413, GP8302, DAC',
9
+ version="0.0.1",
10
+ author="Joel Klein",
11
+ description="The GP8XXX Python module offers an intuitive interface for controlling DAC (Digital to Analog Converter) devices via the I2C protocol. With support for various DAC models.",
12
+ long_description=long_description,
13
+ long_description_content_type="text/markdown",
14
+ url="https://github.com/joe2824/GP8XXX_IIC/",
15
+ project_urls={
16
+ "Bug Tracker": "https://github.com/joe2824/GP8XXX_IIC/issues",
17
+ "Github": "https://github.com/joe2824/GP8XXX_IIC/",
18
+ },
19
+ classifiers=[
20
+ 'Development Status :: 5 - Production/Stable',
21
+ "Programming Language :: Python :: 3",
22
+ 'License :: OSI Approved :: MIT License',
23
+ "Operating System :: POSIX :: Linux",
24
+ ],
25
+ packages=['GP8XXX_IIC'],
26
+ python_requires=">=3",
27
+ install_requires=[
28
+ 'smbus2'
29
+ ]
30
+ )