Go Down

Topic: XYPlotter Control Using Serial Port Doing Odd Things (Read 265 times) previous topic - next topic

MC4

I have a Makeblock xy plotter that I am trying to reprogram using Arduino code and Processing. I want Processing to send (via the serial port) an integer from 0-179  to actuate the servo; send 180, 181, and 182 to move the x-axis stepper one step back, one step forward, and to the home position, respectively; and 190, 191, and 192 to do the same with a y-axis stepper.

The servo is responding perfectly for values from 0-179. However, for all values Processing sends (once every 1 second) to the serial port from 180 to 3327, the x-axis stepper moves continuously in the negative direction. Above 3327 there is no movement. I am stumped.

I'm relatively new to this, so my approach may be flawed. If you have suggestions on that I'm all ears, but also want to be able to learn from this problem along the way. Thanks in advance for any ideas!

Code: [Select]

#include "MeOrion.h"
#include <SoftwareSerial.h>

MeStepper stepperX(PORT_1);
MeStepper stepperY(PORT_2);
MePort port(PORT_7);  //Servo
Servo myservo1;   // create servo object to control a servo
int16_t servo1pin =  port.pin2(); //attaches the servo on PORT_3 SLOT2 to the servo object
int val = 0;                     // Data received from the serial port (Learning Note: when datatype is changed to char, anything over 127 doesn't map correctly...)
int width = 1;                 // Number of steps for 1 unit of desired plotter movement

void setup() {
  myservo1.attach(servo1pin);  // attaches the servo on servopin1
  Serial.begin(9600);           // Start serial communication at 9600 bps
  stepperX.setMaxSpeed(1000);
  stepperX.setAcceleration(20000);
  stepperY.setMaxSpeed(1000);
  stepperY.setAcceleration(20000);
}

void loop() {
  if (Serial.available()) {      // If data is available to read,
    val = Serial.read();         // read it and store it in val
  }
  if(val < 180){
    myservo1.write(val);            // Set the servo position
    delay(15);                      // Wait for the servo to get there
  } else if (val=180){
      stepperX.move(-width);  //move one step in negative x direction
      stepperX.run();     
  } else if (val=181){
      stepperX.move(width);   //move one step in positive x direction
      stepperX.run();
  } else if (val=182){
      stepperX.moveTo(0);     //move to x direction home
      stepperX.run();
  } else if (val=190){
      stepperY.move(-width);  //move one step in negative x direction
      stepperY.run();
  } else if (val=191){
      stepperY.move(width);   //move one step in positive x direction
      stepperY.run();
  } else if (val=192){
      stepperY.moveTo(0);     //move to x direction home
      stepperY.run();
  } else{
                              //If unrecognized input, do nothing
  }
}

ieee488

Do you even know how to control the plotter using just a TeraTerm program? ? ?

If you can't even do that, I wouldn't bother with anything else.   :smiley-roll:


.

Robin2

I have a Makeblock xy plotter that I am trying to reprogram using Arduino code and Processing. I want Processing to send (via the serial port) an integer from 0-179  to actuate the servo; send 180, 181, and 182 to move the x-axis stepper one step back, one step forward, and to the home position, respectively; and 190, 191, and 192 to do the same with a y-axis stepper.
I don't know anything about the plotter you have but I suspect it is completely unrealistic to send single step commands over a serial connection.

For the control of my small CNC lathe my PC sends the number of steps that is required by all 3 motors and leaves it to Arduino to implement the complete move.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

MC4

Robin2, Thanks for pointing that out. I've toyed around with different values for width (normally using width=50), but even at width=1 the steppers do move, albeit slowly.

The main confusion I'm having stems from how the plotter only moves in the negative x direction, regardless of whether it is being sent commands to move in positive x, or even to move the y-axis stepper. Is something basic wrong with the structure of my code? I've wondered if it's a problem with how the data is being communicated across the serial port, but the servo works perfectly using the serial input, so I don't think that is likely the problem.

I may be trying to run before I can walk here, so if there are more basic skills I should master first any pointers would be welcomed.

ieee48, I'm looking into terminal emulators - thanks for the suggestion!

christop

How are you sending values larger than 255 in a byte? Serial.read() gives you an 8-bit value that ranges from 0 to 255.

Also, if there's no data to read, your code will repeat whatever action it previously did because "val" will still contain the same value as it had when you last read data.

Robin2

Let's get back to basics. What does this mean
Quote
I have a Makeblock xy plotter that I am trying to reprogram using Arduino code and Processing.
What exactly is a Makeblock xy plotter? - post a link to its datasheet or website.

What do you mean by "reprogram"?

Do you mean that you have changed the program inside the plotter?
OR
Do you mean that you want a different way to send commands to the standard plotter software?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up