0

Adafruit motor shield V2 motor status
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit motor shield V2 motor status

by chimerical26 on Thu Mar 04, 2021 12:21 pm

Is there any way that I can check the status of the motor?

For example, after I run:
myMotor->step(150, BACKWARD, DOUBLE);

I would like to be able to know when it has completed this so that I can trigger the next step.
PS. I am controlling the arduino over usb using pyserial so timing isn't great but I feel if I could tell that the motor has stopped moving it might help. Maybe I'm wrong.

chimerical26
 
Posts: 9
Joined: Sun Jan 24, 2021 11:20 pm

Re: Adafruit motor shield V2 motor status

by adafruit_support_bill on Thu Mar 04, 2021 12:26 pm

The adafruit stepper library is synchronous. The 'step' function will not return until the motor has completed all the steps.

adafruit_support_bill
 
Posts: 81329
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit motor shield V2 motor status

by chimerical26 on Thu Mar 04, 2021 2:30 pm

Thank you. It must be an issue with the way I'm using pyserial then. Appreciate the response.

chimerical26
 
Posts: 9
Joined: Sun Jan 24, 2021 11:20 pm

Re: Adafruit motor shield V2 motor status

by chimerical26 on Mon Mar 15, 2021 9:00 pm

When I run what I have below I get the output I have below. I would expect an X after every Ard Read if everything is working as it should. Serial connection works fine for simple programs that don't use the Adafruit shield. Without this return telling me the motor has completed its action I have to use timing which is not what I would like. This has been tormenting me for a while now. Can you offer any advice please? Thank you.


Arduino Code:
Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <Adafruit_MotorShield.h>
int incomingData;

Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);

void setup() {
  Serial.begin(9600);
  AFMS.begin();
  myMotor->setSpeed(50);
  TWBR = ((F_CPU /400000l) - 16) / 2;
}

void loop() {
  while (Serial.available()) {
    incomingData = Serial.read();
    if (incomingData == '5') {
      myMotor->step(10, BACKWARD, DOUBLE);
      Serial.println('X');
    }
  }
}


Python Code:
Code: Select all | TOGGLE FULL SIZE
import serial
from time import sleep

ard = serial.Serial('com3', 9600, timeout=0.5) #set up Arduino serial connection and baud rate
sleep(2)
i=0

while(i < 6):
    ard.write(b'5') #tell Arduino rotate 18 degrees
    sleep(0.5)
    i=i+1
    returned = ard.read().decode('ascii')
    print("Ard Read" + returned)

ard.close() # Close serial link with Arduino



Output:
Code: Select all | TOGGLE FULL SIZE
Ard ReadX
Ard Read

Ard Read

Ard ReadX
Ard Read

Ard Read

>>>

chimerical26
 
Posts: 9
Joined: Sun Jan 24, 2021 11:20 pm

Re: Adafruit motor shield V2 motor status

by adafruit_support_bill on Tue Mar 16, 2021 5:27 am

When I run what I have below I get the output I have below. I would expect an X after every Ard Read if everything is working as it should.

Using println(), you should expect an 'X' followed by an ASCII CR and an LF.
https://www.arduino.cc/reference/en/lan ... l/println/

If you want jus the 'X', you should use print(): https://www.arduino.cc/reference/en/lan ... ial/print/

adafruit_support_bill
 
Posts: 81329
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.