Arduino serial port: lost in confusion

Hi
I'm new of Arduino and I have some questions about Arduino Serial port.

  1. The USB connector of Arduino is connected to a RS232 so can we say that is a RS232 but with a USB Connector?
  2. Can I attach directly a rs232 to USB Arduino port?
  3. If I can't, what shall I do to connect a RS232 to an Arduino?

Thanks in advance
By

The USB port on the arduino goes to a special chip (FTDIxxxx) that converts USB protocol into "asynchronous serial", which is then fed into the serial port of the ATmega microcontroller that is the "core" of the Arduino. You can also use this serial port for talking to other serial devices, via digital pins 0/1. You can also run "software serial" on the other digital IO pins. "async serial" describes the format of the bit stream going in/out of the micro.

None of these are QUITE "rs232"; rs232 is a particular SIGNALING specification for using the "async serial" bitstream between assorted devices that describes the voltage levels used, along with a bunch of auxiliary control signals that are frequently ignored.

To connect to a 'real' rs232 device, you will need at least a "level converter", like this one from sparkfun: http://www.sparkfun.com/commerce/product_info.php?products_id=133
You may need additional modifications to satisfy other needs depending on connectors and devices.

There are also a lot of "logic level serial" devices (which is what is on pins 0/1 without any converter), since serial communications is so convenient even within small devices, and converting back and forth to real rs232 is ... excessive. You can probably thank the parallax basic stamp, which was one of the first devices to offer "lots" of serial pins that were not rs232 compatible... (example device: serial LCD module.)

Thank you very much.
By

Thanks, that was an excellent question (and answer). I was also confused about this. Also, I would like to find out the "other side" of this issue. What does it take to talk to the USB port on my computer from the Arduino?

I see the serial monitor results. I also, sort of, understand that this data could be captured in a file on the PC. I'm not sure exactly how... using the Processing language, I guess.

But, what I really would like to be able to do, is use the arduino as a DIRECT input to any program on my PC. For example, I would like to build a one-handed (chording) keyboard based upon the Arduino. I would push the buttons. The Arduino would read the buttons and convert them to keycodes and send them over the USB to the PC.
The PC would just see these as normal keyboard input. That way they could be input to any program (an editor, a browser, etc.)

The Serial Monitor is just a terminal built into the IDE and you can use any terminal program you have. I have used HyperTerminal, ucon and RealTerm to capture data. You could use any programming language that will talk to a serial prot because that is all the USB to serial cable is.

Stephen,

Thanks, yes I have used HyperTerminal in the past. And, I could create a program with serial input. But, what I really want to accomplish is to provide Arduino output as the input to ANY program (even programs that I have not written like WordPad, Notepad or Internet Explorer). I would also like it to be an operating system independent solution.

I think that I need to implement whatever software handshaking protocol the Operating System uses when a new USB peripheral is attached to the computer (or detected at boot time).

What is unclear is if that is "all" I need to do. Is the Arduino hardware capable of doing what I want? It may be a timing intensive
task. I hope someone on the forum will have accomplished this. Or, at least have attempted it and will have some advice and/or pointers on how to get started.

Thanks for your quick response.

Mark

You can't actually speak "USB" from the arduino to the PC. The chip used does ONLY the USB/Serial function (well, maybe some FTDI proprietary things too, for changing configuration of the chip.) I assume it mostly implements a "standard" USB/Serial peripheral.

This means two things.

  1. Any program that can talk to a windows serial port (or linux or macos) can talk to the arduino via the virtual serial port that the FTDI driver creates. This is good.
  2. If you want to have the serial port appear as some other sort of windows peripheral (keyboard or mouse) for all programs, you either have to implement a driver that converts the "serial port" into whatever peripheral you had in mind (shouldn't be impossible; I think serial mice still work when attached to windows, though I've never tried one on the end of a USB serial port), OR you can write a driver that REPLACES the FTDI driver and talks directly to the chip over USB, but implements something other than a serial port on the windows side.
    (Both of these are "hard", probably ranging to "very hard.")

The key fact is that the Arduino is not a "generic USB peripheral"; it's a specific peripheral that implements a serial port. That makes it easier to deal with on both ends, but only while you only need to use it as a serial port.

westfs,

Thanks, yes that is kind of what I expected was the case. I figured, if it was easy, it would have already been done :slight_smile: Still, if this could be accomplished for even just a mouse and keyboard, it would open up a whole new category for Arduino use. I will continue to persue it.

Mark

It does look as though there are some serial-to-keyboard drivers out there, aimed at things like barcode scanners... Search for "serial keyboard driver"

I'm working on bringing similar features (mouse and keyboard control) to Bitlash so it's an area I'm investigating.

There is work happening in several places, mostly not here. Here are some links to get the truly motivated started in the right direction:

avr-usb library
http://obdev.at/products/avrusb/index.html

arduino usb project by rancidbacon (I believe he hangs here, under a different name)
http://code.rancidbacon.com/ProjectLogArduinoUSB

breadboard prototype - avr-usb w zener on Arduino
http://ducksoup.notesoup.net/soupmaster/usblinks/avr-usb-zener.JPG

easylogger - avr-usb project
http://www.obdev.at/products/avrusb/easylogger.html

I have experimented with the zener-diode version of the avr-usb hardware on Arduino. It works for me, but it seems a little fussy about which USB implementations it will talk to. It may work for your application, and the price is right. Love the code.

If bareback makefile is your style the AVROpendous and Teensy boards are superb. I have Bitlash running over there in native/raw C and pushing the mouse around. http://bitlash.net/downloads/bitlash-usb/ The LUFA library and the Teensy examples give you some options on how to get started. I went with LUFA in the code above. The port is not bad once you wrap your head partway around USB. Some links:

teensy: at90usb breakout
http://pjrc.com/teensy/index.html

avropendous home: at90usb breakouts
http://code.google.com/p/avropendous/

LUFA controller firmware for AT90USB

Doubtless there are other worthy projects I have overlooked.

Now wouldn't it be great to have these boards on the Boards menu? :wink:

-br

Thanks for the info and links. The LUFA project looks quite interesting.
I will attempt to get started there.

Mark

Hi
At last I connected the serial card reader to Arduino trought a commercial ttl/rs232 converter based on a MAX232 chip: I connected rx pin 0 of Arduino to tx of MAX232 chip and tx to rx and the vcc and ground pin
I wrote a simple serial program who read serial input and downloaded to arduino but card reader doesn't blink when I pass a card and nothing seems be read.
Any suggestion?
By

aladin-

Give more details (cut sheets?) of the card reader. Sounds like rfid... Are you using multiple power sources?

I'm sorry I couldn't find a way to attach a picture to show it.
However I use a magnetic card reader which has a 9-pin Serial Rs232 cable. What I did is to connect the 9pin connector of a MAX232 module to the card reader. The Max232 module has Vcc +5 volt and GNC connect to Arduino and tx and rx crossed with pin 0 and 1 of arduino. When I run a schetch with serial reading nothing happens.
Thank for your interest
By

I connected rx pin 0 of Arduino to tx of MAX232 chip and tx to rx and the vcc and ground pin

The labelling of RS232 pins is confusing. It depends on which end of the link you are what is labelled RX and TX. It could be that the tx on the MAX232 is actually an input, the signal to transmit rather than the signal that has been transmitted. So I would try connecting the Arduino's rx pin 0 to the rx of the Max232 and the two tx pins together.

Look at:-
Data terminal equipment - Wikipedia for an explanation.

I'll try it.
Thanks for suggestion
By

So i have a symbol barcode scanner we use at work, if i plug it into a standard pc and open word or textpad whatever and scan an item it prints the numeric value of the barcode. I have hooked the tx pin to the rx serial pin and power and ground, this is a db9 rs232 serial interface, .I have the following sketch. which when i scan a barcode it outputs

[ch137]æææææ¦ââÄD¦¬

#include <LiquidCrystal.h>
int i;
// initialize the library with the numbers of the interface pins
//LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {
//lcd.begin(16, 2);
Serial.begin(9600);
}

void loop() {

// lcd.setCursor(0, 0);
if(Serial.available() > 0) {
i = Serial.read();
//lcd.print(byte(i));
Serial.print(byte(i));

}

}