Newbie Question: Interfacing with Computer via USB

Hello,

I'm currently considering to buy an Arduino Nano for controlling 6 motors, 30 meters away from a computer, connected by wires. The 6 PWM outputs in particular have really, really interested me.

But, after reading through the documentation, I do not see a way for an Arduino to accept commands from a computer in real time and act on them. Is there a way, to "analogwrite(getusbdata)" of some sort?

And does the software support getting data from an Arduino?

Furthermore, USBs have a maximum length of 5 meters. This, well, isn't really quite long enough. Is there a way to connect the serial RX/TX to computer? And by TTL does the documentation mean RS232?

Thanks.

Sorry, just wanted to check a few facts before committing to buying quite a few nanos.

EDIT: Just had an idea. Could I communicate between two Arduino Nanos by just connecting TX to RX and RX to TX? If that works, I could use the analog input of one, output it in serial, and input on serial, output on PWM.

But, after reading through the documentation, I do not see a way for an Arduino to accept commands from a computer in real time and act on them. Is there a way, to "analogwrite(getusbdata)" of some sort?

It sure can, using the Serial class. See the SerialCallResponse sample sketch in the Communication category. Both sending and receiving data over the serial port is supported.

I'd recommend keeping the microcontroller(s) close to the computer and running longer wires out to your motors rather than going with a super-long USB cable connection.

You can indeed communicate between to Nanos by connecting their serial ports. It might be a good idea to sketch out a block diagram with proposed interconnections for our review as I think we're getting lost in words, and pictures are much better for this kind of thing.

--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, light sensor, potentiometers, pushbuttons

I think your Arduino will do what you want, but with a bit of modification to the layout, as RuggedCircuits mentioned previously.

Connect your Arduino to your computer via USB. You can use basic Serial commands (provided in the Ardunio reference section of their documentation). If you have the FTDI USB cable, then when you plug in the Arduino, it shows up on your computer as a new Serial port. Programs on the computer can send and recieve serial data this way.

In order to handle the real-time aspect of your question, I would reccomend you implement a timer interrupt to check for data in the serial buffer. You'll have to implement a bit of flow control and command parsing, but that's not too difficult.

No, TTL is not the same as RS232. This is a common misconception. RS232 generally means it uses +/- 12V logic. You might damage your board if you tried to connect these directly to your Arduino. TTL generally means 0 to 5V logic. You can get converters to change RS232 to TTL, but it's unnessecary if you have the FTDI USB cable, since USB runs on 5V logic anyhow.

The boards (and I'm not sure about the nano here) use pins 0 and 1 for RX / TX for the hardware serial port. These pins are shared with the USB -> FTDI Serial connection. You can use software serial and use other pins for RX / TX if you need additional serial connections to the same microcontroller.

Once you have your connection with the computer established, use the analogWrite() function to create the PWM for your motors. The Arduino doesn't push enough Amps to drive most motor circuts, so you wouldn't want to directly connect your motors to the analog pins. Doing so might attempt to draw too much current through the uC, and burn out the chip. Instead, you'll want to use a transistor (or transistor package IC... or H-Bridge. $2.50 for 4 transistors in a chip). This allows you to control a larger power supply... using TTL logic levels. The transistor effectively switches on or off the larger power which supplies your motors.

I may be incorrect on this part, so someone correct this if my thinking here is flawed: There may be significant resistance that could impact the signal from 30m away. So you probably don't want to use the TTL power straight off the uC board to span the distance. Instead, I would use the transistor and power supply close to your microcontroller, and have the larger power flow down the long wires to the motors. This way, you're sure that the PWM signal won't have trouble switching the transistors. There may still be some power loss across the distance, but it will probably be sufficient for your task. If not, there are othere ways to boost the power again if needed. (ie: stick another transistor package with another power supply as a repeater down the line) :wink:

The project i'm attempting is an underwater ROV. The computer will be on shore, the Nano will be underwater with the ROV. It'll need to control a few motors, but that's fine.

Here's the rough diagram.

My questions. When I say Serial.Begin(9600) for example, which one will it use? The USB B plug, or Pins 0 and 1? Or both simultaneously? So I must use the software serial library or something.

This line in particular has me worried:

It communicates on digital pins 0 (RX) and 1 (TX) as well as with the computer via USB. Thus, if you use these functions, you cannot also use pins 0 and 1 for digital input or output.

Source: http://arduino.cc/en/Reference/Serial

P.S. And, eh, one last question. I've read this repeatedly on the website, but I CAN program the nano using USB, yes?

And when I just directly connect the Arduino to the computer via a USB cable, I can control and receive data using Processing?

The USB B plug, or Pins 0 and 1?

The USB plug IS Pins 0 and 1, they are the same thing. If you want another serial connector you will have to use a software emulation of one.

but I CAN program the nano using USB,

Yes

And when I just directly connect the Arduino to the computer via a USB cable, I can control and receive data using Processing

Yes

When I say Serial.Begin(9600) for example, which one will it use? The USB B plug, or Pins 0 and 1? Or both simultaneously? So I must use the software serial library or something.

Yes, you can program the Nano using USB. The board contains a USB-to-serial converter that connects to the RX/TX pins. You can't use the RX/TX pins independently, as you are showing in your diagram.

You could use any two other pins and NewSoftSerial to emulate the hardware serial capabilities.

Those two pins can then be connected to the hardware serial port on the underwater Nano.

And when I just directly connect the Arduino to the computer via a USB cable, I can control and receive data using Processing?

Yes, you can. The same mechanism (USB-to-serial converter) is used to talk to the board as the IDE uses. Of course, you can't have Processing and the IDE talking to the serial port at the same time.

Bah, the shop that supplies these doesn't have any nanos. Only Arduino Duemilanoves. Well, the perils of living in China.

Well, frankly, if i'm going to use RS232, i'll just do away with the -5volts required, seeing as it's just an attempt to protect signal integrity.

Thank you very much, to everyone who's replied up there.

Yes, but it's somewhat beyond my current capabilities as a high school student. The Duemilanoves should do fine - i'll see if the power input connector can be desoldered off to save a tiny bit of space.

Currently, my plan is this. I'll want for the Duemilanove to arrive, and try sending a signal through the serial pins for 30 meters. Of the signal arrives fine, great, i'll leave it at that.

If not, i'll try a simple DC/DC voltage booster and a step down at the other end to remove some noise effects. If THAT doesn't work, i'll switch to RS232.

Sounds good? And thanks again.

I'll probably be back in a few weeks with a few newbie coding questions. Stay tuned for pictures!

EDIT: Yet another question.

Can anyone recognise this prototyping shield and tell me if its for Duemilanove?

try sending a signal through the serial pins for 30 meters. Of the signal arrives fine, great, i'll leave it at that.

That's not going to be a very realistic test: all the motors in your ROV will be generating noise that will complicate things in actual operation.

My suggestions are to use something like the RBBB or Pro Mini in the ROV to save space and power, and either your Duemilanove with a software second serial (if the data traffic is low) or a Mega (to add another hardware serial if the data traffic is high) at the "base station" end. You'll need something like the P4 or USB BUB to program the USB-less Arduino.

For reliable communication, use half-duplex RS-485: it's specifically designed for this kind of application, uses only two wires, and will only cost you about $3-4 for the driver chips. It takes a little more software effort to make the half-duplex thing work, but it's probably worth it for the noise risk it eliminates.

Yes, that looks like a standar proto shield.

Thanks!

Well, The Arduino has not arrived in the mail yet, but lets hope I don't run into any complications. Curse you, Radioshack!

I've looked at a standard driver chip, MAX485. I probably could just about run it in half-duplex mode, but it'll require quite a bit of software coding - and i'm not sure if they ship to China.

Thought: Why not use a full duplex RS485 driver, such as MAX3488 and reduce all the trouble - and thank god for free samples!

I've just repeated your post, haven't I? Thanks again. Theoretically, if I add a diode, the motors shouldn't affect the board too much.

My supplier does not have nanos or minis. The big ones are the best he can do.

We'll see how it goes. I promise pictures from my oscilloscope.

You might want to see whether Futurelec ships to China: since they're close to you, you might avoid the long delivery times that their North American customers complain about.

I only suggested half-duplex because the other people asking for help on their ROV projects have always mentioned being short on wires in the cable. If you've got spares, by all means go full-duplex.

You should check out the "Arduino on a stripboard" projects that people have posted to the Exhibition section. You really don't need much circuitry in addition to the CPU chip, and you might be able to do a Veroboard implementation smaller than a Duemilanove.

This looks kinda cool for your needs, if you don't mind being a beta tester. And the company is based in Shenzhen.

Ooooh, Shiny!

Shame the Due's are already shipping :stuck_out_tongue:

Alright, i'm back, and i'm back with another question. Yippee.

Look at http://bit.ly/9TyfyP(Warning: PDF).

It's a datasheet for a 3-ampere H bridge motor driver. From what I understand, I should connect the Pins to the Arduino in this manner.

Pin 3 (DIRECTION) Input : Digital pin which determines motor direction
Pin 4 (BRAKE) Input: Ground via a 1 micro-farad capacitor, as I don't really want that functionality.
Pin 5 (PWM) Input: To Digital Pin with Analoguewrite set in software.
Pin 8 (CURRENT SENSE) Output: To a current shunt resistor to measure the voltage using one of the analogue pins (If required)
Pin 9 (Thermal Warning): Ground (Resistor required?)

Just posting that to see if i'm current. I'm still relatively new to chomping down data sheets.

Frankly, i'm here just to ask one question. Am I correct if I say that the Bootstrap pins may be left alone at the Arduino's PWM frequencies, as the chip itself has an internal capacitor? And are those pins above wired correctly?

The stuff about the bootstraps are on the bottom of page 9. Thank you.

Am I correct if I say that the Bootstrap pins may be left alone

You are right in that conclusion but wrong as to the reason.

as the chip itself has an internal capacitor?

Which chip, not the ATMEGA

The chip - the H - Bridge chip itself has an internal capacitor, which negates any external capacitors required until at PWM frequencies of above 1khz, which is ... too much for the internal one to handle.

We have a 10 ampere limit on the ROV, and 12 volts. Each bilge motor's running at 12 volts, and 2.5 amperes - ish.

Pin 8, as far as I get from the datasheet, outputs a few milliamperes at a linear proportion to the amperes the motor is drawing. I can use a current shunt resistor to measure the amperes available at Pin 8, and therefore the amperes being drawn by each motor - and by extension, how many amperes are left.

Correct me if i'm wrong anywhere in the post. And thanks again for all the help - this has been a great learning experience.

P.S. I know this is somewhat offtopic, but has anyone got any idea how to do a rotary shaft seal?