0

BabelFish - Extension
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

BabelFish - Extension

by cruiseslater on Tue May 21, 2019 4:03 pm

Afternoon Everyone!

Looking for some help on this as our class has reached a stand still,, I am new to a lot of this myself and not sure what to suggest moving forward from this point on.

Long story short, BabelFish project inspired an interactive school project which combines Adafruit WaveSheild, NFC, NeoPixel Ring (60 Lights), along with 3D printing, mural/painting and carpentry! This project is meant to be installed within a public space of our school to allow free access to the "terminal" as it it based on language acquisition in relation to teachings of the medicine wheel.

thumbnail_20190521_134642.jpg
thumbnail_20190521_134642.jpg (111.81 KiB) Viewed 898 times


We have the enclosure built (carpentry), mural is starting (art), the NFC/Wave shield working together (reads cards and plays a tune), and the neopixel ring working separately. However, when we combine the code for the neopixel ring and NFC/Wave, the ring becomes unresponsive and only the NFC/Wave components respond to input (through card).

I will attach pictures, video and code below, any help would be greatly appreciated! Maybe we are missing something simple, maybe it is a library issue, maybe we have maxed out the device? We are no longer sure, have exhausted our understandings and are looking for outside help.

We have used the Adafruit references (https://learn.adafruit.com/adafruit-shi ... hield-list) and project (https://learn.adafruit.com/babel-fish/overview) to the best of our ability, sorry for the simple written wiring diagram:

thumbnail_20190521_132015.jpg
thumbnail_20190521_132015.jpg (89.17 KiB) Viewed 898 times


Note that the neopixels share a common ground but otherwise have their own power supply with an in line capacitor as recommended. The pixels run on pin 7 (digital), as the pin appeared to be free to us.

From a coding perspective, the following code returns the output noted in the video here (https://youtu.be/G-QloRgMfFo). All pixels flash as expected.

NeoPixel Code:

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

Adafruit_NeoPixel strip(60, 7, NEO_GRBW);

uint32_t red = strip.Color(255,0,0,0);
uint32_t yellow = strip.Color(255,255,0,0);
uint32_t white = strip.Color(0,0,0,255);
uint32_t black = strip.Color(0,0,0,0);
uint32_t green = strip.Color(0,255,0,0);
uint32_t blue = strip.Color(0,0,255,0);

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() {
  //Loop sets med wheel colors, then pulses four cardinal directions
  //This is for testing purposes only with the neopixel ring
  for(int x=1; x<5 ; x++){
  colorWheel(); 
  delay(1000);
  pulseWhite(x);
}
}

//Idle colors for circle when no input given
void colorWheel(){
  strip.fill(red, 0, 15);
  strip.fill(green, 15, 15);
  strip.fill(white, 30, 15);
  strip.fill(yellow, 45, 15);
  strip.show();
}

//Pulse direction as white, 6 pixels, when card detected
void pulseWhite(int direction) {
  strip.fill(black);
  int ledStart = 0;
  switch(direction){
    case 1: //North
    ledStart = 27;
    break;
    case 2: //South
    ledStart = 42;
    break;
    case 3: //East
    ledStart = 57;
    break;
    case 4: //West
    ledStart = 12;
    break;
  }
  strip.setBrightness(200);
   for(int j=0; j<255; j+=5) {
    strip.fill(strip.Color(0,0,0,j), ledStart, 6);
    if(direction == 3){ //helps to bridge gap on bottom of ring
    strip.fill(strip.Color(0,0,0,j), 0, 3); 
    }
    strip.show();
    delay(20);
  }
  for(int j=255; j>=0; j-=5) {
    strip.fill(strip.Color(0,0,0,j), ledStart, 6);
    if(direction == 3){ //helps to bridge gap on bottom of ring
    strip.fill(strip.Color(0,0,0,j), 0, 3); 
    }
    strip.show();
    delay(20);
  }
  strip.setBrightness(25);
}


However, when the neopixel code is integrated into the working NFC/Wave code, the pixels lock up. The NFC and Wave remain responsive though! (See video here: https://youtu.be/vTn6nM54yik). You will see a small inline amplifier (built by a friend) which has been added to boost audio levels. We have tested the setup without the microboard and found that our issue still remains.


Wave/NFC/NeoPixel


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

//NeoPixels
Adafruit_NeoPixel strip(60, 7, NEO_GRBW);
uint32_t red = strip.Color(255,0,0,0);
uint32_t yellow = strip.Color(255,255,0,0);
uint32_t black = strip.Color(0,0,0,0);
uint32_t green = strip.Color(0,255,0,0);
uint32_t white = strip.Color(0,0,0,255);

//PN532
int IRQ = 6;
int RESET = 8;
Adafruit_PN532 nfc(IRQ, RESET);

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

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

//Setup
 
void setup() {
  // set up Serial library at 9600 bps
  Serial.begin(9600);
 
  PgmPrintln("Found 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();

//Initialize NeoPixel Ring
strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
strip.fill(black);          // Turn OFF all pixels ASAP
strip.setBrightness(25); // Set BRIGHTNESS to about 1/5 (max = 255)
delay(1000);
colorWheel();
delay(2000);
Serial.println("Function colorWheel called from setup function");
}
 
// 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)
 
  Serial.println("Waiting for an ISO14443A Card ...");
 
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
  uint32_t cardidentifier = 0;
 
  if (success) {
    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) {
      playcomplete("1.WAV");
      pulseWhite(1);
    }
    if (cardidentifier == 981833538) {
      playcomplete("2.WAV"); //Play Audio
      pulseWhite(2); //Flash cardinal direction
    }
    colorWheel(); //Return to idle colors
    delay(1000);
  }
}

//Helpers

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: ");
  Serial.print(card.errorCode(), HEX);
  PgmPrint(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}

void playcomplete(char *name) {
  playfile(name);
  while (wave.isplaying);
  // see if an error occurred while playing
  sdErrorCheck();
}

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

//Idle colors for circle when no input given
void colorWheel(){
  strip.setBrightness(25);
  strip.fill(red, 0, 15);
  strip.fill(green, 15, 15);
  strip.fill(white, 30, 15);
  strip.fill(yellow, 45, 15);
  strip.show();
}

//Pulse direction as white, 6 pixels, when card detected
void pulseWhite(int direction) {
  strip.fill(black);
  int ledStart = 0;
  switch(direction){
    case 1: //North
    ledStart = 27;
    break;
    case 2: //East
    ledStart = 42;
    break;
    case 3:  //South
    ledStart = 57;
    break;
    case 4:  //West
    ledStart = 12;
    break;
  }
  strip.setBrightness(200);
   for(int j=0; j<255; j+=5) {
    strip.fill(strip.Color(0,0,0,j), ledStart, 6);
    if(direction == 3){ //helps to bridge gap on bottom of ring
    strip.fill(strip.Color(0,0,0,j), 0, 3); 
    }
    strip.show();
    delay(20);
  }
  for(int j=255; j>=0; j-=5) {
    strip.fill(strip.Color(0,0,0,j), ledStart, 6);
    if(direction == 3){ //helps to bridge gap on bottom of ring
    strip.fill(strip.Color(0,0,0,j), 0, 3); 
    }
    strip.show();
    delay(20);
  }
  strip.setBrightness(25);
  colorWheel();
}


Again, any help would be greatly appreciated. We are hoping to have this finished and installed by school graduation (end of June) and have put too much work into the project at this point to back away from it!

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

Please be positive and constructive with your questions and comments.