Tutorial.ArduinoSoftwareRS232 History

Hide minor edits - Show changes to output

September 05, 2006, at 07:56 PM by Heather Dewey-Hagborg -
Changed lines 144-145 from:
''code and tutorial by Heather Dewey-Hagborg''
''Photos by Thomas Dexter''
to:
''code and tutorial by Heather Dewey-Hagborg, photos by Thomas Dexter''
September 05, 2006, at 07:56 PM by Heather Dewey-Hagborg -
Added line 144:
''code and tutorial by Heather Dewey-Hagborg''
August 29, 2006, at 07:07 PM by Heather Dewey-Hagborg -
Changed lines 3-4 from:
In this tutorial you will learn how to communicate with a computer using a MAX3323 single channel RS-232 driver/receiver and a software serial connection on the Arduino. A general purpose software serial tutorial can be found [[here | http://www.arduino.cc/en/Tutorial/SoftwareSerial]].
to:
In this tutorial you will learn how to communicate with a computer using a MAX3323 single channel RS-232 driver/receiver and a software serial connection on the Arduino. A general purpose software serial tutorial can be found [[http://www.arduino.cc/en/Tutorial/SoftwareSerial | here]].
August 29, 2006, at 07:06 PM by Heather Dewey-Hagborg -
Changed lines 3-4 from:
In this tutorial you will learn how to communicate with a computer using a MAX3323 single channel RS-232 driver/receiver and a software serial connection on the Arduino.
to:
In this tutorial you will learn how to communicate with a computer using a MAX3323 single channel RS-232 driver/receiver and a software serial connection on the Arduino. A general purpose software serial tutorial can be found [[here | http://www.arduino.cc/en/Tutorial/SoftwareSerial]].
August 29, 2006, at 07:03 PM by Heather Dewey-Hagborg -
Changed lines 57-58 from:

to:
''TX wires Green, RX wires Blue, +5v wires are red, GND wires are black''
August 29, 2006, at 07:01 PM by Heather Dewey-Hagborg -
Changed lines 23-24 from:
"+5v wires are red, GND wires are black"
to:
''+5v wires are red, GND wires are black''
Changed lines 28-29 from:
to:
''+5v wires are red, GND wires are black''
Changed lines 33-34 from:
to:
''TX wire Green, RX wire Blue, +5v wires are red, GND wires are black''
August 29, 2006, at 06:59 PM by Heather Dewey-Hagborg -
Changed lines 23-24 from:
to:
"+5v wires are red, GND wires are black"
Changed lines 59-60 from:
Now we will write the code to enable serial data communication. This program will simply wait for a character to arrive in the serial recieving port and then spit it back out in uppercase out the transmit port. This is a good general purpose serial debugging program and you should be able to extrapolate from this example to cover all your basic serial needs. Upload the follwoing code into the Arduino microcontroller module:
to:
Now we will write the code to enable serial data communication. This program will simply wait for a character to arrive in the serial recieving port and then spit it back out in uppercase out the transmit port. This is a good general purpose serial debugging program and you should be able to extrapolate from this example to cover all your basic serial needs. Upload the following code into the Arduino microcontroller module:
August 29, 2006, at 06:55 PM by Heather Dewey-Hagborg -
Changed lines 22-23 from:
Attach:MAX3323_pwr.jpg
to:
Attach:MAX3323_pwr2.jpg
Changed lines 26-27 from:
Attach:MAX3323_caps.jpg
to:
Attach:MAX3323_caps2.jpg
Changed lines 30-31 from:
Attach:MAX3323_txrx.jpg
to:
Attach:MAX3323_txrx2.jpg
Changed lines 53-55 from:
Attach:MAX3323_cable.jpg

to:
Attach:MAX3323_cable2.jpg

August 23, 2006, at 09:09 PM by Heather Dewey-Hagborg -
Added lines 61-64:
//Created August 23 2006
//Heather Dewey-Hagborg
//http://www.arduino.cc
August 23, 2006, at 09:05 PM by Heather Dewey-Hagborg -
Changed lines 135-137 from:
If this works, congratulations! Your serial connection is working as planned. You can now use your new serial/computer connection to print debugging statements from your code, and to send commands to your microcontroller.
to:
If this works, congratulations! Your serial connection is working as planned. You can now use your new serial/computer connection to print debugging statements from your code, and to send commands to your microcontroller.

''Photos by Thomas Dexter''
August 23, 2006, at 09:03 PM by Heather Dewey-Hagborg -
Changed lines 35-36 from:
''DB9 Serial Connector Pin Diagram''
to:
''(DB9 Serial Connector Pin Diagram)''

August 23, 2006, at 09:02 PM by Heather Dewey-Hagborg -
Changed lines 32-33 from:
!!!Cables
to:
!!Cables
Changed lines 35-36 from:
("DB9 Serial Connector Pins")
to:
''DB9 Serial Connector Pin Diagram''
Changed lines 55-56 from:
!!!Program the Arduino
to:
!!Program the Arduino
August 23, 2006, at 09:00 PM by Heather Dewey-Hagborg -
Added lines 34-36:
Attach:DB9-pinout.gif
("DB9 Serial Connector Pins")
Deleted lines 48-51:



Attach:DB9-pinout.gif
August 23, 2006, at 08:58 PM by Heather Dewey-Hagborg -
Added lines 43-44:

Added line 48:
Added line 55:
August 23, 2006, at 08:55 PM by Heather Dewey-Hagborg -
Changed lines 22-23 from:
PICTURE
to:
Attach:MAX3323_pwr.jpg
Changed lines 26-27 from:
PICTURE
to:
Attach:MAX3323_caps.jpg
Changed lines 30-31 from:
PICTURE
to:
Attach:MAX3323_txrx.jpg
Changed lines 48-52 from:
Connect the TX line from your computer to pin 8 (R1IN) on the MAX233 and the RX line to pin 7 (T1OUT).

PICTURE

to:
Connect the TX line from your computer to pin 8 (R1IN) on the MAX233 and the RX line to pin 7 (T1OUT). Connect the ground line from your computer to ground on the breadboard.

Attach:MAX3323_cable.jpg
August 23, 2006, at 08:11 PM by Heather Dewey-Hagborg -
Changed lines 20-21 from:
Insert the MAX3323 chip in the breadboard. Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller. Connect pin 15 on the MAX233 chip to ground and pins 16 and 14 - 11 to 5V. Connect a 1uF capacitor across pins 1 and 3, another across pins 4 and 5, another between pin 1 and ground, and the last between pin 6 and ground. If you are using polarized capacitors make sure the negative pins connect to the negative sides (pins 3 and 5 and ground).
to:
Insert the MAX3323 chip in the breadboard. Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller. Connect pin 15 on the MAX233 chip to ground and pins 16 and 14 - 11 to 5V. If you are using an LED connect it between pin 13 and ground.
Added lines 24-27:
Connect a 1uF capacitor across pins 1 and 3, another across pins 4 and 5, another between pin 1 and ground, and the last between pin 6 and ground. If you are using polarized capacitors make sure the negative pins connect to the negative sides (pins 3 and 5 and ground).

PICTURE
August 23, 2006, at 08:01 PM by Heather Dewey-Hagborg -
Changed lines 3-4 from:
In this tutorial you will learn how to communicate with a computer using a MAX233 multichannel RS-232 driver/receiver and a software serial connection on the Arduino.
to:
In this tutorial you will learn how to communicate with a computer using a MAX3323 single channel RS-232 driver/receiver and a software serial connection on the Arduino.
Changed lines 9-10 from:
* MAX233 chip (or similar)
* 1uf polarized capacitor
to:
* MAX3323 chip (or similar)
* 4 1uf capacitors
Changed lines 18-21 from:
Attach:max233_schematic2.jpg

Insert the MAX233 chip in the breadboard. Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller. Connect pin 6 and pin 9 on the MAX233 chip to ground and pin 7 to 5V. Connect the 1uF capacitor across pins 6 and 7 so that the negative pin connects to pin 6 and the positive pin to pin 7. Connect pin 10 to pin 16 pin 11 to pin 15 and pin 12 to pin 17 on the breadboard.
to:
Attach:max3323_pins.jpg

Insert the MAX3323 chip in the breadboard. Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller. Connect pin 15 on the MAX233 chip to ground and pins 16 and 14 - 11 to 5V. Connect a 1uF capacitor across pins 1 and 3, another across pins 4 and 5, another between pin 1 and ground, and the last between pin 6 and ground. If you are using polarized capacitors make sure the negative pins connect to the negative sides (pins 3 and 5 and ground).
Changed lines 24-27 from:
The MAX233 chip has two sets of RS-232 line shifters built in and can handle two simultaneous duplex serial ports. For the purposes of this tutorial we will only being using one port, with corresponding pins referred to as T1IN, T1OUT, R1IN and R1OUT in the MAX233 schematic.

Determine which Arduino pins you want to use for your transmit (TX) and recieve (RX) lines. In this tutorial we will be using Arduino pin 6 for receiving and pin 7 for transmitting. Connect your TX pin (7) to MAX233 pin 2 (T1IN). Connect your RX pin (6) to MAX233 pin 3 (R1OUT).
to:
Determine which Arduino pins you want to use for your transmit (TX) and recieve (RX) lines. In this tutorial we will be using Arduino pin 6 for receiving and pin 7 for transmitting. Connect your TX pin (7) to MAX3323 pin 10 (T1IN). Connect your RX pin (6) to MAX3323 pin 9 (R1OUT).
Changed lines 44-45 from:
Connect the TX line from your computer to pin 4 (R1IN) on the MAX233 and the RX line to pin 5 (T1OUT).
to:
Connect the TX line from your computer to pin 8 (R1IN) on the MAX233 and the RX line to pin 7 (T1OUT).
August 17, 2006, at 08:06 PM by Heather Dewey-Hagborg -
August 17, 2006, at 08:05 PM by Heather Dewey-Hagborg -
Changed lines 32-34 from:
If you do not have one already, you need to make a cable to connect from the serial port (or USB-serial adapter) on your computer and the breadboard. To do this, pick up a female DB9 connector from radioshack. Pick three different colors of wire, one for TX, one for RX, and one for ground. Solder your TX wire to pin 2 of the DB9 connector, RX wire to pin 3 and Ground to pin 5. Connect pins 1 and 6 to pin 4 and pin 7 to pin 8. Heatshrink the wire connections to avoid accidental shorts. Enclose the connector in a backshell to further protect the signal and enable easy unplugging from your serial port.

Attach:DB9-pinout.gif
to:
If you do not have one already, you need to make a cable to connect from the serial port (or USB-serial adapter) on your computer and the breadboard. To do this, pick up a female DB9 connector from radioshack. Pick three different colors of wire, one for TX, one for RX, and one for ground. Solder your TX wire to pin 2 of the DB9 connector, RX wire to pin 3 and Ground to pin 5.
Added lines 35-37:

Connect pins 1 and 6 to pin 4 and pin 7 to pin 8. Heatshrink the wire connections to avoid accidental shorts.
Added lines 39-40:

Enclose the connector in a backshell to further protect the signal and enable easy unplugging from your serial port.
Changed lines 42-44 from:
PICTURE in back shell
to:


Attach:DB9-pinout.gif
August 17, 2006, at 08:02 PM by Heather Dewey-Hagborg -
Added lines 30-31:
!!!Cables
Changed lines 35-36 from:

PICTURE connector soldered,
to:
Attach:ser_con_top.jpg
Attach:ser_con_bottom.jpg
Attach:ser_con_shell.jpg
August 17, 2006, at 08:01 PM by Heather Dewey-Hagborg -
Changed lines 34-35 from:
PICTURE connector soldered, in back shell
to:
PICTURE connector soldered,
PICTURE in back shell
August 17, 2006, at 05:45 PM by Heather Dewey-Hagborg -
Changed lines 112-113 from:
Open up your serial terminal program and set it to 9600 baud, 8 data bits, 1 stop bit, no parity, no hardware flow control. Press the reset button on the arduino board. The word "hi" should appear in the terminal window followed by a line feed character and/or an advancement to the next line. Here are two shots of what it might look like, one in Hyperterminal the free pre-installed windows terminal application, and one in Realterm, another free application with more advanced options.
to:
Open up your serial terminal program and set it to 9600 baud, 8 data bits, 1 stop bit, no parity, no hardware flow control. Press the reset button on the arduino board. The word "hi" should appear in the terminal window followed by an advancement to the next line. Here is a shot of what it should look like in Hyperterminal, the free pre-installed windows terminal application.
Changed lines 115-116 from:
Attach:realterm_hi.jpg
to:
August 17, 2006, at 05:43 PM by Heather Dewey-Hagborg -
Changed lines 112-113 from:
Open up your serial terminal program and set it to 9600 baud, 8 data bits, 1 stop bit, no parity, no hardware flow control. Press the reset button on the arduino board. The word "hi" should appear in the terminal window followed by a line feed character and/or an advancement to the next line. Here are two shots of what it might look like, one in Hyperterminal the free pre-installed windows terminal application, and one in Realterm, another free application with more options.
to:
Open up your serial terminal program and set it to 9600 baud, 8 data bits, 1 stop bit, no parity, no hardware flow control. Press the reset button on the arduino board. The word "hi" should appear in the terminal window followed by a line feed character and/or an advancement to the next line. Here are two shots of what it might look like, one in Hyperterminal the free pre-installed windows terminal application, and one in Realterm, another free application with more advanced options.
Added lines 117-121:
Now, try typing a lowercase character into the terminal window. You should see the letter you typed return to you in uppercase.

Attach:hyperterm_abc.jpg

If this works, congratulations! Your serial connection is working as planned. You can now use your new serial/computer connection to print debugging statements from your code, and to send commands to your microcontroller.
August 17, 2006, at 05:26 PM by Heather Dewey-Hagborg -
Changed lines 112-116 from:
Open up your serial terminal program and set it to 9600 baud, 8 data bits, 1 stop bit, no parity, no hardware flow control. Press the reset button on the arduino board. The word "hi" should appear in the terminal window followed by a line feed character and an advancement to the next line.
to:
Open up your serial terminal program and set it to 9600 baud, 8 data bits, 1 stop bit, no parity, no hardware flow control. Press the reset button on the arduino board. The word "hi" should appear in the terminal window followed by a line feed character and/or an advancement to the next line. Here are two shots of what it might look like, one in Hyperterminal the free pre-installed windows terminal application, and one in Realterm, another free application with more options.

Attach:hyperterm_hi.jpg
Attach:realterm_hi.jpg
August 17, 2006, at 05:19 PM by Heather Dewey-Hagborg -
Changed line 34 from:
PICTURE connector soldered
to:
PICTURE connector soldered, in back shell
Changed lines 110-112 from:
@]
to:
@]

Open up your serial terminal program and set it to 9600 baud, 8 data bits, 1 stop bit, no parity, no hardware flow control. Press the reset button on the arduino board. The word "hi" should appear in the terminal window followed by a line feed character and an advancement to the next line.
August 17, 2006, at 05:02 PM by Heather Dewey-Hagborg -
Changed lines 30-31 from:
If you do not have one already, you need to make a cable to connect from the serial port (or USB-serial adapter) on your computer and the breadboard. To do this, pick up a female DB9 connector from radioshack. Pick three different colors of wire, one for TX, one for RX, and one for ground. Solder your TX wire to pin 2 of the DB9 connector, RX wire to pin 3 and Ground to pin 5. Connect pins 1 and 6 to pin 4 and pin 7 to pin 8. Heatshrink the wire connections to avoid accidental shorts.
to:
If you do not have one already, you need to make a cable to connect from the serial port (or USB-serial adapter) on your computer and the breadboard. To do this, pick up a female DB9 connector from radioshack. Pick three different colors of wire, one for TX, one for RX, and one for ground. Solder your TX wire to pin 2 of the DB9 connector, RX wire to pin 3 and Ground to pin 5. Connect pins 1 and 6 to pin 4 and pin 7 to pin 8. Heatshrink the wire connections to avoid accidental shorts. Enclose the connector in a backshell to further protect the signal and enable easy unplugging from your serial port.
August 17, 2006, at 05:01 PM by Heather Dewey-Hagborg -
Changed line 9 from:
* MAX233 chip
to:
* MAX233 chip (or similar)
Added lines 40-110:

!!!Program the Arduino

Now we will write the code to enable serial data communication. This program will simply wait for a character to arrive in the serial recieving port and then spit it back out in uppercase out the transmit port. This is a good general purpose serial debugging program and you should be able to extrapolate from this example to cover all your basic serial needs. Upload the follwoing code into the Arduino microcontroller module:

[@
#include <ctype.h>

#define bit9600Delay 84
#define halfBit9600Delay 42
#define bit4800Delay 188
#define halfBit4800Delay 94

byte rx = 6;
byte tx = 7;
byte SWval;

void setup() {
pinMode(rx,INPUT);
pinMode(tx,OUTPUT);
digitalWrite(tx,HIGH);
digitalWrite(13,HIGH); //turn on debugging LED
SWprint('h'); //debugging hello
SWprint('i');
SWprint(10); //carriage return
}

void SWprint(int data)
{
byte mask;
//startbit
digitalWrite(tx,LOW);
delayMicroseconds(bit9600Delay);
for (mask = 0x01; mask>0; mask <<= 1) {
if (data & mask){ // choose bit
digitalWrite(tx,HIGH); // send 1
}
else{
digitalWrite(tx,LOW); // send 0
}
delayMicroseconds(bit9600Delay);
}
//stop bit
digitalWrite(tx, HIGH);
delayMicroseconds(bit9600Delay);
}

int SWread()
{
byte val = 0;
while (digitalRead(rx));
//wait for start bit
if (digitalRead(rx) == LOW) {
delayMicroseconds(halfBit9600Delay);
for (int offset = 0; offset < 8; offset++) {
delayMicroseconds(bit9600Delay);
val |= digitalRead(rx) << offset;
}
//wait for stop bit + extra
delayMicroseconds(bit9600Delay);
delayMicroseconds(bit9600Delay);
return val;
}
}

void loop()
{
SWval = SWread();
SWprint(toupper(SWval));
}
@]
August 15, 2006, at 11:37 PM by Heather Dewey-Hagborg -
Changed lines 30-31 from:
If you do not have one already, you need to make a cable to connect from the serial port (or USB-serial adapter) on your computer and the breadboard. Instructions for doing this can be found [[ | here]].
to:
If you do not have one already, you need to make a cable to connect from the serial port (or USB-serial adapter) on your computer and the breadboard. To do this, pick up a female DB9 connector from radioshack. Pick three different colors of wire, one for TX, one for RX, and one for ground. Solder your TX wire to pin 2 of the DB9 connector, RX wire to pin 3 and Ground to pin 5. Connect pins 1 and 6 to pin 4 and pin 7 to pin 8. Heatshrink the wire connections to avoid accidental shorts.

Attach:DB9-pinout.gif

PICTURE connector soldered
August 15, 2006, at 11:17 PM by Heather Dewey-Hagborg -
Changed lines 18-19 from:
Attach:max233_schematic.jpg
to:
Attach:max233_schematic2.jpg
August 15, 2006, at 10:53 PM by Heather Dewey-Hagborg -
Changed lines 22-23 from:
Attach:rs232pwr_web.jpg
to:
PICTURE
Changed lines 28-29 from:
Attach:rs232ttl_web.jpg
to:
PICTURE
Added lines 32-35:
Connect the TX line from your computer to pin 4 (R1IN) on the MAX233 and the RX line to pin 5 (T1OUT).

PICTURE
August 15, 2006, at 10:49 PM by Heather Dewey-Hagborg -
Added line 6:
Added line 8:
* Serial-Breadboard cable
Changed lines 14-31 from:
* Light emitting Diode (LED) - optional, for debugging
to:
* Light emitting Diode (LED) - optional, for debugging

!!Prepare the breadboard

Attach:max233_schematic.jpg

Insert the MAX233 chip in the breadboard. Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller. Connect pin 6 and pin 9 on the MAX233 chip to ground and pin 7 to 5V. Connect the 1uF capacitor across pins 6 and 7 so that the negative pin connects to pin 6 and the positive pin to pin 7. Connect pin 10 to pin 16 pin 11 to pin 15 and pin 12 to pin 17 on the breadboard.

Attach:rs232pwr_web.jpg

The MAX233 chip has two sets of RS-232 line shifters built in and can handle two simultaneous duplex serial ports. For the purposes of this tutorial we will only being using one port, with corresponding pins referred to as T1IN, T1OUT, R1IN and R1OUT in the MAX233 schematic.

Determine which Arduino pins you want to use for your transmit (TX) and recieve (RX) lines. In this tutorial we will be using Arduino pin 6 for receiving and pin 7 for transmitting. Connect your TX pin (7) to MAX233 pin 2 (T1IN). Connect your RX pin (6) to MAX233 pin 3 (R1OUT).

Attach:rs232ttl_web.jpg

If you do not have one already, you need to make a cable to connect from the serial port (or USB-serial adapter) on your computer and the breadboard. Instructions for doing this can be found [[ | here]].
August 15, 2006, at 10:23 PM by Heather Dewey-Hagborg -
Changed lines 6-13 from:

* Computer with a terminal program installed (ie. HyperTerminal or RealTerm on the PC, Zterm on Mac)
* MAX233 chip
* 1uf polarized capacitor
* Solderless breadboard
* Hookup wire
* Arduino Microcontroller Module
* Light emitting Diode (LED) - optional, for debugging
to:
* Computer with a terminal program installed (ie. HyperTerminal or RealTerm on the PC, Zterm on Mac)
* MAX233 chip
* 1uf polarized capacitor
* Solderless breadboard
* Hookup wire
* Arduino Microcontroller Module
* Light emitting Diode (LED) - optional, for debugging
August 15, 2006, at 10:22 PM by Heather Dewey-Hagborg -
Added lines 1-13:
!RS-232

In this tutorial you will learn how to communicate with a computer using a MAX233 multichannel RS-232 driver/receiver and a software serial connection on the Arduino.

Materials needed:

* Computer with a terminal program installed (ie. HyperTerminal or RealTerm on the PC, Zterm on Mac)
* MAX233 chip
* 1uf polarized capacitor
* Solderless breadboard
* Hookup wire
* Arduino Microcontroller Module
* Light emitting Diode (LED) - optional, for debugging

Share