Clarify for me - can an Arduino be run as a peripheral to a PC?

This is a very basic question. It's not totally clear to me if Arduino can be used in the way I need -

Most everything I've read describes uploading code to the Arduino unit to be executed later. But what if I want to run a program on a computer (Windows) all the time, and use the USB-connected Arduino as an I/O board?

Specifically, I need a program to use a USB-connected peripheral to

  1. control a bipolar stepper motor
  2. control a DC servo motor
  3. control a third motor by varying its voltage from 0-3V
  4. communicate with a piece of lab equipment over a serial port
  5. code needs to be in C because that's all I know :slight_smile: ... so, C libraries have to be available

The program running in the laptop will display the data acquired via the serial port and control the 3 other motors based on the data and user input.

Can Arduino do this? Or is it limited to running code that was uploaded to it earlier?

Just want to make sure I'm not fundamentally misunderstanding what an Arduino is and can do. Thank you.

168gr:
Can Arduino do this? Or is it limited to running code that was uploaded to it earlier?

Well, it does both - it runs code that was uploaded to it earlier that if you so choose will describe how it should react to the commands you send to it now.

In other words - yes, you can make it a simple I/O card for your computer. It's a very common application, so you've got lots of experience online to help you along.

You don't need C libraries - just plain ol' serial comms - sort out your own protocol (bitwise operations often involved if data rates are a concern)

The program running in the laptop will display the data acquired via the serial port and control the 3 other motors based on the data and user input.

Can Arduino do this?

Yes

Or is it limited to running code that was uploaded to it earlier?

Yes.
The code you upload will always run. You make the code respond to commends sent by the PC.
See:-
http://playground.arduino.cc/Main/InterfacingWithSoftware

What Windows program will you be using to talk to the Arduino?

This Python demo shows how to communicate between a PC and an Arduino. It should work on Windows if you put in the correct serial port reference in the Python code.

What you describe is a very common requirement.

...R

jremington:
What Windows program will you be using to talk to the Arduino?

One written entirely by me (plus any libraries and drivers needed). I have a working program written in C but the i/o board I have lacks the microsecond resolution to generate the control signal to the servo motor.

Looks like Arduino can do what I need. Just need to browse the different models and start playing with one.

Thanks all.

this sounds like an XY problem.

http://xyproblem.info/

control the stepper motor and the DC servo motor and input values into the PC directly.

it has gobs (a technical term) of memory compared to an Arduino.

the lab equipment, running over a serial port could connect to the PC.

learning a new language to run the Arduino as an extension of the PC, and then write a program in the PC to talk to a (comparatively) crippled piece of equipment seems a bit silly.

168gr:
The program running in the laptop will display the data acquired via the serial port and control the 3 other motors based on the data and user input.

Can Arduino do this? Or is it limited to running code that was uploaded to it earlier?

The Arduino is limited to executing a "program" that was uploaded to the controller.

But there is no reason why "the program" should be unable to do what you want:

  • the program can read 'commands' from Serial
  • then the program can execute 'commands' and send back values over Serial

So Serial command handling is what you want. Of course, all possible commands must be pre-programmed, so that the Arduino knows what to do when it receives a command like:
motor1 forward 3000
or
tempsensor23 read
or
relay4 on

So most likely you want to write a program for serial command handling and upload to an Arduino board.

168gr:
One written entirely by me (plus any libraries and drivers needed). I have a working program written in C but the i/o board I have lacks the microsecond resolution to generate the control signal to the servo motor.

Looks like Arduino can do what I need. Just need to browse the different models and start playing with one.

Thanks all.

How or what do you use to get C to talk to a COM port? That would be very useful to some of us.

Arduino was made to be a Wiring side for Processing and Wiring as described in the book by that name.
The free JAVA based Processing Language is available, the Arduino IDE codes quite like it. Give it a look as it is very featured and well supported. There's even a section of the forum to discuss such things.

But yah, Arduino was made to do what you want among other things.

dave-in-nj:
this sounds like an XY problem.

http://xyproblem.info/

control the stepper motor and the DC servo motor and input values into the PC directly.

it has gobs (a technical term) of memory compared to an Arduino.

the lab equipment, running over a serial port could connect to the PC.

Ah, but this isn't what I want.

I want (specifically) a USB-connected peripheral device that itself connects to a few other devices. There are several reasons for this, ranging from trivial (cable management) to non-trivial (portability, usability with computers that lack serial ports).

I have built such a device with a different USB i/o board but it has some limitations and, for lack of a better word, inelegances. As I mentioned previously, it can't produce the roughly 1000-2000 microsecond square waves to control a servo motor. So it's stuck with a 2nd board with a 555 timer IC and a couple trimpots to tune its output for setting the left/right position of the servo. Works, but ugly.

This isn't a commercial product, but I'm making more than one, for me and several other people to use at different locations. There isn't any standardization of the computers, except the PC operating system. This needs to be a device that plugs into the USB port of a Windows PC and just works when the program is run on the PC.

Briefly, the lab equipment is a scale with a serial data port, and the device I'm building has various mechanisms for dispensing material onto the scale, first quickly in large rough amounts and then slowly with the motors, ultimately to milligram precision. The basic approach is quite simple; continuously monitor the scale weight, and tell the motors what to do based on that reading, and some customizable parameters related to the material being dispensed.

dave-in-nj:
learning a new language to run the Arduino as an extension of the PC, and then write a program in the PC to talk to a (comparatively) crippled piece of equipment seems a bit silly.

The need to write code to upload to the Arduino when what I wanted all along was to have code run on the PC is what led me to dismiss Arduino in the first place, when I started this project. It's only now, that the shortcomings of the i/o board I've got are becoming apparent, that I'm re-evaluating Arduino.

GoForSmoke:
How or what do you use to get C to talk to a COM port? That would be very useful to some of us.

The other (non-Arduino) i/o board ships with a driver and has an API for accessing its serial ports. It's as simple as using function calls like Send() and Receive() either a byte at a time or in blocks.

And if it had the resolution to spit out the control signal for a servo, or run a stepper motor without a separate hardware driver, it'd be perfect. :slight_smile:

GoForSmoke:
Arduino was made to be a Wiring side for Processing and Wiring as described in the book by that name.
The free JAVA based Processing Language is available, the Arduino IDE codes quite like it. Give it a look as it is very featured and well supported. There's even a section of the forum to discuss such things.

But yah, Arduino was made to do what you want among other things.

Thanks. Probably time for me to just go ahead and buy one and spend a day poking around with it.

168gr:
I want (specifically) a USB-connected peripheral device that itself connects to a few other devices. There are several reasons for this, ranging from trivial (cable management) to non-trivial (portability, usability with computers that lack serial ports).

'connects' how?

via gpio ? >> get a basic model

via serial ? >> get a mega 2560 (or are there others with multiple serial ports?)

From the sounds of it, a 2560 would be a better first Arduino for you.

Actually, question:

When you say "communicate with a piece of lab equipment over a serial port"

-> do you mean RS232 or USB ?

1:1:
-> do you mean RS232 or USB ?

RS232.

The Mega 2560 R3 is what I'm looking at now. Thanks.

Nice,

I've used USB/virtual COM port to 2560 then 232 proper to another mega successfully - cable distances had to be very short between the two mega to get the baud rates I needed, but if you're fine with 9600, you'll be able to go much longer ...

1:1:
Nice,

I've used USB/virtual COM port to 2560 then 232 proper to another mega successfully - cable distances had to be very short between the two mega to get the baud rates I needed, but if you're fine with 9600, you'll be able to go much longer ...

Baud rate can be very low. I was only sampling every 100 ms.

Am I likely to have issues with the Mega's UART being a different voltage than a standard RS232 port on the lab scale? I'm looking through documentation now but if the Mega is working at +/-3V don't want to fry it with 12V signals from the scale.

Yes you need to convert the RS232 voltage to TTL levels. This wil also invert the logic levels which is needed.

Why do you think the Mega has +/- 3V? It uses TTL levels of 5V for a mark and 0V for a space.

Grumpy_Mike:
Yes you need to convert the RS232 voltage to TTL levels. This wil also invert the logic levels which is needed.

Thanks. I've read a little about it, and it looks like SparkFun sells an inexpensive device to do it -

Is there any particular solution you recommend?

Grumpy_Mike:
Why do you think the Mega has +/- 3V? It uses TTL levels of 5V for a mark and 0V for a space.

I thought that because my basic problem is I don't know what I'm doing. :slight_smile: I've been reading about lots and lots of products and mixed it up.

Thank you for the correction.

Is there any particular solution you recommend?

Well if it were up to me I would just use a MAX323 chip, but that's me.