33Quick reference for the RP2
44===========================
55
6- .. image :: img/rpipico.jpg
6+ .. image :: img/pico_pinout.png
77 :alt: Raspberry Pi Pico
88 :width: 640px
99
@@ -27,10 +27,9 @@ a troubleshooting subsection.
2727General board control
2828---------------------
2929
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.
3433
3534The :mod: `machine ` module::
3635
@@ -59,7 +58,19 @@ Use the :mod:`time <utime>` module::
5958Timers
6059------
6160
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+
6374
6475.. _rp2_Pins_and_GPIO :
6576
@@ -84,19 +95,28 @@ Use the :ref:`machine.Pin <machine.Pin>` class::
8495UART (serial bus)
8596-----------------
8697
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+
88101
89- from machine import UART
102+ See :ref: ` machine.UART < machine. UART>`. ::
90103
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))
92106 uart1.write('hello') # write 5 bytes
93107 uart1.read(5) # read up to 5 bytes
94108
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+
95114
96115PWM (pulse width modulation)
97116----------------------------
98117
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.
100120
101121Use the ``machine.PWM `` class::
102122
@@ -112,14 +132,18 @@ Use the ``machine.PWM`` class::
112132ADC (analog to digital conversion)
113133----------------------------------
114134
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.
116141
117142Use the :ref: `machine.ADC <machine.ADC >` class::
118143
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
123147
124148Software SPI bus
125149----------------
@@ -132,7 +156,7 @@ Software SPI (using bit-banging) works on all pins, and is accessed via the
132156 # construct a SoftSPI bus on the given pins
133157 # polarity is the idle state of SCK
134158 # 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))
136160
137161 spi.init(baudrate=200000) # set the baudrate
138162
@@ -156,14 +180,15 @@ Software SPI (using bit-banging) works on all pins, and is accessed via the
156180Hardware SPI bus
157181----------------
158182
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::
161186
162187 from machine import Pin, SPI
163188
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 ))
167192
168193Software I2C bus
169194----------------
@@ -173,7 +198,7 @@ accessed via the :ref:`machine.SoftI2C <machine.SoftI2C>` class::
173198
174199 from machine import Pin, SoftI2C
175200
176- i2c = SoftI2C(scl=Pin(5), sda=Pin(4), freq=100000 )
201+ i2c = SoftI2C(scl=Pin(5), sda=Pin(4), freq=100_000 )
177202
178203 i2c.scan() # scan for devices
179204
@@ -191,8 +216,8 @@ has the same methods as software I2C above::
191216
192217 from machine import Pin, I2C
193218
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 )
196221
197222Real time clock (RTC)
198223---------------------
@@ -202,13 +227,15 @@ See :ref:`machine.RTC <machine.RTC>` ::
202227 from machine import RTC
203228
204229 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
206232 rtc.datetime() # get date and time
207233
208234WDT (Watchdog timer)
209235--------------------
210236
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.
212239
213240See :ref: `machine.WDT <machine.WDT >`. ::
214241
@@ -218,21 +245,6 @@ See :ref:`machine.WDT <machine.WDT>`. ::
218245 wdt = WDT(timeout=5000)
219246 wdt.feed()
220247
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)
236248
237249OneWire driver
238250--------------
0 commit comments