I want to control a stepper motor and a servo, so was thinking of an Arduino with the Motor Shield.
However, this is as part of a larger C++ project, using cameras, OpenCV, PointCloud Library etc.
Currently I have a StepperBee to control a stepper motor, but if I add a servo controller, I will end up with 2 usb cables and 2 control boards (one to control stepper, one to control servo). The StepperBee runs as a C++ library, integrated into my larger C++ project, so works well as I can #include the library and control the stepper motor from within my larger program.
My question :
Can Arduino be integrated into a larger (standard) C++ project or does it always have to be saved as a .pde with setup() and loop(), but no main() ?
If not, can anyone suggest the most cost effective way to control a stepper and a servo using a single control board (and just one usb cable!), which can be run as a library #included into a larger C++ project.
It is possible to program the Arduino without using the Arduino IDE. You can use any
compiler process which can generate the compiled assembly language to download
into the Atmel processor.
Whether you can "integrate" this code into a larger "project", would depend on which
"project" paradigm you are using.
I think the issue is that I want to control the stepper motor and servo 'live' from my PC. Currently, I control the stepper with a StepperBee controller board and I can write the following in my C++ code :
#include <st.h> // include the stepperbee library
int main() {
...do some things (eg read images from a camera, process with OpenCV etc)
motor1.step(20) // advance stepper motor by 20 steps
..do some more things (eg more frames captured, user inputs etc etc)
}
From what you say, it sounds like this 'live' control embedded in a C++ program might be difficult to achieve with the Arduino. Is it really designed to work as a standalone unit ? If so, perhaps it is not the right solution for my needs (control a stepper motor AND servo using one USB link, with control signals sent from a C++ program)
The word 'Arduino' covers a number of different hardware solutions but even the humble Uno is able to control a stepper motor and servo based on commands sent over a serial link to its USB socket.
A brief look at the stepperbee suggests that it's working very much as an Arduino attached to a PC would. The PC program is sending commands to it over USB but that's wrapped in a library so that it looks more integrated. You could control a stepper and a servo from an arduino easily enough, but you would have a bit more coding work devising a serial protocol to handle the communication between the PC and the arduino for the PC to give instructions as to what those peripherals should do.
OK, I think I understand. To achieve live control of several motors from my PC I would :
Write a sketch which reads input pins on the Uno board (sent via USB) and moves the motor accordingly.
Upload this to the Arduino Uno
In my normal C++ (Visual Studio Express 2010) editor, write my code, including adding a library which can talk to a USB port
To move the motor I then simply send a pulse down the USB to the predefined input pin.
Nearly
Write a sketch on the Arduino that controls the motors/servos by writing to its pins. The sketch reads the serial input and sets the pins appropriately to move the motors/servos. This is probably what you meant but it was not quite what you wrote.
Thanks, yes, that is what i meant, though articulated poorly!
Writing the sketch looks quite straightforward.
So my only trauma now is the part where i need to get my C++ program to send info to the right input pins on the Arduino board, via USB
(Previously this magic has been hidden in my StepperBee library so i didn't have to worry about it)
I'm not sure I'd burden the PC with the intimate details of what pins things are attached to - let the Arduino worry about that. I'd build a little protocol that would let me send packets on the serial port to say things like "Stepper 1, 300 steps clockwise" or "servo 6 to 150 degrees". Depending on your needs, you might have the arduino respond to let you know when it's done.