Go Down

Topic: Using Arduino Uno Stepper Motor Shield with two stepper motors and RFID reader (Read 6993 times) previous topic - next topic

CaptainChainsaw

Hi,

I'm new to Arduino, in fact this is my very first project.  I thought I would do something useful and relatively simple.  What I am trying to achieve is to use two stepper motors to rotate 180 degrees so that it will pull/push two door locks.  When I looked in to the idea it seemed complex to operate two stepper motors so I tried to keep it simple and buy a motor shield.  I decided on this one:

Stepper Motor Shield that I'm using:
http://altelectronics.co.uk/shop/arduino/arduino-stepper-motor-shield/prod_84.html

Stepper Motor Shield Datasheet:
http://altelectronics.co.uk/shop/images/uploads/datasheets/Arduino_Stepper_motor_shield_datasheet_v1.0.pdf

Shield Schematics:
http://altelectronics.co.uk/shop/images/uploads/schematics/Arduino%20_%20L6470_shield.pdf

Shield Example software:
http://altelectronics.co.uk/shop/images/uploads/software/dSPIN_example_v2.0.zip

This shield will operate two stepper motors (other shields I've come across only control one stepper motor).


Type of stepper motor I'm using:
http://www.hobbytronics.co.uk/motor-control/stepper-motors/stepper-motor

I want to trigger the motors using an RFID reader (RFID-RC522 Funduino).  Using the example code for the stepper motors I can get them to run so I know that code works.  Also I can get the RFID code to run too.  The problem is when I try to attach the RFID reader to the motor shield nothing works.  Obviously the code would need modified to operate both of these, I did try this, but I couldn't get it to work.  I think there's something more fundamentally wrong with what I'm doing.  I have a feeling that I'll need to use different Arduino pins to attach the RFID reader I just don't know how to figure this out.

I've also tried using the RFID code that works and connected the RFID reader to the motor shield exactly as I would if connecting directly to the Arduino, couldn't get anything to display on the serial monitor, I would expect to see something as I know the code works.

The only small nougat of information came from the datasheet:

Quote
STCK1, STCK2 signals

Step Clock signals are accessible on two pins
Arduino pin 4 & Arduino pin 8
(PD4 & PD0
respectively) for driving the step movement directl
y from Arduino. For using this feature the proper
STCK mode has to be programmed and the Direction of
the movement via config register (is not
enabled by default)


To summarise, I can get both motors to run with the example code, I can also get the RFID code to run with its example code if connecting the RFID reader to the Arduino directly.  When I try to connect the RFID reader to the motor shield it doesn't work when only using the RFID code.

I've attached the RFID code and the documentation I have on it.

Anybody got any idea how to to figure out what I need to do in order to get the motor shield to accept the RFID signal so that I can switch the motors on and off?

I'm now pretty lost with this, I'm pleased I managed to at least get the motors running :)

Any help with this would be sincerely appreciated.

CaptainChainsaw

Grumpy_Mike

You can not and should not connect the RFID reader to the stepping motor.
You should connect both shield and reader to the arduino using diffrent pins and use software so that one triggers the other.

Post the code you are having trouble with.

CaptainChainsaw

I see I misunderstood how shields work generally,  probably because the motor shield I'm using is stackable.  What I'm now thinking is that I could use two Arduinos one to handle authentication of the RFID chip and the other to run the motors.  This would mean communicating between the Arduinos.  I guess for this to work I'd need to make sure that the transmit/receive pins are available.

I would send a signal to the transmit pin if authentication was successful, the other Arduino would then pick up this signal and run the motors.  When the code that runs the motors completes it would then send a signal back to the first Arduino and an LED would light up.

This sound like a feasible approach?  This way I could separate out the code and I think I would be able to modify the example code myself.  The biggest change I'd need to make would be the sending/receiving data between the Arduinos.

Thanks again,

CaptainChainsaw

Grumpy_Mike

Quote
What I'm now thinking is that I could use two Arduinos one to handle authentication of the RFID chip and the other to run the motors. 

It is a classic beginners mistake to think that using two Arduinos makes things easier, it doesn't it only makes it more complecated communicating and synchronizing between the two.

This is a very simple project which you can do with one Arduino.

Do some of the tutorial examples and get to know the system before trying you own project.

CaptainChainsaw

The datasheet for the motor shield said that changing a jumper setting would change the CS line.  I changed that and updated the code and the motors still worked.  I then Added the RFID circuit and as that was using pin 10 for the CS line there was no conflict and that also works.  With the shield and RFID reader connected they both work when running their own code.  So the problem now appears to be when trying to use the code for both the shield and RFID reader at the same time.  I was hoping I'd be able to write something simple to say something like:

Code: [Select]

if(rfidTag == '12345')
{
  Serial.print("valid tag");
// invoke motors
}
else
{
  Serial.print("invalid tag")
  return false;
}


Unfortunately it isn't reading the rfid tag, I notice that there are the same values for many of the definitions and I expect this is at least part of the reason why it's not being read, here's one example (there are many more):

Code: [Select]

// RFID Code
#define PCD_IDLE 0x00 //NO action; cancel current commands

// motor code
#define dSPIN_OCD_TH_375mA  0x00


As far as I know the rest of the pins the RFID circuit is using is able to share them.

Anyone got any pointers on how to solve this?



CaptainChainsaw

Hi,

I've attached the code I'm currently using.  The first problem that's obvious when running it is that it breaks when trying to initialise the RFID reader.

The following code 3 is printed to the Serial Monitor, 4 isn't:

Code: [Select]

  /*
    RFID SETUP
  */
    Serial.print("RFID SETUP");
    pinMode(chipSelectPin,OUTPUT); // Set digital pin 10 as OUTPUT to connect it to the RFID /ENABLE pin
    Serial.print("1");
    digitalWrite(chipSelectPin, LOW); // Activate the RFID reader
    Serial.print("2");
    pinMode(NRSTPD,OUTPUT); // Set digital pin 5 , Not Reset and Power-down
    Serial.print("3");
    MFRC522_Init();
    Serial.print("4");
    Serial.print("END RFID SETUP");
    /*
      END RFID SETUP
   */
 



This is the init function:

Code: [Select]

/*
* Function?InitMFRC522
* Description?initilize RC522
* Input parameter?null
* Return?null
*/
void MFRC522_Init(void)
{
    digitalWrite(NRSTPD,HIGH);

    MFRC522_Reset();
         
    //Timer: TPrescaler*TreloadVal/6.78MHz = 24ms
    Write_MFRC522(TModeReg, 0x8D); //Tauto=1; f(Timer) = 6.78MHz/TPreScaler
    Write_MFRC522(TPrescalerReg, 0x3E); //TModeReg[3..0] + TPrescalerReg
    Write_MFRC522(TReloadRegL, 30);
    Write_MFRC522(TReloadRegH, 0);
   
    Write_MFRC522(TxAutoReg, 0x40); //100%ASK
    Write_MFRC522(ModeReg, 0x3D); //CRC initilizate value 0x6363 ???

    //ClearBitMask(Status2Reg, 0x08); //MFCrypto1On=0
    //Write_MFRC522(RxSelReg, 0x86); //RxWait = RxSelReg[5..0]
    //Write_MFRC522(RFCfgReg, 0x7F); //RxGain = 48dB

    AntennaOn(); //turn on antenna
}


Any ideas?

Thanks again :)

Grumpy_Mike

What is the VTSerial.h library you are using? It won't compile without it. Have you a link?

CaptainChainsaw

I've attached the lib that I'm using.  The code compiles fine so it doesn't seem related to the lib.

Grumpy_Mike

Quote
The code compiles fine so it doesn't seem related to the lib.

Yes but without it I can't compile your code can I?

Quote
The following code 3 is printed to the Serial Monitor, 4 isn't:

So you need to do the same debug thing with the MFRC522_Init function and find where that is choking.
If you find you can't do that, or it shifts where freezes then it points out to running out of memory ( SRAM )

CaptainChainsaw

I did attach the lib to my last post so that you could compile it.

Yes I'll have a look at that function and see what's going on with it.  From a brief look at the code I can see that the following value is used both by the stepper motor shield and the RFID reader:
Code: [Select]

0x40

This refers to this line within the function:

Code: [Select]

Write_MFRC522(TxAutoReg, 0x40); //100%ASK


Does this refer to part of a memory address?  If it does indeed require more memory can this be added easily?  Would it then be a case of changing these values so that there's no conflict?

First thing I should do is try and find out what's going on with that function though.


Grumpy_Mike

Quote
From a brief look at the code I can see that the following value is used both by the stepper motor shield and the RFID reader:

Yes but what does it mean?
It looks like it is a value being written to the MFRC522.

Quote
Does this refer to part of a memory address?

No.

Quote
If it does indeed require more memory can this be added easily?

No. - not even with difficulty on any arduino but the mega.

Quote
First thing I should do is try and find out what's going on with that function though.

Yes

CaptainChainsaw

I've had a look at the function that's causing the problem, the issue lies with when its trying to write data.

This is the function

Code: [Select]

/*
* Function?Write_MFRC5200
* Description?write a byte data into one register of MR RC522
* Input parameter?addr--register address?val--the value that need to write in
* Return?Null
*/
void Write_MFRC522(uchar addr, uchar val)
{
  Serial.print("-Write_MFRC522 1-");
    digitalWrite(chipSelectPin, LOW);
Serial.print("-Write_MFRC522 2-");
    //address format?0XXXXXX0
    Serial.print(addr);
    Serial.print("-");
    Serial.print((addr<<1)&0x7E);
    SPI.transfer((addr<<1)&0x7E);
    Serial.print("-Write_MFRC522 3-");
    SPI.transfer(val);
    Serial.print("-Write_MFRC522 4-");
    digitalWrite(chipSelectPin, HIGH);
    Serial.print("-Write_MFRC522 5-");
}




The line that it breaks on is this:

Code: [Select]

SPI.transfer((addr<<1)&0x7E);


When printing addr out to the serial monitor "1" is displayed

When printing (addr<<1)&0x7E to the serial monitor "2" is displayed.

What would this indicate?  Any ideas?

Grumpy_Mike

Quote
When printing addr out to the serial monitor "1" is displayed
When printing (addr<<1)&0x7E to the serial monitor "2" is displayed.

Well that final value is to be expected given the input of addr being set to 1, so it is not much of a clue.

It is odd that writing to an external device would stop the code running on the processor, it should not have any effect.

Have you got a schematic of how you have connected it up?

CaptainChainsaw

Good news, I got the RFID reader to read the tag and then run the motors.  I just need to program the motors to run the way I need them to.  Just by simply moving the function call that initialises the RFID reader to the end of the block of code it was in solved it.

I was thinking of using another reader so I've got one on the outside of the door and one on the inside.  If I join the wires so that both RFID readers use the same arduino pins would that work?  I'm thinking the voltage would half which may prevent it working.  I'm also thinking that as only one reader would get used at a time it wouldn't cause a conflict pinwise - however I could be very wrong.

Thanks again

Go Up