Circuitpython on the Arduino Nano RP2040 Connect Created by Liz Clark
Total Page:16
File Type:pdf, Size:1020Kb
CircuitPython on the Arduino Nano RP2040 Connect Created by Liz Clark Last updated on 2021-09-27 01:10:54 PM EDT Guide Contents Guide Contents 2 Overview 5 Parts 5 Pinouts 7 Pinout Diagram 7 Power Pins 8 I2C, SPI and UART 9 Digital and Analog Logic Pins 9 WiFi 10 Accelerometer and Gyroscope 11 Microphone 11 LEDs 12 Install CircuitPython 13 CircuitPython Quickstart 13 Flash Resetting UF2 14 Installing Mu Editor 16 Download and Install Mu 16 Using Mu 16 Creating and Editing Code 18 Creating Code 18 Editing Code 20 Your code changes are run as soon as the file is done saving. 21 1. Use an editor that writes out the file completely when you save it. 21 2. Eject or Sync the Drive After Writing 22 Oh No I Did Something Wrong and Now The CIRCUITPY Drive Doesn't Show Up!!! 22 Back to Editing Code... 23 Exploring Your First CircuitPython Program 24 Imports & Libraries 24 Setting Up The LED 24 Loop-de-loops 25 What Happens When My Code Finishes Running? 25 What if I don't have the loop? 26 More Changes 27 Naming Your Program File 27 Connecting to the Serial Console 28 Are you using Mu? 28 Setting Permissions on Linux 29 Using Something Else? 30 Interacting with the Serial Console 31 The REPL 35 Returning to the serial console 38 CircuitPython Pins and Modules 39 CircuitPython Pins 39 import board 39 I2C, SPI, and UART 40 What Are All the Available Names? 41 Microcontroller Pin Names 42 CircuitPython Built-In Modules 43 CircuitPython Libraries 44 © Adafruit Industries https://learn.adafruit.com/circuitpython-on-the-arduino-nano-rp2040-connect Page 2 of 99 Installing the CircuitPython Library Bundle 45 Example Files 46 Copying Libraries to Your Board 47 Example: ImportError Due to Missing Library 47 Library Install on Non-Express Boards 49 Updating CircuitPython Libraries/Examples 49 Frequently Asked Questions 50 I have to continue using an older version of CircuitPython; where can I find compatible libraries? 50 Is ESP8266 or ESP32 supported in CircuitPython? Why not? 50 How do I connect to the Internet with CircuitPython? 51 Is there asyncio support in CircuitPython? 52 My RGB NeoPixel/DotStar LED is blinking funny colors - what does it mean? 53 What is a MemoryError? 54 What do I do when I encounter a MemoryError? 54 Can the order of my import statements affect memory? 55 How can I create my own .mpy files? 55 How do I check how much memory I have free? 55 Does CircuitPython support interrupts? 55 Does Feather M0 support WINC1500? 56 Can AVRs such as ATmega328 or ATmega2560 run CircuitPython? 56 Commonly Used Acronyms 56 Welcome to the Community! 57 Adafruit Discord 57 Adafruit Forums 58 Adafruit Github 59 ReadTheDocs 60 Advanced Serial Console on Windows 62 Windows 7 Driver 62 What's the COM? 62 Install Putty 64 Advanced Serial Console on Mac and Linux 66 What's the Port? 66 Connect with screen 68 Permissions on Linux 69 Troubleshooting 72 Always Run the Latest Version of CircuitPython and Libraries 72 I have to continue using CircuitPython 5.x, 4.x, 3.x or 2.x, where can I find compatible libraries? 72 CPLAYBOOT, TRINKETBOOT, FEATHERBOOT, or GEMMABOOT Drive Not Present 72 You may have a different board. 73 MakeCode 73 MacOS 73 Windows 10 73 Windows 7 or 8.1 73 Windows Explorer Locks Up When Accessing boardnameBOOT Drive 74 Copying UF2 to boardnameBOOT Drive Hangs at 0% Copied 75 CIRCUITPY Drive Does Not Appear 75 Device Errors or Problems on Windows 75 Serial Console in Mu Not Displaying Anything 76 CircuitPython RGB Status Light 77 ValueError: Incompatible .mpy file. 77 © Adafruit Industries https://learn.adafruit.com/circuitpython-on-the-arduino-nano-rp2040-connect Page 3 of 99 CIRCUITPY Drive Issues 78 Easiest Way: Use storage.erase_filesystem() 78 Old Way: For the Circuit Playground Express, Feather M0 Express, and Metro M0 Express: 78 Old Way: For Non-Express Boards with a UF2 bootloader (Gemma M0, Trinket M0): 80 Old Way: For non-Express Boards without a UF2 bootloader (Feather M0 Basic Proto, Feather Adalogger, Arduino Zero): 81 Running Out of File Space on Non-Express Boards 81 Delete something! 81 Use tabs 81 MacOS loves to add extra files. 81 Prevent & Remove MacOS Hidden Files 82 Copy Files on MacOS Without Creating Hidden Files 82 Other MacOS Space-Saving Tips 83 Device locked up or boot looping 84 Blink 86 Upload the Code and Libraries to the Arduino Nano RP2040 Connect 86 Digital Input 87 Wiring 87 Upload the Code and Libraries to the Arduino Nano RP2040 Connect 88 Accelerometer/Gyroscope 89 Upload the Code and Libraries to the Arduino Nano RP2040 Connect 89 PDM Microphone 91 Wiring 91 Upload the Code and Libraries to the Arduino Nano RP2040 Connect 92 Plotting Data 93 Mic Data as PWM 94 WiFi 95 Upload the Code and Libraries to the Arduino Nano RP2040 Connect 96 Nina W102 uBlox Module and SPI 97 REPL Output 97 © Adafruit Industries https://learn.adafruit.com/circuitpython-on-the-arduino-nano-rp2040-connect Page 4 of 99 Overview The Arduino Nano RP2040 Connect is the first board from Arduino featuring the RP2040 microcontroller. It's in the Arduino Nano form factor and has WIFI capabilities, making it a great choice for IoT projects. Additionally, it has 16MB of flash, onboard sensors and multiple digital and analog I/O pins. The best part: it runs CircuitPython! This guide will show you how to get started with CircuitPython on the Arduino Nano RP2040 Connect. Parts 1 x Arduino Nano RP2040 Connect Arduino Nano RP2040 Connect Buy Now Fully Reversible Pink/Purple USB A to micro B Cable - 1m long This cable is not only super-fashionable, with a woven pink and purple Blinka-like pattern, it's also fully reversible! That's right, you will save seconds a day by... $3.95 In Stock Add to Cart Half-size breadboard This is a cute half size breadboard, good for small projects. It's 2.2" x 3.4" (5.5 cm x 8.5 cm) with a standard double-strip in the middle and two power rails on both... $5.00 In Stock Add to Cart © Adafruit Industries https://learn.adafruit.com/circuitpython-on-the-arduino-nano-rp2040-connect Page 5 of 99 Tactile Switch Buttons (12mm square, 6mm tall) x 10 pack Medium-sized clicky momentary switches are standard input "buttons" on electronic projects. These work best in a PCB but $2.50 In Stock Add to Cart Diffused 5mm LED Pack - 5 LEDs each in 5 Colors - 25 Pack Need some indicators? We are big fans of these diffused LEDs. They are fairly bright, so they can be seen in daytime, and from any angle. They go easily into a breadboard and will add... $4.95 In Stock Add to Cart Through-Hole Resistors - 220 ohm 5% 1/4W - Pack of 25 ΩMG! You're not going to be able to resist these handy resistor packs! Well, axially, they do all of the resisting for you!This is a 25 Pack of... $0.75 In Stock Add to Cart © Adafruit Industries https://learn.adafruit.com/circuitpython-on-the-arduino-nano-rp2040-connect Page 6 of 99 Pinouts The Arduino Nano RP2040 Connect has many pins and onboard sensors. Let's take a tour of the board. Pinout Diagram © Adafruit Industries https://learn.adafruit.com/circuitpython-on-the-arduino-nano-rp2040-connect Page 7 of 99 Power Pins Two GND pins are marked with a white silkscreen box on the top of the board 3.3V provides 3.3V out and is marked with a red box in the picture VIN is marked with a teal box in the picture +5V is marked with green in the picture. It only provides 5V if the VUSB pads are soldered together on the back of the board, shown in the picture below. © Adafruit Industries https://learn.adafruit.com/circuitpython-on-the-arduino-nano-rp2040-connect Page 8 of 99 I2C, SPI and UART Just like other RP2040 boards, the Arduino Nano RP2040 Connect has I2C, SPI and UART connections available on multiple pins. In CircuitPython, there are board objects for I2C, SPI and UART to utilize the defaults defined by Arduino. These pins are labeled and outlined in red in the photo above. board.I2C() uses SCL/SDA board.SPI() uses SCK/MOSI/MISO board.UART() uses RX/TX Digital and Analog Logic Pins © Adafruit Industries https://learn.adafruit.com/circuitpython-on-the-arduino-nano-rp2040-connect Page 9 of 99 There are 13 digital and 4 analog pin objects defined in CircuitPython. The digital pins are available at D2-D12, A4-A5 and the analog pins are available at A0-A3. A more detailed pinout graphic PDF is available from Arduino (https://adafru.it/TaF) and details each pin's full capabilities. Please note that pins A6 and A7 on the pinout diagram are not routed through the RP2040 and are not accessible through CircuitPython. WiFi The Nina W102 uBlox module is the connect part of the Arduino Nano RP2040 Connect. It interfaces with the RP2040 microcontroller over SPI, which means that you can use the CircuitPython ESP32 SPI libraries to connect to WiFi. The SPI pins used for the module are not the board's default SPI pins. There is a © Adafruit Industries https://learn.adafruit.com/circuitpython-on-the-arduino-nano-rp2040-connect Page 10 of 99 secondary SPI connected to it and its definition in CircuitPython are as follows: esp32_cs = DigitalInOut(board.CS1) esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) spi = busio.SPI(board.SCK1, board.MOSI1, board.MISO1) Accelerometer and Gyroscope The onboard IMU is an LSM6DSOXTR and there is a CircuitPython library available for it.