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
loop()
fromstartUp()
?