Difference between revisions of "QT Py (RP2040 based)"
Jump to navigation
Jump to search
Blwikiadmin (talk | contribs) |
Blwikiadmin (talk | contribs) |
||
Line 584: | Line 584: | ||
* No Built-in support in MMBASIC for the on-board NEOPIXEL | * No Built-in support in MMBASIC for the on-board NEOPIXEL | ||
* Red, Green, Blue LED | * Red, Green, Blue LED | ||
− | * Pull Low to turn on RGB LED | + | * Pull Low to turn on RGB LED bits |
* At-boot - RGB LED blinks Cyan/Green by MMBASIC | * At-boot - RGB LED blinks Cyan/Green by MMBASIC | ||
− | |||
* Red LED = GP17 | * Red LED = GP17 | ||
* Green LED = GP16 | * Green LED = GP16 | ||
Line 592: | Line 591: | ||
<pre> | <pre> | ||
− | SETPIN | + | SETPIN GP17, DOUT:' Red LED |
− | SETPIN | + | SETPIN GP16, DOUT:' Green LED |
− | SETPIN GP25, DOUT | + | SETPIN GP25, DOUT:' Blue LED |
+ | PIN(GP17)=1:' Turn off Red LED | ||
+ | PIN(GP25)=1:' Turn off Blue LED | ||
+ | PIN(GP16)=1:' Turn off Green LED | ||
+ | PIN(GP17)=0:' Turn on Red LED | ||
+ | PIN(GP25)=0:' Turn on Blue LED | ||
+ | PIN(GP16)=0:' Turn on Green LED | ||
</pre> | </pre> |
Revision as of 13:38, 11 July 2022
Contents
- 1 RP2040 QT Py
- 2 Pins (RP2040)
- 2.1 Adafruit RP2040
- 2.1.1 3V
- 2.1.2 5V
- 2.1.3 A0 / D0 - Digital/analog GPIO pin 0
- 2.1.4 A1 / D1 - Digital/analog GPIO pin 1
- 2.1.5 A2 / D2 - Digital/analog GPIO pin 2
- 2.1.6 A3 / D3 - Digital/analog GPIO pin 3
- 2.1.7 SDA / D4
- 2.1.8 SCL / D5
- 2.1.9 TX / A6 / D6
- 2.1.10 RX / A7 / D7
- 2.1.11 SCK / A8 / D8
- 2.1.12 MISO / A9 / D9
- 2.1.13 MOSI / A10 / D10
- 2.1.14 NeoPixel
- 2.2 Seeeduino RP2040
- 2.2.1 3V
- 2.2.2 5V
- 2.2.3 A0 / D0 / P26 - Digital/analog GPIO pin 0
- 2.2.4 A1 / D1 / P27 - Digital/analog GPIO pin 1
- 2.2.5 A2 / D2 / P28 - Digital/analog GPIO pin 2
- 2.2.6 A3 / D3 / P29 - Digital/analog GPIO pin 3
- 2.2.7 SDA / D4 / P6
- 2.2.8 SCL / D5 / P7
- 2.2.9 TX / D6 / P0
- 2.2.10 RX / D7 / P1
- 2.2.11 SCK / D8
- 2.2.12 MISO / D9 / P4
- 2.2.13 MOSI / D10 / P3
- 2.2.14 On-board LEDs
- 2.1 Adafruit RP2040
- 3 Programming
- 4 QT Py Breakout Board
- 5 QTPy49 Board
- 6 Videos
RP2040 QT Py
- Two manufacturers
- USB Type C connector
- RP2040 32-bit Cortex M0+ dual-core
- Runs at ~125 MHz
- 264 KB RAM
- SPI FLASH chip for storing files and CircuitPython/MicroPython code storage
- 8 MB - Adafruit
- 2 MB - Seeedstudio
- No EEPROM
- Can be used with C/C++ (Arduino), MicroPython, or CircuitPython
- Built-in RGB NeoPixel LED
- 13 GPIO pins (11 breakout pads and two QT pads):
- Four 12 bit ADCs (one more than Pico)
- I2C port
- 2 I2C: 1 on QT pins, one on the (Adafruit) breakout pads - Adafruit
- 1 I2C on XAIO
- SPI and UART peripherals, in standard QT Py locations,
- PWM outputs on every IO pin - for servos, LEDs, etc
- There are 6 GPIO in consecutive order for PIO compatibility
- 3.3V logic and power 600 mA
- Both Reset button and Bootloader select buttons for quick restarts (no unplugging-replugging to relaunch code)
Pins (RP2040)
- Pins are mapped differently in MicroPython between Seeeduino XIA and Adafruit QT Py
- The Python board module virtualizes the difference
Adafruit RP2040
Adafruit QT Py RP2040 Product page
3V
- Regulated output from the onboard regulator. You can draw 500mA
5V
- 5v out from the USB port.
- Voltage input
- Requires external diode
- Schottky, signal, power
- Between external power source and this pin
- Cannot power the USB port by supplying 5V to this pin
- There is a protection diode that prevents the 5V from reaching the USB connector.
- This is to protect host computer USB ports, etc.
- Requires external diode
A0 / D0 - Digital/analog GPIO pin 0
- Digital I/O 0
- GPIO29 in MicroPython
- Analog In 0
- True analog output with 10 bit precision
- Does not have PWM
- Capacitive touch input.
A1 / D1 - Digital/analog GPIO pin 1
- Digital I/O 1
- GPIO28 in MicroPython
- Analog In 1
- Capacitive touch input
- AREF pin.
A2 / D2 - Digital/analog GPIO pin 2
- Digital I/O 2
- GPIO27 in MicroPython
- Analog In 2
- PWM
- Capacitive touch input.
A3 / D3 - Digital/analog GPIO pin 3
- Digital I/O 3
- GPIO26 in MicroPython
- Analog In 3
- PWM output
- Capacitive touch input.
SDA / D4
- Digital I/O 4
- I2C SDA pin
- PWM output
- GPIO24 in MicroPython
- No analog on this pin
- No pull up on this pin
- When using with I2C requires an external 2.2K-10K pullup to 3.3V.
SCL / D5
- Digital I/O 5
- I2C SCL
- GPIO25 in MicroPython
- No analog on this pin
- No pull up on this pin
- When using with I2C requires an external 2.2K-10K pullup to 3.3V.
TX / A6 / D6
- Digital I/O 6
- Transmit (output) for Serial1
- GPIO20 in MicroPython
- Analog 6
- PWM output
- Capacitive touch input
RX / A7 / D7
- Digital I/O 7
- Receive (input) for Serial1
- GPIO5 in MicroPython
- Analog 7
- PWM output
- Capacitive touch input
SCK / A8 / D8
- Digital I/O 8
- SPI SCK pin
- GPIO6 in MicroPython
- Analog 8
- PWM output
MISO / A9 / D9
- Digital I/O 8
- SPI MISO pin
- GPIO4 in MicroPython
- Analog 8
- PWM output
MOSI / A10 / D10
- Digital I/O 10
- SPI MOSI pin
- GPIO3 in MicroPython
- Analog 10
- PWM output
NeoPixel
- NEOPIXEL LED Features
- Individually addressable and programmable RGB LEDs
- Operating voltage: 3.3V to 5V
- Power consumption: 60mA per LED at full brightness
- Communication: PWM through data pin
- Driver IC: WS2812
- Data = Pin 11
- Power = Pin 12 - set low for low power usage
- By default pin 12 is set high by Arduino/CircuitPython
- NeoPixel Code example
import board import neopixel pixels = neopixel.NeoPixel(board.NEOPIXEL, 1) # fill((rVal, gVal, bVal)) # rVal, gVal, bVal = red/green/blue values (0-255) pixels.fill((255, 0, 0)) # Note double parens
Seeeduino RP2040
There are 14 GPIO PINs on XIAO RP2040, on which there are 11 digital pins, 4 analog pins, 11 PWM Pins,1 I2C interface, 1 UART interface, 1 SPI interface, 1 SWD Bonding pad interface.
3V
- Regulated output from the onboard regulator. You can draw 500mA
5V
- 5v out from the USB port.
- Voltage input
- Requires external diode
- Schottky, signal, power
- Between external power source and this pin
- Cannot power the USB port by supplying 5V to this pin
- There is a protection diode that prevents the 5V from reaching the USB connector.
- This is to protect host computer USB ports, etc.
- Requires external diode
A0 / D0 / P26 - Digital/analog GPIO pin 0
- board.D0
- board.A0
- P26 in Arduino/MicroPython
- True analog output with 10 bit precision
- PWM output
A1 / D1 / P27 - Digital/analog GPIO pin 1
- board.D1
- board.A1
- P27 in Arduino/MicroPython
- PWM output
A2 / D2 / P28 - Digital/analog GPIO pin 2
- board.D2
- board.A2
- P28 in Arduino/MicroPython
- PWM output
A3 / D3 / P29 - Digital/analog GPIO pin 3
- board.D3
- board.A3
- P29 in Arduino/MicroPython
- PWM output
SDA / D4 / P6
- board.D4
- board.SDA
- P6 in Arduino/MicroPython
- I2C SDA pin
- PWM output
- No pull up on this pin
- When using with I2C requires an external 2.2K-10K pullup to 3.3V.
SCL / D5 / P7
- board.D5
- board.SCL
- P7 in Arduino/MicroPython
- I2C SCL
- No pull up on this pin
- When using with I2C requires an external 2.2K-10K pullup to 3.3V
- PWM output
TX / D6 / P0
- board.D6
- board.TX
- Transmit (output) for Serial1
- P0 in Arduino/MicroPython
- PWM output
RX / D7 / P1
- board.D7
- board.RX
- Receive (input) for Serial1
- P1 in Arduino/MicroPython
- PWM output
SCK / D8
- board.D8
- board.SCK
- SPI SCK pin
- P2 in Arduino/MicroPython
- PWM output
MISO / D9 / P4
- board.D8
- board.MISO
- SPI MISO pin
- P4 in Arduino/MicroPython
- PWM output
MOSI / D10 / P3
- board.D10
- board.MOSI
- SPI MOSI pin
- P3 in Arduino/MicroPython
- PWM output
On-board LEDs
- Red Power LED
- USER LED (RGB)
- RED - P17
- board.LED_RED
- GRN - P16
- board.LED_GREEN
- LED_BUILTIN in Arduino
- BLU - P25
- board.LED_BLUE
- Code to Blink 3 LEDs
- RED - P17
- NEOPIXEL LED Features
- Individually addressable and programmable RGB LEDs
- Operating voltage: 3.3V to 5V
- Power consumption: 60mA per LED at full brightness
- Communication: PWM through data pin
- Driver IC: WS2812
- NEOPIXEL Power - P11 - set low for low power usage
- board.NEOPIXEL_POWER
- NEOPIXEL Data - P12
- board.NEOPIXEL
- NEOPIXEL Demo
Programming
- The RP2040 can be programmed in several languages/environments
- C/C++
- CircuitPython - best choice in most cases
- MicroPython
C/C++
- Can program in C/C++ using
- Arduino IDE
- Pico C++ SDK
C/C++ Adafruit RP2040 - Arduino
- Arduino IDE Setup
- Add the URL to the the Additional Boards Manager URLs
https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
- Tools > Board > Boards Manager
- Search for RP2040
- Scroll down to the Raspberry Pi Pico/RP2040 by Earle F Philhower, III entry
- Click Install to install it
- Tools > Boards menu
- Navigate to the Raspberry Pi RP2040 Boards menu and choose Adafruit QT Py RP2040
C/C++ Seeeduino RP2040 - Arduino
- Arduino IDE Setup for Seeeduino RP2040 version
- Requires Arduino IDE version 1.8 or higher
- Add the URL to the the Additional Boards Manager URLs
https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json
C/C++ RP2040
CircuitPython
- CircuitPython is a derivative of MicroPython
- CircuitPython is the best choice in most use-cases
- Board specific support for both Seeed XAIO and Adafruit QT Py cards
- Welcome To CircuitPython - Adafruit tutorial
- Autorun code - CircuitPython looks for a code file on the board to run
- There are four options: code.txt, code.py, main.txt and main.py
- CircuitPython looks for those files, in that order, and then runs the first one it finds
- Mu code editor
CircuitPython for Adafruit QT Py RP2040
Install CircuitPython on Adafruit QT Py RP2040
- Adafruit CircuitPython Download page
- Running v7.3.0
- Hold down the BOOT (right) button while plugging it into USB
- Download UF2 from Adafruit QT Py CircuitPython RP2040
- Drive will open
- Drop UF2 onto drive
- Blink program
Updating CircuitPython on Adafruit QT Py RP2040
- Save the contents of CIRCUITPY, just in case
- Double-click the reset button to show the BOOT drive
- Drag the update-bootloader .uf2 file to the BOOT drive
- Wait a few tens of seconds for the bootloader to update; the BOOT drive will reappear
- Check INFO_UF2.TXT to verify that the bootloader version has been updated. Then you will need to reload CircuitPython.
- Update mpy files
CircuitPython for Seeed XIAO RP2040
- XIAO RP2040 with CircuitPython
- Our GitHub repo
- Use Thonny IDE
- Left click bottom right corner
- Select CircuitPython (generic)
- Left click bottom right corner
- Select Configure Interpreter
- Select USB Serial Device (COM<x)
- Pins list
import board dir(board) ['__class__', '__name__', 'A0', 'A1', 'A2', 'A3', 'D0', 'D1', 'D10', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'I2C', 'LED', 'LED_BLUE', 'LED_GREEN', 'LED_RED', 'MISO', 'MOSI', 'NEOPIXEL', 'NEOPIXEL_POWER', 'RX', 'SCK', 'SCL', 'SDA', 'SPI', 'TX', 'UART', 'board_id'] >>> print(board.board_id) seeeduino_xiao_rp2040
Install CircuitPython on Seeed XIAO RP2040
- Hold down the "BOOT" button. (The "B" is written on the board shown to the right)
- Connect the XIAO RP2040 to your computer while you still pressing the button.
- The computer then will appear a disk driver(RP1-RP2)
- Download the XIAO-RP2040-CircuitPython.uf2 file for XIAO RP2040
- Drag the .uf2 file to the disk driver("RP1-RP2")
- Check the disk drive if the name has changed to "CIRCUITPY" (takes a few seconds)
- Free memory
>>> import gc >>> gc.mem_free() 208128 >>> import time >>> gc.mem_free() 207952
CircuitPython Example Code
- i2cscan.py - Print list of I2C devices found
SSD1306 Display Examples
- ssd1306_TextFB.py - Displays 21 columns and 8 rows of text
- ssd1306_bouncing_ball.py - Bounce a ball
- ssd1306_framebuftest.py - Frame buffer demo
- ssd1306_simpletest_FB.py - Draws 3 pixels
Digital I/O Examples
Land Boards I2CIO-8 (MCP23008) Examples
- GitHub Repo
- I2CIO8.py Demo code - Bounce an LED across MCP23008 card output pins
- I2CIO8_RW.py - Read jumpers, write back LEDs
>>> dir(i2c) ['__class__', '__enter__', '__exit__', 'deinit', 'readfrom_into', 'scan', 'try_lock', 'unlock', 'writeto', 'writeto_then_readfrom']
Land Boards SWLEDX8-I2C (MCP23017) Examples
- SWLEDX8.py = Control the SWLEDX8-I2C card
Land Boards PROTO16-I2C (MCP23017) Examples
- PROTO16_Blink.py - Control the PROTO16-I2C card
MicroPython
MicroPython on XIAO RP2040
- XIAO RP2040 with MicroPython
- Software Setup
- Download and Install the latest version of Thonny editor according to your operating system
- Launch the Thonny IDE
- Click "Tools→Options" to open the settings.
- Step 4. Chose the "Interpreter" interface and select the device as "MicroPython(Raspberry Pi Pico)" and the port as "Try to detect prot automatically"
- Press and hold the "BOOT" button and then connect the XIAO RP2040 to the PC through the Type-C cable. If it works well, there is an "RPI-RP2" desk shown on the PC.
- Press the "Stop/Restart Backend" button and there will be a pop-up window that helps you install the MicroPython firmware on the board. The XIAO RP2040 uses the same chip as the Raspberry Pi Pico, thereby the XIAO RP2040 is compatible with Pico's MicroPython files.
- Write code (Neopixel example)
- Upload the codes by clicking the "Run current script" button. For the first time, Thonny will ask where you want to save your codes file. Both This Computer and Raspberry Pi Pico are fine.
MMBASIC on XIAO RP2040
- Hardware
- QTPy49 card with Seeed Studio XIAO RP2040
- SD CARD X49
- BASIC Interpreter for the Raspberry Pi Pico running on XIAO RP2040
- MMBasic is a Microsoft BASIC compatible implementation of the BASIC language with floating point, integer and string variables, arrays, long variable names, a built in program editor and many other features
- 8 Flash locations for storage
- Support for SD Card
MMBASIC Credits
Peter Mather led the project, ported the MMBasic interpreter to the Raspberry Pi Pico and wrote the hardware device drivers. Geoff Graham wrote the MMBasic interpreter and the manual. Mick Ames wrote the PIO compiler and its corresponding documentation.
Install MMBASIC on Seeed XIAO RP2040
- Hold down the "BOOT" button
- The "B" is written on the board shown to the right
- Connect the XIAO RP2040 via USB C cable to your computer while still pressing the button
- The computer then will appear a disk driver(RP1-RP2)
- Download the PicoMite_Firmware.zip
- Drag the .uf2 file to the disk drive ("RP1-RP2")
- Card will re-boot
- Connect in TeraTerm over serial
- Free memory
> print mm.ver 5.070501 > memory Program: 0K ( 0%) Program (0 lines) 124K (100%) Free RAM: 1K ( 1%) 3 Variables 0K ( 0%) General 155K (99%) Free
SD Card Wiring
- SD_CARD_X49 card
- NO5V jumper installed
Signal | SD_CARD_X49 | QTPy49 conn | QTPy GP | PiPico Pin |
---|---|---|---|---|
SPI_SCLK | J1-3 | J3-6 | GP2 | GPIO2 |
SPI_MOSI | J1-4 | J3-4 | GP3 | GPIO3 |
SPI_MISO | J1-2 | J3-5 | GP4 | GPIO4 |
SPI_SS | J1-5 | J9-3 | GP26 | GPIO26 |
GND | J1-1 | J9-1 | ||
VCC (3.3V) | J1-7 | J9-2 |
On-Board LED
- No Built-in support in MMBASIC for the on-board NEOPIXEL
- Red, Green, Blue LED
- Pull Low to turn on RGB LED bits
- At-boot - RGB LED blinks Cyan/Green by MMBASIC
- Red LED = GP17
- Green LED = GP16
- Blue LED = GP25 (Used by MMBASIC)
SETPIN GP17, DOUT:' Red LED SETPIN GP16, DOUT:' Green LED SETPIN GP25, DOUT:' Blue LED PIN(GP17)=1:' Turn off Red LED PIN(GP25)=1:' Turn off Blue LED PIN(GP16)=1:' Turn off Green LED PIN(GP17)=0:' Turn on Red LED PIN(GP25)=0:' Turn on Blue LED PIN(GP16)=0:' Turn on Green LED
GPIO from MMBASIC
QTPy49 Marking | GPIO |
---|---|
A0 | GP26 (SD_SS) |
A1 | GP27 |
A2 | GP28 |
A3 | GP29 |
I2C_SDA | GP6 |
I2C_SCL | GP7 |
RX | GP1 |
TX | GP0 |
MMBASIC - Using Pins
- Digital I/O
SETPIN GP27, DIN:' Digital Input SETPIN GP28, DOUT:' Digital Output PIN(GP28) = 1:'Digital output
- Analog Input
SETPIN GP29, AIN:' Analog Input
- SETPIN(s) for Serial and I2C
SETPIN GP1, GP0, COM1 SETPIN GP6, GP7 I2C2
SD Configuration
OPTION SYSTEM SPI GP2, GP3, GP4 OPTION SDCARD GP26
- Verify it is working
> FILES A:/ <DIR> basic <DIR> bmps <DIR> demos <DIR> games <DIR> jpegs <DIR> lbcards <DIR> performance <DIR> wave 8 directories, 0 files
RS-232 (option)
OPTION SERIAL CONSOLE GP0, GP1
QT Py Breakout Board
- Built onto GRID49 card
- Socket for QT Py
- QT Py pins brought to header strips
- 3.3V power distribution on 2x8 header
Pins (CCW direction)
- S12 = A0
- R12 = A1
- Q12 = A2
- P12 = A3
- N12 = SDA
- M12 = SCL
- L12 = TX
- L1 = RX
- M1 = SCK
- N1 = MI
- P1 = MO
- Q1 = 3.3V
- R1 = GND
- S1 = 5V
- A6=B6=C6=D6=E6=F6=G6=H6 = GND
- A7=B7=C7=D7=E7=F7=G7=H7 = 3.3V
QTPy49 Board
Videos