0

Neopixels, Waveshield and NFC
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Neopixels, Waveshield and NFC

by cruiseslater on Wed Oct 02, 2019 12:00 am

Looking to restart a project from last year. Simply put, I need help integrating a neopixels ring into the Adafruit Babelfish project.

Components:
WaveShield (States: pins 6, 7, 8, 9 and the 6 analog in pins (also known as digital i/o pins 14-20) are available.)
Adafruit PN532 NFC/RFID Controller Shield for Arduino -(States: Analog 4 and 5 which are fixed in hardware and cannot be changed for IC2 and an interrupt on pin 2 which has been rewired to pin 6 to accomodate Waveshields use of pin 2)
Neopixel 60 LED Ring

I have confirmed the following code works independently and lights the ring as expected:

NeoPixels--
Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>

Adafruit_NeoPixel strip(60, 7, NEO_GRBW);

void setup() {
  strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  strip.show();            // Turn OFF all pixels ASAP
  strip.setBrightness(25); // Set BRIGHTNESS to about 1/5 (max = 255)
}

void loop() {
  strip.fill(strip.Color(255,0,0,0),0,60);
  strip.show();
}


Further, I have the audio converted and responding to four separate RFID cards using the following code:

BabelFish Template--
Code can be found at (https://learn.adafruit.com/babel-fish/programming)

Only minor changes:
Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NFCShield_I2C.h>
Adafruit_NFCShield_I2C nfc(IRQ, RESET);

to
Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_PN532.h>
Adafruit_PN532 nfc(IRQ, RESET);




Question:
How can I integrate the Neopixels into the code from the babelfish project? I have tried the following with no luck. The ring simply does not respond, but the waveshield plays audio and the PN532 responds to RFID card input.


Code: Select all | TOGGLE FULL SIZE
#include <WaveHC.h>
#include <WaveUtil.h>
#include <Wire.h>
#include <Adafruit_PN532.h>
#include <Adafruit_NeoPixel.h>


#define IRQ 6 // this trace must be cut and rewired!
#define RESET 8
Adafruit_PN532 nfc(IRQ, RESET);

#define LED_PIN    7
#define LED_COUNT 60
Adafruit_NeoPixel strip(60, 7, NEO_GRBW);


SdReader card; // This object holds the information for the card
FatVolume vol; // This holds the information for the partition on the card
FatReader root; // This holds the information for the volumes root directory
FatReader file; // This object represent the WAV file for a pi digit or period
WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time
/*
* Define macro to put error messages in flash memory
*/
#define error(msg) error_P(PSTR(msg))

//////////////////////////////////// SETUP

void setup() {
  // set up Serial library at 9600 bps
  Serial.begin(9600);

  strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  strip.show();            // Turn OFF all pixels ASAP
  strip.setBrightness(25); // Set BRIGHTNESS to about 1/5 (max = 255)
 
  PgmPrintln("Pi speaker");
 
  if (!card.init()) {
    error("Card init. failed!");
  }
  if (!vol.init(card)) {
    error("No partition!");
  }
  if (!root.openRoot(vol)) {
    error("Couldn't open dir");
  }

  PgmPrintln("Files found:");
  root.ls();
 
  // find Adafruit RFID/NFC shield
  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  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);
 
  // configure board to read RFID tags
  nfc.SAMConfig();

}

/////////////////////////////////// LOOP

unsigned digit = 0;

void loop() {

    strip.fill(strip.Color(255,255,0,0),0,60);
    strip.show();
    delay(500);
 
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
  uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)

  // wait for RFID card to show up!
  Serial.println("Waiting for an ISO14443A Card ...");

   
  // Wait for an ISO14443A type cards (Mifare, etc.). When one is found
  // 'uid' will be populated with the UID, and uidLength will indicate
  // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

  uint32_t cardidentifier = 0;
 
  if (success) {
    // Found a card!

    Serial.print("Card detected #");
    // turn the four byte UID of a mifare classic into a single variable #
    cardidentifier = uid[3];
    cardidentifier <<= 8; cardidentifier |= uid[2];
    cardidentifier <<= 8; cardidentifier |= uid[1];
    cardidentifier <<= 8; cardidentifier |= uid[0];
    Serial.println(cardidentifier);

  // repeat this for loop as many times as you have RFID cards
    if (cardidentifier == 580275918) { // this is the card's unique identifier
      playcomplete("1.WAV"); // these are file names for the sample audio files - change them to your own file names
    }
 
    if (cardidentifier == 981833538) {
      playcomplete("2.WAV");
    }

    if (cardidentifier == 983131522) {
      playcomplete("3.WAV");
    }

    if (cardidentifier == 965246322) {
      playcomplete("4.WAV");
    }
  }
}
//////////////////////////////////////////

/////////////////////////////////// HELPERS

/*
* print error message and halt
*/
void error_P(const char *str) {
  PgmPrint("Error: ");
  SerialPrint_P(str);
  sdErrorCheck();
  while(1);
}
/*
* print error message and halt if SD I/O error
*/
void sdErrorCheck(void) {
  if (!card.errorCode()) return;
  PgmPrint("\r\nSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  PgmPrint(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}
/*
* Play a file and wait for it to complete
*/
void playcomplete(char *name) {
  playfile(name);
  while (wave.isplaying);
 
  // see if an error occurred while playing
  sdErrorCheck();
}
/*
* Open and start playing a WAV file
*/
void playfile(char *name) {
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
  }
  if (!file.open(root, name)) {
    PgmPrint("Couldn't open file ");
    Serial.print(name);
    return;
  }
  if (!wave.create(file)) {
    PgmPrintln("Not a valid WAV");
    return;
  }
  // ok time to play!
  wave.play();
}


If this cannot be done would I be better off running the ring from a lilypad or something similar? Please note that a previous thread (viewtopic.php?f=48&t=152012) garnered many views but no responses :(. This is hopefully not a repost as I am trying to simplify my question to hopefully get a better response this time.

Thanks in advance!

cruiseslater
 
Posts: 8
Joined: Tue May 21, 2019 3:25 pm

Re: Neopixels, Waveshield and NFC

by adafruit_support_bill on Wed Oct 02, 2019 5:47 am

What processor are you using? The Arduino UNO has limited memory and you may be running into that limitation.

https://learn.adafruit.com/memories-of- ... ot-dot-dot

adafruit_support_bill
 
Posts: 74610
Joined: Sat Feb 07, 2009 10:11 am

Re: Neopixels, Waveshield and NFC

by cruiseslater on Wed Oct 02, 2019 1:12 pm

I am using the Adafruit METRO 328 (ATmega328)

Also, thanks for that link, just reviewed it and think I will look into the following:

    using the freeMemory() to call throughout primary loop and after card reads to print to serial monitor the current SRAM
    seeing if I reduce pixel count from 60 to maybe 5 to hopefully get a response. I didn't realize that each pixel has to be stored separately, I thought a single color sent to all pixels would be low memory usage.


Ex:
Code: Select all | TOGGLE FULL SIZE
strip.fill(strip.color(255,0,0,0), 0, 60)


Going back to original question, I have the code compiling and sending to the board (so no flash issue?) and plan on using the PROGMEM to store the future string names of all 20 audio files (found an example using amiibo) which should reduce strain on SRAM. Currently I am simply testing with four RFID tags and four small audio files from the counting example within the babel-fish project.

cruiseslater
 
Posts: 8
Joined: Tue May 21, 2019 3:25 pm

Re: Neopixels, Waveshield and NFC

by adafruit_support_bill on Wed Oct 02, 2019 2:06 pm

Testing with a smaller number of pixels would be the simplest way to check for memory issues. If it runs fine with 5 pixels but not with 60, you are most likely looking at a shortage of RAM. Switching to something like a Metro M0 would solve that problem.

If it still misbehaves with only a few pixels, then the problem may lie elsewhere.

adafruit_support_bill
 
Posts: 74610
Joined: Sat Feb 07, 2009 10:11 am

Re: Neopixels, Waveshield and NFC

by cruiseslater on Wed Oct 02, 2019 10:15 pm

Evening,

First off big thanks for your help so far!

It does seem to be a memory issue. It was a slow process but I can get up to 48 neopixels on the 60 neopixel ring responding with a simple color switch from red to white followed by an audio response through the Wave shield. Mind you using 45/60 gave much more reliable results. The IDE is returning:

Code: Select all | TOGGLE FULL SIZE
Sketch uses 13254 bytes (41%) of program storage space. Maximum is 32256 bytes.
Global variables use 1714 bytes (83%) of dynamic memory, leaving 334 bytes for local variables. Maximum is 2048 bytes.


This was achieved by stripping all Serial.Print() from the BabelFish base code and using a simple function to call the color switch from within the conditional statements (which are looking for matching RFID data).

I did run the freeMemory() that was mentioned in the the link provide in a previous reply and found that after setup I generally had around 300 being printed to the serial monitor, and then as the program began to set NeoPixels it would drop to 150-230 (sometimes becoming unresponsive). I am assuming this function returns bytes, which means I must be capping out the memory. I only made it to 45 functional pixels by stripping out the Serial.Print(freeMemory()) lines I had scattered throughout the code to watch memory allocation.

What follows below is the code I currently have working.


Hopefully final questions here:
1) Can I save enough memory by trying to dive into the libraries to remove unused code? If so any recommendations?
2) Would it be more reliable to upgrade as you mention to the Metro MO to ensure adequte memory for the 60 neopixels and simple animations I have planned? Then I could maybe push the art installation a little further with more RFID statements and WAV files in the future? (This project will be installed within a school for everyday use).
3) On that note, will the board work with the PN532 and the waveshield? They look similar in regards to the visual layout but are the pins the same in regards to tech specs and compatibility?

Thanks again for the help so far!

Code: Select all | TOGGLE FULL SIZE
#include <WaveHC.h>
#include <WaveUtil.h>
#include <Wire.h>
#include <Adafruit_PN532.h>
#include <Adafruit_NeoPixel.h>


#define IRQ 6 // this trace must be cut and rewired!
#define RESET 8
Adafruit_PN532 nfc(IRQ, RESET);

#define LED_COUNT  48
#define LED_PIN  7
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW);


SdReader card;
FatVolume vol;
FatReader root;
FatReader file;
WaveHC wave;

#define error(msg) error_P(PSTR(msg))

void setup() {

  Serial.begin(9600);

  strip.begin();           
  strip.show();           
  strip.setBrightness(25);
 
  PgmPrintln("Pi speaker");
 
  if (!card.init()) {
    error("Card init. failed!");
  }
  if (!vol.init(card)) {
    error("No partition!");
  }
  if (!root.openRoot(vol)) {
    error("Couldn't open dir");
  }

  PgmPrintln("Files found:");
  root.ls();
 
  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    while (1); // halt
  }
 
  nfc.SAMConfig();

}

unsigned digit = 0;

void loop() {

  strip.fill(strip.Color(255,0,0,0),0,LED_COUNT);
  strip.show();
  delay(100);

  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };
  uint8_t uidLength;

  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

  uint32_t cardidentifier = 0;
 
  if (success) {
 
    cardidentifier = uid[3];
    cardidentifier <<= 8; cardidentifier |= uid[2];
    cardidentifier <<= 8; cardidentifier |= uid[1];
    cardidentifier <<= 8; cardidentifier |= uid[0];
   
    if (cardidentifier == 580275918) {
      flashWhite();
      playcomplete("1.WAV");
    }
 
    if (cardidentifier == 981833538) {
    flashWhite();
    playcomplete("2.WAV");
    }

    if (cardidentifier == 983131522) {
      flashWhite();
      playcomplete("3.WAV");
    }

    if (cardidentifier == 965246322) {
      flashWhite();
      playcomplete("4.WAV");
    }
  }
}

void flashWhite(){
    strip.fill(strip.Color(0,0,0,255),0,LED_COUNT);
    strip.show();
    delay(100);
}

void error_P(const char *str) {
  PgmPrint("Error: ");
  SerialPrint_P(str);
  sdErrorCheck();
  while(1);
}

void sdErrorCheck(void) {
  if (!card.errorCode()) return;
  PgmPrint("\r\nSD I/O error: ");
  PgmPrint(", ");
  while(1);
}

void playcomplete(char *name) {
  playfile(name);
  while (wave.isplaying);
 
  // see if an error occurred while playing
  sdErrorCheck();
}
/*
* Open and start playing a WAV file
*/
void playfile(char *name) {
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
  }
  if (!file.open(root, name)) {
    PgmPrint("Couldn't open file ");
    return;
  }
  if (!wave.create(file)) {
    PgmPrintln("Not a valid WAV");
    return;
  }
  // ok time to play!
  wave.play();
}

cruiseslater
 
Posts: 8
Joined: Tue May 21, 2019 3:25 pm

Re: Neopixels, Waveshield and NFC

by adafruit_support_bill on Thu Oct 03, 2019 5:55 am

The memory utilization reported by the IDE is a little misleading - since it does not account for stack requirements or dynamic memory allocation. String functions will allocate memory from the heap and every function call requires space on the stack.

1) Can I save enough memory by trying to dive into the libraries to remove unused code? If so any recommendations?

That will save you space in Flash memory. But SRAM is what you are running out of.

2) Would it be more reliable to upgrade as you mention to the Metro MO to ensure adequte memory for the 60 neopixels and simple animations I have planned? Then I could maybe push the art installation a little further with more RFID statements and WAV files in the future? (This project will be installed within a school for everyday use).

The M0 will give you 16x as much SRAM as the UNO. (and 8x more Flash too). That should give you plenty of elbow room for expansion.

3) On that note, will the board work with the PN532 and the waveshield? They look similar in regards to the visual layout but are the pins the same in regards to tech specs and compatibility?

The wave shield is the problem there. This is a very old shield design and only works with the 'classic' Atmega 328-based processors like the Arduino UNO or Metro 328.

Given the sound requirements of your project, the options would be:
a) Offload the pixels to a second processor.
b) Replace the Wave shield with something like a Music Maker shield or an Fx board:
https://www.adafruit.com/product/1788
https://www.adafruit.com/product/2217

adafruit_support_bill
 
Posts: 74610
Joined: Sat Feb 07, 2009 10:11 am

Re: Neopixels, Waveshield and NFC

by cruiseslater on Thu Oct 03, 2019 11:24 am

I think I will be making a new order! I am new to this whole world of electronics and must say that the tutorials and support on this forum have allowed me to learn a lot in a short amount of time. A big thanks goes out to you and everyone else that posts and shares knowledge. I went back and reread the section on memory allocation and what you have mentioned is beginning to make sense.

Wish I didn't miss the Music Maker as a solution last year when I ordered the Wave Shield. I will be looking to order the MetroMO and Music Maker like you have mentioned to ensure adequate memory but have two really quick questions before placing my order.

1) MusicMaker states that it uses pins 13, 12, & 11 (fixed) and pins 7, 6, 4, 3 (https://learn.adafruit.com/adafruit-music-maker-shield-vs1053-mp3-wav-wave-ogg-vorbis-player/pinouts). I currently have my PN532 rewired from IRQ to pin 6 for compatibility with the wave shield, if I simply rewire this to an open pin will it also work with the MusicMaker/MetroMO combo and avoid the duplicate pin use of Digital 6? (PN532 currently uses I2C analog 4 & 5 - Pg 9 https://cdn-learn.adafruit.com/downloads/pdf/adafruit-pn532-rfid-nfc.pdf with the interrupt on pin 6 which was rewired and cut from IRQ/#2)

2) The Music Maker has an onboard amp which can push out to 4 or 8 ohm speakers, which would you recommend for a board being installed in a school hallway for student interaction? Our current solution uses a small homemade amplifier (friend is big into electronics) but it is giving a fair amount of distortion. If the board comes with an AMP I would like to use it to the best of its abilities.

The Music Maker sold me on the Mic and Amplifier abilities, I may look at a future expansion where students can record and playback their voice to compare to the audio being played to help with some language exploration.

Thanks.

cruiseslater
 
Posts: 8
Joined: Tue May 21, 2019 3:25 pm

Re: Neopixels, Waveshield and NFC

by cruiseslater on Sat Oct 12, 2019 6:55 pm

Afternoon!

Components finally arrived and I had some time to test it out today. I feel like I am missing something simple and any help would be appreciated. I ordered a new MetroMO Express and the Music Maker Shield.

I have the music maker shield up and running on my previously purchased Metro328 but when I switch to the MetroMO Express (new) the code no longer runs. I have run code on the MetroMO Express to confirm the board is working; using both the basic blink sketch and the on board neopixel to run something a little more intense.

Any thoughts on why the following would work perfectly on the Metro328 and not the MetroMO Express? I have been scouring forums and documentation but I am clearly missing something with the architecture switch. Thanks!

Please note that the following code is from Adafruit_VS1053.h > player_simple , I removed the code dealing with interrupts to get it working.
Code: Select all | TOGGLE FULL SIZE

// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

// define the pins used
//#define CLK 13       // SPI Clock, shared with SD card
//#define MISO 12      // Input data, from VS1053/SD card
//#define MOSI 11      // Output data, to VS1053/SD card
// Connect CLK, MISO and MOSI to hardware SPI pins.
// See http://arduino.cc/en/Reference/SPI "Connections"

// These are the pins used for the music maker shield
#define SHIELD_RESET  -1      // VS1053 reset pin (unused!)
#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)

// These are common pins between breakout and shield
#define CARDCS 4     // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
 
void setup() {
  Serial.begin(9600);
  Serial.println("Adafruit VS1053 Simple Test");

  if (! musicPlayer.begin()) { // initialise the music player
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
     while (1);
  }
  Serial.println(F("VS1053 found"));
 
   if (!SD.begin(CARDCS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);  // don't do anything more
  }

  // list files
  printDirectory(SD.open("/"), 0);
 
  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(5,5);

  // Play one file, don't return until complete
  Serial.println(F("Playing track 001"));
  musicPlayer.playFullFile("/track001.mp3");
    Serial.println(F("Playing track 002"));
  musicPlayer.playFullFile("/track002.mp3");
 
}

void loop() {
  // File is playing in the background
  if (musicPlayer.stopped()) {
    Serial.println("Done playing music");
    while (1) {
      delay(10);  // we're done! do nothing...
    }
  }
  if (Serial.available()) {
    char c = Serial.read();
   
    // if we get an 's' on the serial console, stop!
    if (c == 's') {
      musicPlayer.stopPlaying();
    }
   
    // if we get an 'p' on the serial console, pause/unpause!
    if (c == 'p') {
      if (! musicPlayer.paused()) {
        Serial.println("Paused");
        musicPlayer.pausePlaying(true);
      } else {
        Serial.println("Resumed");
        musicPlayer.pausePlaying(false);
      }
    }
  }

  delay(100);
}


/// File listing helper
void printDirectory(File dir, int numTabs) {
   while(true) {
     
     File entry =  dir.openNextFile();
     if (! entry) {
       // no more files
       //Serial.println("**nomorefiles**");
       break;
     }
     for (uint8_t i=0; i<numTabs; i++) {
       Serial.print('\t');
     }
     Serial.print(entry.name());
     if (entry.isDirectory()) {
       Serial.println("/");
       printDirectory(entry, numTabs+1);
     } else {
       // files have sizes, directories do not
       Serial.print("\t\t");
       Serial.println(entry.size(), DEC);
     }
     entry.close();
   }
}

cruiseslater
 
Posts: 8
Joined: Tue May 21, 2019 3:25 pm

Re: Neopixels, Waveshield and NFC

by cruiseslater on Sat Oct 12, 2019 7:26 pm

Is it because the Metro MO has SCK/MOSI/MISO moved to 2x3 header (https://cdn-learn.adafruit.com/download ... python.pdf) and not pins 13-11 as on Metro328 (https://cdn-shop.adafruit.com/product-f ... l_v2_0.pdf)?

If so, do I simply need to solder the bridges?

cruiseslater
 
Posts: 8
Joined: Tue May 21, 2019 3:25 pm

Re: Neopixels, Waveshield and NFC

by adafruit_support_bill on Sun Oct 13, 2019 6:24 am

Yes. For processors that are not based on the Atmega 328, you need to bridge the jumpers so that you can use the SPI signals on the ICSP header.

https://learn.adafruit.com/adafruit-mus ... -mega-3-10

adafruit_support_bill
 
Posts: 74610
Joined: Sat Feb 07, 2009 10:11 am

Re: Neopixels, Waveshield and NFC

by cruiseslater on Sun Oct 13, 2019 7:09 pm

Many thanks Bill!

Soldered the bridges on the Music Maker and cut the wire traces for pins 13-11 (to the right) to free the pins for future expansion. I have the core components working now and can now focus on cleaning up audio files and housing the project into something permanent.

Quick review: https://twitter.com/8BitSky/status/1183514737708949504?s=20

For the benefit of others:

Components: Metro MO, Music Maker Shield, NFC Shield (PN532), and Neopixel Ring (x60)

Code: Select all | TOGGLE FULL SIZE
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
#include <Adafruit_PN532.h>
#include <Adafruit_NeoPixel.h>


//VS1053 - musicPlayer
#define SHIELD_RESET  -1      // VS1053 reset pin (unused!)
#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)
#define CARDCS 4     // Card chip select pin
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

//PN532 - nfc
#define IRQ 2
#define RESET 8 

Adafruit_PN532 nfc(IRQ, RESET);

//Neopixels - strip
#define LED_COUNT  60
#define LED_PIN  10

Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW);

 
void setup() {
 
  Serial.begin(9600);

  strip.begin();           
  strip.show();           
  strip.setBrightness(50);
 
// initialise musicPlayer
  if (! musicPlayer.begin()) { // initialise the music player
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
     while (1);
  }
  Serial.println(F("VS1053 found"));
  musicPlayer.setVolume(10,10);
  //musicPlayer.sineTest(0x44, 500);    // Make a tone to indicate VS1053 is working
 
  if (!SD.begin(CARDCS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);  // don't do anything more
  }
  Serial.println("SD OK!");

// initialise nfc
  nfc.begin();
  nfc.SAMConfig();
 
}

void loop() {

  colorWheel();
  delay(100);
 
Serial.print("Waiting for RFID...");
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };
  uint8_t uidLength;

  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

  uint32_t cardidentifier = 0;

  if (success) {
 
    cardidentifier = uid[3];
    cardidentifier <<= 8; cardidentifier |= uid[2];
    cardidentifier <<= 8; cardidentifier |= uid[1];
    cardidentifier <<= 8; cardidentifier |= uid[0];
   
      if (cardidentifier == 580275918) {
        pulseWhite(1);
        musicPlayer.playFullFile("/track001.mp3");
    }
 
    if (cardidentifier == 981833538) {
        pulseWhite(2);
        musicPlayer.playFullFile("/track002.mp3");
    }
   
  }
}

void flashWhite(){
    strip.fill(strip.Color(0,0,0,255),0,LED_COUNT);
    strip.show();
    delay(100);
}

void colorWheel(){
   for(int j=0; j<250; j+=25) {
     strip.fill(strip.Color(j,0,0,0), 0, 15); //Red
     strip.fill(strip.Color(0,0,j,0), 15, 15);  //Blue
     strip.fill(strip.Color(0,0,0,j), 30, 15); //White
     strip.fill(strip.Color(j,j,0,0), 45, 15);  //Yellow
     strip.show();
     delay(20);
  }
}

//Pulse direction as white, full quad
void pulseWhite(int direction) {
  strip.fill(strip.Color(0,0,0,0)); //Strip Off
  strip.show();
  int ledStart = 0;
  switch(direction){
    case 1: //North
    ledStart = 0;
    break;
    case 2: //East
    ledStart = 15;
    break;
    case 3: //South
    ledStart = 30;
    break;
    case 4: //West
    ledStart = 45;
    break;
  }
   for(int j=0; j<250; j+=25) {
    strip.fill(strip.Color(0,0,0,j), ledStart, 15);
    strip.show();
    delay(25);
  }
}
 

cruiseslater
 
Posts: 8
Joined: Tue May 21, 2019 3:25 pm

Re: Neopixels, Waveshield and NFC

by adafruit_support_bill on Sun Oct 13, 2019 8:04 pm

Nice! Thanks for the update.

adafruit_support_bill
 
Posts: 74610
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.