problem merging example programs for PN532 NFC and adafruit-sharpmemory LCD

The products and manuals can be found in the links below although the PN532 picture shows V2 I have version V3.

http://www.elechouse.com/elechouse/index.php?main_page=product_info&cPath=90_93&products_id=2242

http://www.elechouse.com/elechouse/images/product/PN532_module_V3/PN532_%20Manual_V3.pdf manual

GitHub - elechouse/PN532: NFC library for Arduino using PN532 library files and example code

So to summarise I have the two example programs working separately with their respective hardware.
When I merge the programs and uncomment the single line shown below below the program wont find the reader PN532 . As the programs compile okay I assume I have all

the relevant library files up to date.

Adafruit_SharpMem display(SCK, MOSI, SS);// uncommenting this line leads to the following error

after the ‘NDEF Reader’ text is displayed

‘Didn’t find PN53x board’
with line above commented I get the following message.

NDEF Reader
Found chip PN532
Firmware ver. 1.6

Scan a NFC tag

Scan a NFC tag…

I have spent two days 8 plus hours ,per day, trialing different ideas/code from endless web researching pn532 SPI problems I have tried pullup resistors on the CS/SS pin on

both
devices and I have moved the PN532 on to the I2C and HSU configuration and adjusted the respective configuration board switch, and altered the program to suit (line 13 #if 1>#if

  1. I have tried the arduino mini 3.3v and UNO R3 as thats all I have at present. I Couldn’t get I2C to detect the card reader and HSU example code available as far as I could see

was limited to serial number of NFC card and may be my last option.

As for the wiring the PN532 was wired as per the manual for spi i.e SCK= Pin D13 , MISO =pinD12, MOSI = pinD11 ,SS= Pin D10.

The Sharp memory display can be configured to almost any pins from the Adafruit web informaton, I did also tried commoning it up with pin D13 (SCK) pin D11(MOSI) and using

D9 for CS instead of D10(as used by SS of PN532,. If you initialise it first as it gets disabled once the nfc.begin command is executed and vice versa the card reader doesnt get

detected once the screen initialised.

The PN532 has the undetected error above as the line is uncommented to attempt to allow the display to work.

The Sharp memory display LCD Only requires 3 pins to work see code example.

I have a basic ability in developing / cobling Arduino code together over about 2 years on and off.

I’m trying to achieve reading a NFC tag card and displaying the record information on the LCD.
I can achieved both these tasks with using the example code I just want to put them on the same
Arduino if possible.

Ive looked at Gammon Forum : Electronics : Microprocessors : SPI - Serial Peripheral Interface - for Arduino tried things like…SPI.endTransaction()

apology if req for the above if I left something out and the above format, been up all nite dont no what I did but .

Ive attached the two working code examples

And if you were wondering why not use another display well this display cost a fair bit and it consumes, I estimate micro amps of current ,too low for DVM meter to read accurately

when on white with black text setting. This screen has no back light that i can see.

Here is the merged codes.

merged two examples sharpmemtest.ino and ReadTagExtended.ino and elininated non required code:

/*
wire up for the PN532 spi configuration
SCK Pin 13 
MISO Pin 12 
MOSI Pin 11 
SS Pin 10 

For the Adafruit Sharp memory display wire up
SCK 7 //was 10 in example program
MOSI 8 //was 11 in example program
SS 9  //was 13 in example program
*/
#if 1
//change to 1 for spi wired
#include <SPI.h>
#include <PN532_SPI.h>
#include <PN532.h>
#include <NfcAdapter.h>

PN532_SPI pn532spi(SPI, 10);
NfcAdapter nfc = NfcAdapter(pn532spi);
#else

#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>

PN532_I2C pn532_i2c(Wire);
NfcAdapter nfc = NfcAdapter(pn532_i2c);
#endif

#include <Adafruit_GFX.h>
#include <Adafruit_SharpMem.h>

#define SCK 7 //was 10 in example program
#define MOSI 8 //was 11 in example program
#define SS 9  //was 13 in example program
//#define SCK 13 //was 10 in example program
//#define MOSI 11 //was 11 in example program
//#define SS 9  //was 13 in example program



//Adafruit_SharpMem display(SCK, MOSI, SS);uncommenting this line leads to the following error
//'Didn't find PN53x board'

#define BLACK 0
#define WHITE 1

void setup(void) {
Serial.begin(9600);
//Uncomment this section below from display.refresh();and the line above starting 
//Adafruit_SharpMem display(SCK, MOSI, SS);uncommenting this line leads to the following error
//'Didn't find PN53x board'
//and the screen works at the beginning 
//but the card reader doesnt initilaise r and the error below appears
//prints this line  okay NDEF Reade
// then shows message "Didn't find PN53x board"
/*
// draw the first ~12 characters in the font
//  testdrawchar();
display.refresh();
delay(2000);
display.clearDisplay();
// text display tests
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println("Hello, world!");
display.setTextColor(WHITE, BLACK); // 'inverted' text
display.println(3.141592);
display.setTextSize(2);
display.setTextColor(BLACK);
display.print("0x"); display.println(0xDEADBEEF, HEX);
display.refresh();
delay(2000);

*/
Serial.println("NDEF Reader");



nfc.begin();
}

void loop(void) {
Serial.println("nScan a NFC tagn");

if (nfc.tagPresent())
{
NfcTag tag = nfc.read();
Serial.println(tag.getTagType());
Serial.print("UID: ");Serial.println(tag.getUidString());

if (tag.hasNdefMessage()) // every tag won't have a message
{

  NdefMessage message = tag.getNdefMessage();
  Serial.print("nThis NFC Tag contains an NDEF Message with ");
  Serial.print(message.getRecordCount());
  Serial.print(" NDEF Record");
  if (message.getRecordCount() != 1) {
    Serial.print("s");
  }
  Serial.println(".");

  // cycle through the records, printing some info from each
  int recordCount = message.getRecordCount();
  for (int i = 0; i < recordCount; i++)
  {
    Serial.print("nNDEF Record ");Serial.println(i+1);
    NdefRecord record = message.getRecord(i);
    // NdefRecord record = message; // alternate syntax

    Serial.print("  TNF: ");Serial.println(record.getTnf());
    Serial.print("  Type: ");Serial.println(record.getType()); // will be "" for TNF_EMPTY

    // The TNF and Type should be used to determine how your application processes the payload
    // There's no generic processing for the payload, it's returned as a byte[]
    int payloadLength = record.getPayloadLength();
    byte payload[payloadLength];
    record.getPayload(payload);

    // Print the Hex and Printable Characters
    Serial.print("  Payload (HEX): ");
    PrintHexChar(payload, payloadLength);

    // Force the data into a String (might work depending on the content)
    // Real code should use smarter processing
    String payloadAsString = "";
    for (int c = 0; c < payloadLength; c++) {
      payloadAsString += (char)payload[c];
    }
    Serial.print("  Payload (as String): ");
    Serial.println(payloadAsString);

    // id is probably blank and will return ""
    String uid = record.getId();
    if (uid != "") {
      Serial.print("  ID: ");Serial.println(uid);
    }
  }

// draw the first ~12 characters in the font
//  testdrawchar();
//Uncomment out out from display.refresh(); to verify not working after nfc.begin is executed above
// this screen initilase doest work after nfc.begin but works before the line nfc.begin executes but this 
//is of no use as the card data hasnt been read and cant then be read as the nfc.begin hangs up see
//code inserted above. If the code below is executed then on the next loop the nfc.begin hangs up
// with the error message 'Didn't find PN53x board'.
// hence why the lines below are commented out to help try to debug the problem. Not.
/*
display.refresh();
delay(2000);
display.clearDisplay();
// text display tests
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println("Hello, world!");
display.setTextColor(WHITE, BLACK); // 'inverted' text
display.println(3.141592);
display.setTextSize(2);
display.setTextColor(BLACK);
display.print("0x"); display.println(0xDEADBEEF, HEX);
display.refresh();
delay(2000);

*/ 



}
}
delay(3000);
}





[code]

sharpmemtest.ino (5.94 KB)

ReadTagExtended.ino (2.48 KB)