2

I have an Arduino Uno board, Seeed Studio NFC shield v2.1 and, an Arduino GSM shield stacked UNO -> NFC -> GSM, therefore, all the wires are going into pins in the GSM.

I have successfully created a program that measures various sensors on my attached breadboard and then prints them to serial and sends text depending on conditions. I have today added the NFC shield to the middle of the stack (so as to avoid unplugging all the pins in the GSM), now when I run any NFC program, the default ones provided on the serial I get the message "Didn't find PN53x board". However, if I unplug the GSM from on top of it the NFC programs run fine, reading and writing tags.

Is it just that the NFC and GSM will not work together or am I missing something.

Main code

// Include the GSM library
#include <GSM.h>

#define PINNUMBER ""

// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;


int buttonPin = 13;
int buttonState = 0;
int buttonPressed = 0;
int trigPin = 11;    
int echoPin = 12;    
long duration, cm, inches;
int greenLED = 6;
int redLED = 8;
int buzzerPin = 10;


int pressurePin = A5;
int force;



const int inputPin = A0;
unsigned int inputSample;
const int inputWindow = 100;





void setup() {
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(inputPin, INPUT);
  startUp();
  //setupText();




}

void loop() {
  button();
  delay(100);
  if (buttonPressed == 1)
  {
    pressure();
  }
  else if (buttonPressed == 2)
  {
    distance();
  }
  else if (buttonPressed == 3)
  {
    sound();
  }
  else if (buttonPressed == 4)
  {
    pressure();
    distance();
    sound();
  }
}

void sound()
{
  // two variables for minimum and maximum values in window
  unsigned int inputMax = 0;
  unsigned int inputMin = 1024;

  // loop for the window
  for (unsigned int i = 0; i < inputWindow; i++) 
  {
    // read in a single value
    inputSample = analogRead(inputPin);
    // get the minimum and maximum value
    inputMin = min(inputMin, inputSample);
    inputMax = max(inputMax, inputSample);
  }
  // send the values on serial
  Serial.print("Min: ");
  Serial.print(inputMin);
  Serial.print("  Max: ");
  Serial.print(inputMax);
  Serial.print("  Diff: ");
  int Diff = inputMax - inputMin;
  Serial.print(Diff);
  Serial.println();
  if (Diff > 30)
  {
    alarm();
    sendText();
  }
  delay(250);
}

void pressure()
{
  force = analogRead(pressurePin);
  Serial.print("The force is: ");
  Serial.println(force);
  delay(250);
  if (force > 400)
  {
    alarm();
    sendText();
  }
}





void distance()
{
  digitalWrite(trigPin, LOW);
  delayMicroseconds(5);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);
  int echo = pulseIn(echoPin, HIGH);
  int trig = pulseIn(trigPin, HIGH);
  Serial.println(duration);
  Serial.println(echo);
  Serial.println(trig);
  cm = (duration/2) / 29.1; 
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  delay(100);
  if (cm < 5)
  {
    alarm();
    sendText();
  }
}

void alarm()
{
  digitalWrite(redLED, HIGH);
  tone(buzzerPin,2500);
  delay(200);
  digitalWrite(redLED, LOW);
  noTone(buzzerPin); 
  delay(200);
  digitalWrite(redLED, HIGH);
  tone(buzzerPin,300);
  delay(200);
  digitalWrite(redLED, LOW);
  noTone(buzzerPin); 
  delay(200);
  digitalWrite(redLED, HIGH);
  tone(buzzerPin,2500);
  delay(200);
  digitalWrite(redLED, LOW);
  noTone(buzzerPin); 
  delay(200);  
  digitalWrite(redLED, HIGH);
  tone(buzzerPin,300);
  delay(200);
  digitalWrite(redLED, LOW);
  noTone(buzzerPin); 
  delay(200);
  digitalWrite(redLED, HIGH);
  tone(buzzerPin,2500);
  delay(200);
  digitalWrite(redLED, LOW);
  noTone(buzzerPin); 
  delay(200);
  digitalWrite(redLED, HIGH);
  tone(buzzerPin,300);
  delay(200);
  digitalWrite(redLED, LOW);
  noTone(buzzerPin); 
  delay(200);  
  digitalWrite(redLED, HIGH);
  tone(buzzerPin,2500);
  delay(200);
  digitalWrite(redLED, LOW);
  noTone(buzzerPin); 
  delay(200);
  digitalWrite(redLED, HIGH);
  tone(buzzerPin,300);
  delay(200);
  digitalWrite(redLED, LOW);
  noTone(buzzerPin); 
  delay(200);
  digitalWrite(redLED, HIGH);
  tone(buzzerPin,2500);
  delay(200);
  digitalWrite(redLED, LOW);
  noTone(buzzerPin); 
  delay(200);  
}



void button()
{

  buttonState = digitalRead(buttonPin);


  if (buttonState == HIGH) 
  {
    buttonPressed ++;
    digitalWrite(greenLED, HIGH);
    noise();
    delay(2000);
    digitalWrite(greenLED, LOW);

  }

  Serial.println(buttonPressed); 
}

void startUp()
{
  digitalWrite(greenLED, HIGH);
  noise();
  digitalWrite(greenLED, LOW);
  delay(500);
  digitalWrite(greenLED, HIGH);
  noise();
  digitalWrite(greenLED, LOW);
  delay(500);
  digitalWrite(greenLED, HIGH);
  noise();
  digitalWrite(greenLED, LOW);
  delay(500);
  loop();
}

void noise()
{
  tone(buzzerPin, 1000);
  delay(1000);
  noTone(buzzerPin);
}




void sendText()
{
    Serial.println("...");
    Serial.println("...");
    Serial.println("...");
    Serial.println("...");
    Serial.println("...");
    Serial.println("MESSAGE SENT");
    Serial.println("...");
    Serial.println("...");
    Serial.println("...");
    Serial.println("...");
    Serial.println("...");
    delay(4000);
//  char remoteNum[20];
//  Serial.println(remoteNum);
//  // sms text
//  char txtMsg[200];
//  Serial.println("SENDING");
//  Serial.println();
//  Serial.println("Message:");
//  Serial.println(txtMsg);
//
//  // send the message
//  sms.beginSMS("07123456789");
//  sms.print("HELP");
//  sms.endSMS();
//  Serial.println("\nCOMPLETE!\n");
}

void setupText()
{
  // initialize serial communications and wait for port to open:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("SMS Messages Sender");

  // connection state
  boolean notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while (notConnected) {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
      notConnected = false;
    } else {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");
}

Code to be added when at a later date

#include <SPI.h>
    #include "PN532_SPI.h"
    #include "PN532.h"
    #include "NfcAdapter.h"

    PN532_SPI interface(SPI, 10); // create a PN532 SPI interface with the SPI CS terminal located at digital pin 10
    NfcAdapter nfc = NfcAdapter(interface); // create an NFC adapter object

    void setup() {
        Serial.begin(9600); // begin serial communication
        Serial.println("NDEF Reader");
        nfc.begin(); // begin NFC communication
    }

    void loop() {

        Serial.println("\nScan an NFC tag\n");
        if (nfc.tagPresent()) // Do an NFC scan to see if an NFC tag is present
        {
            NfcTag tag = nfc.read(); // read the NFC tag into an object, nfc.read() returns an NfcTag object.
            tag.print(); // prints the NFC tags type, UID, and NDEF message (if available)
        }
        delay(2000); // wait half a second (500ms) before scanning again (you may increment or decrement the wait time)
    }

Edit: Added code

  • What do you use for GSM / NFC - I2C mixed with SPI? Can you post the code? – user400344 Nov 29 '16 at 23:49
  • I've had a quick google of I2C and SPI but don't fully understand them, to be honest with you, I have code reading a pressure sensor and reading an ultrasonic sensor then a separate sketch I intend to integrate into the first reading NFC tags. Apologies for the rubbish reply I'm very basic. – James B Nov 30 '16 at 0:09
  • I have the Uno plugged into my mac via the serial port, then the NFC shield on top of that and the WiFi shield on top of that with the pins from the breadboard in it. – James B Nov 30 '16 at 0:12
  • If you use I2C for NFC your nfc initialization will reflect that. I2C is IIRC a bus where each device is addressable 0, 1, 2, ... - haven't used SPI much. One thing about I2C I know is that one must keep the wires fairly short... <1m. Can you not share at least the init bits of your code? – user400344 Nov 30 '16 at 0:19
  • 1
    Why on earth are you calling loop() from startUp()? – Majenko Nov 30 '16 at 0:30
2

You have a resource conflict between your breadboard sensors and the NFC shield.

int buttonPin = 13;    <= This is SCK
int trigPin = 11;      <= This is MOSI
int echoPin = 12;      <= This is MISO
int buzzerPin = 10;    <= This is chip select

You will have to use different pins for your sensors.

  • Majenko is in fact a cybernetic supercomputer comprised of a thousand chimpanzee brains, and several billion atmega368p's running on solar power in Area 51. – user400344 Nov 30 '16 at 10:40
  • @user400344 Actually that's not entirely true any more. I replaced the several billion ATMega's with a single PIC32MZ. Next year I hope to start a big upgrade programme gradually replacing the chimpanzee brains with orangutan brains. – Majenko Nov 30 '16 at 10:41
  • It is comforting that you're not a rasperry pi. – user400344 Nov 30 '16 at 10:43
  • @user400344 I live in fear of being replaced by a small perl script... – Majenko Nov 30 '16 at 10:44
  • Haha, perlNet will rule the earth and outlast humanity – user400344 Nov 30 '16 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.