Go Down

Topic: Best way to interface PC to arduino (Read 22176 times) previous topic - next topic

bobhaha

Hey guys, first post.

I have done some research into wireless communication between PC and arduino. I would like to wirelessly send ascii characters to the arduino and in turn the arduino will move a stepper motor to a set spot, for example <s 1 10> will move stepper motor 1, 10 steps forward.

Now, bluetooth communication in my eyes would be the easiest as far as I have read, but I have also read that it is driver dependent and that doesn't help if I want to make this a portable application.

I would like to make the program via dev C++ to work with the interface device. USB and bluetooth sound the easiest, but as I said before, they are dependent on drivers.

So basically I'm asking, is there an easy way to interface an arduino and a PC, so that I can easily create a C++ program to send ascii code to the arduino.

Thanks in advance!

PaulS

Quote
Now, bluetooth communication in my eyes would be the easiest as far as I have read, but I have also read that it is driver dependent and that doesn't help if I want to make this a portable application.

Read where? Certainly not on this forum.

Quote
I would like to wirelessly send ascii characters to the arduino

Over what range?

Quote
So basically I'm asking, is there an easy way to interface an arduino and a PC, so that I can easily create a C++ program to send ascii code to the arduino.

Yes. Think XBee.

focalist

#2
Dec 09, 2010, 04:59 pm Last Edit: Dec 09, 2010, 05:09 pm by focalist Reason: 1
Well both the USB and Bluetooth all convert to Serial I/O which goes to the UART on the chip.  The "easiest" way to talk to the Arduino is directly via a serial port, which requires nothing more than the standard system serial driver.

Many clone Arduinos save complexity and cost by supporting only Serial (RS232), just run through a MAX232 chip or similar.  My Adafruit Boarduino is of this type-- I use a serial cable to my MAX232 based Serial-to-TTL cable, which connects directly to the port pins (rx/tx) on the BoArduino.  That way, the BoArduino doesn't need to keep that circuitry on-board, reducing size and cost.

My (and your) "standard" arduino uses a chip on the board to convert from USB to Serial, which is then connected the same way, through a max232 (look on the board) serial-to-ttl converter.

SO... Serial the answer.  How you GET to serial; that's the question..

I've not used any of the wireless solutions (yet), but as I understand XBEE as well as most Bluetooth adapters simply act as a virtual wire.. the computer and Arduino talk over a serial link via bluetooth, the only driver you will need is for your own bluetooth dongle or builtin on your computer.  Once paired, neither the computer nor the Arduino know or care that the connection is wireless.  I have an older inkjet printer that uses bluetooth as a connection option.. once paired to the computer, it's just another COM: port printer.  The actual drivers to make that printer work are another issue, but the connection is simple.

Range for bluetooth is supposed to be something like 10m, I find around 20 feet more realistic for most applications in a noisy electrical environment when using other bluetooth-connected items.

bobhaha

Just with in the 10m radius that bluetooth is usually rated for.

The source was a C++ forum, a member asked about sending ascii data via bluetooth and was told that it is very difficult because of driver issues.

Are you saying that it would be much easier to code a program to work with the xbee "board" for the arduino than any other method of wireless transmission?

Thanks for the fast response!

PaulS

XBees are basically a drop in replacement for the USB cable that is used to program the Arduino. Very easy to use.

bobhaha

Yes, I'm aware of that. My question is mainly aimed at simplicity via the PC end, arduino coding will be much easier. I need to basically find an easy way to transmit ascii via pc to arduino. In your opinion is bluetooth the way to go?

Also is there any sample code you have seen for C++ --> xbee communication via PC?

Again thanks for all the help!

PaulS

Quote
In your opinion is bluetooth the way to go?

I thought I made that clear. No. There. Is that clear, now?

Quote
Also is there any sample code you have seen for C++ --> xbee communication via PC?

It's just a matter of writing to the serial port, and reading from it. Plenty of examples on the forum. Trivially easy from C#, but C++ is easy enough for some people.

bobhaha

Ok, sorry now you have confused me. I was under the impression that an Xbee is a Bluetooth radio frequency device. Is that correct?

From my research, I see there are 2 modes for the Xbee, there is USB and Xbee mode. As far as I know, I want to use the USB mode, which will connect to the PC via bluetooth... is this correct?

Or are you trying to say, there is a sender and receiver Xbee device? If that is the case then this will be the most easiest way because sending and receiving via serial will be much easier to code.  

PaulS

Quote
I was under the impression that an Xbee is a Bluetooth radio frequency device. Is that correct?

It may be in the same frequency, but XBee is NOT bluetooth.

Quote
Or are you trying to say, there is a sender and receiver Xbee device? If that is the case then this will be the most easiest way because sending and receiving via serial will be much easier to code.

Sender on the PC side. Receiver on the Arduino. (Although the radios are transceivers, so both can talk to the other.) Exactly.

focalist

#9
Dec 09, 2010, 10:04 pm Last Edit: Dec 09, 2010, 10:37 pm by focalist Reason: 1
Hey Paul... for my own reference (having seen modules around), are the bluetooth modules NOT "virtual wire"?  I've browsed some at several online vendors, usually mentioning "AT" commands (are you kidding me?  Is this STILL the Hayes/USR commandset from back in the day?).. I just had assumed that pairing by default would make it appear as a serial direct connection, not as a Modem, per se

I had assumed (and ads didn't say directly as I have since noted) that the modules would act as a simple COM port device transparently via the bluetooth connect.. is that not the case?  

If that's the case, then Xbee (because it does support virtual wire mode) is the right way to go for sure...

I had been thinking about getting one of these:
http://www.mdfly.com/index.php?main_page=product_info&cPath=8_47&products_id=428
"Bluetooth TTL Transceiver Module w/ Breakout", $13.95 (9.95 for the 3.3v version)
to play with.. I burned up my RS232/TTL converter, and I figured this is better than replacing the max232 on my hokey cable..  I've bought things from MDfly before, dirt cheap on basics like LED's (50 3mm LED's for $1.35, a 16x2 standard LCD (works great) $4.. they've so far been fast and exactly as described.  It would just "not be like them" to leave it kinda gray, imo)- and it would seem to indicate that it should function as a transparent COM connection, though not worded that exact way.  If it's not going to function as a virtual wire, then it's not very useful for the purpose I (and the poster!) wanted it for, and I'd be wasting $14+a couple bucks shipping.

Thoughts?

PaulS

Quote
I've browsed some at several online vendors, usually mentioning "AT" commands (are you kidding me?  Is this STILL the Hayes/USR commandset from back in the day?).

Just because modems are no longer as prevalent as they once were does not mean that a good protocol should be discarded.

Quote
are the bluetooth modules NOT "virtual wire"?

They are not real wires, but they replace real wires, so, yes, they can be thought of as virtual wires.

Quote
I had assumed (and ads didn't say directly as I have since noted) that the modules would act as a simple COM port device transparently via the bluetooth connect.. is that not the case?  

If you are referring to XBee modules, no. XBee id NOT bluetooth. It is far better.

For one thing, it works. I have not seen a single post on this forum that said "Hey, I got my bluetooth whatever working with my Arduino" or "Hey, I got my bluetooth Arduino working with whatever".

bobhaha

Ok, thanks for the help! Looks like I'll be getting a few Xbee's then.

I found this board http://www.littlebirdelectronics.com/products/XBee-Explorer-Serial.html

Looks like it would be the easiest way to interface.

The board I linked to above is $38  :'( and each Xbee is ~$35 for the 2mW series.... WTF? Is there cheaper clones of the Xbee's? or a cheaper board for serial connection? I have had a look around in the hardware section, but I don't know what I'm looking for....

Thanks...

PaulS

Do you have a real serial port on your computer? Is that port what you are trying to connect to? If so, then that board is what you need.

If you have USB ports, though, something like this
http://www.sparkfun.com/products/8687
is cheaper.

arbarnhart

#13
Dec 10, 2010, 08:45 pm Last Edit: Dec 10, 2010, 08:47 pm by arbarnhart Reason: 1
I have used both BlueTooth and xBee between the Arduino and PC.

The only advantage BlueTooth has is that many PCs already have it built in and if they don't it is incredibly cheap to get and easy to find. If you want almost anyone to be able to connect to your device without special hardware, BlueTooth is a good choice. Even if they have to get an adapter, I would not consider BlueTooth "special"; I can get it off the shelf half a dozen places on the way home (and one of those places only stocks items costing $5 or less).

However, from a usability/usefulness perspective, xBee wins hands down. I can lose BlueTooth connectivity inside my house. I have 900 MHz xBee modules that are good for over a mile with small antennas and about 5 miles with bigger ones. You can also get lower power ones for less money that have no visible antenna. Anyway, more choices in range. When I break a connection to a BlueTooth device, if I had the COM port open in an application that connection is now invalid and can only be re-established when the device is back in range and the partnership re-established. With xBee, my connection is to the xBee attached on my end. Having another xBee come into range or wander out of range does not change the status of my COM port connection to the xBee. Depending on how you set them up, it is possible to communicate with multiple devices using just the single COM port connection.

I will say that it might be semantics, but I disagree with the notion that both are like virtual wires. BlueTooth is, IMO. A wire limits you to one device on the other end and causes a problem if it is cut or stretched too far. An xBee connection is a connection to a transciever that can communicate with other transceivers when they are in range.

PaulS

Quote
I will say that it might be semantics, but I disagree with the notion that both are like virtual wires.

I think we'll chalk it up to semantics. The Series 2.5 XBees can form a mesh. The Series one are point-to-point or point-to-multi-point. In the point-to-point situation, they replace a pair of wires (RX and TX). In a point-to-multi-point situation, they replace many pairs of wires (multiple connections to RX and multiple connections to TX). So, they could be considered virtual wires.

No argument that XBee is superior to bluetooth.

Go Up