Fingerprint sensor

Hey I got this error message and anyone please help me out.

Arduino: 1.8.7 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\dchan\AppData\Local\Temp\arduino_modified_sketch_731187\sketch_feb14b.ino: In member function 'uint8_t Adafruit_Fingerprint::getStructuredPacket(Adafruit_Fingerprint_Packet*, uint16_t)':

sketch_feb14b:306:3: error: expected '}' at end of input

}

^

exit status 1
expected '}' at end of input

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Please post your full sketch. If possible, you should always post code directly in the forum thread as text using code tags (</> button on the toolbar). This will make it easy for anyone to look at it, which will increase the likelihood of you getting help. If the sketch is longer than the forum will allow then it’s OK to add it as an attachment. After clicking the “Reply” button, you will see an “Attachments and other settings” link.

Please always do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

When your code requires a library that’s not included with the Arduino IDE please post a link (using the chain links icon on the toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html . Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile:

#include "Adafruit_Fingerprint.h"
#if defined(__AVR__) || defined(ESP8266)
    #include <SoftwareSerial.h>
#endif
//#define FINGERPRINT_DEBUG
#if ARDUINO >= 100
  #define SERIAL_WRITE(...) mySerial->write(__VA_ARGS__)
#else
  #define SERIAL_WRITE(...) mySerial->write(__VA_ARGS__, BYTE)
#endif
#define SERIAL_WRITE_U16(v) SERIAL_WRITE((uint8_t)(v>>8)); SERIAL_WRITE((uint8_t)(v & 0xFF));
#define GET_CMD_PACKET(...) \
  uint8_t data[] = {__VA_ARGS__}; \
  Adafruit_Fingerprint_Packet packet(FINGERPRINT_COMMANDPACKET, sizeof(data), data); \
  writeStructuredPacket(packet); \
  if (getStructuredPacket(&packet) != FINGERPRINT_OK) return FINGERPRINT_PACKETRECIEVEERR; \
  if (packet.type != FINGERPRINT_ACKPACKET) return FINGERPRINT_PACKETRECIEVEERR;
#define SEND_CMD_PACKET(...) GET_CMD_PACKET(__VA_ARGS__); return packet.data[0];
/***************************************************************************
 PUBLIC FUNCTIONS
 ***************************************************************************/

#if defined(__AVR__) || defined(ESP8266)
/**************************************************************************/
/*!
    @brief  Instantiates sensor with Software Serial
    @param  ss Pointer to SoftwareSerial object
    @param  password 32-bit integer password (default is 0)
*/
/**************************************************************************/
Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial *ss, uint32_t password) {
  thePassword = password;
  theAddress = 0xFFFFFFFF;
  hwSerial = NULL;
  swSerial = ss;
  mySerial = swSerial;
}
#endif
/**************************************************************************/
/*!
    @brief  Instantiates sensor with Hardware Serial
    @param  hs Pointer to HardwareSerial object
    @param  password 32-bit integer password (default is 0)
*/
/**************************************************************************/
Adafruit_Fingerprint::Adafruit_Fingerprint(HardwareSerial *hs, uint32_t password) {
  thePassword = password;
  theAddress = 0xFFFFFFFF;
#if defined(__AVR__) || defined(ESP8266)
  swSerial = NULL;
#endif
  hwSerial = hs;
  mySerial = hwSerial;
}
/**************************************************************************/
/*!
    @brief  Initializes serial interface and baud rate
    @param  baudrate Sensor's UART baud rate (usually 57600, 9600 or 115200)
*/
/**************************************************************************/
void Adafruit_Fingerprint::begin(uint32_t baudrate) {
  delay(1000);  // one second delay to let the sensor 'boot up'
  if (hwSerial) hwSerial->begin(baudrate);
#if defined(__AVR__) || defined(ESP8266)
  if (swSerial) swSerial->begin(baudrate);
#endif
}
/**************************************************************************/
/*!
    @brief  Verifies the sensors' access password (default password is 0x0000000). A good way to also check if the sensors is active and responding
    @returns True if password is correct
*/
/**************************************************************************/
boolean Adafruit_Fingerprint::verifyPassword(void) {
  return checkPassword() == FINGERPRINT_OK;
}
uint8_t Adafruit_Fingerprint::checkPassword(void) {
  GET_CMD_PACKET(FINGERPRINT_VERIFYPASSWORD,
                  (uint8_t)(thePassword >> 24), (uint8_t)(thePassword >> 16),
                  (uint8_t)(thePassword >> 8), (uint8_t)(thePassword & 0xFF));
  if (packet.data[0] == FINGERPRINT_OK)
    return FINGERPRINT_OK;
  else
    return FINGERPRINT_PACKETRECIEVEERR;
}
/**************************************************************************/
/*!
    @brief   Ask the sensor to take an image of the finger pressed on surface
    @returns <code>FINGERPRINT_OK</code> on success
    @returns <code>FINGERPRINT_NOFINGER</code> if no finger detected
    @returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
    @returns <code>FINGERPRINT_IMAGEFAIL</code> on imaging error
*/
/**************************************************************************/
uint8_t Adafruit_Fingerprint::getImage(void) {
  SEND_CMD_PACKET(FINGERPRINT_GETIMAGE);
}
/**************************************************************************/
/*!
    @brief   Ask the sensor to convert image to feature template
    @param slot Location to place feature template (put one in 1 and another in 2 for verification to create model)
    @returns <code>FINGERPRINT_OK</code> on success
    @returns <code>FINGERPRINT_IMAGEMESS</code> if image is too messy
    @returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
    @returns <code>FINGERPRINT_FEATUREFAIL</code> on failure to identify fingerprint features
    @returns <code>FINGERPRINT_INVALIDIMAGE</code> on failure to identify fingerprint features
*/
uint8_t Adafruit_Fingerprint::image2Tz(uint8_t slot) {
  SEND_CMD_PACKET(FINGERPRINT_IMAGE2TZ,slot);
}
/**************************************************************************/
/*!
    @brief   Ask the sensor to take two print feature template and create a model
    @returns <code>FINGERPRINT_OK</code> on success
    @returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
    @returns <code>FINGERPRINT_ENROLLMISMATCH</code> on mismatch of fingerprints
*/
uint8_t Adafruit_Fingerprint::createModel(void) {
  SEND_CMD_PACKET(FINGERPRINT_REGMODEL);
}

/**************************************************************************/
/*!
    @brief   Ask the sensor to store the calculated model for later matching
    @param   location The model location #
    @returns <code>FINGERPRINT_OK</code> on success
    @returns <code>FINGERPRINT_BADLOCATION</code> if the location is invalid
    @returns <code>FINGERPRINT_FLASHERR</code> if the model couldn't be written to flash memory
    @returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
uint8_t Adafruit_Fingerprint::storeModel(uint16_t location) {
  SEND_CMD_PACKET(FINGERPRINT_STORE, 0x01, (uint8_t)(location >> 8), (uint8_t)(location & 0xFF));
}
/**************************************************************************/
/*!
    @brief   Ask the sensor to load a fingerprint model from flash into buffer 1
    @param   location The model location #
    @returns <code>FINGERPRINT_OK</code> on success
    @returns <code>FINGERPRINT_BADLOCATION</code> if the location is invalid
    @returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
uint8_t Adafruit_Fingerprint::loadModel(uint16_t location) {
  SEND_CMD_PACKET(FINGERPRINT_LOAD, 0x01, (uint8_t)(location >> 8), (uint8_t)(location & 0xFF));
}
/**************************************************************************/
/*!
    @brief   Ask the sensor to transfer 256-byte fingerprint template from the buffer to the UART
    @returns <code>FINGERPRINT_OK</code> on success
    @returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
uint8_t Adafruit_Fingerprint::getModel(void) {
  SEND_CMD_PACKET(FINGERPRINT_UPLOAD, 0x01);
}
/**************************************************************************/
/*!

That final comment is incomplete - have you posted all your code?

No

@brief Helper function to receive data over UART from the sensor and process it into a packet
@param packet A structure containing the bytes received
@param timeout how many milliseconds we’re willing to wait
@returns FINGERPRINT_OK on success
@returns FINGERPRINT_TIMEOUT or FINGERPRINT_BADPACKET on failure
*/
/**************************************************************************/
uint8_t Adafruit_Fingerprint::getStructuredPacket(Adafruit_Fingerprint_Packet * packet, uint16_t timeout) {
uint8_t byte;
uint16_t idx=0, timer=0;
while(true) {
while(!mySerial->available()) {
delay(1);
timer++;
if( timer >= timeout) {
#ifdef FINGERPRINT_DEBUG
Serial.println(“Timed out”);
#endif
return FINGERPRINT_TIMEOUT;
}
}
byte = mySerial->read();
#ifdef FINGERPRINT_DEBUG
Serial.print("<- 0x"); Serial.println(byte, HEX);
#endif
switch (idx) {
case 0:
if (byte != (FINGERPRINT_STARTCODE >> 8))
continue;
packet->start_code = (uint16_t)byte << 8;
break;
case 1:
packet->start_code |= byte;
if (packet->start_code != FINGERPRINT_STARTCODE)
return FINGERPRINT_BADPACKET;
break;
case 2:
case 3:
case 4:
case 5:
packet->address[idx-2] = byte;
break;
case 6:
packet->type = byte;
break;
case 7:
packet->length = (uint16_t)byte << 8;
break;
case 8:
packet->length |= byte;
break;
default:
packet->data[idx-9] = byte;
if((idx-8) == packet->length)
return FINGERPRINT_OK;
break;
}
idx++;
}
// Shouldn’t get here so…
return FINGERPRINT_BADPACKET;
}

Actually, I am trying to convert this code from an Arduino Uno to a mega 2560.

Here is my new error

Arduino: 1.8.7 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

libraries\Adafruit_Fingerprint_Sensor_Library\Adafruit_Fingerprint.cpp.o (symbol from plugin): In function `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)':

(.text+0x0): multiple definition of `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)'

sketch\sketch_feb14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions

libraries\Adafruit_Fingerprint_Sensor_Library\Adafruit_Fingerprint.cpp.o (symbol from plugin): In function `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)':

(.text+0x0): multiple definition of `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)'

sketch\sketch_feb14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_Fingerprint_Sensor_Library\Adafruit_Fingerprint.cpp.o (symbol from plugin): In function `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)':

(.text+0x0): multiple definition of `Adafruit_Fingerprint::Adafruit_Fingerprint(HardwareSerial*, unsigned long)'

sketch\sketch_feb14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_Fingerprint_Sensor_Library\Adafruit_Fingerprint.cpp.o (symbol from plugin): In function `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)':

(.text+0x0): multiple definition of `Adafruit_Fingerprint::Adafruit_Fingerprint(HardwareSerial*, unsigned long)'

sketch\sketch_feb14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_Fingerprint_Sensor_Library\Adafruit_Fingerprint.cpp.o (symbol from plugin): In function `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)':

(.text+0x0): multiple definition of `Adafruit_Fingerprint::begin(unsigned long)'

sketch\sketch_feb14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_Fingerprint_Sensor_Library\Adafruit_Fingerprint.cpp.o (symbol from plugin): In function `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)':

(.text+0x0): multiple definition of `Adafruit_Fingerprint::writeStructuredPacket(Adafruit_Fingerprint_Packet const&)'

sketch\sketch_feb14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_Fingerprint_Sensor_Library\Adafruit_Fingerprint.cpp.o (symbol from plugin): In function `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)':

(.text+0x0): multiple definition of `Adafruit_Fingerprint::getStructuredPacket(Adafruit_Fingerprint_Packet*, unsigned int)'

sketch\sketch_feb14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_Fingerprint_Sensor_Library\Adafruit_Fingerprint.cpp.o (symbol from plugin): In function `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)':

(.text+0x0): multiple definition of `Adafruit_Fingerprint::checkPassword()'

sketch\sketch_feb14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_Fingerprint_Sensor_Library\Adafruit_Fingerprint.cpp.o (symbol from plugin): In function `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)':

(.text+0x0): multiple definition of `Adafruit_Fingerprint::verifyPassword()'

sketch\sketch_feb14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_Fingerprint_Sensor_Library\Adafruit_Fingerprint.cpp.o (symbol from plugin): In function `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)':

(.text+0x0): multiple definition of `Adafruit_Fingerprint::getImage()'

sketch\sketch_feb14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_Fingerprint_Sensor_Library\Adafruit_Fingerprint.cpp.o (symbol from plugin): In function `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)':

(.text+0x0): multiple definition of `Adafruit_Fingerprint::image2Tz(unsigned char)'

sketch\sketch_feb14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_Fingerprint_Sensor_Library\Adafruit_Fingerprint.cpp.o (symbol from plugin): In function `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)':

(.text+0x0): multiple definition of `Adafruit_Fingerprint::createModel()'

sketch\sketch_feb14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_Fingerprint_Sensor_Library\Adafruit_Fingerprint.cpp.o (symbol from plugin): In function `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)':

(.text+0x0): multiple definition of `Adafruit_Fingerprint::storeModel(unsigned int)'

sketch\sketch_feb14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_Fingerprint_Sensor_Library\Adafruit_Fingerprint.cpp.o (symbol from plugin): In function `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)':

(.text+0x0): multiple definition of `Adafruit_Fingerprint::loadModel(unsigned int)'

sketch\sketch_feb14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_Fingerprint_Sensor_Library\Adafruit_Fingerprint.cpp.o (symbol from plugin): In function `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)':

(.text+0x0): multiple definition of `Adafruit_Fingerprint::getModel()'

sketch\sketch_feb14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_Fingerprint_Sensor_Library\Adafruit_Fingerprint.cpp.o (symbol from plugin): In function `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)':

(.text+0x0): multiple definition of `Adafruit_Fingerprint::deleteModel(unsigned int)'

sketch\sketch_feb14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_Fingerprint_Sensor_Library\Adafruit_Fingerprint.cpp.o (symbol from plugin): In function `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)':

(.text+0x0): multiple definition of `Adafruit_Fingerprint::emptyDatabase()'

sketch\sketch_feb14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_Fingerprint_Sensor_Library\Adafruit_Fingerprint.cpp.o (symbol from plugin): In function `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)':

(.text+0x0): multiple definition of `Adafruit_Fingerprint::fingerFastSearch()'

sketch\sketch_feb14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_Fingerprint_Sensor_Library\Adafruit_Fingerprint.cpp.o (symbol from plugin): In function `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)':

(.text+0x0): multiple definition of `Adafruit_Fingerprint::getTemplateCount()'

sketch\sketch_feb14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_Fingerprint_Sensor_Library\Adafruit_Fingerprint.cpp.o (symbol from plugin): In function `Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial*, unsigned long)':

(.text+0x0): multiple definition of `Adafruit_Fingerprint::setPassword(unsigned long)'

sketch\sketch_feb14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

C:\Users\dchan\AppData\Local\Temp\ccP97QCr.ltrans0.ltrans.o: In function `main':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:43: undefined reference to `setup'

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:46: undefined reference to `loop'

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Hi,
Can you get it to compile first for a UNO?

Where did you get the original code from?

Can you tell us your electronics, programming, arduino, hardware experience?

Thanks.. Tom... :slight_smile: