Tetris Clone With OLED SSD1306(I2C) for Arduino Nano / Uno





Introduction: Tetris Clone With OLED SSD1306(I2C) for Arduino Nano / Uno

This Instructable is about getting Tiny Tetris running on a 128x64 OLED display using an Arduino Nano or Uno.

Step 1: What You Need.

Arduino Nano or Arduino Uno:






AD Analog Keyboard Module

Note: other key pads and switch configurations could be used but you would need to change the code.

Some cables to connect things:


Step 2: Uno Wiring

Uno wiring:

Note: the key pad shown represents the pad in the parts list, I have not built the one shown but if you did it would be easy to get it working, only a few small changes would be needed in the code.

Fritzing Part

Step 3: Nano Wiring

Nano wiring:

Note: the key pad shown represents the pad in the parts list, I have not built the one shown but if you did it would be easy to get it working, only a few small changes would be needed in the code.

Fritzing Part

Step 4: The Code

If you are new to Arduino have a look at this to get started:

How to have fun with Arduino

Code attached and on GitHub below:

Code on GitHub - this has the most up to date code including Art work and Sound!

There is still a lot to be done with the code, see below:

High score functionality.

[Done] Better key pad control code.

Decent random number generator.

[Done] Start thinking about adding sound.

Create a letter font, create a proper system for rendering numbers and letters.

Tidy up code and optimize for memory, sort out the globals and types.

Create defines for all the magic numbers but they are useful for now.

Step 5: Have Fun!

2 People Made This Project!


  • Oil Contest

    Oil Contest
  • Clocks Contest

    Clocks Contest
  • Woodworking Contest

    Woodworking Contest

We have a be nice policy.
Please be positive and constructive.




Hi, why right key doesn't work ? It doesn't even react in serial monitor when I am using

analoginSerialout example.

I got the AD Analog Module, but for some reason only one of the buttons actually works in the game. Do you think this is a code issue or is it the module?

1 reply


In the Arduino IDE if you go to file -examples - analog - analoginSerialout

Upload the sketch to your board and start the serial monitor - press the various buttons on your pad and make sure the values change.

If all is good make a note of the values for each button.

In the processKeys() function of the Tetris code you can set the limits for each key:

else if (analogKey < 510) && (analogKey > 500)) {



uiKeyCode = KEY_RIGHT;

so if your right key value is 300 you would change values above from 510 and 500 to something like 310 and 290

Hope this explains and it works out for you.

best regards,

I have a 6 pin OLED expansion with a res pin and a DC pin. Would it be possible to share the wire configuration for something like that.

1 reply

Hi Owen,

is it one of these types?


I have never used one but according the the instruction in the above link its possible to put it into I2C mode although some soldering is required, not sure if you can do that?

After that I would imagine it would work.

I keep meaning to get an SPI version of the screen and make the code changes for that type, as long as the screen is based on the SSD1306 it should work fine.

Let me know if you reconfigure your board and get it working.

Best of luck!


Can you make a version that does SPI?

1 reply


I don't have a SPI version of the display, I think it would be a small change in the code though.

Ill order some and experiment but honesty it could be some time, might be quicker ordering a I2C version of the display yourself.


Love your Tetris game, great work. Could you give me a hint how to make it work with a 1.3" display that uses the SH1106 chip? I know that only the lower column address needs to be changed from 0x00 to 0x02. This shifts the display to make it work with SH1106 chips. But I could not find that line in your code. You do have this: #define OLED_SET_COLUMN 0x21 but the 0x21 throws me off and changing it messes up the display. Your help would be greatly appreciated. Thanks a lot.

2 replies


I don’t think I can help you I’m afraid.
I had a quick look over the SH1106 data sheet and from what I can see it’s not compatible with the SSD1306.

There is no Arduino display library used for the Tetris game, it talks directly to the display, this was done for speed so unless the SH1106 has the exact same command set it won’t work as far as I know.

For instance, Tetris uses the vertical addressing mode on the SSD1306 to quickly draw the blocks, I don’t see any reference to addressing modes in SH1106 data sheet.

Note: I have not studied the SH1106 data sheet very well so I could be wrong, please let me know if you have any info on this.


Thank you so much for your reply. I did take a look at the libraries and read about the differences about the SDD1306 and SH1106. The main difference is that the SSD1306 has a 128x64 pixel driver and the SH1106 has a 132x64 pixel driver. And when using the command mode all that is need is to shift the pixels by the amount of 2 so it is centered on the display as I wrote above. I did edit my GPS code that uses also command lines because it is over 6 years old and it works without any problems. But drawing the blocks might be a different matter although displaying converted bitmaps works well to with the SH1106. By looking at the Adafruit_SH1106.cpp files the commands are the same. Anyway I will continue to look into this as I would love to make Tetris work on 1.3" displays too. I let you know here if I find a solution, thanks again.


I've stuck a 1306 oled disp on a Mega and loaded your code however all I get is like a star screen (random points not moving). Do I need to have the JoyStick actually plugged for it to work or have I missed something else?



3 replies


you don't need the joystick plugged in for it to work.

I have never tried it on a Mega but it should work.

Have you tried other display library's with the 1306 on the Mega?

I assume the 1306 you have is I2C interface?


Ok - all done - the version in my repo now 100% attributed to you, tobozo and others.

Sorry it took a bit to spot this - been at work all day.

Please check and let me know whether you're happy with the level of attribution now.

Just to set the record straight Anthony - I'm very disappointed to see all that action on Twitter - although I do appreciate your message, the damage is done. It seems like your Twitter account (and another one - Timinius?) was specifically set up to give me grief. Why do you think I would post on this Instructables page if I wanted to pass your code off as mine?

Not all of the code in the #AttinyArcade version that I published is yours and right from the start your work was credited/attributed via your copyright notice, referring-to your name and your copyright statement for the Lesser GPL (the whole point of this licence is to do exactly what I did - re-use code and make it clear who had modified it). Porting your code to the smaller platform (8k Flash, 512 bytes RAM) meant that I had to reduce both code footprint and memory use by almost half, which was 20+ hours work and required major re-design of significant parts of the code as well as addition of new functionality. I agree that Tobozo should also have been credited - that opening graphic is really neat! I feel bad about that and it was sorted within 3 minutes of me seeing your post here when I got in from work.

I'm always so excited to see anyone using my code anywhere - whether and however I'm credited - as you will have seen from my Twitter feed, this happens in loads of different ways. I'm sad to say that the reaction on Twitter has left me with a bad feeling about this project. I've now deleted the port from my repository and won't be revisiting it.

another christmas present idea!