Check Out Other Learning Guides

We suggest before you begin that you take a look at the learning guides:

These guides will show you how to add a speaker, battery, and button covers to the PyGamer or PyBadge. One of the demo games, Battleship, makes use of sound effects, so you will need to install a speaker or insert a pair of headphones into the headphone jack of the PyGamer. PyBadge does not have a headphone jack, so if you want to use sound effects you will have to install the speaker.

The other tutorial will instruct you on wiring jumpers and an antenna to the RFM69HCW. Also see the information about wiring below.

Wiring the RFM69HCW FeatherWing

The radio FeatherWing requires 3 jumper wires to be installed. The learning guide for this board does not specify how to wire it for a SAMD51 M4 processor such as used in the PyGamer/PyBadge. This guide uses the pins recommended for a Feather M0 and it works quite well.

Specifically the "CS" pad should be wired to the "B" pad. The "RST" pad should be wired to the "A" pad and the "IRQ" pad should be wired to the "D" pad. See the image below.

This is the recommended wiring for an M0 according to the learning guide for this device but it does not match the example programs in the RadioHead Library. If you want to run any of their examples or test programs, you will have to modify the code as described in the section "Installing the Software" below. Included in this guide are some test programs pre-configured for this project as well.

Additionally you will need some sort of antenna. I used a 3 inch long piece of wire as a whip antenna, but there are other antenna options you can use. For details see the learning guide Radio FeatherWing in the section "Assembly".

You will need to solder on a set of header pins. We recommend you do that after you have installed the jumpers.

When completed, insert the Radio FeatherWing into the back of your PyGamer or PyBadge.

Installing The Software

This project relies on three large libraries of code. The PyGamer/PyBadge uses the Adafruit_Arcada_Library and numerous other libraries that it depends upon. If you download that library using the library manager of your Arduino IDE it will automatically download any dependencies as well. For more details on installing the Adafruit_Arcada_Library see the learning guide linked here.

Additionally the RFM69HCW FeatherWing relies on a third party library called RadioHead. For complete instructions on how to install this library refer to the learning guide linked here.

Finally we need the TwoPlayerGame library which is available open source on my GitHub repository. It will have to be installed manually.

Here is a link to the GitHub page for this library. The green button below contains a link to download a zip file directly.

https://github.com/cyborg5/TwoPlayerGame

Unzip the archive into your Arduino/libraries folder and rename it from TwoPlayerGame_Master to just TwoPlayerGame. For further information on manual installation of libraries into the Arduino IDE, check out the guide linked here.

We have provided some demo software in the TwoPlayerGame/examples folder. Among them are some test programs which are preconfigured transmit and receive demos for the Radio FeatherWing.

If you want to use any of the test programs that come with the RadioHead library you can find them in the Arduino/libraries/RadioHead/examples/feather folder. Note however that the default wiring used in those sample programs does not match the ones that we use. They do not have an option for the PyGamer SAMD51 M4 processor. You can modify their example programs as follows.

Look for the section of code that looks like this…

#if defined(ADAFRUIT_FEATHER_M0) // Feather M0 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     3
  #define RFM69_RST     4
  #define LED           13
#endif

Modify that section so that it reads as follows…

#if (defined(ADAFRUIT_FEATHER_M0) || defined(ADAFRUIT_PYGAMER_M4_EXPRESS) )
  #define LED           13
  #define RFM69_CS      10   // "B"
  #define RFM69_RST     11   // "A"
  #define RFM69_INT     6    // "D"
  #define RFM69_IRQN    digitalPinToInterrupt(RFM69_INT)
#endif

Updating Firmware

Can you should make sure that you have the latest bootloader and CircuitPython distribution for your device. Click on the appropriate link below for your device.

At the bottom of the page you will see "UF2 Bootloader". Click on the "DOWNLOAD UPDATER UF2" button. This will download a file such as update-bootloader-arcade_pygamer-v3.10.0.uf2 or update-bootloader-arcade_pybadge-v3.10.0.uf2 although the version number may be different.

You should double-click the reset button on your device and the PYGAMERBOOT or PYBADGEBOOT drive will appear on your computer. Drag-and-drop the .uf2 file onto that drive.

In the next section where it talks about loading sound effects onto internal QSPI memory, it mentions that when you upload the drive.ino program it should automatically go into CircuitPython mode. If for some reason it doesn't, you can force it into that mode by dragging and dropping the latest CircuitPython .UF2 file. So while you are on the download page, go ahead and get the latest CircuitPython at the top right of the page where it says "CircuitPython". The files will be named something like adafruit-circuitpython-pygamer-en_US-5.3.0.uf2 or adafruit-circuitpython-pybadge-en_US-5.3.0.uf2 although the version number may be different.

Loading Sound Effects

The Battleship sample program makes use of sound effects in ".wav" format. You can load them onto the internal QSPI memory of the PyGamer or PyBadge. The PyGamer has 8 MB of internal memory while the PyBadge has only 2 MB. The initial design of the game used sound files that were too big for the PyBadge so we have provided a separate set of striped down mono low sample rate sound effects for the PyBadge. If 8 MB is not enough for your own games, you can also use a microSD card inserted into the slot in the back of the PyGamer. The PyBadge does not have an SD card slot.

If you are using an SD card and have an SD card reader on your computer you can simply insert a formatted SD card in your computer, drag the appropriate file onto it, eject the card and place it in your PyGamer.

Alternatively you can use a program we supply to turn your device into a virtual disk drive and drag-and-drop files directly onto it. If you are using the internal memory, this program is the only way to load sound files onto your device and the procedure is slightly different for either. If using the virtual drive feature, format the SD card and insert it into your PyGamer before turning it on or connecting it to your computer for uploading.

Find the sample program drive.ino in the TwoPlayerGame/utilities/ folder and load it into the Arduino IDE. It will turn your device into a virtual disk drive so that you can drag-and-drop the sound files into it. There is a minor modification that you need to make to the program depending on whether you are using the SD card or the internal QSPI memory. Look for the line that reads:

#define USE_SD_CARD false

If you are using the internal memory then leave it false and if you are using an external SD card edit it to be true

When uploading this program, you must change the USB Stack on the Arduino IDE from "Arduino" to "TinyUSB". You will find this option under the "Tools" menu as seen below.

NOTE: the drive.ino MUST be uploaded using TinyUSB mode but all other programs in this tutorial will work with either TinyUSB or Arduino stacks.

If you are using the internal memory, after uploading drive.ino you should see a new drive on your computer named CIRCUITPY. If for some reason you don't, you will have to force your device into CircuitPython mode as follows:

Double-click the reset button on your device and you should see a drive appear on your computer named either PYGAMERBOOT or PYBADGEBOOT. Drag-and-drop the Circuit Python .uf2 file that is appropriate for your device. The drive should change to CIRCUITPY.

Once you see CIRCUITPY you should then backup any files that might be on there in case you need them for something else. After that, erase all of the files from your device and create a folder in the root directory called /wav. Then drag-and-drop the appropriate sound files into that folder.

If you are using an external SD card and want to use the drive program, make sure you have edited the USE_SD_CARD true as described above. Connect the device to your computer with a USB data cable. You do not need to be in CircuitPython mode before uploading. Upload the drive.ino program and you will see a drive on your computer name "USB drive". Create a folder in the root directory called /wav. Then drag-and-drop the appropriate sound files into that folder.

Copy the sound files for the PyGamer from the TwoPlayerGame/sounds/battleship/PyGamer folder. These can be used on either the internal memory or the SD card.

If you are using the PyBadge you will need the smaller versions of the sound files to copy to the internal memory. Copy them from the TwoPlayerGame/sounds/battleship/PyBadge folder.

NOTE that the Tic-Tac-Toe game does not use sound effects. We may add other games to this repository in the future and we will provide sound effects for them in the TwoPlayerGame/sounds folder.

Testing Your Equipment

We recommend that you run some of the example programs for your PyGamer or PyBadge which can be found in the Adafruit_Arcada_Library/examples folder.

There is a example program called the sound_test.ino in the TwoPlayerGame/utilities folder that you can upload to test your sound effects. You should edit its USE_SD_CARD flag to true or false as necessary before uploading it.

Also in the TwoGamePlayer/utilities folder look for Demo_RX.ino and Demo_TX.ino. Upload one of them to one of your devices and the other to the other device to test transmit and receive functions. These are pre-configured versions of example programs in the RadioHead library.

Once you are certain everything is working, move onto the section on "Demonstration Games" and try out one of our games such as Tic-Tac-Toe or Battleship. That section will instruct you how to upload the games so that your two devices will be configured properly to talk to one another.

This guide was first published on Jul 07, 2020. It was last updated on Jul 07, 2020.

This page (Assembly and Set Up) was last updated on Oct 23, 2021.

Text editor powered by tinymce.