Introducing Adafruit Pygamer Created by Kattni Rembor
Total Page:16
File Type:pdf, Size:1020Kb
Introducing Adafruit PyGamer Created by Kattni Rembor Last updated on 2021-04-26 11:49:30 AM EDT Guide Contents Guide Contents 2 Overview 7 Which Board? 11 Similarities 11 Differences between PyGamer and PyBadge/PyBadge LC 11 Differences between PyBadge & PyBadge LC 11 Comparison Table 11 Update the PyGamer Bootloader 15 Updating Your PyGamer Bootloader 15 Oh no, I updated MacOS already and I can't see the boot drive! 17 Pinouts 18 Microcontroller and Flash 18 Power 19 Display 19 Build the PyGamer Case 24 Prep 25 Paper Protection 26 Speaker 27 Battery 28 Button Caps 29 Case Layers 30 Spacers 31 Backing 31 Fasteners 32 Load a MakeCode Game on PyGamer/PyBadge 35 Board Definition 36 Change Board screen 36 Bootloader Mode 37 Drag and Drop 38 Play! 38 CircuitPython 39 Set up CircuitPython Quick Start! 39 Further Information 39 Installing Mu Editor 41 Download and Install Mu 41 Using Mu 41 Creating and Editing Code 43 Creating Code 43 Editing Code 45 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. 46 2. Eject or Sync the Drive After Writing 47 Oh No I Did Something Wrong and Now The CIRCUITPY Drive Doesn't Show Up!!! 47 Back to Editing Code... 47 Exploring Your First CircuitPython Program 47 Imports & Libraries 48 Setting Up The LED 48 Loop-de-loops 48 What Happens When My Code Finishes Running? 49 What if I don't have the loop? 49 © Adafruit Industries https://learn.adafruit.com/adafruit-pygamer Page 2 of 129 More Changes 49 Naming Your Program File 50 Connecting to the Serial Console 51 Are you using Mu? 51 Setting Permissions on Linux 52 Using Something Else? 52 Interacting with the Serial Console 53 The REPL 56 Returning to the serial console 59 CircuitPython Libraries 60 Installing the CircuitPython Library Bundle 61 Example Files 62 Copying Libraries to Your Board 62 Example: ImportError Due to Missing Library 62 Library Install on Non-Express Boards 64 Updating CircuitPython Libraries/Examples 64 CircuitPython Pins and Modules 65 CircuitPython Pins 65 import board 65 I2C, SPI, and UART 66 What Are All the Available Names? 67 Microcontroller Pin Names 68 CircuitPython Built-In Modules 68 Advanced Serial Console on Windows 69 Windows 7 Driver 69 What's the COM? 69 Install Putty 70 Advanced Serial Console on Mac and Linux 72 What's the Port? 72 Connect with screen 74 Permissions on Linux 75 Welcome to the Community! 77 Adafruit Discord 77 Adafruit Forums 78 Adafruit Github 79 ReadTheDocs 80 Frequently Asked Questions 81 I have to continue using an older version of CircuitPython; where can I find compatible libraries? 81 Is ESP8266 or ESP32 supported in CircuitPython? Why not? 81 How do I connect to the Internet with CircuitPython? 81 Is there asyncio support in CircuitPython? 81 My RGB NeoPixel/DotStar LED is blinking funny colors - what does it mean? 81 What is a MemoryError? 82 What do I do when I encounter a MemoryError? 82 Can the order of my import statements affect memory? 82 How can I create my own .mpy files? 82 How do I check how much memory I have free? 82 Does CircuitPython support interrupts? 82 Does Feather M0 support WINC1500? 82 Can AVRs such as ATmega328 or ATmega2560 run CircuitPython? 83 © Adafruit Industries https://learn.adafruit.com/adafruit-pygamer Page 3 of 129 Commonly Used Acronyms 83 Troubleshooting 84 Always Run the Latest Version of CircuitPython and Libraries 84 I have to continue using CircuitPython 5.x, 4.x, 3.x or 2.x, where can I find compatible libraries? 84 CPLAYBOOT, TRINKETBOOT, FEATHERBOOT, or GEMMABOOT Drive Not Present 84 You may have a different board. 84 MakeCode 84 MacOS 85 Windows 10 85 Windows 7 or 8.1 85 Windows Explorer Locks Up When Accessing boardnameBOOT Drive 86 Copying UF2 to boardnameBOOT Drive Hangs at 0% Copied 86 CIRCUITPY Drive Does Not Appear 86 Windows 7 and 8.1 Problems 87 Serial Console in Mu Not Displaying Anything 87 CircuitPython RGB Status Light 87 ValueError: Incompatible .mpy file. 88 CIRCUITPY Drive Issues 88 Easiest Way: Use storage.erase_filesystem() 89 Old Way: For the Circuit Playground Express, Feather M0 Express, and Metro M0 Express: 89 Old Way: For Non-Express Boards with a UF2 bootloader (Gemma M0, Trinket M0): 90 Old Way: For non-Express Boards without a UF2 bootloader (Feather M0 Basic Proto, Feather Adalogger, Arduino Zero): 90 Running Out of File Space on Non-Express Boards 91 Delete something! 91 Use tabs 91 MacOS loves to add extra files. 91 Prevent & Remove MacOS Hidden Files 91 Copy Files on MacOS Without Creating Hidden Files 92 Other MacOS Space-Saving Tips 92 Device locked up or boot looping 93 Uninstalling CircuitPython 95 Backup Your Code 95 Moving Circuit Playground Express to MakeCode 95 Moving to Arduino 96 Arduino IDE Setup 98 https://adafruit.github.io/arduino-board-index/package_adafruit_index.json 99 Using with Arduino IDE 101 Install SAMD Support 101 Install Adafruit SAMD 101 Install Drivers (Windows 7 & 8 Only) 103 Blink 104 Successful Upload 105 Compilation Issues 105 Manually bootloading 106 Ubuntu & Linux Issue Fix 106 Arcada Libraries 107 Install Libraries 107 © Adafruit Industries https://learn.adafruit.com/adafruit-pygamer Page 4 of 129 Adafruit Arcada 107 If you aren't running Arduino IDE 1.8.10 or later, you'll need to install all of the following! 107 Adafruit NeoPixel 107 Adafruit FreeTouch 108 Adafruit Touchscreen 108 Adafruit SPIFlash 108 Adafruit Zero DMA 108 Adafruit GFX 108 Adafruit ST7735 108 Adafruit ILI9341 109 Adafruit LIS3DH 109 Adafruit Sensor 109 Adafruit ImageReader 109 ArduinoJson 109 Adafruit ZeroTimer 109 Adafruit TinyUSB 110 Adafruit WavePlayer 110 SdFat (Adafruit Fork) 110 Audio - Adafruit Fork 110 Arduino Test 111 Graphics Demos 113 Arcada Library 114 Initialization 114 Joystick & Buttons 114 Backlight, Speaker and Sensors 114 Alert Boxes 114 Arcada Library Docs 116 Adapting Sketches to M0 & M4 117 Analog References 117 Pin Outputs & Pullups 117 Serial vs SerialUSB 117 AnalogWrite / PWM on Feather/Metro M0 118 analogWrite() PWM range 119 analogWrite() DAC on A0 119 Missing header files 119 Bootloader Launching 119 Aligned Memory Access 119 Floating Point Conversion 120 How Much RAM Available? 120 Storing data in FLASH 120 Pretty-Printing out registers 120 M4 Performance Options 121 CPU Speed (overclocking) 121 Optimize 121 Cache 122 Max SPI and Max QSPI 122 Enabling the Buck Converter on some M4 Boards 122 Downloads 123 © Adafruit Industries https://learn.adafruit.com/adafruit-pygamer Page 5 of 129 Files: 123 Fab Print 123 Schematic 123 Laser Cut Acrylic Case 124 3D Model 124 Troubleshooting 126 Digi-Key x Adafruit Order Shipper Game 126 Screen Adhesive Fix 126 © Adafruit Industries https://learn.adafruit.com/adafruit-pygamer Page 6 of 129 Overview What fits in your pocket, is fully Open Source, and can run CircuitPython, MakeCode Arcade or Arduino games you write yourself? That's right, it's the Adafruit PyGamer! We wanted to make an entry-level gaming handheld for DIY gaming, and maybe a little retro-emulation. It's not the fastest and best of everything but it is an all-in-one dev board with a lot of possibilities! The PyGamer is powered by our favorite chip, the ATSAMD51, with 512KB of flash and 192KB of RAM. We add 8 MB of QSPI flash for file storage, handy for images, fonts, sounds, or game assets. On the front you get a 1.8" 160x128 color TFT display with dimmable backlight - we have fast DMA support © Adafruit Industries https://learn.adafruit.com/adafruit-pygamer Page 7 of 129 for drawing so updates are incredibly fast. A dual-potentiometer analog stick gives you great control, with easy diagonal movement - or really any direction you like. There's also 4 square-top buttons, which fit our square top button caps (https://adafru.it/ET7). The buttons are arranged to mimic a gaming handheld, with 2 menu-select buttons and 2 fire-action buttons. There's also 5 NeoPixel LEDs to dazzle or track activity. On the back we have a full Feather-compatible header socket set, so you can plug in any FeatherWing to expand the capabilities of the PyGamer. There's also 3 STEMMA connectors - two 3-pin with ADC/PWM capability and one 4-pin that connects to I2C - you can use this for Grove sensors as well. For built in sensors, there's a light sensor that points out the front, and a 3-axis accelerometer that can detect taps and free-fall. To make bleeps and bloops, plug in any set of stereo headphones. For projects where you need more volume, you can plug in one of our 8 ohm speakers (https://adafru.it/CEv). The PyGamer will auto-switch to speakers when they're plugged in. You can power the PyGamer from any of our LiPoly batteries (https://adafru.it/waX), but we like this 350mAh one (https://adafru.it/kBj) which will fit into the acrylic case. An on-off switch will save battery power when not in use. Or power from the Micro USB port - it will also charge up the battery if one is attached. Now, how to program it? Well you've got a lot of options! MakeCode Arcade is the easiest to start for making games , you can drag-and-drop blocks and load games over the disk-drive bootloader (https://adafru.it/DCY) CircuitPython (https://adafru.it/FxM) lets you draw graphics, play wave files and print out text in any fonts - all in Python! There's tons of sensor support as well.