A small game console directly programmable in Python. I always wanted to make this, and after my work on #PewPew FeatherWing I finally decided that I'm ready.
The first version may be a bit of a stretch — I tried to make it as small as possible, fitting in the 5x5cm limit of PCB manufacturers, so that it will be cheap to make the PCBs. Using the cheap ST7735 TFT display, and a cheap ATSAMD21E chip. I also tried to put all the components on one side of the board.
Of course the hard part is writing a game library, and the actual games. There is already one simple platformer game written as a demo, and the software library is getting new features added as needed.
I finally worked on an improvement that I long wanted to do to the _stage library, which is at the heart of µGame: make the communication with the display asynchronous by using DMA. This way I can have two buffers, and calculate the contents of one of them while the other one is being sent to the display.
As a test I used the balls demo from the tutorial, but with all waiting for the next frame removed — so they move as fast as they can.
Here is how it works before DMA:
And here is how it works with DMA:
As you can see, there is barely any perceptible difference at all!
The code I wrote for this is pretty nasty and hacky, and after seeing this, I don't think I have the heart to clean it up and send it as a pull request — it's simply not worth it.
However, I will keep an eye for other ways of improving the firmware.
UPDATE: Yes, I made some more precise measurements as well. Running through 1000 frames of the animation took the DMA version 31.034s and the non-DMA version 32.699s. That is 32.22 fps with DMA and 30.58 fps without.
UPDATE2: I did a second test, with full-screen updates this time. 159.08s for non-DMA, versus 148.708s for DMA. That's 6.28 fps versus 6.72 fps. Even with such a large amount of data, the difference is negligible compared to the time spent computing it.
The upcoming CircuitPython 4.0 introduces, among other things, built-in support for displays. That means that when there is an error in your code, you will be able to see it right there on the screen, without having to connect to some gnarly serial ports. For now the built-in display code is slow — fast enough for displaying text, but not for games. So I went and modified my #Stage, a Tile and Sprite Engine library to coexist with the displayio support, to get the best of both world — console using displayio, and fast updates using stage.
There are still some tweaks left to do, perhaps use of a smaller font, and I still need to resolve the audioio problems that appeared with CircuitPython 3.0, but there are already nice improvements.
I also hope to see if I can use DMA to speed up display updates considerably.
CircuitPython 3.2.0 has been released a while ago, and brings a lot of bug fixes and some performance improvements. It would be nice to use it for µGame. Unfortunately, it also had some changes in how audio is handled, and since that interacted with available memory in ways that made the example games not work, it required more work on my part than just rebasing the repository.
In order to upgrade your device, you need to download the .uf2 file, and copy it to the TRINKETBOOT disk that appears when you press the "reset" button (located next to the direction buttons) twice. Once the file is copied, the device will reboot with the new firmware in place.
A while back @davedarko made a simple case for µGame and made it available on Thingiverse. Now there is more choice, as Jovan Maric created another case. This one works even if you already attached your battery.
After working on research and design for the #µGame Turbo for several months, and after Adafruit has started to work on their own version of a game console for CircuitPython, I decided that the improvements are not really worth the extra price and work, and decided to come back and focus on regular µGame more.
There will be no more hardware iterations (except perhaps a small update changing the USB port to one that is more friendly to the fabricators), but there is still a lot that can be done in firmware and in the libraries. In particular, I have some ideas that I want to try to speed up the screen updates and to make more memory available for the games.
The CircuitPython 3.0 is coming, Beta0 version was just released last week, and I've been working a little bit to make sure that all the libraries for µGame work with it. Right now I'm struggling with a change in the API for AudioIO, which makes CircuitPython try to allocate an extra 512 bytes of RAM every time you try to play a sound. Obviously that fails randomly in any larger game, as there is simply no room for it. But I'm sure a solution can be found — in the worst case, I will switch to a different way of making sounds.
The freshly assembled µGames arrived straight from @Makerfabs and you can again get them from Tindie — there is a link at the top of this page. I will also take a few to #Hackaday | Belgrade 2018 — you can let me know in advance if you want to save on the shipping costs. I am not sure yet what other meetups I will attend (Makerfaire Prague is a possibility, and Europython is pretty much settled).
I didn't mention this yet here, but I have started work on an improved (and more expensive) version of this device. I the good old style of 80s, I decided to call it #µGame Turbo (if there is going to be a third version, it will be Super µGame Turbo, of course). I'm still researching most things, but the goal is to mostly have a physically bigger screen (same resolution), more memory and better audio (better speaker, volume control, headphone jack). It should be software-compatible with the current µGame, though.
I am not sure how that project will go, and whether I will be selling that new version of the device too — there are currently simply too many variables.
I just asked @Makerfabs for a quote on a new batch of µGames to be produced, and if everything goes well, they will be in stock in a couple of weeks. Also, the 3.0 version of CircuitPython is coming soon, and there will be a firmware update. The new version has greatly improved memory management, so it should help a little. I also fixed a few small bugs, and I plan to finally add the build-in art assets, which should also help with memory somewhat.
In the meantime, I started to work on #µGame Turbo, and I entered it in the Hackaday Prize. I am not yet entirely sure where I will take this project, the only thing I'm certain of is that I want to keep it compatible with the current µGame — so that all the people who bought it are not left with an obsolete device. The new version will have more memory, so hopefully you won't need to pre-compile your files anymore, and I want to try and make it have proper audio, with volume control and headphone jack, a physically bigger display, and better connectors for external stuff. It will probably be more expensive, too, so it's more like an alternative to µGame coexisting with it side-by-side rather than a replacement.
Finally, I just started today some sketches for another handheld, a #CircuitPython Game Badge, which is supposed to be even more minimal than µGame. The goal here is to minimize the price and power consumption, so that it could be used as a conference badge, given out to all participants. It's not going to be compatible with µGame, though.
The SAMD21 chip is great for its native USB and the way you can just copy files on it, but since it's relatively new, the development boards for it are rather pricey. Plus, it really has small RAM and slow SPI, which limits what kind of games you can make.
For making your own µGame clone, the ESP8266 could be a much better choice. 90kB of RAM and 40MHz SPI communication with the display (the esp can do 80MHz, but the display can't) make it a perfect solution. The only problem is a somewhat convoluted way of getting files on it, using external tools, but I might be able to do something about that with #ESP8266 Dev Board with True USB if I'm lucky. So I set out to try the µGame software on the ESP8266.
The first try was using the CircuitPython firmware for Adafruit HUZZAH. Since the original µGame runs CircuitPython. Unfortunately, turns out that the HUZZAH board has been a little bit neglected, and some things don't work as expected with the current version. In particular, I couldn't get SPI to work while also using GPIO12 as D/C pin. After some failed attempts at fixing it quickly, I decided to try the good old MicroPython again.
To do that, however, I had to port my _stage tile and and sprite engine to MicroPython from CircuitPython. While the two versions are very similar to the user, they differ substantially in their internal file organization, so I spent a whole night on this. But the result is very good:
I'm using a new version of the #D1 Mini X-Pad Shield here, and a standard ST7735 breakout module. The picture on the screen doesn't look good, because of lighting — sorry about that, I don't have access to a better environment at the moment.
While several people are working on 3D-printed cases for the µGame, @davedarko is the first to deliver! He designed a minimalist case that covers the battery on the back, but leaves the PCB exposed for perusal. Since his µGame already had a battery attached, he sent the design to Szymon Jakubiak for printing and testing. When all was confirmed working, he printed two of them in colors matching the prototypes, and sent them to me: