Go Down

Topic: 28BYJ48 Stepper Motor Physical Resistance Problem (Read 345 times) previous topic - next topic

kunwarsethi

Jan 09, 2018, 06:03 am Last Edit: Jan 09, 2018, 06:08 am by kunwarsethi
Hi Everyone,
I'm new to coding on Arduino and i'm new to stepper motors in general.

  • Objective: Detect physical resistance to "home" my 28BYJ48 stepper motor and UN2003 driver board.
  • Cannot use a limit switch in my project which is why i'm relying on voltage drop.
  • Using a ESP8266 (ESP-12E) wifi controller.
  • I've tried Accelstepper but I can't seem to understand it, I will eventually try to move towards it because of the built in homing feature.

Wiring: (The driver board is wired to the ESP-12E pins 16,4,0,5)
https://ibb.co/cqWsp6
I was looking at some of SBright33s posts about connecting the input directly to one of the motor windings to detect a voltage drop and while that does work, the voltage fluctuates too much when it goes from one winding to the next.  It's been about 6 weeks since I've started this project and I haven't been able to figure it out myself which is why i'm asking for help. Here's what I have so far..



Code: [Select]
#include <Stepper.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

const char *ssid = "myESPNetwork";
const char *password = "password"; //the password should be 8 char or more
ESP8266WebServer server(80);

//setting up the webpage:
char HTML[ ] = "<html><body><h1><a href=\"\\\"><button>Refresh</button></a><a href=\"calibrate\"><button>Calibrate</button></a></body></html>";
void handleRoot() {
  server.send(200, "text/html", HTML);
}

const int stepsPerRevolution = 514; //steps per revolution for the stepper motor
Stepper myStepper(stepsPerRevolution, 16, 4, 0, 5); //16,4,0,5 are the pins on the microcontroller

int steps;
int stepEnd;

void delaySeconds(int seconds) { //easier way to delay in seconds instead of milliseconds
  for (int i = 0; i <= seconds * 10; i++) {
    delay(100);
    ESP.wdtFeed();
  }
}

void setup() {
  Serial.begin(9600);
  Serial.println();
  Serial.print("Configuring access point...");
  /* You can remove the password parameter if you want the AP to be open. */
  WiFi.softAP(ssid, password);

  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.on("/", handleRoot);
  server.on("/calibrate", calibrate);
  server.begin();
  Serial.println("HTTP server started");  ESP.wdtDisable(); //WDT (Watch Dog Timer) Disable is for the wifi board so it doesnt soft reset it because nothing's happening
}
void loop() {
  server.handleClient();
  ESP.wdtDisable();
}

void calibrate() {
  server.send(200, "text/html", HTML);
  Serial.println("Calibrating...");
  delaySeconds(2);
  for (int i = 0; i <= 400; i++) { //just to check the voltage
    myStepper.step(-1);
    int sensor = analogRead(A0);
    float voltage = sensor * (1.6 / 1024.0); //for some reason 3.3/1024 isn't accurate
    Serial.println(voltage);
  }

  boolean motorOn = true;
  while (motorOn == true) { //spin counter-clockwise until voltage drops (hits a dead end)
    int sensorValue = analogRead(A0);
    float Voltage = sensorValue * (1.6 / 1024.0); //for some reason 3.3/1024 isn't accurate
    myStepper.step(-1);
    ESP.wdtDisable();
    float uvoltage = Voltage;
    if (Voltage > 1.1 && uvoltage < Voltage - .03) { //check if voltage is above 1.1 (while fluctuating) and if it drops .03V or more (when there's resistance) stop the motor
      motorOn == false;
      delaySeconds(2);
      break;
      Serial.println("Home Position Found!");
    }
  }

  steps = 0;
  Serial.print("Home Position:");
  Serial.println(steps);
  Serial.println("Looking for end position...");

  boolean motorOn = true;
  while (motorOn == true) { //spin clockwise until voltage drops (hits a dead end)
    int sensorValue = analogRead(A0);
    float Voltage = sensorValue * (1.6 / 1024.0);
    myStepper.step(1);
    steps++;
    myStepper.setSpeed(60);
    ESP.wdtDisable();
    float uvoltage = Voltage;
    if (Voltage > 1.1 && uvoltage < Voltage - .03) {
      motorOn == false;
      delaySeconds(2);
      break;
      Serial.println("End Position Found!");
    }
  }

  int stepEnd = steps;
  Serial.print("Ending Position:");
  Serial.println(stepEnd);
  Serial.println();
  Serial.println();
}



CrossRoads

You need some way to detect an increase in current as the motor hits the home stop and "stalls", drawing higher current until you stop driving it, or blow the motor driver. One way is to measure voltage across a shunt resistor. Might vary just as much as your current method tho.
If you don't want to measure voltage directly, you could compare the rise in voltage across the shunt (from increased current) using a comparator with a setpoint to drive a signal high or low into an interrupt pin or similar. See the LM358 circuit that does the autovoltage select on the Uno for an example, it compares Vin to 3.3V and drives the output high or low based on the comparison.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

kunwarsethi

I've tried checking the current on the winding and it doesn't go up for some reason, i'm guessing it's because the gears are slipping. I've also tried using a shunt resistor to check current but in my opinion I feel like it won't be reliable in the long run. I'll try looking into the voltage comparator tomorrow.

The main issue i'm frustrated with right now is that i'm able to detect voltage drop from the winding which is exactly what I want (it'll go from 3.3V to 3.05V without a voltage reducer, and from 1.4V to 1.21V with the 2 resistors in the voltage reducer) immediately when there's resistance but because of the fluctuation (reading 3.3V .8V .8V .8V 3.3V etc), the analog input on my ESP-12E isn't able to catch it even with my constraints.

TomGeorge

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Not the Fritzy picture, but a proper schematic, showing your stepper, the 2003 driver board and the ESP with power supplies.

Thanks..  Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

jremington

#4
Jan 11, 2018, 05:13 pm Last Edit: Jan 11, 2018, 05:16 pm by jremington
It is very difficult to detect a stalled stepper motor from the winding current alone. The current is essentially the same, regardless of whether the stepper is taking a step or stalled.

To detect an adjustable home position, limit switches or optical interrupters are almost always used, but another option is to send enough pulses to drive the motor into an end stop, regardless of the starting position. This won't damage the motor or the driver.

MarkT

You _cannot_ reliably detect stalls on stepper motors electrically, chose another approach.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

TomGeorge

Hi,
Wiring: (The driver board is wired to the ESP-12E pins 16,4,0,5)

I am trying to locate pin 0?
How are you powering the stepper?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Thanks.. Tom.. :)
Everything runs on smoke, let the smoke out, it stops running....

kunwarsethi

Hi, using this ESP-12E - https://acrobotic.com/media/wysiwyg/products/esp8266_devkit_horizontal-01.png

Going to use a different method because I agree that this isn't reliable enough. Thanks for all the replies.

TomGeorge

Everything runs on smoke, let the smoke out, it stops running....

Go Up