Download Print this page

Interrupts; Multicore Support - Raspberry Pi Pico Python SDK Manual

A micropython environment for rp2040 microcontrollers

Advertisement

Raspberry Pi Pico Python SDK
You can specify which ADC channel you're using by pin number, e.g.
adc = machine.ADC(26)
or by channel,
adc = machine.ADC(4)
adc = machine.ADC(0)
An example reading the fourth analogue-to-digital (ADC) converter channel, connected to the internal temperature sensor:
Pico MicroPython Examples:
 1
import
 2
import
 3
 4 sensor_temp = machine.ADC(4)
 5 conversion_factor =
 6
 7
while
 8
reading = sensor_temp.read_u16() * conversion_factor
 9
10
temperature =
11
print(temperature)
12
utime.sleep(2)

3.4. Interrupts

You can set an IRQ like this:
Pico MicroPython Examples:
1
from
machine
2
3 p2 = Pin(2, Pin.IN, Pin.PULL_UP)
4
p2.irq(lambda
5 Pin.IRQ_FALLING)
It should print out something when GP2 has a falling edge.

3.5. Multicore Support

Example usage:
Pico MicroPython Examples:
 1
import
 2
 3
def
task(n, delay):
 4
led = machine.Pin(25, machine.Pin.OUT)
3.4. Interrupts
# Connect to GP26, which is channel 0
# Connect to the internal temperature sensor
# Connect to channel 0 (GP26)
https://github.com/raspberrypi/pico-micropython-examples/tree/master/adc/temperature.py
machine
utime
3.3
/ (65535)
True:
27
- (reading -
https://github.com/raspberrypi/pico-micropython-examples/tree/master/irq/irq.py
import
Pin
pin:
print("IRQ with
https://github.com/raspberrypi/pico-micropython-examples/tree/master/multicore/multicore.py
time, _thread, machine
0.706)/0.001721
Lines 1 - 5
flags:", pin.irq().flags()),
Lines 1 - 12
Lines 1 - 12
14

Advertisement

loading
Need help?

Need help?

Do you have a question about the Pico Python SDK and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Pico seriesPico 2