Task: Use an Arduino to Read Digital Output from an Atari 8-Bit Computer Joystick Port
Needed: Arduino UNO, Arduino IDE software, Atari joystick, Jumper wires, Breadboard, 10k ohm resistor, Atari XL computer
Time: about 1-2 hours with all components ready
In a previous post, I explain how to connect an Arduino microcontroller to an Atari 8-bit computer through the SIO port. Additionally, I demonstrate how to use this setup to control a servo motor. Here, I demonstrate how get an Arduino or other microcontroller to communicate with the Atari 8-bit computer through the joystick port. An advantage of using the joystick port is that it is simpler than SIO and there are multiple ports to work with. Note that I used an Atari 800xl for this project. I could not get it to work with two different Atari 800s.
The joystick port can be used for both input and output. When using a joystick to play a game you are using port for input. Here, a 5V DC electrical current is passed from the Atari through the port to the joystick providing a current with which to measure the direction the stick is being pushed and whether the fire button is pressed. These signals are then read by the Atari Peripheral Interface Adapter (PIA) and saved in memory.
By default, the Atari PIA chip is set up to read input data from the joystick ports. The first step in getting the PIA to write data out through the joystick port is to tell it to do so through several POKEs to the port A control register (location 54018 or $D303) and to port A itself (location 54016 or $D300). We first POKE the port control register with 56 (POKE 54018,56). This lets it know we are going to next indicate whether we want port A to be used for input or output. We next POKE a 255 to the port A register letting the Atari know we want the port to be used for output (POKE 54016,255). We would POKE a 0 here for input. Next, we let the port control register know we are done with a POKE of 60 (POKE 54018,60). These register locations can be read about in the Atari Memory Map book. Here is an article by Marshall Dubin from The Creative Atari that explain how this work in some detail.
We are now ready to POKE some data out through the port to be read by the Arduino. We will only use pins 1-4 shown above for this purpose because there are the only pins in the joystick port controlled by the PIA chip. These correspond to wire colors of white (pin 1), blue (pin 2), green (pin 3), and brown (pin 4). We will also use the ground wire colored black (pin 8) for this project. Note that each pin can only output a binary or digital signal of 1s and 0s. The binary values of pins 1-4 for joystick port 1 and pins 1-4 of joystick port 2 are controlled by a single 8-bit byte. Thus, a byte with binary values 10000000 (decimal = 1) would send a single 1 bit through pin 1 of joystick port 1. A value of 11111111 (decimal = 255) would single a single bit through all eight pins across the two joystick ports. Note that the ports are by default set to 255 and thus are sending 1s through all pins at powerup.
The goal of this project is to program the Atari to send 1s and 0s through pin 1 of joystick port 1. These bits will be read by the Arduino through its digital input port and then displayed in the monitor of the Arduino IDE on a PC. These signals could be read by the Arduino and used to control a motor or some other device as we did in the servo motor project. This would make it possible to write an Atari program to control and Arduino.
Second, download and install the Arduino IDE (shown below). This is the software we will use to write programs for the Arduino. The programming language is similar to C and the IDE will compile and run the code on the Arduino. Try this simple program for blinking the LED light that comes on the Arduino board. Simply copy and paste the code into the IDE and hit the arrow or compile button. This will compile and run the code on the Arduino. Make sure the Arduino is plugged in via the USB cable and select it from menu in the header to the right of the arrow button. You should see the LED on the Arduino blink.
You are now ready to load the Arduino code we will use to read digital pin 7 that will be connected to the Atari joystick pin 1 (white wire) for reading the single bit of data (1 or 0). You can open the code in this text file and copy it to the Arduino IDE. When executed at the end of the project (keep reading below), this code will print to the Serial Monitor window of the IDE (see image below) “Data = 0” when pin 1 of Atari joystick port 1 is sending a 0 bit and “Data = 1” when it is sending a 1 bit.
Third, you will need an Atari joystick cable to detach from the joystick and some jumper wires. I bought this kit that included jumper wires along with some other useful components. Note that you could attach the female end of a jumper wire directly to the joystick port pin if you don’t want to sacrifice a joystick.
Fourth, prepare the joystick cable by using some wire cutters to remove the cable from the joystick. Remove the rubber cover on about 2-3 inches to expose the colored wires. Remove the rubber cover of the white wire to expose the copper. This is the one we will use to connect to the Arduino as it is used by joystick port 1 and pin 1. See image above for wire colors.
Fifth, connect a jumper wire (I used a white one) to the white joystick wire. I just wrapped the wire tightly around the lead on the jumper wire. You could solder it for a more permanent connection. Also connect a jumper wire (I used black) to the black ground wire from the joystick cable. As shown below, I then connected the white jumper to a breadboard (row 50, column a below). I then connect another white jumper from row 50 and column e of the breadboard to digital input 7 on the Arduino (bottom right). Next, connect the black ground jumper to the breadboard (row 40, column a below). Connect another black jumper from row 40 and column e of the breadboard to the ground connector on the Arduino. It is highly recommended that you add a pull-down resistor (I used a 10k ohm) connecting the data input line (row 50) with the ground line (row 40). This helps stabilize the signal from the Atari to the Arduino. Note that the breadboard and jumper wires are used so we don’t need to solder anything.
Sixth, it is time to program the Atari to send data out through the joystick port. The following BASIC program will turn on the port for output and send 0 bits to the Arduino via POKE 54016,0 when run. Once you have confirmed you see the 0s coming through on the Arduino IDE monitor you can then change the bits to 1s by changing line 130 to POKE 54016,255.
100 POKE 54018,56
110 POKE 54016,255
120 POKE 54018,60
130 POKE 54016,0
200 GOTO 130
Finally, it is time to try it out. Plug in the Arduino board to your PC using the USB cable and compile the code for reading the digital 7 input on the board. Make sure the Serial Monitor is on. This can be accessed in the upper right of the IDE. Power up your Atari into BASIC and make sure the joystick cable is plugged into port 1. The monitor should be printing “Data = 1” as this is the default state of the Atari on powerup. Run the BASIC program from above with line 130 reading POKE 54016,0. The IDE should now be printing Data = 0. Once this is confirmed you can change like 130 to POKE 54016,255 to change it back to 1s. That is it! You now have an Arduino reading the output of the Atari through the joystick port!
This project worked well on my Atari 800XL. However, I could not get it to work on two different Atari 800s. I am not sure why.
For further reading I recommend the book Electronic Computer Projects for Commodore and Atari Personal Computers by Soori Sivakumaran (1986). Chapter 12 has some interesting ideas and some code. Chapter 13 talks about robotics. Note, this author used a POKE 54018,48 instead of 56 and POKE 54018,52 instead of 60 to talk to the port controller. I confirmed these values turn on the same required bits and work fine.
Also note this interesting Compute! article from 1981 using the joystick port to control a printer. Pretty cool.