Adafruit Feather M4 Express Created by Lady Ada
Total Page:16
File Type:pdf, Size:1020Kb
Adafruit Feather M4 Express Created by lady ada Last updated on 2021-09-27 01:10:35 PM EDT Guide Contents Guide Contents 2 Overview 8 Update the UF2 Bootloader 12 Updating Your Bootloader 12 Pinouts 16 Power Pins 16 Logic pins 17 I2S Pins: 18 Parallel Capture Peripheral 18 QSPI Flash and NeoPixel 19 Other Pins! 20 Debugging Interface 20 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 35 Arduino IDE Setup 36 https://adafruit.github.io/arduino-board-index/package_adafruit_index.json 37 Using with Arduino IDE 39 Install SAMD Support 39 Install Adafruit SAMD 40 Install Drivers (Windows 7 & 8 Only) 41 Blink 43 Successful Upload 44 Compilation Issues 45 Manually bootloading 45 Ubuntu & Linux Issue Fix 46 Adapting Sketches to M0 & M4 47 Analog References 47 Pin Outputs & Pullups 47 Serial vs SerialUSB 47 AnalogWrite / PWM on Feather/Metro M0 48 analogWrite() PWM range 49 © Adafruit Industries https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51 Page 2 of 228 analogWrite() DAC on A0 49 Missing header files 49 Bootloader Launching 50 Aligned Memory Access 50 Floating Point Conversion 50 How Much RAM Available? 51 Storing data in FLASH 51 Pretty-Printing out registers 51 M4 Performance Options 52 CPU Speed (overclocking) 52 Optimize 53 Cache 53 Max SPI and Max QSPI 53 Enabling the Buck Converter on some M4 Boards 54 What is CircuitPython? 55 CircuitPython is based on Python 55 Why would I use CircuitPython? 55 CircuitPython on Feather M4 Express 57 Set up CircuitPython Quick Start! 57 Further Information 58 Installing Mu Editor 59 Download and Install Mu 59 Using Mu 59 Creating and Editing Code 61 Creating Code 61 Editing Code 63 Your code changes are run as soon as the file is done saving. 64 1. Use an editor that writes out the file completely when you save it. 64 2. Eject or Sync the Drive After Writing 65 Oh No I Did Something Wrong and Now The CIRCUITPY Drive Doesn't Show Up!!! 65 Back to Editing Code... 66 Exploring Your First CircuitPython Program 67 Imports & Libraries 67 Setting Up The LED 67 Loop-de-loops 68 What Happens When My Code Finishes Running? 68 What if I don't have the loop? 69 More Changes 70 Naming Your Program File 70 Connecting to the Serial Console 71 Are you using Mu? 71 Setting Permissions on Linux 72 Using Something Else? 73 Interacting with the Serial Console 74 The REPL 78 Returning to the serial console 81 CircuitPython Libraries 82 Installing the CircuitPython Library Bundle 83 Example Files 84 © Adafruit Industries https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51 Page 3 of 228 Copying Libraries to Your Board 85 Example: ImportError Due to Missing Library 85 Library Install on Non-Express Boards 86 Updating CircuitPython Libraries/Examples 87 Frequently Asked Questions 88 I have to continue using an older version of CircuitPython; where can I find compatible libraries? 88 Is ESP8266 or ESP32 supported in CircuitPython? Why not? 88 How do I connect to the Internet with CircuitPython? 89 Is there asyncio support in CircuitPython? 90 My RGB NeoPixel/DotStar LED is blinking funny colors - what does it mean? 91 What is a MemoryError? 92 What do I do when I encounter a MemoryError? 92 Can the order of my import statements affect memory? 93 How can I create my own .mpy files? 93 How do I check how much memory I have free? 93 Does CircuitPython support interrupts? 93 Does Feather M0 support WINC1500? 94 Can AVRs such as ATmega328 or ATmega2560 run CircuitPython? 94 Commonly Used Acronyms 94 Welcome to the Community! 95 Adafruit Discord 95 Adafruit Forums 96 Adafruit Github 97 ReadTheDocs 98 Advanced Serial Console on Windows 100 Windows 7 Driver 100 What's the COM? 100 Install Putty 102 Advanced Serial Console on Mac and Linux 104 What's the Port? 104 Connect with screen 106 Permissions on Linux 107 Uninstalling CircuitPython 110 Backup Your Code 110 Moving Circuit Playground Express to MakeCode 110 Moving to Arduino 111 Troubleshooting 114 Always Run the Latest Version of CircuitPython and Libraries 114 I have to continue using CircuitPython 5.x, 4.x, 3.x or 2.x, where can I find compatible libraries? 114 CPLAYBOOT, TRINKETBOOT, FEATHERBOOT, or GEMMABOOT Drive Not Present 114 You may have a different board. 115 MakeCode 115 MacOS 115 Windows 10 115 Windows 7 or 8.1 115 Windows Explorer Locks Up When Accessing boardnameBOOT Drive 116 Copying UF2 to boardnameBOOT Drive Hangs at 0% Copied 117 CIRCUITPY Drive Does Not Appear 117 Device Errors or Problems on Windows 117 © Adafruit Industries https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51 Page 4 of 228 Serial Console in Mu Not Displaying Anything 118 CircuitPython RGB Status Light 118 ValueError: Incompatible .mpy file. 119 CIRCUITPY Drive Issues 120 Easiest Way: Use storage.erase_filesystem() 120 Old Way: For the Circuit Playground Express, Feather M0 Express, and Metro M0 Express: 120 Old Way: For Non-Express Boards with a UF2 bootloader (Gemma M0, Trinket M0): 122 Old Way: For non-Express Boards without a UF2 bootloader (Feather M0 Basic Proto, Feather Adalogger, Arduino Zero): 122 Running Out of File Space on Non-Express Boards 123 Delete something! 123 Use tabs 123 MacOS loves to add extra files. 123 Prevent & Remove MacOS Hidden Files 124 Copy Files on MacOS Without Creating Hidden Files 124 Other MacOS Space-Saving Tips 125 Device locked up or boot looping 126 CircuitPython Essentials 128 CircuitPython Pins and Modules 129 CircuitPython Pins 129 import board 129 I2C, SPI, and UART 130 What Are All the Available Names? 131 Microcontroller Pin Names 132 CircuitPython Built-In Modules 133 CircuitPython Built-Ins 134 Thing That Are Built In and Work 134 Flow Control 134 Math 134 Tuples, Lists, Arrays, and Dictionaries 134 Classes, Objects and Functions 134 Lambdas 134 Random Numbers 135 CircuitPython Digital In & Out 136 Find the pins! 137 Read the Docs 139 CircuitPython Analog In 140 Creating the analog input 140 get_voltage Helper 140 Main Loop 140 Changing It Up 141 Wire it up 141 Reading Analog Pin Values 144 CircuitPython Analog Out 145 Creating an analog output 145 Setting the analog output 145 Main Loop 145 Find the pin 146 CircuitPython PWM 150 PWM with Fixed Frequency 150 Create a PWM Output 151 Main Loop 151 © Adafruit Industries https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51 Page 5 of 228 PWM Output with Variable Frequency 152 Wire it up 153 Where's My PWM? 157 CircuitPython Servo 159 Servo Wiring 159 Standard Servo Code 162 Continuous Servo Code 162 CircuitPython Internal RGB LED 164 Create the LED 165 Brightness 165 Main Loop 165 Making Rainbows (Because Who Doesn't Love 'Em!) 166 Circuit Playground Express Rainbow 167 CircuitPython NeoPixel 169 Wiring It Up 169 The Code 170 Create the LED 171 NeoPixel Helpers 172 Main Loop 172 NeoPixel RGBW 172 Read the Docs 174 CircuitPython DotStar 175 Wire It Up 175 The Code 176 Create the LED 178 DotStar Helpers 179 Main Loop 179 Is it SPI? 180 Read the Docs 180 CircuitPython UART Serial 182 The Code 183 Wire It Up 184 Where's my UART? 187 Trinket M0: Create UART before I2C 188 CircuitPython I2C 190 Wire It Up 190 Find Your Sensor 193 I2C Sensor Data 194 Where's my I2C? 195 CircuitPython HID Keyboard and Mouse 197 CircuitPython Keyboard Emulator 197 Create the Objects and Variables 199 The Main Loop 199 CircuitPython Mouse Emulator 200 Create the Objects and Variables 202 CircuitPython HID Mouse Helpers 202 Main Loop 203 CircuitPython Storage 204 Logging the Temperature 206 CircuitPython CPU Temp 209 CircuitPython Expectations 210 Always Run the Latest Version of CircuitPython and Libraries 210 I have to continue using CircuitPython 3.x or 2.x, where can I find compatible libraries? 210 © Adafruit Industries https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51 Page 6 of 228 Switching Between CircuitPython and Arduino 210 The Difference Between Express And Non-Express Boards 211 Non-Express Boards: Gemma, Trinket, and QT Py 211 Small Disk Space 211 No Audio or NVM 211 Differences Between CircuitPython and MicroPython 211 Differences Between CircuitPython and Python 212 Python Libraries 212 Integers in CircuitPython 212 Floating Point Numbers and Digits of Precision for Floats in CircuitPython 212 Differences between MicroPython and Python 212 UF2 Bootloader Details 213 Entering Bootloader Mode 214 Using the Mass Storage Bootloader 216 Using the BOSSA Bootloader 217 Windows 7 Drivers 217 Verifying Serial Port in Device Manager 218 Running bossac on the command line 220 Using bossac Versions 1.7.0, 1.8 220 Using bossac Versions 1.9 or Later 220 Updating the bootloader 221 Getting Rid of Windows Pop-ups 222 Making your own UF2 223 Installing the bootloader on a fresh/bricked board 224 Downloads 225 Datasheets 225 Schematic & Fab Print 225 Pinout Diagram 226 © Adafruit Industries https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51 Page 7 of 228 Overview It's what you've been waiting for, the Feather M4 Express featuring ATSAMD51. This Feather is fast like a swift, smart like an owl, strong like a ox-bird (it's half ox, half bird, OK?) This feather is powered by our new favorite chip, the ATSAMD51J19A - with its 120MHz Cortex M4 with floating point support and 512KB Flash and 192KB RAM.