This project is submitted for

Details

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.

Project Logs

The SAMD21 powering the µGame consoles is not a daemon of speed. With 48MHz clock and software floating point operations, not to mention the overhead from CircuitPython interpreter, it's barely enough for a dozen frames per second in a relatively simple game. But there is good news: a recently released beta version of CircuitPython, 4.1.0, has enabled an optimization option which has been so far disabled to save on firmware size. It had been re-enabled, because it turns out that it provides a five time speedup of the CircuitPython virtual machine, and the size savings weren't that big anyways.

So now suddenly all µGames are going to be 5x faster as soon as you upgrade their firmware with 4.1.0 that you can download from http://circuitpython.org.

Yesterday I received the order for the last µGame on Tindie. That makes it 111 units sold on Tindie (and maybe a dozen more sold elsewhere). Since I don't plan on making any more of them, that was the last µGame being sold.

The project is not finished, of course — I will continue to improve the firmware, and I want to write a few more games for it. I won't be making promises, though — reality has a way of getting into my plans.

If you want to try developing such games with CircuitPython yourself, you can now get the PyBadge board from Adafruit — apart from a slightly bigger screen and much more powerful MCU, it's compatible, so all the games should work on it.

I have certainly learned a lot with this project, and I hope there will still grow a community of users for it.

The CircuitPython 4.0.0 has just been released, and it does include support for µGame. However, due to last-minute breaking changes in RC4, and my travelling that made it impossible to fix it over the weekend in time for the release, the Stage library is broken in that release and won't work.

So please refrain from upgrading for now.

I'm being told that there should be a version 4.0.1 released next week or so, which will have it all fixed.

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.

Hi, great idea! Check out #Stage, a Tile and Sprite Engine — there is a MicroPython branch there for a working version of the library I'm using for µGame. It only misses sound support, because at the time ESP8266 being a second-class citizen in MicroPython didn't have support for the Sigma-Delta peripheral or another easy way to play PCM/WAV files in the background. You might be able to port the code from NodeMCU for that: https://nodemcu.readthedocs.io/en/master/modules/pcm/

Hi deshipu, I would like to know from where you source your st7735 ? Because it's quite to find outside ebay/aliexpress/etc, and I want to be sure to get the exact same reference each time I order some.

Another one… Do you know if there is any difference between the red,green,blue tab version ? I tried setting FRMCTR1 to a higher refresh rate on my blue one, and I can't really (the screen becomes white). But with the default parameters, if update the whole buffer really quickly I can clearly see white lines appearing, as if the screen couldn't handle it. Do you have any tip on that ?

The different versions of this display will be connected to the chip in different ways: some will be RGB, some BGR, they will have different offsets (since the chip can handle up to 132x162 resolution, and the display is only 128x128, there is some freedom in which pins you can use horizontally and vertically).

Finally, some of those displays don't actually use the ST7735 chip, but a different one that just happens to use the same commands. Those chips will have different timing requirements.

I haven't seen the white lines effect on any displays I have tried, so I'm not sure what you describe, and of course I have no solution for it.

The first one is when refreshing the whole screen at 40/50fps, and the second at 10/20fps. The moving square is blurry mainly because of my smartphone, but the background is "whiteish" and this is my problem. The display seems to not handle correctly this refresh rate.

Edit: Here https://photos.app.goo.gl/rPQSrKKuJRss3VX28 , here I use the same code on a st7735 128x160. Off course the square is blurry too, but as you can see the background is the same color on the fast and the slow fps. But this one has red tab. I think there are different performances for each display model.

On the first image the sprite is going up and down and on the second left and right. When going up and down you can see black (empty ?) lines like some kind of interleave. And when going up and down no problem.

No, sorry. I'm not that experienced with TFT displays, really. I find it interesting that you have that effect not only at the edges of the moving sprite, but also in the middle of it, which, strictly speaking, didn't really move, at least not for a few frames.

This is a problem of pixel density. Each pixel is composed of 3 leds (R,G,B), and each led is in a rectangle shape. If you use only (or mainly) 1 led for a pixel in a horizontal movement (or vertical depending of how your setup is) the distance between each illuminated led is greater than for a pixel with 3 leds illuminated. Resulting in a "black strips" problem.

So for low pixel density screens, using sprites with composite colors is a good idea.

This device is really cool, mine arrived today and I can't wait until tonight when I'll start writing games on it. One concern I have though is static discharge on this cute thing. Do you know if anyone has designed a 3D case for this yet? Do you have CAD file available for the uGame that I can draw a case around? Cheers!

That is true, but they already can use GB Studio to make games for GB and a million GB emulators, including the Pocket Sprite, ODROID-GO, Pokitto, all RetroPie-based consoles, and, last but not least, pretty much any single Nintendo console. Porting a gameboy emulator to this device would be a lot of work, and I wouldn't really make this any different from all the other devices already on the market. I would rather spend that time writing new games.

I'm still working on the version of firmware based on CircuitPython 3. The tests I did while it was developed worked fine, but there are several details that require some changes — in particular, the API for playing WAV files has changed, and that requires some work, which in turn changes the memory use and makes the Vacuum Invaders no longer fit...

Im curious about the 4 debug pins on the back. They seem to be PA-14/15/16/28 on the chip. So these are just general purpose pins? Do you use them as a uart or i2c or something else? Ive just been pondering some cool uses for this with a bluetooth/wifi connection or some such.

The debug pins are on the side — they are PA30 and PA31, for SWIM. The four pins on the back are just pins that I had free, so I broke them out just in case. I don't really have any use for them, but you could connect an accelerometer or some other sensor there, I suppose.

You sir are an awesome hacker. The ugame and st775r library is working but the _stage module means I have to compile the micropython firmware by myself right? Sorry if I am asking too much, but do you have a compiled firmware of your esp8266?

And Btw, I am finally order your X-pad shield in order to build this with an esp8266.

Yes, unfortunately the _stage module is not included in MicroPython by default, and you have to build your own firmware with it. Give it a try, and if you have problems with it, we can look for a different solution.

The only thing that makes avoiding building the firmware since I tinker with micropython is linux. Since my PC only have minimum RAM for virtualbox and compiling it on the Raspberry Pi is a real challenge. But it seems I have to give it a try then. Thanks for the suggestion

I suppose that sooner or later you will install Linux on your computer. There is no xtensa compiler for the ARM processors, as far as I know, so you may have problems with compiling on the Raspberry Pi.

Yes, technically there is nothing preventing you from that. It uses the same microcontroller as Arduino Zero and many Adafruit boards, so the support is there. However, you will probably need to write your own board definition file (to expose the pins that are used for the screen, buttons and audio), and write or port the libraries for handling the screen and audio.

I was actually thinking about porting the Arduboy/Gamebuino libraries to it, however, there is only so much time I have, and I would rather focus on CircuitPython, as that's the unique feature of this device.

the thing is i don't like the idea of that having some layer, i need barebones to code gfx library and the game engine itself - absolutely not based on python.

The console hardware is extremely cool (missing wifi only) - and i'm interested in coding C++ for that, so you say that's possible., that's very nice - as i am interested in building a real game engine for it in C++.

when you plug it into usb, is it becoming available as a serial port for Arduino IDE ? how is it programmed?

If you press reset twice, that runs the bootloader, which makes a fake USB drive appear called "TRINKETBOOT" (because I used Adafruit's bootloader for that board). You just need to copy a .uf2 file to it to flash your firmware. You can generate an .uf2 file from a .hex file with uf2tool (https://github.com/Microsoft/uf2). I think that Adafruit's Arduino board definitions for the M0 boards do all this for you, so you could use that as a base, and just change the pin definitions. You can see which pins are used for what here: https://github.com/adafruit/circuitpython/blob/master/ports/atmel-samd/boards/ugame10/pins.c

I think that whatever I do, some people are going to be confused. And I think that this is fine. Confusion is a sign of learning — it means you are breaking the old patterns and discovering something new.

There is no game.mpy in the repository. I tried to use the console with minicom, and I can see the Python repl and enter commands, but there is no error output. I tried the tutorial, but it didn't autostart the main.py, only after reset (after I deleted all files and created a new main.py). And once the main.py file was corrupt after reset. Once it autostarted, but then the file in the editor was invalid, because it mounted the file system again.I'm using Debian Linux. Doesn't look like a good system so far for newbie users. Compare this to Arduino, which works out of the box.

I can assure you this also works out of the box. I suspect you have corrupted the filesystem by unplugging or hard-resetting it while the files were still copying. Normally you wouldn't touch the reset button, it resets automatically. You can run fsck on it, or follow the troubleshooting link I gave earlier to fix it. To avoid it in the future, please unmount the drive before unplugging or hard-resetting the device, so that all the data can be safely copied. I will add a section about this to the user guide.

Is your screen 160x128? You can use new gamebuino meta libraries (not published yet) for this console. Same screen resolution, same microcontroller. Also check Pokitto, Gamebuino and Arduboy libraries. They all open source and you can learn lot of thing from these consoles. I really like this idea. If you will sell or publish this console open source please let me know. I really like to get one.

Thank you. I will definitely look at their code once it becomes available — what I have so far are tricks I picked up from old platforms, like Gameboy or NES. I expect they will be using similar techniques.

I think that gamebouino libraries won't work for me, because while the display has similar resolution (128x128 for mine) and number of colors, it's connected differently — mine uses SPI, their is most likely connected using parallel protocol — otherwise they wouldn't be able to achieve the speed they are claiming.

I also really want this to be easily programmable in Python, and all the consoles you listed use C, which admittedly is easier performance-wise, but not in the speed of development.