T2W1: PyGamer and MakeCode Arcade
Welcome to the Lowell STEMapalooza elective class for Term 2! For the first project in the term we will learn how to program our own hand-held game console, the PyGamer from Adafruit. We will program it using MakeCode Arcade, a visual programming language similar to Scratch that was developed by Microsoft. Everyone will get a board, which can plug in to your Chromebook over USB for programming, but also has a battery for portable use.
1.8" 160x128 color TFT display
Accelerometer (motion and tilt sensor)
Front-facing light sensor
Analog thumbstick for X and Y inputs
Push buttons, labeled A and B and Select and Start
Slide switch for power
5 mini NeoPixels, each one can display any color
Stereo headphone jack
Mini speaker with class D amplifier
Micro SD card slot for storing more game assets
Rechargeable battery port
Push button for reset
Lots of connectors for expansion
PyGamer CPU Specs:
ATSAMD51J19 @ 120MHz with 3.3V logic/power
512KB of FLASH + 192KB of RAM on the microcontroller
8 MB of SPI Flash storage for Python code and libraries
MicroUSB port for charging, programming, and debugging
We will be programming our PyGamer boards with MakeCode Arcade, which is easy to learn but has some powerful and convenient features. MakeCode is a visual programming language like Scratch that is developed by Microsoft and lets you run your programs on a bunch of different microcontroller boards. MakeCode lets you write programs by arranging graphical blocks instead of typing program code into a text editor. It includes an on-screen emulator of the device you are working with so you can try out your code before downloading it to the device. The Arcade version of MakeCode includes a bunch of useful features for game programming, like a sprite editor and support for simple physics and collisions, music and sounds, tile maps, and game score and life indicators.
The right side of the MakeCode window holds your program code diagram. The column of blocks in the middle holds the statements and functions you can add to your code. The section on the left is an emulator for your PyGamer board that lets you test and debug your programs before they get downloaded to the real hardware. At the bottom of the window, the Download button lets you send your program to the PyGamer board.
To download a MakeCode program to your PyGamer board, first make sure the board is connected to your Chromebook using a USB cable. The PyGamer board should show up as a flash disk drive called "PYGAMERBOOT" when it is plugged in. When you first plug it in you might get notifications about a "Removable device detected". You can dismiss the notification by clicking on the "X", or you can open the ChromeOS Files app to see what is in the PyGamer flash memory - program code will show up as a *.UF2 file (or possibly a *.py file if CircuitPython has been used).
To start the download, press the small "RESET" button at the top of the PyGamer board. The LEDs below the screen should turn red and then stay green. When the LEDs are green the board is waiting for a download. If the LEDs don't turn green there may be another type of program loaded and you may need to click again, or double-click on the RESET button.
Once the LEDs are green, press the pink [Download] button at the bottom of the MakeCode window. ChromeOS will download the *.UF2 file into your default downloads folder and a small window will pop up. Click on the link that lets you see the files to open the ChromeOS file browser. Find the file that just downloaded (look in the "Recent" file list if you are not sure) and drag it onto the "PYGAMERBOOT" drive at the bottom of the left side drive list. This should copy the saved file to the PyGamer board, and the green lights should turn off - the PyGamer board is now running your program!
Loading Sample Games and Tutorials
For the rest of the class time, try loading some of the sample MakeCode Arcade games from the start page under "Blocks Games" or "Community Games". This will help you practice opening and transferring games to the PyGamer, and will give you an idea of what can be done on the platform - think Nintendo Gameboy rather than Switch. You can play the games on your Chromebooks using the emulator window on the left side of the screen, but try downloading them to your PyGamer handheld for the full experience!
After trying some games, either start the MakeCode tutorials on the start page, or open one of the Blocks Games and try modifying some of the artwork, colors, or values inside the code and see what affect it has on the game. The idea is to explore and get comfortable in the Make Code Arcade editor environment.
Next class we will talk about MakeCode programming and go through more of the tutorials so we can be set to write our own games in future weeks!