0

Babel Fish LED Expansion
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Babel Fish LED Expansion

by joshstern on Mon Feb 26, 2018 1:18 pm

Hi all,

After spending some time getting the Babel Fish project up and running on my Uno (thanks to those who helped on the forums!), I'm now faced with an interesting issue of having LED's illuminate in addition to the sounds playing.

Basically, I'd like a strip of NeoPixels to be going through rainbowCycle until an NFC/RFID chip is swiped, then flash gold. After a delay of X number of seconds, return back to rainbowCycle. In turn, if a chip isn't registered, flash the NeoPixels red.

I have the two shields stacked on top of the Arduino but I only get a single Pixel to illuminate, the wrong color too.

Here is my modified code:

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


#define IRQ 6 // this trace must be cut and rewired!
#define RESET 8
#define PIN 11

Adafruit_NFCShield_I2C nfc(IRQ, RESET);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(41, PIN, NEO_GRB + NEO_KHZ800);

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);
 
  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();

  strip.begin();
  strip.show(); // Initialize all pixels to 'off'

}

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

unsigned digit = 0;

void loop() {
  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);
    rainbowCycle(20);

  // repeat this for loop as many times as you have RFID cards
    if (cardidentifier == 3377906341) {
      playcomplete("WINWOOSH.WAV"); //play success sound
      colorWipe(strip.Color(255, 215, 0), 50); //gold color as soon as sound is done playing
      delay(1000); //sleep 1 second
    }
 
    if (cardidentifier == 3127854084) {
      playcomplete("PANDORA.WAV");
      colorWipe(strip.Color(255, 215, 0), 50); //gold color as soon as sound is done playing
      delay(1000);
    }
   
    if (cardidentifier == 1357560551) {
      playcomplete("WINWOOSH.WAV");
      colorWipe(strip.Color(255, 215, 0), 50); //gold color as soon as sound is done playing
      delay(1000);
    }
   
    if (cardidentifier == 3243562806) {
      playcomplete("WINWOOSH.WAV");
      colorWipe(strip.Color(255, 215, 0), 50); //gold color as soon as sound is done playing
      delay(1000);
    }
   
    if (cardidentifier == 3395972868) {
      playcomplete("WINWOOSH.WAV");
      colorWipe(strip.Color(255, 215, 0), 50); //gold color as soon as sound is done playing
      delay(1000);
    }
  }
}

/////////////////////////////////// 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();
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}


Any suggestions?

Josh

joshstern
 
Posts: 37
Joined: Wed May 28, 2014 4:28 pm

Re: Babel Fish LED Expansion

by adafruit_support_bill on Mon Feb 26, 2018 1:35 pm

Code: Select all | TOGGLE FULL SIZE
#define PIN 11

Adafruit_NFCShield_I2C nfc(IRQ, RESET);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(41, PIN, NEO_GRB + NEO_KHZ800);


Pin 11 is likely the problem. Pin 11 is part of the SPI bus and is used to communicate with the SD card. Connect your Neopixels to one of the available pins listed here: https://learn.adafruit.com/adafruit-wav ... /faq#faq-7

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

Re: Babel Fish LED Expansion

by joshstern on Mon Feb 26, 2018 2:36 pm

adafruit_support_bill wrote:
Code: Select all | TOGGLE FULL SIZE
#define PIN 11

Adafruit_NFCShield_I2C nfc(IRQ, RESET);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(41, PIN, NEO_GRB + NEO_KHZ800);


Pin 11 is likely the problem. Pin 11 is part of the SPI bus and is used to communicate with the SD card. Connect your Neopixels to one of the available pins listed here: https://learn.adafruit.com/adafruit-wav ... /faq#faq-7


Hi Bill,

Thanks for this suggestion. I've switched the data pin to unused pin 7 but I'm still running into issues. Now I don't have any NeoPixels on neither in "standby" or when I scan a card.

Josh

joshstern
 
Posts: 37
Joined: Wed May 28, 2014 4:28 pm

Re: Babel Fish LED Expansion

by adafruit_support_bill on Mon Feb 26, 2018 2:45 pm

Try running the StrandTest example from the Neopixel library to verify that the strip is correctly connected and functional. Be sure to change the pin in the code to match the pin that you are using.

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

Re: Babel Fish LED Expansion

by joshstern on Mon Feb 26, 2018 2:52 pm

adafruit_support_bill wrote:Try running the StrandTest example from the Neopixel library to verify that the strip is correctly connected and functional. Be sure to change the pin in the code to match the pin that you are using.


Just loaded the strandtest on and I can confirm the strip is working properly. See the attached photo. It runs properly through the two shields too so something must be within the code itself.
Attachments
20180226_104653 copy.jpg
20180226_104653 copy.jpg (320.93 KiB) Viewed 395 times

joshstern
 
Posts: 37
Joined: Wed May 28, 2014 4:28 pm

Re: Babel Fish LED Expansion

by adafruit_support_bill on Mon Feb 26, 2018 2:59 pm

The other possibility is that you are out of memory. The SD card buffer takes a big chunk. And I believe that the NFC takes a good size buffer as well.
https://learn.adafruit.com/memories-of- ... ot-dot-dot

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

Re: Babel Fish LED Expansion

by joshstern on Mon Feb 26, 2018 3:03 pm

adafruit_support_bill wrote:The other possibility is that you are out of memory. The SD card buffer takes a big chunk. And I believe that the NFC takes a good size buffer as well.
https://learn.adafruit.com/memories-of- ... ot-dot-dot


I'm using 89% of available dynamic memory.

Additionally, that link takes me to a 404 page :(

joshstern
 
Posts: 37
Joined: Wed May 28, 2014 4:28 pm

Re: Babel Fish LED Expansion

by adafruit_support_bill on Mon Feb 26, 2018 3:18 pm

89% is just what the compiler knows about up front. The SRAM is also shared by the stack and any dynamic allocations.

Not sure what is up with the broken link. Here is the pdf version. https://cdn-learn.adafruit.com/download ... rduino.pdf

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

Re: Babel Fish LED Expansion

by joshstern on Mon Feb 26, 2018 3:39 pm

adafruit_support_bill wrote:89% is just what the compiler knows about up front. The SRAM is also shared by the stack and any dynamic allocations.

Not sure what is up with the broken link. Here is the pdf version. https://cdn-learn.adafruit.com/download ... rduino.pdf


Gotcha. Thanks Bill!

joshstern
 
Posts: 37
Joined: Wed May 28, 2014 4:28 pm

Re: Babel Fish LED Expansion

by joshstern on Tue Mar 06, 2018 10:51 pm

adafruit_support_bill wrote:89% is just what the compiler knows about up front. The SRAM is also shared by the stack and any dynamic allocations.

Not sure what is up with the broken link. Here is the pdf version. https://cdn-learn.adafruit.com/download ... rduino.pdf


Hi Bill,

So I invested in an Arduino Mega 2560 to compensate for the lack of ram. However, I'm getting a "Did not find PN53x" error. I followed your suggestion here (viewtopic.php?f=31&t=33801&start=45) and connected pins 20 and 21 to SCL and SDA but I still get the board not found error. Any ideas?

Josh

joshstern
 
Posts: 37
Joined: Wed May 28, 2014 4:28 pm

Re: Babel Fish LED Expansion

by adafruit_support_bill on Wed Mar 07, 2018 6:51 am

The shield should work without changes on an R3 or later Mega. What version Mega do you have?
Please post some photos showing your soldering to the shield.

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

Re: Babel Fish LED Expansion

by joshstern on Wed Mar 07, 2018 1:36 pm

adafruit_support_bill wrote:The shield should work without changes on an R3 or later Mega. What version Mega do you have?
Please post some photos showing your soldering to the shield.



This is the board I'm using: https://www.velleman.eu/products/view/?id=435498 (picked it up at my local Fry's Electronics).
Attachments
20180307_092636.jpg
20180307_092636.jpg (560.34 KiB) Viewed 277 times
20180307_092629.jpg
20180307_092629.jpg (519.02 KiB) Viewed 277 times
20180307_092624.jpg
20180307_092624.jpg (554.88 KiB) Viewed 277 times

joshstern
 
Posts: 37
Joined: Wed May 28, 2014 4:28 pm

Re: Babel Fish LED Expansion

by adafruit_support_bill on Wed Mar 07, 2018 1:43 pm

We need to see the underside of the shield so we can check the soldering.

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

Re: Babel Fish LED Expansion

by joshstern on Wed Mar 07, 2018 1:48 pm

adafruit_support_bill wrote:We need to see the underside of the shield so we can check the soldering.


Sorry about that Bill.

Here are some photos of the underside of the PN532 and Wave shield. My phone has a strange focus to it, so if you need me to focus in on any specific component, let me know.

The Mega came preassembled and pre soldered.
Attachments
20180307_094527.jpg
20180307_094527.jpg (429.01 KiB) Viewed 275 times
20180307_094007.jpg
20180307_094007.jpg (499.21 KiB) Viewed 275 times
20180307_093933.jpg
20180307_093933.jpg (499.39 KiB) Viewed 275 times

joshstern
 
Posts: 37
Joined: Wed May 28, 2014 4:28 pm

Re: Babel Fish LED Expansion

by adafruit_support_bill on Wed Mar 07, 2018 2:00 pm

The solder looks OK. Try plugging the RFID shield directly into the Mega and see if you can run the example code from the library.

It looks like you cut off the SDA and SCL pins, so you will have to use the jumpers.

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

Please be positive and constructive with your questions and comments.