Skip to content

Commit e9decca

Browse files
author
Martin O'Hanlon
authored
Merge pull request #73 from RaspberryPiFoundation/dev
0.3.0
2 parents b29a880 + ef9ed53 commit e9decca

19 files changed

+9689
-40
lines changed

docs/api.rst

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ Speaker
5656
:inherited-members:
5757
:members:
5858

59+
Motor
60+
-----
61+
62+
.. autoclass:: Motor
63+
:show-inheritance:
64+
:inherited-members:
65+
:members:
66+
67+
Robot / Rover
68+
-------------
69+
70+
.. autoclass:: Robot
71+
:show-inheritance:
72+
:inherited-members:
73+
:members:
5974

6075
DigitalOutputDevice
6176
-------------------
@@ -87,22 +102,30 @@ Switch
87102
:inherited-members:
88103
:members:
89104

90-
Potentiometer
91-
-------------
105+
Potentiometer / Pot
106+
-------------------
92107

93108
.. autoclass:: Potentiometer
94109
:show-inheritance:
95110
:inherited-members:
96111
:members:
97112

98-
TemperatureSensor
99-
-----------------
113+
TemperatureSensor / TempSensor / Thermistor
114+
-------------------------------------------
100115

101116
.. autoclass:: TemperatureSensor
102117
:show-inheritance:
103118
:inherited-members:
104119
:members:
105120

121+
DistanceSensor
122+
--------------
123+
124+
.. autoclass:: DistanceSensor
125+
:show-inheritance:
126+
:inherited-members:
127+
:members:
128+
106129
DigitalInputDevice
107130
------------------
108131

docs/changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Change log
66
0.2.0 - 2022-06-29
77
~~~~~~~~~~~~~~~~~~
88

9-
+ Compatibility fix LED
9+
+ Pico W compatibility fix for onboard LED
1010

1111
0.1.1 - 2022-06-08
1212
~~~~~~~~~~~~~~~~~~

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __getattr__(cls, name):
3838
# add the ticks_ms function to time (as it is in micropython)
3939
import time
4040
setattr(time, 'ticks_ms', lambda x: None)
41+
setattr(time, 'ticks_us', lambda x: None)
4142

4243
# -- Project information -----------------------------------------------------
4344

docs/developing.rst

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ Install sphinx using ::
3838

3939
pip3 install sphinx
4040

41-
To build the documentation, run the following command from the docs directory ::
41+
To test the documentation build, run the following command from the docs directory ::
4242

4343
$ make html
4444

4545
The website will be built in the directory docs/_build/html.
4646

47-
Documentation can be viewed at `picozero.readthedocs.io`_.
47+
Documentation can be viewed at `picozero.readthedocs.io`_ and is automatically built and deployed on commit.
4848

4949
.. _picozero.readthedocs.io: https://picozero.readthedocs.io
5050

@@ -59,4 +59,16 @@ The tests are design to be run on a Raspberry Pi Pico.
5959

6060
3. Copy the ``test_picozero.py`` to the pico.
6161

62-
4. Run the ``test_picozero.py`` file.
62+
4. Run the ``test_picozero.py`` file.
63+
64+
If a test fails it is helpful to be able to see verbose error messages. To see error messages you need to modify the ``lib/unittest.py`` file on the pico.
65+
66+
Locate the following code in the ``run_class`` function::
67+
68+
# Uncomment to investigate failure in detail
69+
#raise
70+
71+
Uncomment ``raise``::
72+
73+
# Uncomment to investigate failure in detail
74+
raise

docs/examples/motor_move.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from picozero import Motor
2+
from time import sleep
3+
4+
motor = Motor(14, 15)
5+
6+
motor.move()
7+
sleep(1)
8+
motor.stop()

docs/examples/robot_rover_forward.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from picozero import Robot
2+
from time import sleep
3+
4+
robot_rover = Robot(left=(14,15), right=(12,13))
5+
6+
# move forward
7+
robot_rover.forward()
8+
sleep(1)
9+
robot_rover.stop()

docs/examples/robot_rover_square.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from picozero import Robot
2+
from time import sleep
3+
4+
robot_rover = Robot(left=(14,15), right=(12,13))
5+
6+
for i in range(4):
7+
# move forward for 1 second
8+
robot_rover.forward(t=1, wait=True)
9+
# rotate to the left for 1 second
10+
robot_rover.left(t=1, wait=True)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from picozero import DistanceSensor
2+
from time import sleep
3+
4+
ds = DistanceSensor(echo=4, trigger=5)
5+
6+
while True:
7+
print(ds.distance)
8+
sleep(0.1)

docs/images/distance_sensor_bb.svg

Lines changed: 817 additions & 0 deletions
Loading

docs/images/robot_bb.svg

Lines changed: 8150 additions & 0 deletions
Loading

docs/recipes.rst

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ Print the value, voltage and percent reported by a potentiometer:
154154

155155
In the Thonny Python editor, choose View->Plotter to plot the output of :meth:`print`.
156156

157-
158157
Buzzer
159158
------
160159

@@ -169,6 +168,29 @@ Control a passive buzzer or speaker that can play different tones or frequencies
169168

170169
.. literalinclude:: examples/speaker.py
171170

171+
Motor
172+
-----
173+
174+
Move a motor which is connected via 2 pins (forward / backward) and a motor controller board
175+
176+
.. literalinclude:: examples/motor_move.py
177+
178+
Robot rover
179+
-------------
180+
181+
Make a simple 2 wheeled robot rover.
182+
183+
.. image:: images/robot_bb.svg
184+
:alt: A diagram of the Raspberry Pi Pico connected to 2 motors via a motor controller board powered by a battery pack
185+
186+
Move the rover forward for 1 second and stop.
187+
188+
.. literalinclude:: examples/robot_rover_forward.py
189+
190+
Move the rover *roughly* in a square:
191+
192+
.. literalinclude:: examples/robot_rover_square.py
193+
172194
Play a tune
173195
~~~~~~~~~~~
174196

@@ -188,4 +210,14 @@ Internal Temperature Sensor
188210

189211
Check the internal temperature of the Raspberry Pi Pico in degrees Celcius:
190212

191-
.. literalinclude:: examples/pico_temperature.py
213+
.. literalinclude:: examples/pico_temperature.py
214+
215+
Ultrasonic Distance Sensor
216+
--------------------------
217+
218+
Get the distance in metres from an ultrasonic distance sensor (HC-SR04).
219+
220+
.. image:: images/distance_sensor_bb.svg
221+
:alt: A diagram of the Raspberry Pi Pico connected to HC-SR04 distance sensor
222+
223+
.. literalinclude:: examples/ultrasonic_distance_sensor.py

docs/sketches/distance_sensor.fzz

26.9 KB
Binary file not shown.
File renamed without changes.

docs/sketches/robot.fzz

138 KB
Binary file not shown.

examples/motor.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from picozero import Motor
2+
from time import sleep
3+
4+
m = Motor(12, 13)
5+
6+
# turn the motor for 1 second
7+
print("the motor is turning")
8+
m.move()
9+
sleep(1)
10+
m.stop()
11+
12+
# or alternatively turn it at half speed for 2 seconds
13+
m.move(speed=0.5, t=2)
14+
print("the motor will turn at half speed and stop after 2 seconds")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from picozero import DistanceSensor
2+
from time import sleep
3+
4+
ds = DistanceSensor(5, 4)
5+
6+
while True:
7+
print(ds.distance)
8+
sleep(0.1)

picozero/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
Speaker,
2020

2121
RGBLED,
22+
Motor,
23+
Robot,
2224

2325
DigitalInputDevice,
2426
Switch,
@@ -32,4 +34,6 @@
3234
pico_temp_sensor,
3335
TempSensor,
3436
Thermistor,
37+
38+
DistanceSensor,
3539
)

0 commit comments

Comments
 (0)