Real-World Interface (Antic Relay Controller)

Year
1989
Type
DIY project
Category
Relay / control interface
Manufacturer
Homebrew design by John Little (Antic)
Schematic: joystick plug pin 1 via 1K resistor to a 2N2222 transistor driving a relay coil, with 4.7K pull-up R3 and an indicator LED

Overview

"An Atari grows orchids in Texas." In Antic, February 1989 (Vol. 7 No. 10), John Little described how he made his Atari the controller for his Austin greenhouse. It turns misters on for a few seconds at a time, as often as he likes, within allowed hours, and leaves them on if the power fails. The project, Real-World Interface, is a simple joystick-port relay driver and a type-in BASIC program, INTRFACE.BAS, that works on any 8-bit Atari with disk or cassette. With a few line edits it becomes a general-purpose relay timer for anything you want to switch.

The circuit

Part Notes
PC board Radio Shack 276-168
R1, R2 1 kΩ
R3 4.7 kΩ pull-up (see below)
Q1 2N2222 NPN transistor
Relay Radio Shack 275-216
LED indicator
Cable 9-conductor ribbon, female DB-9

A joystick-port output pin drives the 2N2222 through a resistor, and the transistor switches the relay coil. The one subtlety is drive strength. On the 400 and 800, every PORTB pin (joystick ports 3 and 4) has a built-in 4.7 kΩ pull-up to +5 V. PORTA pins (ports 1 and 2) don't, and a "high" from PORTA alone is too weak to drive the circuit. So for XL/XE owners, who only have PORTA, Little added R3, a 4.7 kΩ pull-up, to the output line. On a 400/800 you can omit R3, use port 3, and set A800=1 in line 5 of the program.

Programming the port

PORTA is at 54016 ($D300). Joystick 1's four pins are bits 0–3 and joystick 2's are bits 4–7. Its control register PACTL is at 54018 ($D302). With bit 2 of PACTL cleared, a value POKEd into PORTA sets the data direction (1 = output). With bit 2 set, POKEs are output data. The program saves PACTL, subtracts 4, POKEs 255 into PORTA to make all eight pins outputs, then restores PACTL. After that, POKE 54016,1 puts +5 V on joystick-1 pin 1, and POKE 54016,0 drops it.

Watch the power-up state. Every pin is high when the Atari is switched on, so a connected relay pulls in immediately. When the program reconfigures the port, the pins drop low until you POKE a value. Plan your wiring with that in mind.

Fail-safe design

Little wired the relay "backwards" on purpose. The water valve, a battery-powered RainMatic timer valve with its programming module removed and a 6 V lantern battery fitted, is on while the relay is released. The program energises the relay to shut the water off. If the mains fails and the Atari stops, the relay drops out and the misters run, which helps keep the plants cool in the heat. When power returns, the port's power-on high state pulls the relay in and stops the water, before any program is running. A thermostat in series keeps the valve closed when the greenhouse is too cold, and closes it if the temperature drops while water is flowing.

The clock

Timing comes from a short machine-language VBI routine loaded into the upper half of page 6. It watches the OS jiffy counter RTCLOCK (location 20), keeps seconds and minutes in locations 19 and 18, and keeps hours in zero-page location 207, with 208–209 used as a jiffy counter. Little noticed that the NTSC jiffy is really 1/59.92334 s, not 1/60 s, so the clock gains about 4.6 jiffies a minute. His routine adds a correction jiffy every 783 jiffies. The 24-hour clock runs on even when the BASIC program stops.

Using the program

At start-up you set the clock, the earliest and latest start times (just RETURN for round-the-clock), and the on and off durations. RETURN at both of those gives manual on/off control instead. While it runs you can stop with the output on or off, or change parameters without resetting the clock. To make it a generic relay controller, swap the words WATER and RELAY and the senses of ON and OFF in the lines listed in the article, and swap lines 500 and 510.

Safety

Keep mains-voltage loads on the far side of a properly rated relay, and never connect anything but low-voltage logic to the joystick port. Little's valve ran on 6 V batteries, which is the safest pattern to copy.

Credits