Hello,
I am working on a rfid enabled door unlocker using an arduino UNO Pololu DRV8825 stepper driver, and RC522 RFID module. Im struggling getting my stepper motors to turn. The code is much too long to post entirely here so im going to post chunks of the important parts to my question here:
Important note: i have the following code working on the arduino:
// ConstantSpeed.pde
// -*- mode: C++ -*-
//
// Shows how to run AccelStepper in the simplest,
// fixed speed mode with no accelerations
/// \author Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2009 Mike McCauley
// $Id: ConstantSpeed.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $
#include <AccelStepper.h>
AccelStepper stepper(1, 4, 3);
int slp = 8;
void setup()
{
digitalWrite(slp, HIGH);
//attachInterrupt(buttonInt, unlock, RISING);
stepper.setMaxSpeed(100000);
stepper.setAcceleration(100*4);
stepper.moveTo(50*8);
}
void loop()
{ fun();
}
void fun()
{stepper.run();
}
Now for the Not working code:
First include the accelstepper library
and tell the library what pins are hooked up:
AccelStepper stepper1(1, 4, 3);
then under void setup();
I set my max speed, acceleration, and distance
stepper1.setMaxSpeed(10000);
stepper1.setAcceleration(100*4);
stepper1.moveTo(50*8);
then on to my main loop. This basically check the EEPROM to see if a card is stored.
if ( findID(readCard) ) { // If not, see if the card is in the EEPROM
Serial.println("Welcome, You shall pass");
opendoor(); // Open the door lock
}
else { // If not, show that the ID was not valid
Serial.println("You shall not pass");
delay(10);
Warning: I am a beginner coder so this code is by no means close to perfect. I an trying my best to get it to work then i will optimize it.
Now for my functions i defined to open the door: The arduino runs the wakedriver() function which sets the slp (sleep pin) to high. The stepper motor is then under holding torque. Unfortunately it dosent do anthing else from h
void wakedriver()
{
digitalWrite(slp, HIGH); //power driver from sleep
delay(10); // Pause while the driver wakes up
}
void opendoor()
{
wakedriver(); //Run wake driver I HAVE THE DRIVER WAKING UP AND AT HOLDING TORQUE
stepper1.run(); //make stepper run based on what was done in setup
if (stepper1.distanceToGo()==0) //if the motors have moved the designated amount
{door();} //run door else have the steppers continue running. not sure if this is needed.
else
stepper1.run();
}
void door()
{
if (digitalRead(doorswitch)==HIGH); //check to see if the switch is pushed
lockdoor(); // if it is lock the door
}
void lockdoor()
{
stepper1.moveTo(-50*8); //move the steppers in the opposite direction to lock the door.
digitalWrite(slp, LOW); //put the driver in sleep mode to power down stepper.
}
Any and all help would be greatly appreciated
Tyler