JoyPi-Advanced-RaspberryPi 2.0.0__py3-none-any.whl

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,134 @@
1
+ from spidev import SpiDev
2
+ import time
3
+ from gpiozero import DigitalOutputDevice
4
+
5
+ class gyroscope:
6
+
7
+ scaleFactor = 0
8
+ scale_gyroscope = 700
9
+ scale_range = 46.5
10
+ offset = 0
11
+
12
+ def __init__(self, bus = 0, device = 0, cs = 14):
13
+ self.bus, self.device = bus, device
14
+ self.spi = SpiDev()
15
+ self.open()
16
+ self.spi.max_speed_hz = 1000000 # 1MHz
17
+ self.cs = DigitalOutputDevice(pin = cs, initial_value = True)
18
+ tmp = self.read_register(27) & 0x26
19
+ self.write_register(27, 0x18 | tmp)
20
+
21
+
22
+ def open(self):
23
+ """
24
+ Opens up SPI communication
25
+ """
26
+ self.spi.open(self.bus, self.device)
27
+ self.spi.max_speed_hz = 1000000 # 1MHz
28
+
29
+
30
+ def close(self):
31
+ """
32
+ Closes SPI communication
33
+ """
34
+ self.spi.close()
35
+ self.cs.close()
36
+
37
+
38
+ def read_register(self, reg):
39
+ """
40
+ read value from register
41
+ """
42
+ self.cs.toggle()
43
+ tmp = self.spi.xfer3([(reg | 0x80), 0])
44
+ self.cs.toggle()
45
+ return tmp[1]
46
+
47
+
48
+ def write_register(self, reg, data):
49
+ """
50
+ write value to register
51
+ """
52
+ self.cs.toggle()
53
+ self.spi.writebytes([ (reg & 0x7F), data])
54
+ self.cs.toggle()
55
+
56
+
57
+ def getTemperature(self):
58
+ """
59
+ returns read temnperature
60
+ """
61
+ temp = (self.read_register(0x41) << 8) + self.read_register(0x42)
62
+ return (temp / 100)
63
+
64
+
65
+ def getXValue(self):
66
+ """
67
+ returns x value
68
+ """
69
+ x = (self.read_register(0x43) << 8) + self.read_register(0x44)
70
+ if (x / self.scale_gyroscope > self.scale_range):
71
+ return x / self.scale_gyroscope - (2 * self.scale_range)
72
+ else:
73
+ return x / self.scale_gyroscope
74
+
75
+
76
+ def getYValue(self):
77
+ """
78
+ returns y value
79
+ """
80
+ y = (self.read_register(0x45) << 8) + self.read_register(0x46)
81
+ if (y / self.scale_gyroscope > self.scale_range):
82
+ return y / self.scale_gyroscope - (2 * self.scale_range)
83
+ else:
84
+ return y / self.scale_gyroscope
85
+
86
+
87
+ def getTilt(self):
88
+ """
89
+ returns tilt directions
90
+ """
91
+ tiltThreshold = 2
92
+ y = self.getYValue()
93
+ x = self.getXValue()
94
+ if (y > 5):
95
+ return 'right'
96
+ elif (y < -5):
97
+ return 'left'
98
+ elif (x > 3):
99
+ return 'forward'
100
+ elif (x < -3):
101
+ return 'backward'
102
+ else:
103
+ return 'No movement'
104
+
105
+
106
+ def who_am_i(self):
107
+ """
108
+ returns device ID
109
+ """
110
+ return (self.read_register(0x75))
111
+
112
+
113
+ def scale_Factor(self, scale):
114
+ """
115
+ set scale factor of gyroscope
116
+ """
117
+ self.scaleFactor = scale
118
+ self.write_register(0x19, 0)
119
+ self.write_register(0x1B, scale +1)
120
+ if (scale == 0):
121
+ self.scale_gyroscope = 700
122
+ self.scale_range = 46.5
123
+
124
+ elif (scale == 8):
125
+ self.scale_gyroscope = 350
126
+ self.scale_range = 93
127
+
128
+ elif (scale == 16):
129
+ self.scale_gyroscope = 175
130
+ self.scale_range = 187
131
+
132
+ elif (scale == 24):
133
+ self.scale_gyroscope = 87.5
134
+ self.scale_range = 374
@@ -0,0 +1,88 @@
1
+ from gpiozero import AngularServo
2
+ import time
3
+
4
+ class servomotor:
5
+
6
+ def __init__(self, pin = 18, position = 0,
7
+ min_angle = -90, max_angle = 90,
8
+ min_pulse_width = 0.0005, max_pulse_width = 0.0025):
9
+ self.position = position
10
+ self.start_pos = position
11
+ self.min_angle = min_angle
12
+ self.max_angle = max_angle
13
+
14
+ self.motor = AngularServo(pin, initial_angle=position,
15
+ min_angle=min_angle, max_angle=max_angle,
16
+ min_pulse_width=min_pulse_width,
17
+ max_pulse_width=max_pulse_width)
18
+
19
+ def setDirection(self, set_pos, speed = 5):
20
+ """
21
+ moves servomotor to a specified position with a specified speed
22
+
23
+ :param set_pos: set_pos (-90 to 90 / right to left)
24
+ :param speed: speed (1 to 5 / slow to fast)
25
+ """
26
+ # catch values out of the intervall
27
+ set_pos = max(self.min_angle, min(set_pos, self.max_angle))
28
+ speed = max(1, min(speed, 5))
29
+
30
+ # map speed to motion profile
31
+ step_deg = {1: 1.0, 2: 2.0, 3: 3.0, 4: 5.0, 5: 8.0}[speed]
32
+ delay_s = {1: 0.03, 2: 0.02, 3: 0.015, 4: 0.01, 5: 0.008}[speed]
33
+
34
+ # define direction
35
+ direction = 1 if set_pos > self.position else -1
36
+ # setup cariable with current position
37
+ current_position = self.position
38
+
39
+ # turn from current position to set_pos with a certain speed
40
+ while True:
41
+ # check if servo is in right position or overshooted then end loop
42
+ if (direction == 1 and self.position >= set_pos) or (direction == -1 and self.position <= set_pos):
43
+ break
44
+ # calculate next angular step
45
+ current_position += direction * step_deg
46
+
47
+ # check if servo would overshoot target
48
+ if direction == 1: current_position = min(current_position, set_pos)
49
+ else: current_position = max(current_position, set_pos)
50
+
51
+ # set servo to calculated position
52
+ self.motor.angle = current_position
53
+ self.position = current_position
54
+
55
+ # delay to controll speed of turning
56
+ time.sleep(delay_s)
57
+ # ensure that position of servo is right
58
+ self.motor.angle = set_pos
59
+ self.position = set_pos
60
+
61
+
62
+ def setPosition(self, pos):
63
+ """
64
+ set angular position of servomotor
65
+
66
+ :param pos: angle to which the servomotor moves min = -90 and max = 90
67
+ """
68
+ self.motor.angle = pos
69
+ self.position = pos
70
+
71
+ def setHome(self):
72
+ """
73
+ set servo back to start position
74
+ """
75
+ self.setDirection(self.start_pos)
76
+
77
+ def getPosition(self):
78
+ """
79
+ returns the position of the servomotor
80
+ """
81
+ return self.position
82
+
83
+ def end(self):
84
+ """
85
+ moves servo to start position, stops PWM communication and cleans up
86
+ """
87
+ self.setHome()
88
+ self.motor.close()
@@ -0,0 +1,116 @@
1
+ import math
2
+ from gpiozero import DigitalOutputDevice
3
+ import time
4
+
5
+ class stepmotor:
6
+
7
+ def __init__(self, pin1 = 22, pin2 = 23, pin3 = 24, pin4 = 4):
8
+ self.pin_A = DigitalOutputDevice(pin1, initial_value = False)
9
+ self.pin_B = DigitalOutputDevice(pin2, initial_value = False)
10
+ self.pin_C = DigitalOutputDevice(pin3, initial_value = False)
11
+ self.pin_D = DigitalOutputDevice(pin4, initial_value = False)
12
+ self.interval = 0.0011
13
+
14
+ def step1(self):
15
+ self.pin_D.on()
16
+ time.sleep(self.interval)
17
+ self.pin_D.off()
18
+
19
+ def step2(self):
20
+ self.pin_D.on()
21
+ self.pin_C.on()
22
+ time.sleep(self.interval)
23
+ self.pin_D.off()
24
+ self.pin_C.off()
25
+
26
+ def step3(self):
27
+ self.pin_C.on()
28
+ time.sleep(self.interval)
29
+ self.pin_C.off()
30
+
31
+ def step4(self):
32
+ self.pin_B.on()
33
+ self.pin_C.on()
34
+ time.sleep(self.interval)
35
+ self.pin_B.off()
36
+ self.pin_C.off()
37
+
38
+ def step5(self):
39
+ self.pin_B.on()
40
+ time.sleep(self.interval)
41
+ self.pin_B.off()
42
+
43
+ def step6(self):
44
+ self.pin_A.on()
45
+ self.pin_B.on()
46
+ time.sleep(self.interval)
47
+ self.pin_A.off()
48
+ self.pin_B.off()
49
+
50
+ def step7(self):
51
+ self.pin_A.on()
52
+ time.sleep(self.interval)
53
+ self.pin_A.off()
54
+
55
+ def step8(self):
56
+ self.pin_D.on()
57
+ self.pin_A.on()
58
+ time.sleep(self.interval)
59
+ self.pin_D.off()
60
+ self.pin_A.off()
61
+
62
+ def turn(self,count):
63
+ for i in range (int(count)):
64
+ self.step1()
65
+ self.step2()
66
+ self.step3()
67
+ self.step4()
68
+ self.step5()
69
+ self.step6()
70
+ self.step7()
71
+ self.step8()
72
+
73
+ def turnReverse(self, count):
74
+ for i in range(int(count)):
75
+ self.step8()
76
+ self.step7()
77
+ self.step6()
78
+ self.step5()
79
+ self.step4()
80
+ self.step3()
81
+ self.step2()
82
+ self.step1()
83
+
84
+ def close(self):
85
+ self.pin_A.close()
86
+ self.pin_B.close()
87
+ self.pin_C.close()
88
+ self.pin_D.close()
89
+
90
+ def turnSteps(self, steps):
91
+ """
92
+ Rotate by n steps
93
+ """
94
+ if steps < 0:
95
+ self.turnReverse(abs(int(steps)))
96
+ else:
97
+ self.turn(int(steps))
98
+
99
+ def turnDegrees(self, deg):
100
+ """
101
+ Rotate n degrees
102
+ """
103
+ if deg < 0:
104
+ self.turnReverse(abs(round(deg*512/360,0)))
105
+ else:
106
+ self.turn(round(deg*512/360,0))
107
+
108
+
109
+ def turnDistance(self, dist, rad):
110
+ """
111
+ Rotation by distance value
112
+ """
113
+ if dist < 0:
114
+ self.turnReverse(abs(round(512*dist/(2*math.pi*rad),0)))
115
+ else:
116
+ self.turn(round(512*dist/(2*math.pi*rad),0))
@@ -0,0 +1,98 @@
1
+ Metadata-Version: 2.4
2
+ Name: JoyPi_Advanced_RaspberryPi
3
+ Version: 2.0.0
4
+ Summary: This library enables usage of some sensors and actors of the Joy-Pi Advanced on the Raspberry Pi.
5
+ Project-URL: Homepage, https://github.com/joy-it/JoyPi_Advanced_RaspberryPi
6
+ Project-URL: Issues, https://github.com/joy-it/JoyPi_Advanced_RaspberryPi/issues
7
+ Author-email: Joy-IT <service@joy-it.net>
8
+ License-File: LICENSE
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python :: 3
11
+ Requires-Python: >=3.9
12
+ Description-Content-Type: text/markdown
13
+
14
+ # Joy-Pi Advanced Library for Raspberry Pi
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
+
17
+ ## Included modules
18
+ This library includes the following modules:
19
+ - ADC
20
+ - Gyroscope
21
+ - Barometer
22
+ - Button Matrix
23
+ - Color Sensor
24
+ - LED Matrix
25
+ - Servo Motor
26
+ - Stepper Motor
27
+
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
+ ## Dependencies
32
+ 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
+
34
+ - [`rpi_ws281x`](https://github.com/jgarff/rpi_ws281x) - for the LED matrix - with `pip install rpi_ws281x`
35
+ - [`Adafruit CircuitPython BusDevice`](https://github.com/adafruit/Adafruit_CircuitPython_BusDevice) - for the barometer - with `pip install adafruit-circuitpython-busdevice`
36
+ - [`Adafruit_CircuitPython_MCP230xx`](https://github.com/adafruit/Adafruit_CircuitPython_MCP230xx) - for the button matrix - with `pip install adafruit-circuitpython-mcp230xx`
37
+
38
+ ## Installation
39
+ ```
40
+ pip install JoyPi_Advanced_RaspberryPi
41
+ ```
42
+ ## Library Guide
43
+ ### ADC
44
+ - `adc(bus = 0, device = 0)` - initialize ADC with default values
45
+ - `open()` - starts communication
46
+ - `read_value(channel)` - returns raw value from a selected channel
47
+ - `read_voltage(channel, value=None)` - returns measured voltage from a selected channel, raw value can also be calculated into voltage with this method
48
+ - `close()` - ends communication
49
+ ### Gyroscope
50
+ - `gyroscope(bus = 0, device = 2)`- initialize gyroscope with default values
51
+ - `open()` - starts communication
52
+ - `close()` - ends communication
53
+ - `getTemperature()` - returns measured temperature
54
+ - `getTilt()` - returns the tilted direction
55
+ - `scale_Factor(scale)` - sets scale factor of the gyroscope (0, 8, 16 or 24)
56
+ ### Barometer
57
+ - `barometer(i2c: busio.I2C, i2c_address = 0x77, resolution=4096)` - initialize barometer with default values
58
+ - `get_pressure()` - returns the measured pressure
59
+ - `get_temperature()`- returns the measured temperature
60
+ - `get_altitude(reference_pressure = 1013.25)` - return the calculated altitude with the measured pressure and your local pressure (`reference_pressure`)
61
+ ### Button matrix
62
+ - `buttonmatrix(i2c: busio.I2C, i2c_address = 0x22)`- initialize button matrix with default values
63
+ - `getKey()` - returns the pressed button
64
+ - `clearMemory()` - clears class variable `calculated`
65
+ - `calculate()` - method to use the button matrix as a calculator
66
+ ### Color sensor
67
+ - `colour(i2c_address = 0x10)`- initialize colour sensor with default values
68
+ - `enableSensor()` - start communication
69
+ - `disableSensor()`- end communication
70
+ - `getRGBW()` - returns measured RGBW values
71
+ - `setIntegrationTime()` - set integration time (`0`-40ms, `1`-80ms, `2`-160ms, `3`-320ms, `4`-640ms or `5`-1280ms)
72
+ - `forceMode()` - forces measurement mode
73
+ - `autoMode()`- automatic measurement mode
74
+ - `readAll()` - returns RGB colours as well as raw values
75
+ ### LED matrix
76
+ - `LEDMatrix( pin = 18, brightness = 100)`- initialize LED matrix with default values
77
+ - `clean()` - clears the LED matrix
78
+ - `setPixel(position, colour)` - sets specific pixel to a selected colour
79
+ - `RGB_on(colour)` - sets the complete matrix to one selected colour
80
+ - `rainbow(wait_ms=20, iterations=1)` - rainbow effect on the whole matrix with default values
81
+ - `colourWipe(colour, wait_ms=50)` - Move selected colour pixel by pixel onto the matrix with default speed
82
+ - `theaterChase( colour, wait_ms=50, iterations=10)` - chaser animation with a selected colour with deafult speed
83
+ - `show()` - displays set pixels
84
+ - `demo1()` - demo program version 1
85
+ - `demo2()` - demo program version 2
86
+ ### Servo motor
87
+ - `servomotor(pin = 18, position = 0)` - initialize servo motor with default values
88
+ - `setDirection(set_pos, speed = 5)` - moves servomotor to a selected position in specified speed (1-5 : slowest - fastest)
89
+ - `setPosition(pos)` - moves servomotor to a selected position with default speed
90
+ - `setHome()` - sets servomotor to start position
91
+ - `getPosition()` - returns position of servo motor
92
+ - `end()` - moves servo into start position, stops communication and cleans up communication
93
+ ### Stepper motor
94
+ - `stepmotor(pin1 = 22, pin2 = 23, pin3 = 24, pin4 = 4)`- initialize step motor with default values
95
+ - `turnSteps(steps)` - turns a selected amount of steps
96
+ - `turnDegrees(deg)` - turns a selected amount of degree
97
+ - `turnDistance(dist, rad)` - rotates by distance value
98
+ - `close()` - close all used pins
@@ -0,0 +1,13 @@
1
+ JoyPi_Advanced_RaspberryPi/LEDMatrix.py,sha256=8JNh0ohQopWtbCIX28R5eOXBPeopK0b0lDJQfMOjaM4,5386
2
+ JoyPi_Advanced_RaspberryPi/__init__.py,sha256=f3EEO5VotY0d15Cr35XwMq7iQ1SSwYId-gf-qrCba_o,339
3
+ JoyPi_Advanced_RaspberryPi/adc.py,sha256=uD8kx5AQzXrzkqTWWQsznt6Tmp--rxhD1XrmmlfizoQ,2851
4
+ JoyPi_Advanced_RaspberryPi/barometer.py,sha256=Pvhtg77Fi9LMMIrnrmDk9MBdnho93kzy574HNbbt698,3503
5
+ JoyPi_Advanced_RaspberryPi/buttonmatrix.py,sha256=REaGy0q2C0iYvoDr2WidsITNT67dp49il6u9eVNkSCY,4369
6
+ JoyPi_Advanced_RaspberryPi/colour.py,sha256=ExkvKWuBeBnu344YoJhFYRoDhq1hK0wMzKkZkJ7WZBM,3987
7
+ JoyPi_Advanced_RaspberryPi/gyroscope.py,sha256=pP6V2upAqPfajaKcJBPrgQSSpUFVUSDId0k8uli7abw,3516
8
+ JoyPi_Advanced_RaspberryPi/servomotor.py,sha256=H-soLiQqiyvR6gNu0LffV19QIBWAiokwg2Kc9WYzblM,3169
9
+ JoyPi_Advanced_RaspberryPi/stepmotor.py,sha256=YpggJICaSLzTvSDpGDJK8kC2VDP6aM__I-phwGiP6dA,2957
10
+ joypi_advanced_raspberrypi-2.0.0.dist-info/METADATA,sha256=GyP76-xTNSkhb9f-z66YJks5wykuM1Dsy44vuJBZkXc,5393
11
+ joypi_advanced_raspberrypi-2.0.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
12
+ joypi_advanced_raspberrypi-2.0.0.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
13
+ joypi_advanced_raspberrypi-2.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any