# Tic-Tac-Toe game with Arduino/Raspberry Pi and STONE Screen (Solved)

#### Young2

Joined Dec 7, 2020
93
I recently bought Arduino UNO and Raspberry Pi boards, and I also bought a new TFT LCD from STONE, and I want to make a simple mini-game about Tic Tac Toe.
Which microcontroller should I use is better? Does anyone have a similar project or experience that I can learn from?
It's my first time to do such a small game, is there anything I need to pay attention to?

Last edited by a moderator:

#### click_here

Joined Sep 22, 2020
548
How advanced do you want it to be?

On one end of the spectrum you have a pseudo-random number generator, on the other end is neural networks and machine learning.

You may also want the computer to choose the most likely spot for a win based on a points system - "chess engine"

#### Young2

Joined Dec 7, 2020
93
How advanced do you want it to be?

On one end of the spectrum you have a pseudo-random number generator, on the other end is neural networks and machine learning.

You may also want the computer to choose the most likely spot for a win based on a points system - "chess engine"
I'm a novice, and I can't make that advanced algorithm yet.
My idea is to make a simple logic, the first click is a circle after the next time to take the opposite is a cross, and so on. And then write a victory condition judgment.

#### click_here

Joined Sep 22, 2020
548
Quickly draw out your I/O so that you know how many pins you need. There are a lot of tricks thay can reduce the pin count, but I'd say keep it simple to begin with.

The RPi will be overkill for what you need, so I'd suggest that you go with the Arduino Mega.

A basic approach would be to have red leds for one team and green for the other.

You could use 2 x 9 buttons as inputs on a proto board.

For now plug all I/O directly into seporate pins (i.e. 1 to 1)

For the program the best approach for a beginner would be to generate a random number for the computer's turn - If the space is already taken, choose one to the left (take care to keep in the bounds of how many spots there are)

For simplicity I'd suggest that the computer always goes first.

To win, a long but simple if/else if/else if will get you there

To display a winner you can turn off all leds but the winning ones

To play again, just do a power reset.

After you get this working there is so much that you can do with it!

#### Young2

Joined Dec 7, 2020
93
Quickly draw out your I/O so that you know how many pins you need. There are a lot of tricks thay can reduce the pin count, but I'd say keep it simple to begin with.

The RPi will be overkill for what you need, so I'd suggest that you go with the Arduino Mega.

A basic approach would be to have red leds for one team and green for the other.

You could use 2 x 9 buttons as inputs on a proto board.

For now plug all I/O directly into seporate pins (i.e. 1 to 1)

For the program the best approach for a beginner would be to generate a random number for the computer's turn - If the space is already taken, choose one to the left (take care to keep in the bounds of how many spots there are)

For simplicity I'd suggest that the computer always goes first.

To win, a long but simple if/else if/else if will get you there

To display a winner you can turn off all leds but the winning ones

To play again, just do a power reset.

After you get this working there is so much that you can do with it!
Thanks for your detailed advice, I have Arduino Uno in my hands now, do you have any good advice for this?

#### click_here

Joined Sep 22, 2020
548
First step - Design the electronics

18 LEDs (2 x 9) and 9 buttons

This is a problem, because you only have 14 I/O

The best option is to choose a micro that fits the bill - i.e. buy a mega.

A good option with the uno is to use an I/O expantion chip.

There are other tricks that I know, but they get more involved.

What direction do you want to go?

#### KeithWalker

Joined Jul 10, 2017
3,030
The easiest would be using an Arduino. You are not limited by the number of LEDs and push-buttons you can drive. There are quite a few alternative ways of doing it. For example you can make the game work with a touchscreen display or a simple monochrome graphic display and a joystick. Do an internet search of "arduino tic tac toe". You will get lots of examples using different methods. Some are complete with a tutorial that explains in detail how it is done.

#### BobTPH

Joined Jun 5, 2013
8,664
I'm a novice, and I can't make that advanced algorithm yet.
My idea is to make a simple logic, the first click is a circle after the next time to take the opposite is a cross, and so on. And then write a victory condition judgment.
Does your display include a touchscreen? You seem to imply it does.

The first thing I would do is to try to get the display working. What type of interface does it have? Is there a library module for it on Arduino?

Bob

#### BobaMosfet

Joined Jul 1, 2009
2,105
Title: Understanding Basic Electronics, 1st Ed.
Publisher: The American Radio Relay League
ISBN: 0-87259-398-3

#### KeithWalker

Joined Jul 10, 2017
3,030
Do you have any programming experience?

#### Young2

Joined Dec 7, 2020
93
First step - Design the electronics

18 LEDs (2 x 9) and 9 buttons

This is a problem, because you only have 14 I/O

The best option is to choose a micro that fits the bill - i.e. buy a mega.

A good option with the uno is to use an I/O expantion chip.

There are other tricks that I know, but they get more involved.

What direction do you want to go?
My user interface is a nine-box checkerboard and the button controls and image controls I put on it.

When there are three identical symbols in a line, it is enough to prove that the user who used this symbol wins. I thought everything could be done in a simple way. I initially thought of setting up two users, one using ○ and one using ×, but then I thought it would be simpler to specify that the first time whichever user clicked on it would be ○, the second would be reversed, and so on.

#### click_here

Joined Sep 22, 2020
548
I don't know how I missed the LCD [facepalm]

The first step is getting the display working.

It might be worth looking into something called the Model view controller (mvc) design pattern. It's a way of structuring your code.

A good first goal is getting to the point where the model updates the view. i.e. If you had an array of values representing each space in memory, can you make your user interface update to display it.

Start by getting something on the screen.

Then having your code change something on the screen

Then updating the UI based on what your model has in it

#### Young2

Joined Dec 7, 2020
93
Does your display include a touchscreen? You seem to imply it does.

The first thing I would do is to try to get the display working. What type of interface does it have? Is there a library module for it on Arduino?

Bob
yes, I use a touchscreen display.

It has RS422, RS485, RS232, and TTL interfaces.
I am using STONE's new product touch screen, the old product of the previous green board is no library on arduino, the new product of the black board I heard that arduino official is currently developing, should be open later.
In fact, there is no library module can be used directly, I have tried some simple functions are feasible.

#### Young2

Joined Dec 7, 2020
93
Do you have any programming experience?
I have a little bit of programming experience, having studied programming when I was in school before. Thanks for your suggestion, I searched arduino tic-tac-toe and saw some helpful projects and articles for me, I will study them carefully.

#### Young2

Joined Dec 7, 2020
93
Most use LEDs. Here is a sampling. GitHub has many projects in various languages and various outputs for ideas. Pretty popular idea.
tic-tac-toe · GitHub Topics · GitHub
Tic Tac Toe Soldering Kit | Cyber City Circuits
Tic Tac Toe Soldering Kit | Hackaday.io
Tic Tac Toe Soldering Kit from Jim Heaney on Tindie
Thank you very much for your enthusiastic reply. Although it is not quite the same form as what I want to do, I think the principle is the same, and I will study it carefully.

#### Young2

Joined Dec 7, 2020
93
Hi guys, I've recently made new progress, I've finished designing my GUI, the program compiles without problems, but there is a problem when uploading it to the board.
Code:
Arduino:1.8.12 (Windows 10), Development board: "Arduino Uno"

The project uses 6336 bytes, which occupies (19%) of the program storage space. The maximum is 32256 bytes. data section exceeds available space in board

Global variables used 3046 bytes, (148%) of dynamic memory, leaving -998 bytes for local variables. The maximum is 2048 bytes.
There is not enough memory; visit the following URL to follow the instructions to reduce memory usage.
http://www.arduino.cc/en/Guide/Troubleshooting#size
Error while compiling for development board Arduino Uno.

Turn on in File -> Preferences
"Show detailed output during compilation" option
This report will contain more information.
How do I solve this problem?

#### SamR

Joined Mar 19, 2019
5,019
This would be a good start...

#### click_here

Joined Sep 22, 2020
548
Just reading that warning, it's saying that there are too many Global variables used. It also says "dynamic" which could be allocated memory (using the "new" keyword, or malloc)

Does this make sense in the context of your program?