Is the problem I have to do with wrong pins or code?

Hi,

I'm using a motor shield to run two stepper motors with my Arduino Mega. I also want to use an RFID reader. I've plugged everything in but I had to change two pins because SS (pin 5) and RESET (pin 53) are already being used by the motor shield. I changed the pins in the code to reflect the change I made but it doesn't seem to do anything. The code runs to a point, in my loop function I have this:

  // Look for new cards, and select one if present
  if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
    Serial.println("Select new card");
    delay(50);
    return;
  }

In the console it shows "Select new card" continually. That's all my code does.

Is this a problem with not using the pins as per the documentation or a code issue? My code is an Elegoo example and I've only modified the pin numbers.

Any thoughts?

Thank you :slight_smile:

My stepper motor shield:

My RFID board:

Here's my complete RFID code:

//www.elegoo.com
//2016.12.09

/*
 * --------------------------------------------------------------------------------------------------------------------
 * Example to change UID of changeable MIFARE card.
 * --------------------------------------------------------------------------------------------------------------------
 * This is a MFRC522 library example; for further details and other examples see: https://github.com/miguelbalboa/rfid
 * 
 * This sample shows how to set the UID on a UID changeable MIFARE card.
 * NOTE: for more informations read the README.rst
 * 
 * @author Tom Clement
 * @license Released into the public domain.
 *
 * Typical pin layout used:
 * -----------------------------------------------------------------------------------------
 *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
 *             Reader/PCD   Uno           Mega      Nano v3    Leonardo/Micro   Pro Micro
 * Signal      Pin          Pin           Pin       Pin        Pin              Pin
 * -----------------------------------------------------------------------------------------
 * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
 * SPI SS      SDA(SS)      10            53        D10        10               10
 * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
 * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
 * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
 */

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN   39     // Configurable, see typical pin layout above
#define SS_PIN    31   // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance

/* Set your new UID here! */
#define NEW_UID {0xDE, 0xAD, 0xBE, 0xEF}

MFRC522::MIFARE_Key key;

void setup() {
  Serial.println("Setup");
  Serial.begin(9600);  // Initialize serial communications with the PC
  Serial.println("1");
  while (!Serial);     // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  Serial.println("2");
  SPI.begin();         // Init SPI bus
  Serial.println("3");
  mfrc522.PCD_Init();  // Init MFRC522 card
  Serial.println("4");
  Serial.println(F("Warning: this example overwrites the UID of your UID changeable card, use with care!"));
  
  // Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
  for (byte i = 0; i < 6; i++) {
    key.keyByte[i] = 0xFF;
  }
}

// Setting the UID can be as simple as this:
//void loop() {
//  byte newUid[] = NEW_UID;
//  if ( mfrc522.MIFARE_SetUid(newUid, (byte)4, true) ) {
//    Serial.println("Wrote new UID to card.");
//  }
//  delay(1000);
//}

// But of course this is a more proper approach
void loop() {
  
  // Look for new cards, and select one if present
  if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
    //Serial.println("Select new card");
    delay(50);
    return;
  }
  
  // Now a card is selected. The UID and SAK is in mfrc522.uid.
  
  // Dump UID
  Serial.print(F("Card UID:"));
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
  } 
  Serial.println();

  // Dump PICC type
//  MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
//  Serial.print(F("PICC type: "));
//  Serial.print(mfrc522.PICC_GetTypeName(piccType));
//  Serial.print(F(" (SAK "));
//  Serial.print(mfrc522.uid.sak);
//  Serial.print(")\r\n");
//  if (  piccType != MFRC522::PICC_TYPE_MIFARE_MINI 
//    &&  piccType != MFRC522::PICC_TYPE_MIFARE_1K
//    &&  piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
//    Serial.println(F("This sample only works with MIFARE Classic cards."));
//    return;
//  }
  
  // Set new UID
  byte newUid[] = NEW_UID;
  if ( mfrc522.MIFARE_SetUid(newUid, (byte)4, true) ) {
    Serial.println(F("Wrote new UID to card."));
  }
  
  // Halt PICC and re-select it so DumpToSerial doesn't get confused
  mfrc522.PICC_HaltA();
  if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
    return;
  }
  
  // Dump the new memory contents
  Serial.println(F("New UID and contents:"));
  mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
  
  delay(2000);
}

Hi, @duin0n00b
Welcome to the forum.

Can you post link to data/specs of the shield?
Can you post link to data/specs of the RFID reader.
Can you post your complete code? (Using code tags)

Thanks... Tom.. :grinning: :+1: :coffee: :australia:

1 Like

No problem, understood. I've updated my post. Thank you :slight_smile:

I think I've fixed it, or at least progressed on to the next problem. I've changed the pins to more closely match the required pins. Seems to work with the changeable RESET pin, should be 5 but I'm now using 39.

So using pins:

RST/Reset RST 39
SPI SS SDA(SS) 53
SPI MOSI MOSI 51
SPI MISO MISO 50
SPI SCK SCK 52

An L293D shield is for brushed DC motors, NOT for (most) stepper motors.

Some low impedance hybrid stepper motors can be driven with that shield, but most modern stepper motors are low impedance (high current). If you use those with your shield, then you will smoke the motor or the driver chips on the shield.
Post the model number or weblink of the stepper motor, so we can check.
Leo..

Hi, this is the stepper I'm using:

If I need a new motor driver board, is there any you can recommend?

DN

An L293D is totally unsuitable for a 1.7Amp 1.65ohm stepper.
You need a current controlled driver, like the DRV8825.
Leo..

Thank you so much! I'll replace the motor driver board when the new ones arrive. I've got the stepper working with the current board but I'm only testing it so I'm thinking that's not going to use the full power of the motor.

DN

Seems you don't know that stepper motors on a common H-bridge use the most power when they are not running.
Leo..

It seems you are correct :slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.