3
3
Quick reference for the RP2
4
4
===========================
5
5
6
- .. image :: img/rpipico.jpg
6
+ .. image :: img/pico_pinout.png
7
7
:alt: Raspberry Pi Pico
8
8
:width: 640px
9
9
@@ -27,10 +27,9 @@ a troubleshooting subsection.
27
27
General board control
28
28
---------------------
29
29
30
- The MicroPython REPL is on the USB serial port.
31
- Tab-completion is useful to find out what methods an object has.
32
- Paste mode (ctrl-E) is useful to paste a large slab of Python code into
33
- the REPL.
30
+ The MicroPython REPL is accessed via the USB serial port. Tab-completion is useful to
31
+ find out what methods an object has. Paste mode (ctrl-E) is useful to paste a
32
+ large slab of Python code into the REPL.
34
33
35
34
The :mod: `machine ` module::
36
35
@@ -59,7 +58,19 @@ Use the :mod:`time <utime>` module::
59
58
Timers
60
59
------
61
60
62
- How do they work?
61
+ RP2040's system timer peripheral provides a global microsecond timebase and
62
+ generates interrupts for it. The software timer is available currently,
63
+ and there are unlimited number of them (memory permitting). There is no need
64
+ to specify the timer id (id=-1 is supported at the moment) as it will default
65
+ to this.
66
+
67
+ Use the :mod: `machine.Timer ` class::
68
+
69
+ from machine import Timer
70
+
71
+ tim = Timer(period=5000, mode=Timer.ONE_SHOT, callback=lambda t:print(1))
72
+ tim.init(period=2000, mode=Timer.PERIODIC, callback=lambda t:print(2))
73
+
63
74
64
75
.. _rp2_Pins_and_GPIO :
65
76
@@ -84,19 +95,28 @@ Use the :ref:`machine.Pin <machine.Pin>` class::
84
95
UART (serial bus)
85
96
-----------------
86
97
87
- See :ref: `machine.UART <machine.UART >`. ::
98
+ There are two UARTs, UART0 and UART1. UART0 can be mapped to GPIO 0/1, 12/13
99
+ and 16/17, and UART1 to GPIO 4/5 and 8/9.
100
+
88
101
89
- from machine import UART
102
+ See :ref: ` machine.UART < machine. UART>`. ::
90
103
91
- uart1 = UART(1, baudrate=9600, tx=33, rx=32)
104
+ from machine import UART, Pin
105
+ uart1 = UART(1, baudrate=9600, tx=Pin(4), rx=Pin(5))
92
106
uart1.write('hello') # write 5 bytes
93
107
uart1.read(5) # read up to 5 bytes
94
108
109
+ .. note ::
110
+
111
+ REPL over UART is disabled by default. You can see the :ref: `rp2_intro ` for
112
+ details on how to enable REPL over UART.
113
+
95
114
96
115
PWM (pulse width modulation)
97
116
----------------------------
98
117
99
- How does PWM work on the RPi RP2xxx?
118
+ There are 8 independent channels each of which have 2 outputs making it 16
119
+ PWM channels in total which can be clocked from 7Hz to 125Mhz.
100
120
101
121
Use the ``machine.PWM `` class::
102
122
@@ -112,14 +132,18 @@ Use the ``machine.PWM`` class::
112
132
ADC (analog to digital conversion)
113
133
----------------------------------
114
134
115
- How does the ADC module work?
135
+ RP2040 has five ADC channels in total, four of which are 12-bit SAR based
136
+ ADCs: GP26, GP27, GP28 and GP29. The input signal for ADC0, ADC1, ADC2 and
137
+ ADC3 can be connected with GP26, GP27, GP28, GP29 respectively (On Pico board,
138
+ GP29 is connected to VSYS). The standard ADC range is 0-3.3V. The fifth
139
+ channel is connected to the in-built temperature sensor and can be used for
140
+ measuring the temperature.
116
141
117
142
Use the :ref: `machine.ADC <machine.ADC >` class::
118
143
119
- from machine import ADC
120
-
121
- adc = ADC(Pin(32)) # create ADC object on ADC pin
122
- adc.read_u16() # read value, 0-65535 across voltage range 0.0v - 3.3v
144
+ from machine import ADC, Pin
145
+ adc = ADC(Pin(26)) # create ADC object on ADC pin
146
+ adc.read_u16() # read value, 0-65535 across voltage range 0.0v - 3.3v
123
147
124
148
Software SPI bus
125
149
----------------
@@ -132,7 +156,7 @@ Software SPI (using bit-banging) works on all pins, and is accessed via the
132
156
# construct a SoftSPI bus on the given pins
133
157
# polarity is the idle state of SCK
134
158
# phase=0 means sample on the first edge of SCK, phase=1 means the second
135
- spi = SoftSPI(baudrate=100000 , polarity=1, phase=0, sck=Pin(0), mosi=Pin(2), miso=Pin(4))
159
+ spi = SoftSPI(baudrate=100_000 , polarity=1, phase=0, sck=Pin(0), mosi=Pin(2), miso=Pin(4))
136
160
137
161
spi.init(baudrate=200000) # set the baudrate
138
162
@@ -156,14 +180,15 @@ Software SPI (using bit-banging) works on all pins, and is accessed via the
156
180
Hardware SPI bus
157
181
----------------
158
182
159
- Hardware SPI is accessed via the :ref: `machine.SPI <machine.SPI >` class and
160
- has the same methods as software SPI above::
183
+ The RP2040 has 2 hardware SPI buses which is accessed via the
184
+ :ref: `machine.SPI <machine.SPI >` class and has the same methods as software
185
+ SPI above::
161
186
162
187
from machine import Pin, SPI
163
188
164
- spi = SPI(1, 10000000 )
165
- spi = SPI(1, 10000000 , sck=Pin(14), mosi=Pin(13 ), miso=Pin(12))
166
- spi = SPI(2 , baudrate=80000000 , polarity=0, phase=0, bits=8, firstbit=0, sck=Pin(18 ), mosi=Pin(23 ), miso=Pin(19 ))
189
+ spi = SPI(1, 10_000_000) # Default assignment: sck=Pin(10), mosi=Pin(11), miso=Pin(8 )
190
+ spi = SPI(1, 10_000_000 , sck=Pin(14), mosi=Pin(15 ), miso=Pin(12))
191
+ spi = SPI(0 , baudrate=80_000_000 , polarity=0, phase=0, bits=8, sck=Pin(6 ), mosi=Pin(7 ), miso=Pin(4 ))
167
192
168
193
Software I2C bus
169
194
----------------
@@ -173,7 +198,7 @@ accessed via the :ref:`machine.SoftI2C <machine.SoftI2C>` class::
173
198
174
199
from machine import Pin, SoftI2C
175
200
176
- i2c = SoftI2C(scl=Pin(5), sda=Pin(4), freq=100000 )
201
+ i2c = SoftI2C(scl=Pin(5), sda=Pin(4), freq=100_000 )
177
202
178
203
i2c.scan() # scan for devices
179
204
@@ -191,8 +216,8 @@ has the same methods as software I2C above::
191
216
192
217
from machine import Pin, I2C
193
218
194
- i2c = I2C(0)
195
- i2c = I2C(1, scl=Pin(5 ), sda=Pin(4 ), freq=400000 )
219
+ i2c = I2C(0) # default assignment: scl=Pin(9), sda=Pin(8)
220
+ i2c = I2C(1, scl=Pin(3 ), sda=Pin(2 ), freq=400_000 )
196
221
197
222
Real time clock (RTC)
198
223
---------------------
@@ -202,13 +227,15 @@ See :ref:`machine.RTC <machine.RTC>` ::
202
227
from machine import RTC
203
228
204
229
rtc = RTC()
205
- rtc.datetime((2017, 8, 23, 2, 12, 48, 0, 0)) # set a specific date and time
230
+ rtc.datetime((2017, 8, 23, 2, 12, 48, 0, 0)) # set a specific date and
231
+ # time, eg. 2017/8/23 1:12:48
206
232
rtc.datetime() # get date and time
207
233
208
234
WDT (Watchdog timer)
209
235
--------------------
210
236
211
- Is there a watchdog timer?
237
+ The RP2040 has a watchdog which is a countdown timer that can restart
238
+ parts of the chip if it reaches zero.
212
239
213
240
See :ref: `machine.WDT <machine.WDT >`. ::
214
241
@@ -218,21 +245,6 @@ See :ref:`machine.WDT <machine.WDT>`. ::
218
245
wdt = WDT(timeout=5000)
219
246
wdt.feed()
220
247
221
- Deep-sleep mode
222
- ---------------
223
-
224
- Is there deep-sleep support for the rp2?
225
-
226
- The following code can be used to sleep, wake and check the reset cause::
227
-
228
- import machine
229
-
230
- # check if the device woke from a deep sleep
231
- if machine.reset_cause() == machine.DEEPSLEEP_RESET:
232
- print('woke from a deep sleep')
233
-
234
- # put the device to sleep for 10 seconds
235
- machine.deepsleep(10000)
236
248
237
249
OneWire driver
238
250
--------------
0 commit comments