Google Chat: zj734465502@gmail.com
+86-0755-88291180
sales01@spotpear.com
dragon_manager@163.com
services01@spotpear.com
manager01@spotpear.com
WhatsApp:13246739196
In order to facilitate the development of Pico/Pico2 boards using MicroPython on a computer, it is recommended to download the Thonny IDE
The first parameter ID represents the GPIO number, and the value should be 0-29. If GPIO13 is used, fill in 13 here.
The second parameter mode represents the GPIO mode and can be set to no initialization, input mode, output mode and open-drain mode
The third parameter pull is to use the internal pull-up and pull-down resistor, which can be set to pull-up, pull-down and floating. Note that this parameter is only valid in input mode.
The fourth parameter is the output value, and the port value is valid in output or open-drain mode.
Its function is to re-initialize the GPIO, and the parameters are the same as the PIN constructor, so I won't go into details here.
The value function in the PIN class is used to return the value of the GPIO port without filling in the parameter, and write the parameter into the GPIO port when the parameter is filled in, and the parameter can be 0 or 1;
The PIN class irq function is an external interrupt function, the first parameter is the interrupt trigger callback function; the second parameter trigger is the interrupt trigger condition, which is set to edge trigger or level trigger.
This article is only for RP2040 MicroPython firmware, and the source code shall prevail. This article is written according to the official source code at the time of writing, which is used to provide convenience for beginners and is for reference only. Those who are capable are recommended to refer to MicroPython.
Its function will reinitialize the specified GPIO and set it to PWM output mode.
The first parameter pin is the Pin object explained in the previous tutorial, which is used to specify the use of GPIO, and the object will be reinitialized.
deinit is a deinitialization function whose function is to clear initialization and stop PWM output.
The freq function is a PWM frequency setting function that automatically calculates the frequency divider parameter (frequency division factor) and the TOP register parameter (counter maximum count value) according to the parameter value.
The duty_u16 function is used to set the duty cycle. Through the parameter value, the corresponding value will be automatically calculated and given to the CC register. When the counter count value is smaller than the CC register, the PWM pin outputs a high level, otherwise it outputs a low level.
The role of the duty_ns function is to set the duration of a cycle to output a high level. Its parameter value is the high level time in ns.
This article is only for RP2040 MicroPython firmware, and the source code shall prevail. This article is written according to the official source code at the time of writing, which is used to provide convenience for beginners and is for reference only. Those who are capable are recommended to refer to MicroPython.
The ADC object constructor is used to initialize the corresponding ADC channel. The parameter ID is the ADC channel used. You can use the Pin object or directly specify the ADC channel.
When using the Pin object, the specified GPIO needs to support the ADC function, namely GPIO26-29;
Use the specified ADC channel, channel 0-3 corresponds to GPIO26-29, channel number 4 corresponds to the internal temperature sensor.
The read_u16 function reads the corresponding channel ADC and returns the read value;
It should be noted here that the return value of this function does not directly return the value read by the ADC, but the processed value, and its value range is 0-65535;
Therefore, the ADC voltage calculation formula should be:
Vin =\frac{3.3*ReadData}{65535}Vin=655353.3∗ReadData
The ADC read voltage is 3.3 times the return value divided by 65535 in V
This article is only for RP2040 MicroPython firmware, and the source code shall prevail. This article is written according to the official source code at the time of writing, which is used to provide convenience for beginners and is for reference only. Those who are capable are recommended to refer to MicroPython.
machine.UART is the constructor of the UART object, which is used to initialize the corresponding channel and pin. D The first parameter id is to use the UART channel, which can be 0 or 1.
The second parameter baudrate is the baud rate used.
The third parameter bits is the data bit length (only 8 bits are valid at this stage).
The fourth parameter parity is whether to use the parity bit.
The fifth parameter stop is the length of the stop bit.
The sixth and seventh parameters tx and rx are transceiver pins, which should be Pin objects.
The write function, used to send a string, returns the number of bytes sent by the value. buf: Sending a string The write function is used to send a string and return the number of bytes sent. The parameter buf is the string to be sent.
The sendbreak function sends a stop signal on the bus. This will drive the bus low for longer than the normal transmission of the character takes.
Memory Operation
Software I2C
I2C.readinto(buf, nack=True,)
Demo Address
This article is only for RP2040 MicroPython firmware, and the source code shall prevail. This article is written according to the official source code at the time of writing, which is used to provide convenience for beginners and is for reference only. Those who are capable are recommended to refer to MicroPython.
Demo Address
This article is only for RP2040 MicroPython firmware, and the source code shall prevail. This article is written according to the official source code at the time of writing, which is used to provide convenience for beginners and is for reference only. Those who are capable are recommended to refer to MicroPython.
MicroPython introduces a new @rp2.Asm_pio decorator and rp2.PIO class.
1. Program definition, including how many pins are used and if they are in/out pins. This is defined in @rp2.asm_pio.
2. Program, which sets the frequency of the state machine and which pin to bind to. These parameters are set when a state machine is set up to run a specific program.
All program configuration (such as autopull) is done in the @asm_pio decorator. Only setting the frequency and base pins needs to be set in the StateMachine constructor.
@asm_pio
@asm_pio( out_init=None, set_init=None, sideset_init=None, in_shiftdir=0, out_shiftdir=0, autopush=False, autopull=False, push_thresh=32, pull_thresh=32, fifo_join=0 )
rp2.StateMachine Function
PIO_ASM
1. target: Jump address, values 0-31 are allowed because PIO has only 32 instruction space. 2. condition :
Of course, you can also not fill in the conditions, and the specified address will be jumped unconditionally.
data : data, 0-31
Demo Address
This article is only for RP2040 MicroPython firmware, and the source code shall prevail. This article is written according to the official source code at the time of writing, which is used to provide convenience for beginners and is for reference only. Those who are capable are recommended to refer to MicroPython.
For C/C++, it is recommended to use Pico VS Code for development. This is a Microsoft Visual Studio Code extension designed to make it easier for you to create, develop, and debug projects for the Raspberry Pi Pico series development boards. No matter if you are a beginner or an experienced professional, this tool can assist you in developing Pico with confidence and ease. Here's how to install and use the extension.
Cmake Path: ${HOME}/.pico-sdk/cmake/v3.28.6/bin/cmake.exe Git Path: ${HOME}/.pico-sdk/git/cmd/git.exe Ninja Path: ${HOME}/.pico-sdk/ninja/v1.12.1/ninja.exe Python3 Path: ${HOME}/.pico-sdk/python/3.12.1/python.exe
https://github.com/earlephilhower/arduino-pico/releases/download/4.0.2/package_rp2040_index.json
Note: If you already have an ESP32 board URL, you can use a comma to separate the URLs as follows:
https://dl.espressif.com/dl/package_esp32_index.json,https://github.com/earlephilhower/arduino-pico/releases/download/4.0.2/package_rp2040_index.json
MircoPython video demo (github)
MicroPython firmware/Blink demos (C)
Raspberry Pi official C/C++ demo (github)
Raspberry Pi official micropython demo (github)
Arduino official C/C++ demo (github)