Good day! I have an Arduino Mega ADK 2560 and I'm trying to merge two sketches that I need to use for the system that I am making. Both sketches are working perfectly with it's respective android applications. But when I tried to merge the sketches, I get this error:
In file included from \vmware-host\Shared Folders\Documents\Arduino\libraries\Adb/Adb.h:34,
from RFIDroid_Merged.ino:8:
\vmware-host\Shared Folders\Documents\Arduino\libraries\Adb/usb.h:194: error: redefinition of 'class USB'
\vmware-host\Shared Folders\Documents\Arduino\libraries\USB_Host_Shield/Usb.h:116: error: previous definition of 'class USB'
The codes I am trying to merge are these two:
- A code that reads the unique codes on the NFC tags when it is tapped on the NFC Shield mounted on the Arduino. It displays the tag on an android application.
#include <SPI.h>
#include <Adb.h>
#include <max3421e.h>
#include <PN532.h>
#include <EEPROM.h>
#define PN532_CS 10
//CS of NFC is pin 10
PN532 nfc(PN532_CS);
// Adb connection.
Connection * connection;
// Elapsed time for ADC sampling. The rate at which ADC value is sent to Android device.
long lastTime;
// ID of the MiFare Card
uint32_t id;
uint32_t ID;
byte idbk[10];
// Event handler for the shell connection.
void adbEventHandler(Connection * connection, adb_eventType event, uint16_t length, uint8_t * data)
{
// Data packet contains one byte from Android to determine when to start reading NFC
if (event == ADB_CONNECTION_RECEIVE)
{
Serial.println("->ADB_CONNECTION_RECEIVE");
Serial.println(data[0],DEC);
if(data[0] != 0)
{
digitalWrite(53, HIGH);
digitalWrite(6, HIGH);
//ADB::closeAll();
//NFC Begins
{
// look for MiFare type cards
nfc.begin();
//Read the NFC Shield version
uint32_t versiondata = nfc.getFirmwareVersion();
//Warning for non-compatible NFC shields
if (!versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
// Got ok data, print it out!
Serial.print("Found chip PN5");
Serial.println((versiondata>>24) & 0xFF, HEX);
Serial.print("Firmware ver. ");
Serial.print((versiondata>>16) & 0xFF, DEC);
Serial.print('.');
Serial.println((versiondata>>8) & 0xFF, DEC);
Serial.print("Supports ");
Serial.println(versiondata & 0xFF, HEX);
// configure board to read RFID tags and cards
nfc.SAMConfig();
id =0;
while (id==0)
{
id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);
if (id != 0) {
Serial.println();
Serial.print("Read card #");
Serial.println(id);
}
}
//nfc.end();
// Store the NFC ID read to the EEPROM
EEPROM.write(10,id>>24);
EEPROM.write(11,id>>16);
EEPROM.write(12,id>>8);
EEPROM.write(13,id);
}
digitalWrite(6, LOW); // Change the state of LED to indicate NFC ready to read
delay(500);
digitalWrite(6,HIGH);
} else {
}
}
}
void setup()
{
//NFC Read Next Init
pinMode(12, OUTPUT);
digitalWrite(12, LOW);
//Read the ID stored from EEPROM
id = ((uint32_t) EEPROM.read(10)<<24) | ((uint32_t) EEPROM.read(11)<<16) | ((uint32_t) EEPROM.read(12)<<8)|((uint32_t) EEPROM.read(13));
//Serial port debug purpose
Serial.begin(19200);
// Set Digital pin 6 (LED is connected) as output to indicate that NFC ready to be read.
pinMode(6,OUTPUT);
digitalWrite(6,LOW);
// Note start time
lastTime = millis();
// Initialise the ADB subsystem.
ADB::init();
Serial.println("-> ADB init");
// Open an ADB stream to the phone's shell. Auto-reconnect. Use any unused port number eg:4500
connection = ADB::addConnection("tcp:4500", true, adbEventHandler);
Serial.println("-> connection 4500");
}
void loop()
{
//Display the last ID read
if ((millis() - lastTime) > 1000)
{
ID = id;
Serial.println("Last ID Read: ");
Serial.println(ID);
idbk[0] = ID%10;
idbk[1] = ID%100/10;
idbk[2] = ID%1000/100;
idbk[3] = ID%10000/1000;
idbk[4] = ID%100000/10000;
idbk[5] = ID%1000000/100000;
idbk[6] = ID%10000000/1000000;
idbk[7] = ID%100000000/10000000;
idbk[8] = ID%1000000000/100000000;
idbk[9] = ID/1000000000;
connection->write(10, (uint8_t*)&idbk);
lastTime = millis();
}
// Poll the ADB subsystem.
ADB::poll();
}
- Turns an LED on and off when a toggle button in its android application is tapped.
#include <Wire.h>
#include <Servo.h>
#include <Max3421e.h>
#include <Usb.h>
#include <AndroidAccessory.h>
#include <CapSense.h>
#define TOUCH_RECV 14
#define TOUCH_SEND 15
#define RELAY1 A0
#define RELAY2 A1
AndroidAccessory acc("Google, Inc.",
"DemoKit",
"DemoKit Arduino Board",
"1.0",
"http://www.android.com",
"0000000012345678");
\
// 10M ohm resistor on demo shield
CapSense touch_robot = CapSense(TOUCH_SEND, TOUCH_RECV);
void setup();
void loop();
void init_relays()
{
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
}
void init_joystick(int threshold);
byte c;
void setup()
{
Serial.begin(115200);
Serial.print("\r\nStart");
init_relays();
// autocalibrate OFF
touch_robot.set_CS_AutocaL_Millis(0xFFFFFFFF);
c = 0;
acc.powerOn();
}
void loop()
{
byte err;
byte idle;
static byte count = 0;
byte msg[3];
long touchcount;
if (acc.isConnected()) {
int len = acc.read(msg, sizeof(msg), 1);
int i;
byte b;
uint16_t val;
int x, y;
char c0;
if (len > 0) {
// assumes only one command per packet
if (msg[0] == 0x2) {
} else if (msg[0] == 0x3) {
if (msg[1] == 0x0)
digitalWrite(RELAY1, msg[2] ? HIGH : LOW);
else if (msg[1] == 0x1)
digitalWrite(RELAY2, msg[2] ? HIGH : LOW);
}
}
msg[0] = 0x1;
} else {
digitalWrite(RELAY1, LOW);
digitalWrite(RELAY2, LOW);
}
delay(10);
}
Can someone help me solve this error and maybe guide/teach me how to properly merge these two sketches? I am about to merge the two corresponding android applications of these sketches as well. And i want to have a merged sketch that will enable the arduino to read the nfc tags and display it to the android application as well as have a feature where the same sketch can turn an LED on and off when a certain button in the merged android application is tapped.
Any response and help will be appreciated.
Thanks.