Skip to content

10. Machine Design

Group Project: Pinball Machine

I was paired up with three students from Charlotte Latin: Drew Griggs, Miller Workman, and Jack Hollingsworth. This group decided to build a pinball machine for our group project and I hopped on board to offer help. After a quick group huddle over Zoom, the students decided to have me focus on the software development for the project. Given that I am collaborating remotely, I thought this would be appropriate and a reasonable contribution for the group project. The following documentation will lay out my adventures in Raspberry Pi and setting up a Pinball software user interface. The documentation for our final group project is located here, on the Charlotte Latin group page.

Research & Support

Raspberry Pi

I began by doing a little bit of research on GUI and application interfaces. Admittedly, I have done very little software development and have done more directly at the electronics and microcontroller level of programming. However, I am using this as an opportunity to learn a new skill. I know that Applications is a topic that is coming up so hopefully this will give me a bit of a head start.

Setup

I had an extra Raspberry Pi 3+ in the lab, and so I used this to setup a new install Raspberry Pi OS on a microSD card using balenaEtcher to flash the image onto the card. Downloading and flashing the new operating system takes about 15-20 minutes depending on your internet connection. Mine is slow, so it took a solid 30 minutes. I went with the Desktop version as we will be using graphics and I will likely need to get directly on to the machine to set it up for the pinball interface.

Development Environment

I installed []Adafruit Web IDE which is a browser-based IDE that can connect to a Pi on your local network and develop code remotely. This was convenient, as I could have access to all my customary programs (macOS) and not have to develop directly on the Pi.

In the end, I did not end up using this as much. There were some issues connecting and compiling code. I ended up just plugging in directly and programming with the built in development tools on the Pi.

Python

It seems most Raspberry projects use Python as the language of choice. Not wanting to rock the boat too much, I decided to explore Python and use that to create the pinball’s interface. There are number of libraries that may assist in the development of this project. Part of what makes Python so great is the community and number of libraries and projects to build off of.

Adafruit’s Circuit Python Guide was helpful in getting the python libraries installed for working with GPIO pins and electronics that interface with the Pi. The pip installable library is called, Blinka.

Here are the current list of libraries I am utilizing: - blinka (circuit python) - pygame - tkinter (gui package) - qtpy6 (gui package)

Pinball Graphical User Interface (GUI)

GUI: Version One

# Fab Academy Group Project

from tkinter import *
from tkinter import ttk  # Normal Tkinter.* widgets are not themed!
from ttkthemes import ThemedTk
from PIL import Image, ImageTk

root = ThemedTk(theme='Adapta')
root.geometry('500x350')
root.title('Pinball Machine')

# Define an action or behavior for the interface
def myClick():
    clickLabel = Label(root, text="Begin!")

# Creates a label with some text and places it somewhere in the grid
myLabel1 = Label(root, text="Hello, Pinball Machine!").grid(row=0,column=0)
myLabel2 = Label(root, text="SCORE:  ").grid(row=1,column=0)

# Buttons
startButton = Button(root, text="START", padx=50, pady=50, command=myClick()).grid(row=2,column=0)

root.mainloop()

GUI: Version Two

After doing a bit more research, I learned about some different GUI libraries that abstract Tkinter a bit and make it easy to get simple interfaces developed faster. I decided going with guizero to develop the second version of the interface. Below is the final code that I developed and shared with the Charlotte Latin group of students.

from guizero import App, Text, PushButton, Slider
import serial

ser = serial.Serial('/dev/ttyACM0',9600)
scoreArduino = 1 # set to 1 to ensure Arduino is updating score variable

def start_game():
    startGameMsg.value = "Begin!"

def update_score():
    scoreGame.value = "Score: " + str(int(ser.readline()))

# create root program interface
app = App(title="Fab Academy Pinball Machine")

intro = Text(app, text="Welcome to our Fab(ulous) Pinball Machine!")
startGame = PushButton(app, text="START", command=start_game)
startGameMsg = Text(app)
scoreGame = Text(app)
scoreGame.repeat(100, update_score)
app.display()

Pinball Control Software

My group developed most (nearly all) of the Arduino code, however, I was tasked with interfacing the Arduino and Raspberry Pi to create the interface. This would allow the Arduino to directly control the actuators (solenoids) and sensors (capactive) to detect points and keep track of score.

Serial.println(score); // send score data to pi 

The above code is how the Arduino can use the Serial interface to communicate to the Raspiberry Pi via USB. The Raspiberry listens on the respective Serial port for a message. Once it detects that message, it displays the score on the interface.

Files


Last update: October 18, 2021