Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
I am excited that my Stepper motor and motor driver are coming today to pair up with my Arduino board I got a few months ago. Everything I have been learning in C can be put to the test tonight as I try to write a program to spin it around. I have read a few articles on the web about writing and compiling code in Xcode instead of the Arduino IDE.

Hope I can find them :)

-Lars
 
Boy, you've got three plates spinning at once? Pascal, C, Arduino.

Good for you! Let us know how it turns out.

B
 
I know it's nuts. Pascal I have to take to get into iphone programing class which I guess is their way of saying Objective-C. C is good because it is the foundation of driving DC Servos and stepper motors. My end goal which I mentioned before is to use an ipad to drive stepper motors via blue tooth. I don;t know if the new Game Kit SDK's allow this yet. I did see on the news that a mega yachts interiors are controlled but an iPad. So it has to be blue tooth of Wi-Fi.

-Lars
 
Do the motors and/or whatever they are attached to (the Arduino board, I guess) have Bluetooth or WiFi support?
 
I did see on the news that a mega yachts interiors are controlled but an iPad. So it has to be blue tooth of Wi-Fi.

-Lars

Don't assume that. The control module might have an http interface or something like that... so yes, it's getting to that via wi-fi, but it doesn't mean that the iPad is doing anything "special" to get at the hardware.

-Lee
 
Don't assume that. The control module might have an http interface or something like that...

Or serial via the headphone port or dock connector (output only via audio out).

Apple may hold the keys to the digital wired interface, but analog (audio) provides an easy workaround for low bitrates.

B
 
Do the motors and/or whatever they are attached to (the Arduino board, I guess) have Bluetooth or WiFi support?

Nope. It is a USB cable but they do sell bluetooth boards. I don't want to get a head of myself though, I want to make this work first. Tonight will be the first night that I get to play with hardware and test my C skills to date.

Don't assume that. The control module might have an http interface or something like that

That is true. The final product that I want to make will have a micro controller with bluetooth on board. My friend said he would help me with that part since he works for the military designing hardware. I would think that iPad OS would be able to do a handshaking with 3rd party hardware to upload information to the Micro Controller. I don't know what is included with the new Game Kit SDK they released though. I heard dome bluetooth stuff. I am still a couple years away at the rate I am learning / working so I hope that feature will be there when I am.

-Lars
 
You can get both Bluetooth and WiFi modules for the Arduino.

Probably the thing to do is develop some simple state control software running on the Arduino that would feed the stepper driver board. I assume the driver board takes care of the pulse patterns for you, so you'd basically just issue step/direction commands to it. You could develop an interface that simply passed those along over the wireless connection, but the logical approach might be to develop a higher level interface, so you can define commands like "rotate 175 degrees clockwise" or "move to position A" (assuming the stepper is controlling some kind of axis motion) or "rotate at 100% speed" (assuming you defined multiple speed pulse rates). All depends on what your motor application is.
 
I got everything in tonight and plugged in. The test code from xcode worked and it caused the board to blink like it should. The template that I bring up every time has default information on the screen almost like when I start a new C project it has the default "Hello World" That I delete. Here is the code
Code:
#include "WProgram.h"
#include "SoftwareSerial.h"

// prototypes
void blink(int n, int d);

// variables
int ledPin = 13; // LED connected to digital pin 13


void setup(){
	Serial.begin(9600);	// opens serial port, sets data rate to 9600 bps

	pinMode(ledPin, OUTPUT);      // sets the digital pin as output
	Serial.println("------------------");
	Serial.println("   hello world");
	Serial.println("------------------");
}


void loop(){

  blink(2, 500); // blink led 2 times, 500 ms interval
  delay(1000); // wait 1 sec
}




void blink(int n, int d){
  for (int i=0;i<n;i++)
  {
    digitalWrite(ledPin, HIGH);
    delay(d/2);
    digitalWrite(ledPin, LOW);
    delay(d/2);
  }
}

int main(void)
{
	init();

	setup();
    
	for (;;)
		loop();
        
	return 0;
}

I understand the 'void blink' prototype and can see that function. What I don't get is the 'void setup()' and 'void loop()'. It seems to me that they are functions but I see no prototypes for them. Then in main() I see a call to 'init();' but I don't see any function defined for it?
 
Prototypes are not mandatory in C. All that matters is that either a prototype or the function definition itself comes before any use of the function.

The init function must be defined in some other piece of code that you're linking with the project, and must be declared in one of the headers you include.
 
The init function must be defined in some other piece of code that you're linking with the project, and must be declared in one of the headers you include.
Specifically look at these two files
Code:
#include "WProgram.h"
#include "SoftwareSerial.h"
if you don't see an prototype for init look at any other header files that may be included in those headers.

B
 
larswik, you're supposed to provide the functions 'void setup(void)' and ' void loop(void)'.

The Arduino IDE does some preprocessing of your project before compilation, including scanning your code and inserting function declarations for you.


I'm curious. Did you say above somewhere that you are using Xcode as your IDE? If so can you point me to where you learned to setup an Xcode project for such use?
 
I got the information on this site for setting for using xcode.
http://www.quietless.com/kitchen/se...e-upload-to-an-arduino-atmega328-duemilanove/

The template above was the default when I select it from the 'others' section when I create a new project. I want to strip it down and save a new template that only has what it needs to to start a new Arduino project. I am guessing it is only the 2 #includes, int ledpin, setup() and init() in main. The rest is for the blinking led.

-Lars
 
Well it'll probably need a few more include files than that. Again the Arduino IDE also inserts some additional include files during the compilation process.

In the Arduino IDE bring up your (or a) project (sketch in their parlance) hold the "shift" key down and hit the compile button. This will output the complete sequence of tools with options and (I think, but can't remember for sure) files used to build the executable.

Thanks for the link I hope to take a look at in this evening.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.