Skip to content

Commit 4c64368

Browse files
authored
Merge pull request #7 from freaf87/master
Merge latest changes
2 parents cd8d97c + 6836f15 commit 4c64368

25 files changed

Lines changed: 1347 additions & 131 deletions

02_Code/FSEDevBoard/FseDevBoard/buzzer.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@
2828
class BUZZER(GPIO_Manager):
2929
"""Driver for a BUZZER connected by GPIO."""
3030

31-
_pin = 17
32-
_pins = [_pin]
33-
34-
def __init__(self):
31+
def __init__(self, pin = 4):
3532
super(BUZZER, self).__init__()
33+
self._pin = pin
34+
self._pins = [self._pin]
3635
wiringpi.pinMode(self._pin, wiringpi.OUTPUT)
3736

3837
def buzzerHigh(self):
@@ -48,7 +47,7 @@ def buzzForTime(self, time):
4847
sleep(time)
4948

5049
if __name__ == "__main__":
51-
with BUZZER() as buzzer:
50+
with BUZZER(4) as buzzer:
5251
while True:
5352
for i in list(range(40,0,-1)):
5453
print ("distance = {0} cm".format(i))

02_Code/FSEDevBoard/FseDevBoard/hcsr04.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ class UltrasonicTimeoutError(Exception):
3232
class HCSR04(GPIO_Manager):
3333
"""Interface with an HCSR04 ultrasonic range sensor."""
3434

35-
_trigger_pin = 15
36-
_echo_pin = 14
37-
_pins = [_trigger_pin, _echo_pin]
3835
_timeout = 0.1 # seconds
3936
_average_count = 1
4037

41-
def __init__(self):
38+
def __init__(self, triggerPin = 15, echoPin = 14):
4239
super(HCSR04, self).__init__()
40+
self._trigger_pin = triggerPin #15
41+
self._echo_pin = echoPin #14
42+
self._pins = [self._trigger_pin, self._echo_pin]
4343
wiringpi.pinMode(self._trigger_pin, wiringpi.OUTPUT)
4444
wiringpi.pinMode(self._echo_pin, wiringpi.INPUT)
4545

02_Code/FSEDevBoard/FseDevBoard/pushbutton.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,16 @@ class PUSHBUTTON(GPIO_Manager):
3333

3434
def __init__(self):
3535
super(PUSHBUTTON, self).__init__()
36-
wiringpi.pinMode(self._pin, wiringpi.OUTPUT)
36+
wiringpi.pinMode(self._pin, wiringpi.INPUT)
3737
self.state = False
3838

39-
def PBStatus(self):
39+
def getPBStatus(self):
4040
return wiringpi.digitalRead(self._pin)
4141

4242

4343
if __name__ == "__main__":
44-
while True:
45-
if PBStatus == False:
46-
# do something button pressed
47-
pass
48-
else:
49-
pass
50-
time.sleep(0.5)
44+
with PUSHBUTTON() as PB:
45+
while True:
46+
if PB.getPBStatus() == False:
47+
print("Pushbutton pressed...")
48+
time.sleep(0.25)

02_Code/FSEDevBoard/FseDevBoard/rgbLed.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from os.path import dirname
1818
sys.path.append(dirname(__file__))
1919

20-
2120
from pca9685 import PWM_Driver
2221
import time
2322
import sys

02_Code/FSEDevBoard/FseDevBoard/tb6612fng.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
"""Driver for 2 TB6612FNG DC motors mounted to a single chassis."""
1919
import sys
20+
import os
2021
from os.path import dirname
2122
sys.path.append(dirname(__file__))
2223

@@ -28,27 +29,23 @@
2829
class MotorDriver(GPIO_Manager):
2930
"""Interface with 2 TB6612FNG DC Motor drivers."""
3031
# Configure motor 1
31-
_m1_dir1_pin = 6
32-
_m1_dir2_pin = 12
33-
_m1_pwm_pin_annex = 5 # solve error mapping (Vers.01)
34-
_m1_pwm_pin = 18
32+
_m1_dir1_pin = 19
33+
_m1_dir2_pin = 16
34+
_m1_pwm_pin = 12
3535

3636
# Configure motor 2
37-
_m2_dir1_pin = 19
38-
_m2_dir2_pin = 16
39-
_m2_pwm_pin_annex = 26 # solve error mapping (Vers.01)
37+
_m2_dir1_pin = 26
38+
_m2_dir2_pin = 20
4039
_m2_pwm_pin = 13
4140

42-
_standby_pin = 20
41+
_standby_pin = 21
4342

4443
PWM_OUTPUTS = [_m1_pwm_pin, _m2_pwm_pin]
4544

46-
INPUT_PINS = [_m1_pwm_pin_annex, _m2_pwm_pin_annex]
47-
4845
OUTPUT_PINS = [_m1_dir1_pin, _m1_dir2_pin,
4946
_m2_dir1_pin, _m2_dir2_pin,
5047
_standby_pin]
51-
_pins = PWM_OUTPUTS + INPUT_PINS + OUTPUT_PINS
48+
_pins = PWM_OUTPUTS + OUTPUT_PINS
5249

5350
@staticmethod
5451
def to_dc(dc):
@@ -64,11 +61,6 @@ def __init__(self):
6461
for pin in self.PWM_OUTPUTS:
6562
wiringpi.pinMode(pin, wiringpi.PWM_OUTPUT)
6663

67-
for pin in self.INPUT_PINS:
68-
wiringpi.pinMode(pin, wiringpi.INPUT)
69-
# Make sure all annex_pin are set LOW
70-
wiringpi.pullUpDnControl(pin, wiringpi.PUD_DOWN)
71-
7264
def right_forward(self):
7365
"""Drive right motor forward."""
7466
wiringpi.digitalWrite(self._m1_dir1_pin, wiringpi.LOW)
@@ -138,28 +130,28 @@ def __exit__(self, *args):
138130
with MotorDriver() as tb6612fng:
139131
while True:
140132
print("forward")
141-
tb6612fng.forward()
133+
tb6612fng.forward(50)
142134
time.sleep(3)
143135

144136
tb6612fng.stop()
145137
time.sleep(3)
146138

147139
print("reverse")
148-
tb6612fng.reverse()
140+
tb6612fng.reverse(50)
149141
time.sleep(3)
150142

151143
tb6612fng.stop()
152144
time.sleep(3)
153145

154146
print("left")
155-
tb6612fng.left()
147+
tb6612fng.left(50)
156148
time.sleep(3)
157149

158150
tb6612fng.stop()
159151
time.sleep(3)
160152

161153
print("right")
162-
tb6612fng.right()
154+
tb6612fng.right(50)
163155
time.sleep(3)
164156

165157
tb6612fng.stop()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ Typical usage::
99

1010
Contributors
1111
============
12-
Daniel Lee, Frederic Afadjigla
12+
Frederic Afadjigla

02_Code/FSEDevBoard/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
url='https://fullstackembedded.com',
1010
license='LICENSE.txt',
1111
description='Drivers for FSEDevBoard used in FSE workshops.',
12-
long_description=open('README.md').read(),
12+
long_description=open('README.txt').read(),
1313
install_requires=[
1414
"smbus2",
1515
"wiringpi",

02_Code/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# FSEDevBoard package
2-
2+
33
## Installing
44
% sudo apt install python3 python3-pip
55
% pip3 install virtualenv
@@ -14,5 +14,8 @@
1414
(venv) % pip3 install FseDevBoard-0.0.1.tar.gz
1515

1616
### Running the PDC example
17-
(venv) % cd ../../applications
18-
(venv) % python3 PDC.py
17+
Note: Because applications using PWM must have root privileges, it is necessary to switch to root so that the venv is respected.
18+
% sudo su
19+
% source venv/bin/activate
20+
(venv) % cd ../../applications
21+
(venv) % python3 PDC.py

02_Code/applications/PDC.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
class PDC(object):
3030
""" PDC class """
3131
def __init__(self):
32-
self.ultrasonic = HCSR04()
32+
self.ultrasonic = HCSR04(15, 14)
3333
self.rgbled = RGBLED()
34-
self.buzzer = BUZZER()
34+
self.buzzer = BUZZER(4)
3535
self.rgbled.pwmDriver.setPwmFreq(600)
3636

3737
def setPDCColor(self, color):
1.6 MB
Binary file not shown.

0 commit comments

Comments
 (0)