Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

A Turing machine set up according to user instructions that uses the Raspberry Pi camera to interact with a physical tape

License

Notifications You must be signed in to change notification settings

MaxDobbs32/Turing-Machine-Raspberry-Pi

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Building a Turing Machine with Raspberry Pi

I'm made a Turing Machine, and here's the code to run it! A Turing Machine is an early model of a computer developed by Alan Turing, where a computer has access to an infinite tape (array) of information to operate on. Inside the computer are predefined states that act like code. Based on reading, say, 1 (a filled square) or 0 (an empty square), a state decides whether to change the bit, whether to move left/right, and which state to switch to next.

My project uses a Raspberry Pi to simulate a Turing Machine, with a camera to read square bit values from the tape. The physical tape is used as input. Because of the difficulty of actually writing to a real piece of tape, the computer first stores the values into a large array of bits internally. The Turing Machine code operates on this array, and then a portion of the resulting tape is printed in the console.

How to set it up

  1. Make sure you have a working Raspberry Pi with the camera plugged in
  2. Clone this repository or download and unzip it.
  3. Install g++ if you do not already have it.
  4. In your terminal application, run the following command within the repository: g++ TuringMachine.cpp -o TuringMachine.o
  5. Find or make a thin, long piece of paper to act as the tape.
  6. Draw squares along the tape, empty white squares for 0 and filled black squares for 1. At the end of the tape, draw a green square. This tells the program to stop reading.
  7. Ensure in advance that the camera can see the colors on the tape as it passes by.
    • I built a lego arch that locked the camera into place facing down. I pulled the tape undeneath the arch, so that the camera could take pictures of bits and interpret their values. You might also be able to simply hold the camera in place.

How to run Turing machine

  1. In your terminal application, run the following command: python main.py
  2. First, the program will ask you to input states for the Turing Machine. You can name the states and decide how they respond to reading a 1 or a 0. You can also skip this process to use predefined states, as recorded in states.txt
  3. Next, the program will read bits on the tape. Drag the tape by the camera so that it captures individual squares or bits along it. The camera will continue reading squares until it reads the green square, so make sure to conclude with the color green.
  4. Wait for an output. The Turing Machine code is initialized with the states you chose and the array of bits equivalent to those found on the physical tape. The Turing Machine will edit bits on the tape according to the states, and it will either halt or continue for long enough that the program stops the process (e.g. 100,000,000 operations).
  5. The program concludes by outputting a portion of the resulting array of bits (currently set to 60 bits about the center). Congratulations, you successfully ran a Turing Machine.

Citations

For setting up code to interact with the camera:

For analysing pixels in images:

About

A Turing machine set up according to user instructions that uses the Raspberry Pi camera to interact with a physical tape

Resources

License

Stars

Watchers

Forks

Morty Proxy This is a proxified and sanitized view of the page, visit original site.