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

6,870

28

12

Posted

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

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!

Recommendations

  • Epilog Challenge 9

    Epilog Challenge 9
  • First Time Author Contest 2018

    First Time Author Contest 2018
  • Sew Warm Contest 2018

    Sew Warm Contest 2018
user

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

Tips

Questions

11 Comments

user

Can you make a version that does SPI?

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.

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.

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.

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.

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

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,

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!