Hi community,
I have posted about this project here before and received some great help. (last post about the topic)
Now I've run into another problem I can't quite get my head around.
I'm running an Arduino Uno R3 together with the CC3000 WiFi-module by adafruit, the PN532 NFC-Reader by Adafruit and the Sainsmart 1.8' TFT module.
With all the libraries my sketch is now at 32.248 Bytes. The free RAM is continually shown as 477, no matter where I call it.
My sketch stops at the initialization of the NFC-module, though, and I really have no answer as to why it does that.
I'll post both the old sketch without the TFT and the new one with the TFT for comparison.
Both sketches consist of four pages.
And so you don't get confused about it: In the old sketch I used LEDs to show the status of the Arduino
and The old sketch contains a lot of debuggind messages which I had to cut because of sketch size.
The old one works fine, but the newer version... ![]()
Old sketch:
//WLAN-Libs
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
//NFC-Libs
#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>
//Motor-Libs
#include <Servo.h>
#define IRQ (2)
#define RESET (4) // Not connected by default on the NFC Shield
Adafruit_NFCShield_I2C nfc(IRQ, RESET);
//Status-LEDs
int dev_ready = 6, dev_proc = 8, dev_err = 9;
unsigned long t = millis();
const unsigned long connectTimeout = 15L * 1000L;
//Motor-settings
const int stepsPerRevolution = 180; // change this to fit the number of steps per revolution
// for your motor
int pos = 0;
Servo Motor; // initialize the stepper library on pins 6 through 9:
//Wifi-settings
// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10
// Use hardware SPI for the remaining pins
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIV2); // you can change this clock speed
#define WLAN_SSID "WLAN" // cannot be longer than 32 characters!
#define WLAN_PASS "PASSWORD"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY WLAN_SEC_WPA2
Adafruit_CC3000_Client www; //defines how we will refer to the cc3000 connection object
//Connection details
#define WEBSITE "10.2.10.72" //enter host-IP here
#define WEBPAGE "/arduino/sql_entries.php"
//used for storing data for upload
int tag1_id, user_id;
//int tag2_id, tag3_id, tag4_id, tag5_id; //more vars for more devices to log (uncomment if needed)
//tells the sketch whether to poll or not
int pollCounter = 1;
boolean pollFlag = false;
//declare a variable to hold a numeric IP address
uint32_t ip = cc3000.IP2U32(10,2,10,72);
/**************************************************************************/
/*!
@brief Initialization of the modules (Motor, Wifi, NFC-Reader)
*/
/**************************************************************************/
void setup(void)
{
Serial.begin(115200);
//Set up LEDs for use
pinMode( dev_ready, OUTPUT);
pinMode( dev_proc, OUTPUT);
pinMode( dev_err, OUTPUT);
digitalWrite(dev_ready, HIGH);
digitalWrite(dev_proc, HIGH);
digitalWrite(dev_err, HIGH);
delay(1000);
digitalWrite(dev_ready, LOW);
digitalWrite(dev_proc, LOW);
digitalWrite(dev_err, LOW);
delay(1000);
//Set up the Motor for the lock
Motor.attach(7);
Motor.write(100);
delay(500);
Motor.write(55);
delay(500);
//Set up the Wifi module
Serial.print(F("Free RAM: ")); Serial.println(getFreeRam(), DEC);
// Initialise the Wifi module
Serial.println(F("\nInitializing..."));
if (!cc3000.begin())
{
Serial.println(F("Couldn't begin()! Check your wiring?"));
digitalWrite(dev_err, HIGH);
while(1);
}
cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
Serial.println(F("Connected!"));
// Wait for DHCP to complete
Serial.println(F("Request DHCP"));
do {
digitalWrite(dev_proc, HIGH);
delay(100);
digitalWrite(dev_proc, LOW);
} while((!cc3000.checkDHCP()) && ((millis() - t) < connectTimeout));
// Display the IP address DNS, Gateway, etc.
while (! displayConnectionDetails()) {
digitalWrite(dev_proc, HIGH);
delay(100);
digitalWrite(dev_proc, LOW);
}
//Set up the NFC module
Serial.println(F("\nStarting NF-Reader..."));
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print(F("Didn't find PN53x board"));
digitalWrite(dev_err, HIGH);
while (1); // halt
}
// Got ok data, print it out!
Serial.print(F("Found chip PN5")); Serial.println((versiondata>>24) & 0xFF, HEX);
Serial.print(F("Firmware ver. ")); Serial.print((versiondata>>16) & 0xFF, DEC);
Serial.println('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
// configure board to read RFID tags
nfc.SAMConfig();
}
/**************************************************************************/
/*!
@brief If a TAG is read, the values are translated into an int ID
that is then passed on to be send to the server. Differentiation
between the User-TAG and the Device-TAG is being made.
*/
/**************************************************************************/
void loop(void)
{
//Text and LED for User to see system is ready
digitalWrite(dev_ready, LOW);
digitalWrite(dev_proc, LOW);
digitalWrite(dev_err, LOW);
digitalWrite(dev_ready, HIGH);
Serial.println(F("Waiting for an ISO14443A Card ..."));
NFC_ID_handler();
if ( pollCounter > 1) {
data_sender();
pollCounter = 1;
}
else {
pollCounter++;
}
delay(2000);
} //end of the loop
/**************************************************************************/
/*!
@brief Tries to read the IP address and other connection details
*/
/**************************************************************************/
bool displayConnectionDetails(void)
{
uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
{
Serial.println(F("Unable to retrieve the IP Address!\r\n"));
digitalWrite(dev_err, HIGH);
return false;
}
else
{
Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
Serial.println();
}
}