Hi
I am working on https://robokits.co.in/robot-kits/arduino-robot-kit/roundbot-arduino-compact-indoor-robot-fully-assembled?cPath=10_156& where I an trying to move the bot forward backward to read an RFID tag using RFID module. When I upload the navigation code and RFID reading part individually everything works fine. But when I am integrating both the codes to one file, only one motor moves. Somewhere SPI.begin() is causing and issue. I am new to arduino and need help figuring out the issue.
Below is my code :
<
#include <SPI.h>
#include <MFRC522.h>
#include<SoftwareSerial.h>
#include <MotorDriver.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
SoftwareSerial bt(0,1);
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
MotorDriver m;
//*****************************************************************************************//
void setup() {
bt.begin(9600);
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
}
void loop() {
while(Serial.available())
{
char In=Serial.read();
if(In=='f' || In=='F') // Forward
{
m.motor(1,FORWARD,255);
m.motor(2,FORWARD,255);
}
else if(In=='b' || In=='B') //backward
{
m.motor(1,BACKWARD,255);
m.motor(2,BACKWARD,255);
}
else if(In=='r' || In=='R') // Release
{
m.motor(1,RELEASE,0);
m.motor(2,RELEASE,0);
}
else if(In=='s' || In=='S') // stop
{
m.motor(1,BRAKE, 0);
m.motor(2,BRAKE,0);
}
}
// Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
MFRC522::MIFARE_Key key;
for (byte i = 0; i < 6; i++) key.keyByte = 0xFF;
-
//some variables we need*
-
byte block;*
-
byte len;*
-
MFRC522::StatusCode status;*
-
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.*
-
if ( ! mfrc522.PICC_IsNewCardPresent()) {*
-
return;*
-
}*
-
// Select one of the cards*
-
if ( ! mfrc522.PICC_ReadCardSerial()) {*
-
return;*
-
}*
_ Serial.println(F("Card Detected"));_
_ bt.println(F("Card Detected"));_ -
//-------------------------------------------*
-
mfrc522.PICC_DumpDetailsToSerial(&(mfrc522.uid)); //dump some details about the card*
-
byte buffer1[18];*
-
block = 4;*
-
len = 18;*
-
//------------------------------------------- GET FIRST NAME*
-
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 4, &key, &(mfrc522.uid)); //line 834 of MFRC522.cpp file*
-
if (status != MFRC522::STATUS_OK) {*
-
Serial.print(F("Authentication failed: "));*
-
Serial.println(mfrc522.GetStatusCodeName(status));*
-
bt.print(F("Authentication failed: "));*
-
bt.println(mfrc522.GetStatusCodeName(status));*
-
return;*
-
}*
-
status = mfrc522.MIFARE_Read(block, buffer1, &len);*
-
if (status != MFRC522::STATUS_OK) {*
-
Serial.print(F("Reading failed: "));*
-
Serial.println(mfrc522.GetStatusCodeName(status));*
-
bt.print(F("Reading failed: "));*
-
bt.println(mfrc522.GetStatusCodeName(status));*
-
return;*
-
}*
-
Serial.print(F("id: "));*
-
bt.print(F("id: "));*
-
//PRINT ID*
-
for (uint8_t i = 0; i < 16; i++)*
-
{*
_ if (buffer1 != 32)_
* {*
_ Serial.write(buffer1*);
bt.write(buffer1);
}
}
byte buffer2[18];
block = 1;_
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 1, &key, &(mfrc522.uid)); //line 834*
* if (status != MFRC522::STATUS_OK) {
_ Serial.print(F("Authentication failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
bt.print(F("Authentication failed: "));
bt.println(mfrc522.GetStatusCodeName(status));
return;
}_
status = mfrc522.MIFARE_Read(block, buffer2, &len);
if (status != MFRC522::STATUS_OK) {
_ Serial.print(F("Reading failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
bt.print(F("Reading failed: "));
bt.println(mfrc522.GetStatusCodeName(status));
return;
}
Serial.println();
bt.println();
Serial.print(F("Category: "));
bt.print(F("Category: "));
//PRINT NAME*
* for (uint8_t i = 0; i < 16; i++) {*
Serial.write(buffer2 ); // Serial.write
bt.write(buffer2 );
* }
Serial.println();
bt.println();
Serial.println(F("End Reading"));
bt.println(F("End Reading"));
delay(1000); //change value if you want to read cards faster*
* mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();*
}
/>
RKI-3200.pdf (554 KB)_