I keep getting an error with my arduino code, Please help


#1

Hi,
My Arduino code was working perfectly fine until I needed to upload it again and then it showed an error code
Please help.

#include <SPI.h>
#include <Wire.h>
#include <MFRC522.h>
#include <Servo.h>
#define RST_PIN 9
#define SS_PIN 10

#define address 2

uint16_t xor_uid = 0;

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

void setup()
{
Serial.begin(9600);
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
Wire.begin(address); // join i2c bus with address #8
Wire.onRequest(sendCardInfo); // register event
//mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max);
myservo.attach(6);
}

uint16_t read_card() {
uint16_t xor_uid = 0;
if (! mfrc522.PICC_ReadCardSerial())
{ //Okay. This does the same PICC_Select as the previous ReadCardSerial(), but this one fails if there is no card on the reader. Funny.
//Seems like we need two Select’s in a row to detect card’s presence.
xor_uid = 0;
}
else
{
for (int i = 0; i < mfrc522.uid.size; i=i+2)
{
xor_uid = xor_uid ^ (mfrc522.uid.uidByte[i]<<8 | mfrc522.uid.uidByte[i+1]);
}
}
return xor_uid;
}

void loop()
{
mfrc522.PICC_ReadCardSerial(); //Always fails
mfrc522.PICC_IsNewCardPresent(); //Does RequestA
xor_uid = read_card();
if (xor_uid > 0) {
myservo.write(180);

}
else
{
myservo.write(0);
}
delay(1);
}

void sendCardInfo() {
byte myArray[2]; //Thanks http://thewanderingengineer.com/2015/05/06/sending-16-bit-and-32-bit-numbers-with-arduino-i2c for this solution
myArray[0] = (xor_uid >> 8) & 0xFF;
myArray[1] = xor_uid & 0xFF;
Wire.write(myArray, 2);
}

My error code is:

Sketch uses 6966 bytes (21%) of program storage space. Maximum is 32256 bytes.
Global variables use 439 bytes (21%) of dynamic memory, leaving 1609 bytes for local variables. Maximum is 2048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xf4
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xf4
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xf4
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xf4
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xf4
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xf4
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xf4
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xf4
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xf4
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xf4
Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

Please help the Arduino site doesn’t help at all
thanks :slight_smile:


#2

Hi,

Double check your board settings. Go to Tools and make sure to choose the correct board, its model and the correct com port

Good Luck.


#3

I have a question for you. Does this error message come up when you have a different code in your Arduino? Like is this the only program that comes back with this error message or is it all of the programs you make?