Introducing Adafruit Feather RP2040 Created by Kattni Rembor
Total Page:16
File Type:pdf, Size:1020Kb
Introducing Adafruit Feather RP2040 Created by Kattni Rembor Last updated on 2021-09-27 01:09:35 PM EDT Guide Contents Guide Contents 2 Overview 6 Pinouts 12 Power Pins and Connections 13 Logic Pins 14 I2C and SPI on RP2040 14 PWM on RP2040 14 Analog Pins 15 Digital Pins 15 CircuitPython Pins vs GPxx Pins 15 CircuitPython I2C, SPI and UART 15 GPIO Pins by Pin Functionality 16 I2C Pins 16 SPI Pins 16 UART Pins 16 PWM Pins 16 Microcontroller and Flash 17 Buttons and RST Pin 17 LEDs 18 STEMMA QT 19 Debug Interfaces 19 Assembly 22 Header Options! 22 Soldering in Plain Headers 25 Prepare the header strip: 25 Add the breakout board: 26 And Solder! 26 Soldering on Female Header 28 Tape In Place 28 Flip & Tack Solder 29 And Solder! 30 Power Management 32 Battery + USB Power 32 Power supplies 33 Measuring Battery 33 ENable pin 34 Alternative Power Options 34 Install CircuitPython 36 CircuitPython Quickstart 36 Safe Mode 37 Entering Safe Mode in CircuitPython 6.x 38 Entering Safe Mode in CircuitPython 7.x 38 In Safe Mode 39 Flash Resetting UF2 39 Installing Mu Editor 40 Download and Install Mu 40 Using Mu 40 Creating and Editing Code 42 Creating Code 42 Editing Code 44 Your code changes are run as soon as the file is done saving. 45 1. Use an editor that writes out the file completely when you save it. 45 © Adafruit Industries https://learn.adafruit.com/adafruit-feather-rp2040-pico Page 2 of 125 2. Eject or Sync the Drive After Writing 46 Oh No I Did Something Wrong and Now The CIRCUITPY Drive Doesn't Show Up!!! 46 Back to Editing Code... 47 Exploring Your First CircuitPython Program 48 Imports & Libraries 48 Setting Up The LED 48 Loop-de-loops 49 What Happens When My Code Finishes Running? 49 What if I don't have the loop? 50 More Changes 51 Naming Your Program File 51 Connecting to the Serial Console 52 Are you using Mu? 52 Setting Permissions on Linux 53 Using Something Else? 54 Interacting with the Serial Console 55 The REPL 59 Returning to the serial console 62 CircuitPython Pins and Modules 63 CircuitPython Pins 63 import board 63 I2C, SPI, and UART 64 What Are All the Available Names? 65 Microcontroller Pin Names 66 CircuitPython Built-In Modules 67 CircuitPython Libraries 68 Installing the CircuitPython Library Bundle 69 Example Files 70 Copying Libraries to Your Board 71 Example: ImportError Due to Missing Library 71 Library Install on Non-Express Boards 73 Updating CircuitPython Libraries/Examples 73 Frequently Asked Questions 74 I have to continue using an older version of CircuitPython; where can I find compatible libraries? 74 Is ESP8266 or ESP32 supported in CircuitPython? Why not? 74 How do I connect to the Internet with CircuitPython? 75 Is there asyncio support in CircuitPython? 76 My RGB NeoPixel/DotStar LED is blinking funny colors - what does it mean? 77 What is a MemoryError? 78 What do I do when I encounter a MemoryError? 78 Can the order of my import statements affect memory? 79 How can I create my own .mpy files? 79 How do I check how much memory I have free? 79 Does CircuitPython support interrupts? 79 Does Feather M0 support WINC1500? 80 Can AVRs such as ATmega328 or ATmega2560 run CircuitPython? 80 Commonly Used Acronyms 80 Welcome to the Community! 81 Adafruit Discord 81 Adafruit Forums 82 Adafruit Github 83 ReadTheDocs 84 © Adafruit Industries https://learn.adafruit.com/adafruit-feather-rp2040-pico Page 3 of 125 Advanced Serial Console on Windows 86 Windows 7 Driver 86 What's the COM? 86 Install Putty 88 Advanced Serial Console on Mac and Linux 90 What's the Port? 90 Connect with screen 92 Permissions on Linux 93 Troubleshooting 96 Always Run the Latest Version of CircuitPython and Libraries 96 I have to continue using CircuitPython 5.x, 4.x, 3.x or 2.x, where can I find compatible libraries? 96 CPLAYBOOT, TRINKETBOOT, FEATHERBOOT, or GEMMABOOT Drive Not Present 96 You may have a different board. 97 MakeCode 97 MacOS 97 Windows 10 97 Windows 7 or 8.1 97 Windows Explorer Locks Up When Accessing boardnameBOOT Drive 98 Copying UF2 to boardnameBOOT Drive Hangs at 0% Copied 99 CIRCUITPY Drive Does Not Appear 99 Device Errors or Problems on Windows 99 Serial Console in Mu Not Displaying Anything 100 CircuitPython RGB Status Light 101 ValueError: Incompatible .mpy file. 101 CIRCUITPY Drive Issues 102 Easiest Way: Use storage.erase_filesystem() 102 Old Way: For the Circuit Playground Express, Feather M0 Express, and Metro M0 Express: 102 Old Way: For Non-Express Boards with a UF2 bootloader (Gemma M0, Trinket M0): 104 Old Way: For non-Express Boards without a UF2 bootloader (Feather M0 Basic Proto, Feather Adalogger, Arduino Zero): 105 Running Out of File Space on Non-Express Boards 105 Delete something! 105 Use tabs 105 MacOS loves to add extra files. 105 Prevent & Remove MacOS Hidden Files 106 Copy Files on MacOS Without Creating Hidden Files 106 Other MacOS Space-Saving Tips 107 Device locked up or boot looping 108 CircuitPython Essentials 110 Blink 111 LED Location 111 Blinking an LED 111 Digital Input 113 LED and Button 113 Controlling the LED with a Button 113 Built-In NeoPixel LED 115 NeoPixel Location 115 NeoPixel Color and Brightness 115 RGB LED Colors 117 © Adafruit Industries https://learn.adafruit.com/adafruit-feather-rp2040-pico Page 4 of 125 NeoPixel Rainbow 118 CPU Temperature 121 Microcontroller Location 121 Reading the Microcontroller Temperature 121 Downloads 123 Files: 123 Schematic 123 Fab Print 123 3D Model 124 © Adafruit Industries https://learn.adafruit.com/adafruit-feather-rp2040-pico Page 5 of 125 Overview A new chip means a new Feather, and the Raspberry Pi RP2040 is no exception. When we saw this chip we thought "this chip is going to be awesome when we give it the Feather Treatment" and so we did! This Feather features the RP2040, and all niceties you know and love about Feather Measures 2.0" x 0.9" x 0.28" (50.8mm x 22.8mm x 7mm) without headers soldered in © Adafruit Industries https://learn.adafruit.com/adafruit-feather-rp2040-pico Page 6 of 125 Light as a (large?) feather - 5 grams RP2040 32-bit Cortex M0+ dual core running at ~125 MHz @ 3.3V logic and power 264 KB RAM 8 MB SPI FLASH chip for storing files and CircuitPython/MicroPython code storage. No EEPROM Tons of GPIO! 21 x GPIO pins with following capabilities: Four 12 bit ADCs (one more than Pico) Two I2C, Two SPI and two UART peripherals, we label one for the 'main' interface in standard Feather locations 16 x PWM outputs - for servos, LEDs, etc The 8 digital 'non-ADC/non-peripheral' GPIO are consecutive for maximum PIO compatibility Built in 200mA lipoly charger with charging status indicator LED Pin #13 red LED for general purpose blinking RGB NeoPixel with power pin on GPIO so you can depower it for low power usages. On-board STEMMA QT connector that lets you quickly connect any Qwiic, STEMMA QT or Grove I2C devices with no soldering! Both Reset button and Bootloader select button for quick restarts (no unplugging-replugging to relaunch code) 3.3V Power/enable pin Optional SWD debug port can be soldered in for debug access (https://adafru.it/w5e) 4 mounting holes 12 MHz crystal for perfect timing. 3.3V regulator with 500mA peak current output USB Type C connector lets you access built-in ROM USB bootloader and serial port debugging Inside the RP2040 is a 'permanent ROM' USB UF2 bootloader . What that means is when you want to © Adafruit Industries https://learn.adafruit.com/adafruit-feather-rp2040-pico Page 7 of 125 program new firmware, you can hold down the BOOTSEL button while plugging it into USB (or pulling down the RUN/Reset pin to ground) and it will appear as a USB disk drive you can drag the firmware onto. Folks who have been using Adafruit products will find this very familiar - we use the technique on all our native-USB boards. Just note you don't double-click reset, instead hold down BOOTSEL during boot to enter the bootloader! The RP2040 is a powerful chip, which has the clock speed of our M4 (SAMD51), and two cores that are equivalent to our M0 (SAMD21). Since it is an M0 chip, it does not have a floating point unit, or DSP hardware support - so if you're doing something with heavy floating-point math, it will be done in software and thus not as fast as an M4. For many other computational tasks, you'll get close-to-M4 speeds! For peripherals, there are two I2C controllers, two SPI controllers, and two UARTs that are multiplexed across the GPIO - check the pinout for what pins can be set to which. There are 16 PWM channels, each pin has a channel it can be set to (ditto on the pinout). You'll note there's no I2S peripheral, or SDIO, or camera, what's up with that? Well instead of having specific hardware support for serial-data-like peripherals like these, the RP2040 comes with the PIO state machine system which is a unique and powerful way to create custom hardware logic and data processing blocks that run on their own without taking up a CPU. For example, NeoPixels - often we bitbang the timing-specific protocol for these LEDs. For the RP2040, we instead use PIO object that reads in the data buffer and clocks out the right bitstream with perfect accuracy.