The circuit uses a MAX232 for level shifting, from the 0-5V from the
ATTiny2313 to the -10 to +10V of the PC, and also helps
isolate the ATTiny2313 from any problems which may occur with a faulty
RS-232 cable. Two gate drivers for MOSFETs are used to control the
motors. Otherwise the circuit is fairly straight-forward, consisting of
amplifiers for driving the laser and LED, and a regulator for the
chips. The firmware for the ATTiny2313 was written in
MikroC
Pro, since I had used MikroBasic
for PICs previously. I used the built in UART library, which made
programing the µC a one-hour job, including troubleshooting.
The entire code is also very short, and easy to understand. I decided
to use a basic control protocol, in which each bit corresponds to an
output. Since only 6 outputs are used this works well, and the final
two bits can be used to detect bytes which are obviously errorous.
In
addition to programming the ATTiny2313, I also had to make a windows
program to ease control of the turret. This was the real programming
exercise in this project, as I had never programmed for windows before.
I started out using Visual Studio C++, thinking it would be similar to
C. How wrong I was! I've never had a tougher time programming, and just
as I was about to give up on this project, and tried Visual Basic
instead. Talk about a difference! I don't know if it's a newb thing,
but I found Basic and the complier much more intuitive, and the code
examples would actually work. At any rate the small program I had made
in C++ which didn't work, was quickly ported to basic where it worked
almost instantly. After much trail and error, learning,
and revisions I
created a rather simple program which makes controlling the turret a
breeze. A wide range of COM ports can be selected, though the baud-rate
and other settings are preset- why change them? The ATTiny2313 will
send back the received command, and it is veiwable in the turret
control software as well. The directional buttons for the motors can
also be controlled via standard gamer layout on the keyboard, or W for
up, S for down, and A or D for left or right. I also created a program
for port relaying. It will allow you to select two COM ports that can
be connected together virtually by the computer. This has allowed me to
control the turret from my cell-phone, over bluetooth. :-O I'm still
working out some bugs in the bluetooth app, so it's not released yet,
but the port relay software is. I'm not sure if the program requires
that you download some .NET package, or if it's stand-alone. I've
zipped the
sources
files so making your own serial applications is easier. All of the
files needed for this project have been zipped
here.
That includes schematic, firmware and PC software.
In the end the motors weren't slow enough and the turret is hard to
steer with any precision. It does prove that the concept works however,
and by using either stepper motors or servos it can be made much more
fun to steer. I plan on upgrading this turret some time in the future.