Week18 Continue Mechanical and Machine

Continue our work of the eggbot for stroboscopic animation.

From code to motor move

Problem 1: the Arduino stepper moving is a blocking function

First I tried the Arduino built-in stepper motor code, and found the move function is blocking hence I cannot control multiple stepper motors to move simultaneously.

I searched and found the AccelStepper which seemed meet my needs.

Problem 2: the stepper motor shaked

I read the pinouts [http://domoticx.com/arduino-shield-cnc-shield/]. For each motor there are only 3 pins, I’ve no idea and guessed to use the pin8 (stepper enable/disable).

It works well for single motor, but shaked randomly when the two motors run together.


I checked power, connectivity, but no finding. I thought it must becuase I set the wrong pin.

I followed sample code from the CNC shield documentation again, and use the same constructor. The motor worked fine for single but did not run at all when used in MultiStepper.

Then I read the MultiStepper document more carefully, and found this note:
Caution: only constant speed stepper motion is supported: acceleration and deceleration is not supported All the steppers managed by MultiStepper will step at a constant speed to their target (albeit perhaps different speeds for each stepper).

I modified the code to set maxSpeed instead of acceleration, and the motors worked well finally.

Problem 3: add the servo for pen up and down

From the CNC shield, I could not find free pin for servo. Lucky that although we have 4 stepper motors in the machine, but only need two to run simultaneously. Thus, I connect the servo with stepper motor Z’s step pin, and it worked fine.

Problem 4: the original E-code is too complex

I updated the E-Code design as following: * D: pen down, run the servo S to make pen touch the egg * U : pen up, run the servo S to make the pan not touch the egg * P: use stepper motorB and P * T: use stepper motorB and T * x1,y1;x2,y2;x3,y3;…;xn,yn;#
* the position pairs for motors to move to;start with * and end with #;each pair is in
x,y;* format

For example, the following code draws two squares: PU*0,0#D*0,100;100,100;100,0;0,0;#U*300,300;#D*300,400;400,400;400,300;300,300;#U

From processing to arduino

I wrote a processing project to simulate the animations.

You can see the static image, and then adjust the rolling speed to get different animations.

It also allow user draw pattern and see the animation result.

Problem5: the motor did not run

It send the code to arduino use Serial port. However, the motor did not run at all after sending the data.

Debugged for a while and I found its because the string is too long and Arduino cannot handle it. Although I have the limitation in Processing code, it did not help, because

    if(this.cmd.length()>300) {
      this.send();
    }

After change the Arduino code from ReadString to ReadUntil(“\n”), it worked fine.

We tried with table tennis ball, and it worked but with some flaws. The connection under the ball was to soft so it bent while painting. The axle center of the pen was not aligned with the ball, so the pen did not touch the ball all the time. We will fix these issues with some new 3D printed components.

Useful links:
CNC shield datasheet
details about 4988 stepper motor driver