Controlling stepper motors without Maxuino (adventures)


    Dec 18 2015 | 3:53 pm
    using this simple arduino sketch I was able to get the motor spinning.
    const int stepPin = 3; 
    const int dirPin = 4; 
     
    void setup() {
    
      pinMode(stepPin,OUTPUT); 
      pinMode(dirPin,OUTPUT);
      
    }
    void loop() {
      digitalWrite(dirPin,HIGH); 
    
      digitalWrite(stepPin, HIGH);
      digitalWrite(stepPin, LOW);
    
      delayMicroseconds(1000);
    }
    
    It can be somewhat inconsistent with the delay at 1000 microseconds. Sometimes when I upload the sketch, the motor stalls and I have to reupload it, and then it will start working. I have managed to push it down to 975 at times.
    ------
    The next step obviously is controlling it with Max. I have already tried it with Firmata/Maxuino and it works splendidly. The ability to store each motor's parameters, and then control step/speed/acceleration/deceleration is amazing. However it can only control 6 motors at a time. This is an issue because my final project involves 30 motors. First of all, a single arduino uno can't control that many motors so i'd have to have multiple arduinos and that means multiple instances of maxuino running. So that limit shouldn't be an issue. I might even use a Mega/Due so i can control more motors on one board. However the next issue is the speed at which I can send all these motors signals.
    I'll present the next bit of code to control the motors through Max.
    const int stepPin = 3; 
    const int dirPin = 4; 
    int xDIR = 0;
    byte xStep = 0;
     
    void setup() {
    
      pinMode(stepPin,OUTPUT); 
      pinMode(dirPin,OUTPUT);
      Serial.begin(9600);
      
    }
    void loop() {
      digitalWrite(dirPin,HIGH); 
      
      xStep = Serial.read();
    
      digitalWrite(stepPin,xStep);  
    
    }
    
    Using this (and the attached patch, copy compressed doesn't seem to be working properly) I'm able to turn on/off the spinning of a motor using pulses from a [metro] and control the speed depending on how fast the metro is. The baud rate 9600 seems to be a bit too slow and messages get backed up. I'm not sure if this is due to the Arduino Uno being slow, or more of a combination of serial speeds/baud rate. I've increased the baud rate, and sometimes it works, but sometimes the motor can spin choppily and make weird chunky/clunky sounds.
    So maybe messages are getting bottlenecked by the speed of USB and I would benefit from using ethernet/wifi. So a couple of questions:
    Can I change my arduino code or baud rate at all to deliver more consistent results? Is the way I'm sending pulses from Max to the Arduino the best way of doing it? Would upgrading from an Uno to Mega/Due be better for message transmission speeds? Is ethernet/wifi (and [udpsend]) the way to go with sending messages to 30 motors? If so, does Maxuino/Firmata(configurable) support this type of transmission?) My control station computer won't be near to the motors, so i'm running at least 15 meters of wire between, and I'm guessing ethernet will be better than USB (even with active usb extenders).
    Cheers, Greg
    ------
    all that said, maxuino/firmata runs really well, better than any arduino sketch/max patch I can come up with right now. However, I'd love to see any alternatives.