40-fps 16-bpp platform game on a Cortex M0+ board

An ATSAMD21 (same as Arduino Zero) handles parallax scrolling, 16-bpp graphics at 40-fps on a 160x128 TFT LCD

Similar projects worth following
A poor's man hand-held console is made using a small Cortex M0+ board (Arduino Zero compatible), some switches, a widespread 1.8” 160x128 pixels TFT display and few other external components. In this project we focus on a platform game.

The framerate is fixed at 40 fps (without frame cap, the frame rate would vary between 41 and 51 fps), and the graphics engine can handle dual playfield with parallax scrolling, at 16bpp (65536 colors).
Some more optimization is still possible, without using assembly, which could lead to a better constant fps value.

The graphics engine can be used for many other types of games: racing game, shoot ‘em up, etc.

Sound samples and music (not yet implemented) will be stored on an SD card, which can be mounted on the SD card slot on the bottom side of the TFT module board.

Still missing: game score and player life/energy overlays.

In this example, the game graphics is from Sunny Land free game art from ansimuz (see links)


I wanted to see how far I could push the Cortex M0+ of the Arduino Zero. I think it is a balanced microcontroller: not too limited like an AVR, not too fancy, like a Cortex M4 (which has enough computing power even to run Doom).

I wanted to do something that could be challenging and, at the same time, funny. Well, I love 2D platform games. Why not starting from them?

Even if 2D platform games might seem outdated, they still require a good amount of memory, and if no hardware 2D acceleration is present, all the data must be processed by the CPU or, if present, by the DMA.

Initially I went on the conservative way: the ATSAMD21 specifies a maximum SPI frequency of about 12MHz, and by specification, the ST7735 controller allows a maximum SPI frequency of 15MHz (66ns SCLK time). Therefore I set the SPI frequency to 12 MHz and I also fixed the frame rate to 25 fps (without cap, the refresh frequency fluctuated from 28 to 33 Hz. I wanted to save a couple of fps because I will need to implement the sound later).

However I have recently realized that both the display and the ATSAMD21 can work at 24 MHz! That's a good overclock amount!  (still the CPU is not overclocked!)

Now, the uncapped frame rate goes up to 51 fps, and, with capping a constant 40-fps frame rate can be achieved!

Specifications achieved so far:

  • Resolution: 160 x 128 pixel
  • Color depth: 16 bpp
  • Dual playfield with parallax scrolling
  • Multiple on-screen sprites.
  • Frame rate: minimum 40 fps using an out-of-spec 24 MHz SPI frequency value. Using a 12 MHz SPI, we can achieve more than 28 fps. 

The hardware:

The hardware is composed by three boards.

  • Then there is of course the TFT LCD. I chose a 1.8” SPI 160x128 TFT module, with SD card slot (which might be useful to store audio samples and music). The controller of that particular module is an ST7735. I verified that the ILI9341 modules work too, without software modifications. As you can see, by default they come without the right side header soldered on them. You must solder it.
  • And well, to play a game you’ll need some sort of input, something like a gamepad! I decided to implement a 8-key gamepad. These are placed on the carrier board, which hosts also few passive components and an 8-DIP IC, which is an operational amplifier for the earpieces. The op amp is connected to the 10-bit DAC output of the ATSAMD21.

The power can be provided either through the micro USB connector of uChip, or externally, for instance using 3 AA/AAA batteries. 

 The board layout and schematics will be available in KiCad format (a popular free PCB CAD program).

Preliminary considerations

Before jumping head-first into the project let’s make some rough estimations. Is it feasible?

Computing Power. Enough?

Yes, the ATSAMD21 is quite powerful. Enough powerful? It is a 48 MHz Cortex M0+, with a good DMA engine. Let’s make a ballpark calculations. The 48MHz frequency means that we have about 93 clock cycles per each pixel, at 25 fps. In these cycles we can use both the CPU and the DMA (unless they access the same memory/resource). Each pixel is 16 bit, but both CPU and DMA can make 32 bit accesses. Therefore...

Read more »

  • 1 × 1.8 " TFT Display (160x128) A very popular 1.8" TFT display already soldered on a PCB board. Very common on ebay and aliexpress
  • 1 × uChip A small Arduino Zero compatible board, which can be fitted in a 16-pin IC socket.
  • 1 × The carrier board This includes keys and few other components

  • 40 fps achieved!

    Nicola Wrachien4 days ago 0 comments

    By setting the SPI speed to 24 MHz (note! this means using the MCU and the display out of their specs) we can achieve a constant frame rate of 40 fps! Without frame rate cap, it goes up to 51 fps!

View project log

Enjoy this project?



mehdi wrote 2 days ago point

Nice Job broo!!!

i hope you done soon

could you share code?

i interested about your idea to draw graphics object, i want see how :D


  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates