RASPBERRY PI BATTLESHIPS
After I built my Giant 10 x 10 LED board, I thought what do I do with it now? Simple, build a GIANT game of battleships. I had coded one before on the SenseHAT so I knew that it was possible. However, there were other, better versions out their which people had made I found a program by Tim Mulford (28/8/2015) and set about adapting it for the LED screen. The game is controlled by dialling in the x and y coordinates via the dial on an old Swiss Bakelite phone from the 1960s. It houses a Raspberry Pi which responds to the 'dialling' and then sends data to the board triggering the responses and game play up dates.
One of the main challenges was finding a schematic for the telephone. Each model and brand of phone has a different dial wire configuration. There are some excellent sites available that list the schematics, but I was not having much luck. Another issue was that the dial was not turning at a constant speed. I thought that it was broken but some GT spray soon fixed it. On removing the phone cover I found the model number and he manufacturer on the inside and a quick Goggle search led me to a really interesting Swiss website about the company. It turns out that they supplied 'listening devices' and 'phone surveillance systems' during the second world war. I was a little concerned that I had acquired the phone of a prominent world leader! But, still no schematic. In the end I took a punt and emailed the owner of one of the websites and 'Bob' (not a very spy sounding name) replied with his take on the wiring layout. Guess what, his suggestion worked, but the program kept reading the same number no matter which number you dialled. A little bit of trial and error with various GPIO pins and wires and the dial was sorted. If you are interested in how to hook up a phone for yourself then check out the video below on how to get started.
ISSUES, FAILS and CHALLENGES:
Sockets; Python has a built in module called sockets which enables you to send data to and from different Python programs that are running on separate machines. In my project, between the LED board and the phone. I got a version of this working with a test program between the phone and LED board but I needed two way communication, the LED board needed to feedback a Hit, Miss and so on to the Phone. A big shout out to Cleo_QC who looked at my code and suggested using a newer version of Sockets, she even created a working example, thank you so much. Cleo_QC also helped with socket timings as one of the key issues was that the socket was timing out before the data was sent or received, which meant that the game could not respond in time or respond correctly.
Responding to the outcomes: This feature uses a basic IF ELIF ELSE statement to respond to an incoming message from the LED board. Key words or phrases are sent as data and the Raspberry Pi in the Phone picks these up and then responds. An example code is shown below:
# THIS FUNCTION HANDLES THE INCOMING DATA AND THEN RESPONDS WITH THE AUDIO FILE
sock.settimeout(4) # Adjust to meet the network lag!
data = sock.recv(1024)
print ("received message:", data)
voice = (data.decode())
if voice == "MISS":
print ("audio You missed") #Replace with sound
ammo = ammo - 1
ammoupdate = (ammo, " Torpedo Left")
#print ("Your ammo is now ", ammo)
# ASK PLAYER TO DIAL
elif voice == "HIT":
print ("audio You HIT") #Replace with sound
Sound: Sound and feedback is an important feature of the game and I wanted to use the speaker in the hand set so that the player could hold the phone to their ear. This was achieved by soldering (very carefully) the two wires from the speaker to the back of the Raspberry Pi. This means that the sound plays through the speaker whilst still enabling the audio jack to be used with an external speaker so that everybody can hear what is happening.
Enabling VNC: Eventually I completed the internal hardware setup and the code was working, so time to put it all back together. I screwed the last screw in and was happy, then I realised, I had not enabled VNC or SSH on the Pi inside the phone so, I had no way to update it. Finds the screwdriver, unscrews everything.....
Cleaning the Phone: To clean the phone and remove the discolouration I used a brush and wiped the phone case down with hair dye. I then placed the phone into a clear plastic bag and left it in the sun for the day. After a quick wash under warm water the phone looked restored.
Starting the Crontab: Use of the crontab caused me several headaches and frustrations, but, it was user error. The NeoPixels require the Python code to be run in Sudo. Guess what? The crontab I entered was
@reboot pythoon battleships.py
No sudo used, no NeoPixels working!
Drilling the Bakelite: Make sure you use a mask! When I drilled into the phone it created a lovely yellow colour. I was intrigued until I want online and read that old Bakelite was made with arsenic and asbestos and should not be cracked!