JoyPi-Advanced-RaspberryPi 2.0.0__tar.gz → 2.0.2__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.
Files changed (25) hide show
  1. joypi_advanced_raspberrypi-2.0.2/.gitignore +2 -0
  2. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/PKG-INFO +5 -7
  3. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/README.md +3 -5
  4. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/examples/colour.py +9 -5
  5. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/pyproject.toml +1 -1
  6. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/src/JoyPi_Advanced_RaspberryPi/LEDMatrix.py +1 -8
  7. joypi_advanced_raspberrypi-2.0.2/src/JoyPi_Advanced_RaspberryPi/colour.py +232 -0
  8. joypi_advanced_raspberrypi-2.0.0/setup.py +0 -14
  9. joypi_advanced_raspberrypi-2.0.0/src/JoyPi_Advanced_RaspberryPi/colour.py +0 -123
  10. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/.gitattributes +0 -0
  11. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/LICENSE +0 -0
  12. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/examples/LEDMatrix.py +0 -0
  13. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/examples/adc.py +0 -0
  14. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/examples/barometer.py +0 -0
  15. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/examples/buttonmatrix.py +0 -0
  16. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/examples/gyroscope.py +0 -0
  17. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/examples/servomotor.py +0 -0
  18. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/examples/stepmotor.py +0 -0
  19. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/src/JoyPi_Advanced_RaspberryPi/__init__.py +0 -0
  20. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/src/JoyPi_Advanced_RaspberryPi/adc.py +0 -0
  21. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/src/JoyPi_Advanced_RaspberryPi/barometer.py +0 -0
  22. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/src/JoyPi_Advanced_RaspberryPi/buttonmatrix.py +0 -0
  23. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/src/JoyPi_Advanced_RaspberryPi/gyroscope.py +0 -0
  24. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/src/JoyPi_Advanced_RaspberryPi/servomotor.py +0 -0
  25. {joypi_advanced_raspberrypi-2.0.0 → joypi_advanced_raspberrypi-2.0.2}/src/JoyPi_Advanced_RaspberryPi/stepmotor.py +0 -0
@@ -0,0 +1,2 @@
1
+ /dist/*
2
+ .gitignore
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: JoyPi_Advanced_RaspberryPi
3
- Version: 2.0.0
3
+ Version: 2.0.2
4
4
  Summary: This library enables usage of some sensors and actors of the Joy-Pi Advanced on the Raspberry Pi.
5
5
  Project-URL: Homepage, https://github.com/joy-it/JoyPi_Advanced_RaspberryPi
6
6
  Project-URL: Issues, https://github.com/joy-it/JoyPi_Advanced_RaspberryPi/issues
@@ -15,6 +15,7 @@ Description-Content-Type: text/markdown
15
15
  This library is a collection for the Raspberry Pi for several modules on the Joy-Pi Advanced. See [here](https://www.joy-pi.net) for more information.
16
16
 
17
17
  ## Included modules
18
+
18
19
  This library includes the following modules:
19
20
  - ADC
20
21
  - Gyroscope
@@ -25,9 +26,6 @@ This library includes the following modules:
25
26
  - Servo Motor
26
27
  - Stepper Motor
27
28
 
28
- > [!WARNING]
29
- > The Joy-Pi Advanced 2 is no longer compatible with this library for the LED Matrix. To ensure compatibility with the Raspberry Pi 5, the LED matrix is now controlled via I²C because of the RP2040 microcontroller chip. The LED matrix can now be controlled with the Joy-Pi Advanced via [this repository](http://github.com/joy-it/JoyPi_RGB_Matrix_RaspberryPi).
30
-
31
29
  ## Dependencies
32
30
  This library has some dependencies which are used to control the modules of the Joy Pi Advanced. To use this library, you will need to install the following dependencies:
33
31
 
@@ -36,8 +34,8 @@ This library has some dependencies which are used to control the modules of the
36
34
  - [`Adafruit_CircuitPython_MCP230xx`](https://github.com/adafruit/Adafruit_CircuitPython_MCP230xx) - for the button matrix - with `pip install adafruit-circuitpython-mcp230xx`
37
35
 
38
36
  ## Installation
39
- ```
40
- pip install JoyPi_Advanced_RaspberryPi
37
+ ```bash
38
+ pip install JoyPi-Advanced-RaspberryPi
41
39
  ```
42
40
  ## Library Guide
43
41
  ### ADC
@@ -2,6 +2,7 @@
2
2
  This library is a collection for the Raspberry Pi for several modules on the Joy-Pi Advanced. See [here](https://www.joy-pi.net) for more information.
3
3
 
4
4
  ## Included modules
5
+
5
6
  This library includes the following modules:
6
7
  - ADC
7
8
  - Gyroscope
@@ -12,9 +13,6 @@ This library includes the following modules:
12
13
  - Servo Motor
13
14
  - Stepper Motor
14
15
 
15
- > [!WARNING]
16
- > The Joy-Pi Advanced 2 is no longer compatible with this library for the LED Matrix. To ensure compatibility with the Raspberry Pi 5, the LED matrix is now controlled via I²C because of the RP2040 microcontroller chip. The LED matrix can now be controlled with the Joy-Pi Advanced via [this repository](http://github.com/joy-it/JoyPi_RGB_Matrix_RaspberryPi).
17
-
18
16
  ## Dependencies
19
17
  This library has some dependencies which are used to control the modules of the Joy Pi Advanced. To use this library, you will need to install the following dependencies:
20
18
 
@@ -23,8 +21,8 @@ This library has some dependencies which are used to control the modules of the
23
21
  - [`Adafruit_CircuitPython_MCP230xx`](https://github.com/adafruit/Adafruit_CircuitPython_MCP230xx) - for the button matrix - with `pip install adafruit-circuitpython-mcp230xx`
24
22
 
25
23
  ## Installation
26
- ```
27
- pip install JoyPi_Advanced_RaspberryPi
24
+ ```bash
25
+ pip install JoyPi-Advanced-RaspberryPi
28
26
  ```
29
27
  ## Library Guide
30
28
  ### ADC
@@ -2,14 +2,18 @@
2
2
  # Required modules are inserted and configured
3
3
  import time
4
4
  from JoyPi_Advanced_RaspberryPi import colour
5
+ import busio
6
+ import board
5
7
 
8
+ # Create I2C bus.
9
+ i2c = busio.I2C(board.SCL, board.SDA)
6
10
  # Create object sensor to control colour sensor
7
- sensor = colour()
11
+ colour_sensor = colour(i2c, colour.INTEGRATION_TIME_160MS)
8
12
 
9
13
  # set integration time
10
- sensor.setIntegrationTime(2)
14
+ colour_sensor.setIntegrationTime(colour.INTEGRATION_TIME_160MS)
11
15
  # set senor to auti�Mode
12
- sensor.autoMode()
16
+ colour_sensor.autoMode()
13
17
  # initialize variable to save last printed colour
14
18
  last_colour = ""
15
19
 
@@ -17,7 +21,7 @@ last_colour = ""
17
21
  try:
18
22
  while True:
19
23
  # get dominant colour and raw values
20
- colour, raw_values = sensor.readAll()
24
+ colour, raw_values = colour_sensor.readAll()
21
25
  # check if a new colour is detected
22
26
  if last_colour != colour:
23
27
  # print colour and raw values
@@ -26,4 +30,4 @@ try:
26
30
  last_colour = colour
27
31
  except:
28
32
  # deactivate colour sensor
29
- sensor.disableSensor()
33
+ colour_sensor.disableSensor()
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "JoyPi_Advanced_RaspberryPi"
7
- version = "2.0.0"
7
+ version = "2.0.2"
8
8
  authors = [
9
9
  { name="Joy-IT", email="service@joy-it.net" },
10
10
  ]
@@ -1,15 +1,8 @@
1
1
  import time
2
2
  from rpi_ws281x import PixelStrip, Color
3
3
 
4
-
5
4
  class LEDMatrix:
6
- """
7
- The Joy-Pi Advanced 2 is no longer compatible with this library for the LED
8
- matrix. To ensure compatibility with the Raspberry Pi 5, the LED matrix is now
9
- controlled via I²C because of the RP2040 microcontroller chip. The LED matrix
10
- can now be controlled with the Joy-Pi Advanced via this repository
11
- http://github.com/joy-it/JoyPi_RGB_Matrix_RaspberryPi
12
- """
5
+
13
6
  def __init__(self, pin = 18, brightness = 100):
14
7
  # LED strip configuration
15
8
  self.LED_COUNT = 64 # Number of pixels
@@ -0,0 +1,232 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ ###################################################################################
5
+ # Edited by Joy-IT
6
+ #
7
+ ###################################################################################
8
+ # Copyright 2020 <pi@kb>
9
+ #
10
+ # This program is free software; you can redistribute it and/or modify
11
+ # it under the terms of the GNU General Public License as published by
12
+ # the Free Software Foundation; either version 2 of the License, or
13
+ # (at your option) any later version.
14
+ #
15
+ # This program is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ # GNU General Public License for more details.
19
+ #
20
+ # You should have received a copy of the GNU General Public License
21
+ # along with this program; if not, write to the Free Software
22
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23
+ # MA 02110-1301, USA.
24
+ #
25
+ # Written by BitHead (Britany Head)
26
+ # https://forums.raspberrypi.com/viewtopic.php?t=263498
27
+ # Step 1) Enable I2C in Raspi-Config (Interfacing Options)
28
+ # Step 2) sudo apt-get install i2c-tools python3-smbus
29
+ # Step 3) plug it in (don't forget your pull-up resistors) and run this program
30
+
31
+ import busio
32
+ from adafruit_bus_device import i2c_device
33
+ import time
34
+ import threading
35
+ import numpy as np
36
+
37
+ class colour:
38
+
39
+ REG_CONF = 0x00
40
+ REG_RED = 0x08
41
+ REG_GREEN = 0x09
42
+ REG_BLUE = 0x0A
43
+ REG_WHITE = 0x0B
44
+
45
+ INTEGRATION_TIME_40MS = 0
46
+ INTEGRATION_TIME_80MS = 1
47
+ INTEGRATION_TIME_160MS = 2
48
+ INTEGRATION_TIME_320MS = 3
49
+ INTEGRATION_TIME_640MS = 4
50
+ INTEGRATION_TIME_1280MS = 5
51
+
52
+ _INTEGRATION_TIME_VALUES = {
53
+ INTEGRATION_TIME_40MS: 0x00,
54
+ INTEGRATION_TIME_80MS: 0x10,
55
+ INTEGRATION_TIME_160MS: 0x20,
56
+ INTEGRATION_TIME_320MS: 0x30,
57
+ INTEGRATION_TIME_640MS: 0x40,
58
+ INTEGRATION_TIME_1280MS: 0x50,
59
+ }
60
+
61
+ _INTEGRATION_TIME_DELAY = {
62
+ INTEGRATION_TIME_40MS: 0.05,
63
+ INTEGRATION_TIME_80MS: 0.09,
64
+ INTEGRATION_TIME_160MS: 0.17,
65
+ INTEGRATION_TIME_320MS: 0.33,
66
+ INTEGRATION_TIME_640MS: 0.65,
67
+ INTEGRATION_TIME_1280MS: 1.29,
68
+ }
69
+
70
+ BIT_SD = 0x01
71
+ BIT_AF = 0x02
72
+ BIT_TRIG = 0x04
73
+ MASK_INTEGRATION_TIME = 0x70
74
+
75
+ def __init__(self, i2c: busio.I2C, integration_time=INTEGRATION_TIME_160MS, i2c_address = 0x10):
76
+ """
77
+ initialize colour sensor
78
+ i2c_address - i2c_address of colour sensor (default 0x10)
79
+ """
80
+ self.address = i2c_address
81
+ if integration_time not in self._INTEGRATION_TIME_VALUES:
82
+ raise ValueError("integration_time is not in range")
83
+ self.integration_time = integration_time
84
+ self.device = i2c_device.I2CDevice(i2c, self.address)
85
+ self.enableSensor()
86
+
87
+ def write(self, cmd, val):
88
+ """
89
+ write value into register on the colour sensor
90
+ cmd - register
91
+ val - value to be written
92
+ """
93
+ data = bytes([
94
+ cmd & 0xFF,
95
+ val & 0xFF,
96
+ (val >> 8) & 0xFF,
97
+ ])
98
+ with self.device as bus_device:
99
+ bus_device.write(data)
100
+
101
+ def read(self, cmd):
102
+ """
103
+ read value from register on the colour sensor
104
+ cmd - register
105
+ """
106
+ register = bytes([cmd & 0xFF])
107
+ data = bytearray(2)
108
+ last_error = None
109
+ for _ in range(3):
110
+ try:
111
+ with self.device as bus_device:
112
+ bus_device.write_then_readinto(register, data)
113
+ return data[0] | (data[1] << 8)
114
+ except OSError as error:
115
+ last_error = error
116
+ time.sleep(0.02)
117
+ raise last_error
118
+
119
+ def enableSensor(self):
120
+ """
121
+ activate Sensor
122
+ """
123
+ config = self._INTEGRATION_TIME_VALUES[self.integration_time]
124
+ config &= ~self.BIT_SD
125
+ config &= ~self.BIT_AF
126
+ config &= ~self.BIT_TRIG
127
+ self.write(self.REG_CONF, config)
128
+ time.sleep(self._INTEGRATION_TIME_DELAY[self.integration_time])
129
+
130
+ def disableSensor(self):
131
+ """
132
+ deactivate Sensor
133
+ """
134
+ config = self.read(self.REG_CONF)
135
+ config |= self.BIT_SD
136
+ self.write(self.REG_CONF, config)
137
+
138
+ def setIntegrationTime(self, integration_time):
139
+ """
140
+ set integration time with variable integration_time
141
+ integration_time - _INTEGRATION_TIME_VALUES
142
+ INTEGRATION_TIME_40MS = 40 ms
143
+ INTEGRATION_TIME_80MS = 80 ms
144
+ INTEGRATION_TIME_160MS = 160 ms
145
+ INTEGRATION_TIME_320MS = 320 ms
146
+ INTEGRATION_TIME_640MS = 640 ms
147
+ INTEGRATION_TIME_1280MS = 1280 ms
148
+ """
149
+ if integration_time not in self._INTEGRATION_TIME_VALUES:
150
+ raise ValueError("integration_time is not in range")
151
+ config = self.read(self.REG_CONF)
152
+ config &= ~self.MASK_INTEGRATION_TIME
153
+ config |= self._INTEGRATION_TIME_VALUES[integration_time]
154
+ config &= ~self.BIT_SD
155
+ self.integration_time = integration_time
156
+ self.write(self.REG_CONF, config)
157
+ time.sleep(self._INTEGRATION_TIME_DELAY[self.integration_time])
158
+
159
+ def getRed(self):
160
+ """
161
+ returns measured value for colour red
162
+ """
163
+ return self.read(self.REG_RED)
164
+
165
+ def getBlue(self):
166
+ """
167
+ returns measured value for colour blue
168
+ """
169
+ return self.read(self.REG_BLUE)
170
+
171
+ def getGreen(self):
172
+ """
173
+ returns measured value for colour green
174
+ """
175
+ return self.read(self.REG_GREEN)
176
+
177
+ def getWhite(self):
178
+ """
179
+ returns measured value for colour white
180
+ """
181
+ return self.read(self.REG_WHITE)
182
+
183
+ def getRGBW(self):
184
+ """
185
+ returns colour values from colour sensor - red, green, blue, white
186
+ """
187
+ red = self.getRed()
188
+ time.sleep(0.005)
189
+ green = self.getGreen()
190
+ time.sleep(0.005)
191
+ blue = self.getBlue()
192
+ time.sleep(0.005)
193
+ white = self.getWhite()
194
+ return red, green, blue, white
195
+
196
+ def forceMode(self):
197
+ """
198
+ forces measurement mode - triggers to start
199
+ """
200
+ config = self.read(self.REG_CONF)
201
+ config &= self.MASK_INTEGRATION_TIME
202
+ config |= self.BIT_AF
203
+ config |= self.BIT_TRIG
204
+ config &= ~self.BIT_SD
205
+ self.write(self.REG_CONF, config)
206
+ time.sleep(self._INTEGRATION_TIME_DELAY[self.integration_time])
207
+
208
+ def autoMode(self):
209
+ """
210
+ automatic measurement mode
211
+ """
212
+ config = self.read(self.REG_CONF)
213
+ config &= self.MASK_INTEGRATION_TIME
214
+ config &= ~self.BIT_AF
215
+ config &= ~self.BIT_TRIG
216
+ config &= ~self.BIT_SD
217
+ self.write(self.REG_CONF, config)
218
+ time.sleep(self._INTEGRATION_TIME_DELAY[self.integration_time])
219
+
220
+ def readAll(self):
221
+ """
222
+ returns most recognized colour and raw values
223
+ """
224
+ red, green, blue, white = self.getRGBW()
225
+ values = {
226
+ "red": red,
227
+ "green": green,
228
+ "blue": blue,
229
+ }
230
+
231
+ dominant_color = max(values, key=values.get)
232
+ return dominant_color, [red, green, blue, white]
@@ -1,14 +0,0 @@
1
- import setuptools
2
- from distutils.core import setup
3
- from codecs import open
4
- from os import path
5
-
6
-
7
- setuptools.setup(
8
- name="JoyPi_Advanced_RaspberryPi",
9
- setup_requires=["setuptools_scm"],
10
- description="Library for the use of the Joy Pi Advanced",
11
- author="Joy-IT",
12
- license="MIT",
13
- packages=setuptools.find_packages()
14
- )
@@ -1,123 +0,0 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- #
4
- ###################################################################################
5
- # Edited by Joy-IT
6
- #
7
- ###################################################################################
8
- # Copyright 2020 <pi@kb>
9
- #
10
- # This program is free software; you can redistribute it and/or modify
11
- # it under the terms of the GNU General Public License as published by
12
- # the Free Software Foundation; either version 2 of the License, or
13
- # (at your option) any later version.
14
- #
15
- # This program is distributed in the hope that it will be useful,
16
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
- # GNU General Public License for more details.
19
- #
20
- # You should have received a copy of the GNU General Public License
21
- # along with this program; if not, write to the Free Software
22
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23
- # MA 02110-1301, USA.
24
- #
25
- # Written by BitHead (Britany Head)
26
- # https://forums.raspberrypi.com/viewtopic.php?t=263498
27
- # Step 1) Enable I2C in Raspi-Config (Interfacing Options)
28
- # Step 2) sudo apt-get install i2c-tools python3-smbus
29
- # Step 3) plug it in (don't forget your pull-up resistors) and run this program
30
-
31
- import smbus
32
- import time
33
- import threading
34
- import numpy as np
35
-
36
- class colour:
37
-
38
- def __init__(self, i2c_address = 0x10):
39
- """
40
- initialize colour sensor
41
- i2c_address - i2c_address of colour sensor (default 0x10)
42
- """
43
- self.address = i2c_address
44
- self.bus = smbus.SMBus(1)
45
- self.enableSensor()
46
-
47
- def write(self, cmd, val):
48
- """
49
- write value into register on the colour sensor
50
- cmd - register
51
- val - value to be written
52
- """
53
- self.bus.write_word_data(self.address, cmd, val)
54
-
55
- def read(self, cmd):
56
- """
57
- read value from register on the colour sensor
58
- cmd - register
59
- """
60
- return self.bus.read_word_data(self.address, cmd)
61
-
62
- def enableSensor(self):
63
- """
64
- activate Sensor
65
- """
66
- conf = self.read(0x00) & 0x00FE
67
- self.write(0x00, conf)
68
-
69
- def disableSensor(self):
70
- """
71
- deactivate Sensor
72
- """
73
- conf = (self.read(0x00) & 0x00FE) | 0x000
74
- self.write(0x00, conf)
75
- time.sleep(.001)
76
-
77
- def getRGBW(self):
78
- """
79
- returns colour values from colour sensor - red, green, blue, white
80
- """
81
- return self.read(0x08), self.read(0x09), int(self.read(0x0A) * 1.5), self.read(0x0B)
82
-
83
- def setIntegrationTime(self, int_time):
84
- """
85
- set integration time with variable int_time
86
- int_time - integration time
87
- 0 = 40 ms
88
- 1 = 80 ms
89
- 2 = 160 ms
90
- 3 = 320 ms
91
- 4 = 640 ms
92
- 5 = 1280 ms
93
- """
94
- if int_time < 0 or int_time > 5:
95
- raise ValueError('int_time is not in range')
96
- conf = self.read(0x00) & 0x0003
97
- self.write(0x00, (conf | (int_time << 4)))
98
-
99
- def forceMode(self):
100
- """
101
- forces measurement mode - triggers to start
102
- """
103
- conf = (self.read(0x00) & 0x0072) | 0x0002
104
- self.write(0x00, conf)
105
-
106
- def autoMode(self):
107
- """
108
- automatic measurement mode
109
- """
110
- conf = self.read(0x00) & 0x0070
111
- self.write(0x00, conf)
112
-
113
- def readAll(self):
114
- """
115
- returns most recognized colour and raw values
116
- """
117
- r, g, b, w = self.getRGBW()
118
- raw_val = [r, g, b, w]
119
- dominant_col, dominant_val = "red", r
120
- if g > dominant_val: dominant_col, dominant_val = "green", g
121
- if b > dominant_val: dominant_col, dominant_val = "blue", b
122
-
123
- return dominant_col, raw_val