Introduction
One
of the chief advantages of the PICAXE system is the ease and low cost
of getting started. The chips themselves are inexpensive, the
programming software is free, and no hardware programmer is needed. The
hardware connection from the PICAXE to a personal computer consists of a
cable (AXE026) that connects to a serial port on the PC, or a different cable (AXE027)
that connects to a USB port. This article provides details on those
connections, as well as the information needed to assemble a serial
cable at little cost.
PICAXE Serial Data Communications
In
order to communicate with a PICAXE microcontroller, a personal computer
is most often used. Communications to the PICAXE are primarily for the
purpose of programming it, and communications from the PICAXE may be
displayed on the computer monitor for debugging the program, or simply
for seeing the results of the program instructions. Only three wires are
required between the PICAXE and the personal computer: one carries
information from the PICAXE to the computer, one carries information
from the personal computer to the PICAXE, and the third wire connects
the signal ground on the computer to the ground on the PICAXE µC.
Communications in both directions are in a serial format, i.e., logic 1s
and 0s are sent one after the other over each wire in a specific order
to represent every letter, numeral, and symbol in the message.
On the personal computer end, the serial data format is called RS232,
which includes a total of nine (or ten, but that's another story)
leads, each with a different designation. However, only two of the leads
are used for actual data communications: the Receive Data lead
(abbreviated RxD,) and the Transmit Data lead (abbreviated TxD.)
Likewise on the PICAXE end, only two leads are used for data
communications: the Serial Out lead (abbreviated SO,) and the Serial In
lead (abbreviated SI.) When the signal ground in the PC and 0V (ground)
in the PICAXE are connected together, and SO in the PICAXE is connected
to RxD in the PC, the PICAXE can "talk" to the PC. Likewise, when the
signal ground in the PC and 0V (ground) in the PICAXE are connected
together, and TxD in the PC is connected to SI in the PICAXE, the PC can
"talk" to the PICAXE. Thus, three wires between the PC and the PICAXE
enable two way communications.
On the personal computer end, the serial data format is called RS232, which includes a total of nine (or ten, but that's another story) leads, each with a different designation. However, only two of the leads are used for actual data communications: the Receive Data lead (abbreviated RxD,) and the Transmit Data lead (abbreviated TxD.) Likewise on the PICAXE end, only two leads are used for data communications: the Serial Out lead (abbreviated SO,) and the Serial In lead (abbreviated SI.) When the signal ground in the PC and 0V (ground) in the PICAXE are connected together, and SO in the PICAXE is connected to RxD in the PC, the PICAXE can "talk" to the PC. Likewise, when the signal ground in the PC and 0V (ground) in the PICAXE are connected together, and TxD in the PC is connected to SI in the PICAXE, the PC can "talk" to the PICAXE. Thus, three wires between the PC and the PICAXE enable two way communications.
Connecting to a PC with an RS232 (Serial) Port via a DB9 Connector
In
the early days of personal computing, almost every PC had an RS232
serial port. Today, very few laptops and only some desktop machines have
one. If your PC has an RS232 port available, that's the least expensive
route to PICAXE connectivity. And the easiest way to make that
connection is with an AXE026 cable available for $10 or less. However,
it's also possible to make your own cable, which can not only save a
little money, but also allows you to learn something about RS232 wiring.
An RS232 connection on a PC usually uses a specific type of connector
called a DB9. The "D" refers to the shape of the housing, and the "9"
refers to the number of pins in the connector. (If you are interested,
you can research the origin of the "B" on your own, but it's not vital
information at this time.) There are two "genders" of DB9 connectors:
the DB9F (female) connectors (shown below left) have nine holes to
receive nine pins, and the DB9M (male) connectors (shown below right)
have nine pins. Look for a DB9M on your PC; if you find one, it's
probably an RS232 port, and should be labeled as RS232, Serial, or Com.
Without an RS232 port, you will need to skip to Connecting to a PC with a
USB Port later in this article.
Assuming you have an RS232 port available on the PC, you need to
locate the three leads to connect to the PICAXE. Each of the DB9 pins
has a specific number (as shown in the photos above) and carries a
specific signal; RxD is on pin 2, TxD is on pin 3, and Signal Ground is
on pin 5. Therefore, what is required is to connect the DB9 pins to the
PICAXE pins according to the table below.
RS232 Signal Designation
DB9 Pin Number
PICAXE Pin Designation
PICAXE Leg Number
Receive Data (RxD)
2
Serial Out
Depends on the PICAXE model.
Transmit Data (TxD)
3
Serial In
Signal Ground
5
0V (Ground)
In order to plug into the DB9M (male) connector on the PC, and extend
the three leads to your PICAXE, you will need a DB9F (female) connector
that has a cable attached. Such cables are often available in thrift
stores or on the web for very little money.
Most often, identification of the three wires in the cable that you
need requires that you check the continuity of the wires in the cable.
That is usually done with a Digital Multimeter (DMM) by setting the
meter in the resistance measurement mode, connecting one of the meter
probes to pins 2, 3, and 5 (in turn) in the DB9F, and then checking the
resistance from each pin to each wire. When a very low resistance (less
than 5 ohms) is detected, note which wire (by color) and which pin (by
number) to which your DMM probes are connected. The three wires that
show low resistance to pins 2, 3, and 5 are the only wires in the cable
that you will need. The others should be arranged so that they will not
short together and are out of the way.
An alternative method is to start with a bare DB9F, and connect a
different color wire to each of the pins numbered 2, 3, and 5. The three
wires should be insulated stranded wires in the AWG22 to AWG30 range,
and should be twisted together to form a cable.
An RS232 connection on a PC usually uses a specific type of connector called a DB9. The "D" refers to the shape of the housing, and the "9" refers to the number of pins in the connector. (If you are interested, you can research the origin of the "B" on your own, but it's not vital information at this time.) There are two "genders" of DB9 connectors: the DB9F (female) connectors (shown below left) have nine holes to receive nine pins, and the DB9M (male) connectors (shown below right) have nine pins. Look for a DB9M on your PC; if you find one, it's probably an RS232 port, and should be labeled as RS232, Serial, or Com. Without an RS232 port, you will need to skip to Connecting to a PC with a USB Port later in this article.
Assuming you have an RS232 port available on the PC, you need to locate the three leads to connect to the PICAXE. Each of the DB9 pins has a specific number (as shown in the photos above) and carries a specific signal; RxD is on pin 2, TxD is on pin 3, and Signal Ground is on pin 5. Therefore, what is required is to connect the DB9 pins to the PICAXE pins according to the table below.
RS232 Signal Designation | DB9 Pin Number | PICAXE Pin Designation | PICAXE Leg Number |
---|---|---|---|
Receive Data (RxD) | 2 | Serial Out | Depends on the PICAXE model. |
Transmit Data (TxD) | 3 | Serial In | |
Signal Ground | 5 | 0V (Ground) |
In order to plug into the DB9M (male) connector on the PC, and extend the three leads to your PICAXE, you will need a DB9F (female) connector that has a cable attached. Such cables are often available in thrift stores or on the web for very little money.
Most often, identification of the three wires in the cable that you need requires that you check the continuity of the wires in the cable. That is usually done with a Digital Multimeter (DMM) by setting the meter in the resistance measurement mode, connecting one of the meter probes to pins 2, 3, and 5 (in turn) in the DB9F, and then checking the resistance from each pin to each wire. When a very low resistance (less than 5 ohms) is detected, note which wire (by color) and which pin (by number) to which your DMM probes are connected. The three wires that show low resistance to pins 2, 3, and 5 are the only wires in the cable that you will need. The others should be arranged so that they will not short together and are out of the way.
An alternative method is to start with a bare DB9F, and connect a different color wire to each of the pins numbered 2, 3, and 5. The three wires should be insulated stranded wires in the AWG22 to AWG30 range, and should be twisted together to form a cable.
Connecting to the PICAXE
Once
you have a cable with a DB9F on one end, and the three wires that are
to go to the PICAXE identified, those wires must be prepped for whatever
method you plan to use to connect the cable to the PICAXE. The most
common way is via a 3.5mm stereo plug that mates with a 3.5mm stereo
jack. Such a plug is shown in the photo below left, and a suitable jack
is shown below right. Both must be wired as shown in the schematic
diagram below.
If
you are on a really tight budget, you can omit the 3.5mm plug and jack,
and just plug the cable's three wires directly into the solderless
breadboard. To do so will probably require that you solder some AWG22
solid wire extensions onto the cable wires similar to those shown in the
photo below.
If you are on a really tight budget, you can omit the 3.5mm plug and jack, and just plug the cable's three wires directly into the solderless breadboard. To do so will probably require that you solder some AWG22 solid wire extensions onto the cable wires similar to those shown in the photo below.
Connecting to a PC with a USB Port via AXE027 Cable
The
easiest way to connect your PICAXE to a PC is via an AXE027 cable,
which is available for about $20. The AXE027 cable is approximately 70
inches long, and has a standard USB Type A male connector on one end,
and a 3.5mm 3-conductor plug on the other. It is intended to be plugged
into a USB Type A female connector on a personal computer, and into a
3.5mm 3-conductor jack in the PICAXE circuit. However, there is more to
the AXE027 than meets the eye. Inside the plastic housing covering the
USB connector is a USB-to-serial circuit, as shown below right.
This circuit performs the task of converting the USB data signals (D+
and D-) to a serial format that correctly interfaces with the Serial
Out and Serial In leads of the PICAXE µC. A proprietary software driver
is required to use the AXE027, and is available here,
along with full installation and setup instructions. The photo below
shows how the AXE027 can be connected to a PICAXE, and the photos and
schematic drawing provided in the Connecting to the PICAXE section of
this article supply additional details.
"What
about making a substitute for the AXE027 using one of those USB to
serial converter boards I have been reading about?" you might ask. It is
possible, but it's not as easy as it might seem. The PICAXE signalling
scheme is inverted from that used on most standard USB to serial
converter circuits, and without that inversion, the PICAXE simply won't
communicate with a PC. Designing and building a pair of inverter
circuits is better left for another time.
After all, you have programming to do!
This circuit performs the task of converting the USB data signals (D+ and D-) to a serial format that correctly interfaces with the Serial Out and Serial In leads of the PICAXE µC. A proprietary software driver is required to use the AXE027, and is available here, along with full installation and setup instructions. The photo below shows how the AXE027 can be connected to a PICAXE, and the photos and schematic drawing provided in the Connecting to the PICAXE section of this article supply additional details.
"What about making a substitute for the AXE027 using one of those USB to serial converter boards I have been reading about?" you might ask. It is possible, but it's not as easy as it might seem. The PICAXE signalling scheme is inverted from that used on most standard USB to serial converter circuits, and without that inversion, the PICAXE simply won't communicate with a PC. Designing and building a pair of inverter circuits is better left for another time.
After all, you have programming to do!
No comments:
Post a Comment