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:

Nano

Uno

Display:

OLED I2C SSD1306

Keypad:

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:

Cables

Step 2: Uno Wiring

Picture of 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

Picture of 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!

Picture of Have Fun!

Comments

jbc8 (author)2017-11-12

Can you make a version that does SPI?

BADFEED (author)jbc82017-11-17

Hi,

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.

iHayri (author)2017-09-24

Hi,

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.

BADFEED (author)iHayri2017-09-26

Hi,

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.

iHayri (author)BADFEED2017-09-26

Hi,

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.

D6equj5 (author)2017-08-10

Hi,

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?

Thanks

D6

BADFEED (author)D6equj52017-08-11

Hi,

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?

regards,

KunI3 made it! (author)2017-03-28

hello, badfeed. i have a question, if the change the lcd like that? how to program that?

thank you

BADFEED (author)KunI32017-03-29

Hi,

I don't know anything about that display and I imagine the system for comunicating with it is different to the SSD1306.

Sorry I can be of more help.

good luck with it though, nice looking display..

Lintang_Wisesa made it! (author)2017-01-07

It's awesome! I made it w/ joystick/thumbstick controlled, demo: https://youtu.be/jGtNyWtdwFM

BADFEED (author)Lintang_Wisesa2017-01-07

Cool :)

Good job getting the thumb stick working with it!

SarahH25 (author)2016-12-13

another christmas present idea!

DIY Hacks and How Tos (author)2016-09-17

Fun project for teaching people about Arduinos and displays.

About This Instructable

5,881views

28favorites

License:

More by BADFEED:Tetris Clone with OLED SSD1306(I2C) for Arduino Nano / Uno
Add instructable to: