Smart 4 in a Row Game
I am a leader of scouts in Moen Belgium and I wanted to make a game for my kids. After some brainstorming I had an idea; a game based on four in a row that gives small tasks to earn a disc of the four in a row. If you also want to give the members of your youth movement a fun afternoon, read on to find out how!
Supplies
In the file above you get a list with al the electronics I used for this project(everything with a link). You can also find a file with a list of the materials and tools I used.
Building the Circuit
The first thing you need to do before you start programming your electronics is building the circuit.
Let's look at each component separately.
- IR sensors: There are 7 of them. All 7 are connected to the Ground pin of the Raspberry Pi and the 5V pin. Then you have to connect each data pin to a GPIO pin of the Raspberry Pi. Which pin doesn't really matter, you can easily chance the pins in the code. Choose the left over pins.
- Arduino: You connect the Arduino to the Raspberry Pi with a level shifter. The low voltage(lv) side is for the Pi and the high voltage(hv) is for the Arduino. Lv is for the 3v3 of the Pi, the gnd next to lv is for the ground of the PI. Lv1 is for the tx of the Pi and lv2 for the rx. Hv is for the 5V of the Arduino and the gnd next to the hv is for the gnd of the Arduino. Hv1 is for the rx of the Arduino and hv2 for the tx. They need to be crossed.
- RFID: The RFID works on 3v3, connect the vcc pin to the 3v3 from the arduino. The rst pin to D9, gnd to the ground, miso to D10, Mosi to D11, SCK to D12 and SDA to D13.
- Buzzer: There are 3 buzzers in this project, a buzzer is easy to connect. One side is for the gnd and the other side is for a GPIO pin. You can choose wich GPIO pins you use, just chance them easily in the code.
- 8x8 led matrix: There are 2 led matrixen, they use both a MAX7219 chip. Connect the both VCC to the 5v of the PI, the gnd to the gnd , DIN to the MOSI, CLK to the clk and one cs to cs0 and the other to cs1.
- One-Wire Temperature Sensor: This is a little bit of a difficult one. This one needs a 10K resistor that you put between the data pin and the vcc. Then you can connect the data pin to GPIO, the vcc to 5v and the gnd to the gnd of the Pi.
- LCD: I used a 4 bit connection for the LCD because I don't have enough GPIO pins. I think it's clear enough on the picture how to connect it. The used resistor is a 10k one. It's al powered with 5V.
Create a Place to Put Away the Circuit
In this step I will explain how I put everything away.
I had a big 4 in a row to use but you can also make one yourself.
- I disassembled the 4 in a row frame
- With the multitool I sawed out the pieces that were in the way. Now you can see there is room to put in the ir sensors.
- I made my own cables with the connectors en cables in the materials and tools.pdf file.
- I connect the cables with the ir sensors and put tham in the 4 in a row.
- With a sort of gum for sticking pictures to the wall i made sure they wont move.
- I drilled a hole in the legs of the 4 in a row so I can lead the cables true it.
- Now you have to assemble the 4 in a row and done with that.
For the rest of the components you can make whatever you want. I made a stond where I can put my laptop on but this is not necessary. Let your imagination run wild.
Setup the Raspberry Pi
First of al download the image from the link.
Once it is downloaded you can write your sd-card with a program like balenaEtcher or win32 disk imager.
Now we can start with changing the image so we can use it.
- Put the sd-card in the Raspberry Pi and connect the Pi to power.
- Connect the Pi to your pc with a netwerk cable. Make an SSH-connection to 192.168.168.169 with Putty or your basic cmd interface. The user is student and the password is W8w00rd.
- Now your logged in go to 'sudo raspi-config' choose (6)Advanced > (1)Expand Filestystem and reboot the Pi.
- Make sure your Pi has wifi acces
- get administrator rights with 'sudo -i'
- wpa_passphrase 'your wifi name' 'wifi passowrd' >> /etc/wpa_supplicant/wpa_supplicant.conf
- wpa_cli -i wlan0
- wget www.google.com (to test)
- Make sure you have all the latest updates with:
- apt update (look if there are updates available)
- apt upgrade
- Now we gonna configure MySQLWorkbench
- Start MySQLWorkbench
- Make a new connection with Connection Method: Stadarc TCP/IP over SSH
- ssh hostname: 192.168.168.169
- ssh username: student
- ssh password: W8w00rd (save if possible)
- MySQL hostname: 127.0.0.1
- MySQL server port: 3306
- Username: student
- Password: W8w00rd
- Visual Studio Configuration
- Open visual studio code
- Install the Remote-SSH extension
- Press F1 and search SSH, choose for 'Remote-SSH: Add New SSH Host'
- ssh student@192.168.168.169
- Choose where to save the file
- press F1 again and search SSH. choose for 'Remote-SSH: Connect To Host'
- Choose the option 192.168.168.169
- There will be a new window and you need to give the password (W8w00rd)
- Visual Studio will open your connection
- Clone the GitHub repo
- Press the Source Control logo and choose for Clone Repository
- Paste the link from the repo
- place in the '/home/student/' folder
- Make sure Apache shows your front end
- sudo -i
- nano /etc/apache2/sites-available/000-default.conf
- change DocumentRoot /var/www/html or DocumentRoot /home/student/.../front-end to DocumentRoot /home/student/2021-2022-projectone-ChysAster/front-end
- save with Ctl + x , Y and enter
- restrat apache with: service apache2 restart
- Now the rights one the root folder have to be right
- nano /etc/apache2/apache2.conf , go down to <Directory/> Optinas FollowSymLinks ... </Directory>
- chance to <Directory/> Options Indexes FollowSymLinks Includes ExecCGI (enter) AllowOverride All (enter) Require all granted (enter) </Directory>
- save with ctrl + x, y and enter
- Restart apache with 'service apache2 restart'
Now your Rasperry Pi is ready to use!
The Code
The schema above shows simply how the code works.
Downloads
Setup Arduino Code
Start your Arduino IDE and paste the code below:
#include <AddicoreRFID.h> #include <SPI.h> #define uchar unsigned char #define uint unsigned int uchar fifobytes; uchar fifoValue; AddicoreRFID myRFID; const int chipSelectPin = 10; const int NRSTPD = 5; void setup() { Serial.begin(9600); SPI.begin(); pinMode(chipSelectPin,OUTPUT); digitalWrite(chipSelectPin, LOW); pinMode(NRSTPD,OUTPUT); digitalWrite(NRSTPD, HIGH); myRFID.AddicoreRFID_Init(); } void loop() { // Serial.println("Hello from Arduino!"); // delay(1000); uchar i, tmp, checksum1; uchar status; uchar str[MAX_LEN]; uchar RC_size; uchar blockAddr; String mynum = ""; str[1] = 0x4400; status = myRFID.AddicoreRFID_Request(PICC_REQIDL, str); if (status == MI_OK) { // Serial.println("RFID tag detected"); } status = myRFID.AddicoreRFID_Anticoll(str); if (status == MI_OK) { // Serial.print("Nummer:\t"); // Serial.println(str[0]); if(str[0] == 188) { Serial.print(str[0]); } else if(str[0] == 129) { Serial.print(str[0]); } Serial.println(); delay(1000); } myRFID.AddicoreRFID_Halt(); }
Now just push the code to the Arduino and you are done. Make sure the tx and rx pins are not connected
Database
For the Database we use MySQLWorkbench, we already did this setup in step 3.
In the photo above you can see the schema of the needed database. If you have questions about this just leave a comment and I will help you.
Enjoy This Game!
Now we have done the complete setup. All you have to do is start the app.py script in the code and browse to the ip-adress given on the LCD and your done.You can see there are different other tabs on the site, I think the nicest thing to do is to find them out yourself. I hope you guys enjoy this!