Waiting for Fedex for my stepper motor

Discussion in 'Mac Programming' started by larswik, Jan 31, 2011.

  1. larswik macrumors 68000

    Joined:
    Sep 8, 2006
    #1
    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
     
  2. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #2
    Boy, you've got three plates spinning at once? Pascal, C, Arduino.

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

    B
     
  3. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #3
    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
     
  4. admanimal macrumors 68040

    Joined:
    Apr 22, 2005
    #4
    Do the motors and/or whatever they are attached to (the Arduino board, I guess) have Bluetooth or WiFi support?
     
  5. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #5
    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
     
  6. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #6
    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
     
  7. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #7
    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.

    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
     
  8. notjustjay macrumors 603

    notjustjay

    Joined:
    Sep 19, 2003
    Location:
    Canada, eh?
    #8
    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.
     
  9. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #9
    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?
     
  10. admanimal macrumors 68040

    Joined:
    Apr 22, 2005
    #10
    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.
     
  11. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #11
    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
     
  12. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #12
    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?
     
  13. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #13
    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
     
  14. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #14
    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.
     

Share This Page