Go Down

Topic: Neopixel & Arduino Pro Nano 5V 16Mhz color Timing/fading problem (Read 1 time) previous topic - next topic

grantf

Hello,

I am trying to port the Meditation Trainer for the Adafruit Circuit Playground Development Board to the Arduino Pro Nano and am having some issues with the Neopixel display.

The original Project is here:
https://learn.adafruit.com/heart-rate-variability-sensor/overview

The issue I am having are two things

Issue#1: The Neopixel breathing ring that goes around and fades doesn't stay the color white.  It changes color from blue, to purple and yellows and greens.... On the circuit playground it is white, then a dimmer white, then off.  so I think that's a timing issue?

Issue#2: The heartbeat led that beat's show different colors.  The two LED's that blink in sync should be the same color but one is showing one range and the other another.

Here is a sample video.
https://onedrive.live.com/embed?cid=7015FC12E89B72B2&resid=7015FC12E89B72B2%2112009&authkey=ALkrW9mfV6XUZz4


There are 4 INO files to the code I'm using, I've attached the code I'm using.  I'm sure the answer I'm looking for is in the notes, but I am not familiar enough with the software/coding side to get this working.  I am guessing it has to do with the timing but I'm at a loss :(...Do I need an 8mhz Arduino perhaps?  Or is there a way to change the code to make it work with a 16mhz chip?  Or is there something completely different that I should be looking towards.

Any help would be appreciated....  Thanks in advance!


PaulRB

Please attach your code and post your links following forum guidelines.

PaulRB

Also please post links to the type of Arduino you are using. I have never heard of an Arduino Pro Nano before.

grantf

Hi PaulRB,

The code is attached as *.ino files on the first post, it supersedes the number of characters permitted so unfortunately you will need to download them.

Lastly, here is a link to the datasheet for the Arduino Nano.  This is what I'm using, the 16mhz 5V version.


https://www.arduino.cc/en/uploads/Main/ArduinoNanoManual23.pdf



Best regards,

Grumpy_Mike

Quote
https://www.arduino.cc/en/uploads/Main/ArduinoNanoManual23.pdf
In what way is a Arduino Pro Nano?

How have you wired it up? Schematic please.

Why have you split up the code into four parts? Please post all your code as a text attachment if it needs to be an attachment, as many mobile devices do not cope with .ino extensions even though they are actually text.

grantf

Hello Grumpy Mike,

For the pure sake of keeping things clean I guess, I am porting the project from an adafruit circuit playground project to an Arduino Nano so rather than reinvent the wheel I kept the format it was originally in.  I agree that the Arduino Pro Nano is nowhere near like the Arduino Nano and it's a mistake on my part, I had named a folder on my computer as Arduino Pro as I also have a trinket, adafruit circuit playground, Uno and a couple of ESP8266 varieties so I sometimes lose track of what everything is called

But for simplicity, here is the code attached as a txt file, and a schematic.

It's a Neopixel ring with the Data5 output going to the input of the neopixel and the  AnalogIn3 being attached to the Heart Rate Monitor Analog pin.

Attached is a Jpg

PaulRB

Code: [Select]

/*  Meditation Trainer by Collin Cunningham for Adafruit Industries
 based on Pulse Sensor Amped 1.4 by Joel Murphy and Yury Gitman   http://www.pulsesensor.com

 Uses a Circuit Playground board's built-in LEDs to diplay a breath pacer, pulse, and relaxation rating

 Hardware requirements:
 - Adafruit Circuit Playground https://www.adafruit.com/products/3000
 - Pulse Sensor Amped https://www.adafruit.com/products/1093

 Wiring:
 - Pulse Sensor Black wire to Circuit Playground GND
 - Pulse Sensor Red wire to Circuit Playground VBATT
 - Pulse Sensor Purple wire to Circuit Playground #6

 Breath Pacer:
 Eight of the neopixel LEDs on the Circuit Playground are used to display a breath pacer which is helpful for ideal timing of inhale/exhale cycles.  Breath in as the LEDs pulse toward one side, and breath out as they move back to the other side.

 Pulse/Relaxation:
 The remaining two LEDs flash with each pulse detected and their color indicates a basic HRV "coherence" rating which roughly translates to the user's level of relaxation:
 - red = low relaxation
 - blue = moderate relaxation
 - green = high relaxation
 
*/

#include <Adafruit_NeoPixel.h>
#define PIN 5
#define FIRST_BREATH_LED 0
#define MIDDLE_BREATH_LED 8
#define LAST_BREATH_LED 11

//  Variables
int pulsePin = A3;                 // Pulse Sensor purple wire connected to analog pin 7

int fadeRate = 0;                 // used to fade LED on with PWM on fadePin
int numPixels = 12;
int breathLED = FIRST_BREATH_LED;
int prevBreathLED = FIRST_BREATH_LED;
bool breathToggle = false;
unsigned long lastBreath = 0;
boolean alive = false;     // we've detected a hearbeat in the last 1.5sec
unsigned long lastAlive;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(numPixels, PIN, NEO_GRBW + NEO_KHZ800);

// Volatile Variables, used in the interrupt service routine!
volatile int BPM;                   // int that holds raw Analog in 0. updated every 2mS
volatile int Signal;                // holds the incoming raw data
volatile int IBI = 600;             // int that holds the time interval between beats! Must be seeded!
volatile boolean Pulse = false;     // "True" when User's live heartbeat is detected. "False" when not a "live beat".
volatile boolean QS = false;        // becomes true when Arduoino finds a beat.
volatile int tCoh = 10;             // coherence values total
volatile int rCoh = 50;             // coherence rating

// Regards Serial OutPut  -- Set This Up to your needs
static boolean serialVisual = true;   // Set to 'false' by Default.  Re-set to 'true' to see Arduino Serial Monitor ASCII Visual Pulse

unsigned long ledTimes[] = {520, 520, 520,520, 520, 520, 520, 520, 520, 520, 740, 740 };  //mostly linear led times for breath pacer

void setup() {
  Serial.begin(115200);             // we agree to talk fast!
//  CircuitPlayground.begin();
  strip.begin();
  strip.setBrightness(30); //adjust brightness here
  strip.show(); // Initialize all pixels to 'off'
  
  interruptSetup();                 // sets up to read Pulse Sensor signal every 2mS
  // IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE BOARD VOLTAGE,
  // UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF PIN4
  //   analogReference(EXTERNAL);

  lastBreath = millis();
}


//  Where the Magic Happens
void loop() {

  serialOutput() ;

  if (QS == true) {    // A Heartbeat Was Found
    //    updateBreathLED();
    alive = true;
    lastAlive = millis();
    // BPM and IBI have been Determined
    // Quantified Self "QS" true when arduino finds a heartbeat
    fadeRate = 255;         // Makes the LED Fade Effect Happen
    // Set 'fadeRate' Variable to 255 to fade LED with pulse
    serialOutputWhenBeatHappens();   // A Beat Happened, Output that to serial.
    QS = false;                      // reset the Quantified Self flag for next time
  }
  
  unsigned long now = millis();
  if (now - lastAlive > 5000) {
    alive = false;
    //reset coherence values
    tCoh = 10;
    rCoh = 10;
  }

  ledFadeToBeat();                      // Makes the LED Fade Effect Happen
  
  delay(20);                             //  take a break
  
}

//This is the ring timer.

void updateBreathLED() {

  //  if (!alive) {
  //    for (int i = 1; i <= numPixels - 2; i++) {
  //      CircuitPlayground.strip.setPixelColor(i, CircuitPlayground.strip.Color(0, 0, 0));
  //    }
  //    breathLED = 0;
  //    return;
  //  }

  if (breathLED < FIRST_BREATH_LED) {
    breathLED = FIRST_BREATH_LED;
    breathToggle = false;
  }
  else if (breathLED > LAST_BREATH_LED) {
    breathLED = LAST_BREATH_LED;
    breathToggle = true;
  }

  //check if we're due to update the breath indicator
  unsigned long timeNow = millis();
  unsigned long timeSince = timeNow - lastBreath;

  unsigned long breathTime = ledTimes[breathLED];
  if (breathToggle) { breathTime = ledTimes[12 - breathLED]; }

  //  if (timeSince >= 545) {
  if (timeSince >= breathTime) {
    prevBreathLED = breathLED;  //save ref to last LED for chase/fade
    if (breathToggle) {
      breathLED -= 1;
    }
    else {
      breathLED += 1;
    }
    lastBreath = timeNow;
  }

  for (int i = 1; i <= numPixels - 1; i++) {
    if ((i == FIRST_BREATH_LED ) || (i == LAST_BREATH_LED)) { //first and last LEDs are used by pulse
      continue;
    }
    if (i == breathLED) { //leading breath LED
     strip.setPixelColor(i, strip.Color(200, 200, 200));
    }
    else if (i == prevBreathLED) {  //chaser/fade LED
      strip.setPixelColor(i, strip.Color(16, 16, 16));
    }
        
    else strip.setPixelColor(i, strip.Color(0, 0, 0));
  }

}


void ledFadeToBeat() {
  fadeRate -= 15;                         //  set LED fade value
  fadeRate = constrain(fadeRate, 0, 255); //  keep LED fade value from going into negative numbers!

  //find color mods
  int r, g, b;
  if (tCoh >= 6) {
    r = 1; g = 0; b = 0;
  }
  else if (tCoh >= 3) {
    r = 0; g = 0; b = 1;
  }
  else {
    r = 0; g = 1; b = 0;
  }

  //fade first and last pixels to represent pulse
  strip.setPixelColor(0, strip.Color(fadeRate * r, fadeRate * g, fadeRate * b));
  strip.setPixelColor(11, strip.Color(fadeRate * r, fadeRate * g, fadeRate * b));
  
  
  //move breath LED
  updateBreathLED();

  strip.show();

}





PaulRB

This entire section appears to be a comment.
Code: [Select]


/*
  These notes put together by Joel Murphy for Pulse Sensor Amped, 2015

  The code that this section is attached to uses a timer interrupt
  to sample the Pulse Sensor with consistent and regular timing.
  The code is setup to read Pulse Sensor signal at 500Hz (every 2mS).
  The reasoning for this can be found here:
  http://pulsesensor.com/pages/pulse-sensor-amped-arduino-v1dot1
 
  There are issues with using different timers to control the Pulse Sensor sample rate.
  Sometimes, user will need to switch timers for access to other code libraries.
  Also, some other hardware may have different timer setup requirements. This page
  will cover those different needs and reveal the necessary settings. There are two
  part of the code that will be discussed. The interruptSetup() routine, and
  the interrupt function call. Depending on your needs, or the Arduino variant that you use,
  check below for the correct settings.
 
 
  ******************************************************************************************
  ARDUINO UNO, Pro 328-5V/16MHZ, Pro-Mini 328-5V/16MHz (or any board with ATmega328P running at 16MHz)
 
 >> Timer2
 
    Pulse Sensor Arduino UNO uses Timer2 by default.
    Use of Timer2 interferes with PWM on pins 3 and 11.
    There is also a conflict with the Tone library, so if you want tones, use Timer1 below.
   
      void interruptSetup(){     
        // Initializes Timer2 to throw an interrupt every 2mS.
        TCCR2A = 0x02;     // DISABLE PWM ON DIGITAL PINS 3 AND 11, AND GO INTO CTC MODE
        TCCR2B = 0x06;     // DON'T FORCE COMPARE, 256 PRESCALER
        OCR2A = 0X7C;      // SET THE TOP OF THE COUNT TO 124 FOR 500Hz SAMPLE RATE
        TIMSK2 = 0x02;     // ENABLE INTERRUPT ON MATCH BETWEEN TIMER2 AND OCR2A
        sei();             // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED     
      }
 
    use the following interrupt vector with Timer2
   
      ISR(TIMER2_COMPA_vect)
     
 >> Timer1
   
    Use of Timer1 interferes with PWM on pins 9 and 10.
    The Servo library also uses Timer1, so if you want servos, use Timer2 above.
   
      void interruptSetup(){     
        // Initializes Timer1 to throw an interrupt every 2mS.
        TCCR1A = 0x00; // DISABLE OUTPUTS AND PWM ON DIGITAL PINS 9 & 10
        TCCR1B = 0x11; // GO INTO 'PHASE AND FREQUENCY CORRECT' MODE, NO PRESCALER
        TCCR1C = 0x00; // DON'T FORCE COMPARE
        TIMSK1 = 0x01; // ENABLE OVERFLOW INTERRUPT (TOIE1)
        ICR1 = 16000;  // TRIGGER TIMER INTERRUPT EVERY 2mS 
        sei();         // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED     
      }
     
    Use the following ISR vector for the Timer1 setup above
   
      ISR(TIMER1_OVF_vect)
     
 >> Timer0
 
    DON'T USE TIMER0! Timer0 is used for counting delay(), millis(), and micros().
                      Messing with Timer0 is highly unadvised!
 
  ******************************************************************************************
  ARDUINO Fio, Lilypad, ProMini328-3V/8MHz (or any board with ATmega328P running at 8MHz)
 
  >> Timer2
 
    Pulse Sensor Arduino UNO uses Timer2 by default.
    Use of Timer2 interferes with PWM on pins 3 and 11.
    There is also a conflict with the Tone library, so if you want tones, use Timer1 below.
   
      void interruptSetup(){     
        // Initializes Timer2 to throw an interrupt every 2mS.
        TCCR2A = 0x02;     // DISABLE PWM ON DIGITAL PINS 3 AND 11, AND GO INTO CTC MODE
        TCCR2B = 0x05;     // DON'T FORCE COMPARE, 128 PRESCALER
        OCR2A = 0X7C;      // SET THE TOP OF THE COUNT TO 124 FOR 500Hz SAMPLE RATE
        TIMSK2 = 0x02;     // ENABLE INTERRUPT ON MATCH BETWEEN TIMER2 AND OCR2A
        sei();             // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED     
      }
 
    use the following interrupt vector with Timer2
   
      ISR(TIMER2_COMPA_vect)
     
 >> Timer1
   
    Use of Timer1 interferes with PWM on pins 9 and 10.
    The Servo library also uses Timer1, so if you want servos, use Timer2 above.
   
      void interruptSetup(){     
        // Initializes Timer1 to throw an interrupt every 2mS.
        TCCR1A = 0x00; // DISABLE OUTPUTS AND PWM ON DIGITAL PINS 9 & 10
        TCCR1B = 0x11; // GO INTO 'PHASE AND FREQUENCY CORRECT' MODE, NO PRESCALER
        TCCR1C = 0x00; // DON'T FORCE COMPARE
        TIMSK1 = 0x01; // ENABLE OVERFLOW INTERRUPT (TOIE1)
        ICR1 = 8000;  // TRIGGER TIMER INTERRUPT EVERY 2mS 
        sei();         // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED     
      }
     
    Use the following ISR vector for the Timer1 setup above
   
      ISR(TIMER1_OVF_vect)
     
 >> Timer0
 
    DON'T USE TIMER0! Timer0 is used for counting delay(), millis(), and micros().
                      Messing with Timer0 is highly unadvised!
 
 
  ******************************************************************************************
  ARDUINO Leonardo (or any board with ATmega32u4 running at 16MHz)
 
  >> Timer1
 
    Use of Timer1 interferes with PWM on pins 9 and 10.
   
      void interruptSetup(){
          TCCR1A = 0x00;
          TCCR1B = 0x0C; // prescaler = 256
          OCR1A = 0x7C;  // count to 124 
          TIMSK1 = 0x02;
          sei();
      }
 
  The only other thing you will need is the correct ISR vector in the next step.
       
      ISR(TIMER1_COMPA_vect)
 
 
  ******************************************************************************************
  ADAFRUIT Flora, ARDUINO Fio v3 (or any other board with ATmega32u4 running at 8MHz)
 
  >> Timer1
 
    Use of Timer1 interferes with PWM on pins 9 and 10.
   
      void interruptSetup(){
          TCCR1A = 0x00;
          TCCR1B = 0x0C; // prescaler = 256
          OCR1A = 0x3E;  // count to 62
          TIMSK1 = 0x02;
          sei();
      }
 
  The only other thing you will need is the correct ISR vector in the next step.
       
      ISR(TIMER1_COMPA_vect)

  ******************************************************************************************
  ADAFRUIT Gemma (or any other board with ATtiny85 running at 8MHz)
 
    NOTE: Gemma does not do serial communication!
          Comment out or remove the Serial code in the Arduino sketch!
 
  Timer1
 
    Use of Timer1 breaks PWM output on pin D1
   
      void interruptSetup(){     
        TCCR1 = 0x88;      // Clear Timer on Compare, Set Prescaler to 128 TEST VALUE
        GTCCR &= 0x81;     // Disable PWM, don't connect pins to events
        OCR1C = 0x7C;      // Set the top of the count to  124 TEST VALUE
        OCR1A = 0x7C;      // Set the timer to interrupt after counting to TEST VALUE
        bitSet(TIMSK,6);   // Enable interrupt on match between TCNT1 and OCR1A
        sei();             // Enable global interrupts     
      }

    The only other thing you will need is the correct ISR vector in the next step.
   
      ISR(TIMER1_COMPA_vect)
 
 
  ******************************************************************************************
 
 
 
 
 
  ******************************************************************************************
 
 
 
 
 
  ******************************************************************************************
 
 
 
 
 
  ******************************************************************************************
 
 
 
 
 
  ******************************************************************************************
 
 
 
 
 
  ******************************************************************************************
 
 
 
 
 
  ******************************************************************************************
 
 
 
 
*/








PaulRB

Code: [Select]

volatile int rate[10];                    // array to hold last ten IBI values
volatile unsigned long sampleCounter = 0;          // used to determine pulse timing
volatile unsigned long lastBeatTime = 0;           // used to find IBI
volatile int P = 512;                     // used to find peak in pulse wave, seeded
volatile int T = 512;                     // used to find trough in pulse wave, seeded
volatile int thresh = 525;                // used to find instant moment of heart beat, seeded
volatile int amp = 100;                   // used to hold amplitude of pulse waveform, seeded
volatile boolean firstBeat = true;        // used to seed rate array so we startup with reasonable BPM
volatile boolean secondBeat = false;      // used to seed rate array so we startup with reasonable BPM

volatile int lastIBI = 0;
volatile boolean goingUp;

//Coherence vars
volatile int coh = 0;              // running coherence rating
volatile unsigned long lastCoh = 0;
volatile unsigned long cohPeriod = 12000;


//void interruptSetup(){
//  // Initializes Timer2 to throw an interrupt every 2mS.
//  TCCR2A = 0x02;     // DISABLE PWM ON DIGITAL PINS 3 AND 11, AND GO INTO CTC MODE
//  TCCR2B = 0x06;     // DON'T FORCE COMPARE, 256 PRESCALER
//  OCR2A = 0X7C;      // SET THE TOP OF THE COUNT TO 124 FOR 500Hz SAMPLE RATE
//  TIMSK2 = 0x02;     // ENABLE INTERRUPT ON MATCH BETWEEN TIMER2 AND OCR2A
//  sei();             // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED
//}

void interruptSetup() {
  TCCR1A = 0x00;
  TCCR1B = 0x0C; // prescaler = 256
  OCR1A = 0x7C;  // count to 124
  TIMSK1 = 0x02;
  sei();
}


PaulRB

Code: [Select]


// THIS IS THE TIMER 2 INTERRUPT SERVICE ROUTINE.
// Timer 2 makes sure that we take a reading every 2 miliseconds
ISR(TIMER1_COMPA_vect) {                        // triggered when Timer2 counts to 124
  cli();                                      // disable interrupts while we do this
  Signal = analogRead(pulsePin);              // read the Pulse Sensor
  sampleCounter += 2;                         // keep track of the time in mS with this variable
  int N = sampleCounter - lastBeatTime;       // monitor the time since the last beat to avoid noise

  //  find the peak and trough of the pulse wave
  if (Signal < thresh && N > (IBI / 5) * 3) { // avoid dichrotic noise by waiting 3/5 of last IBI
    if (Signal < T) {                       // T is the trough
      T = Signal;                         // keep track of lowest point in pulse wave
    }
  }

  if (Signal > thresh && Signal > P) {        // thresh condition helps avoid noise
    P = Signal;                             // P is the peak
  }                                        // keep track of highest point in pulse wave

  //  NOW IT'S TIME TO LOOK FOR THE HEART BEAT
  // signal surges up in value every time there is a pulse
  if (N > 250) {                                  // avoid high frequency noise
    if ( (Signal > thresh) && (Pulse == false) && (N > (IBI / 5) * 3) ) {
      Pulse = true;                               // set the Pulse flag when we think there is a pulse
//      digitalWrite(blinkPin, HIGH);               // turn on pin 13 LED
      lastIBI = IBI;                              // save reference to last IBI
      IBI = sampleCounter - lastBeatTime;         // measure time between beats in mS
      lastBeatTime = sampleCounter;               // keep track of time for next pulse
      
      //update coherence
      unsigned long now = millis();
      if ((now - lastCoh) > cohPeriod) {
        lastCoh = now;
        tCoh = coh;
        coh = 0;
      }

      if (IBI < lastIBI && goingUp == true) { // check IBI wave trend
        goingUp = false;                 // now changing direction from up to down
        coh += 1;                        // record peak
      }
      else if (IBI > lastIBI && goingUp == false) {
        goingUp = true;                  // now changing direction from down to up
      }

      if (secondBeat) {                      // if this is the second beat, if secondBeat == TRUE
        secondBeat = false;                  // clear secondBeat flag
        for (int i = 0; i <= 9; i++) {       // seed the running total to get a realisitic BPM at startup
          rate[i] = IBI;
        }
      }

      if (firstBeat) {                       // if it's the first time we found a beat, if firstBeat == TRUE
        firstBeat = false;                   // clear firstBeat flag
        secondBeat = true;                   // set the second beat flag
        sei();                               // enable interrupts again
        return;                              // IBI value is unreliable so discard it
      }


      // keep a running total of the last 10 IBI values
      word runningTotal = 0;                  // clear the runningTotal variable

      for (int i = 0; i <= 8; i++) {          // shift data in the rate array
        rate[i] = rate[i + 1];                // and drop the oldest IBI value
        runningTotal += rate[i];              // add up the 9 oldest IBI values
      }

      rate[9] = IBI;                          // add the latest IBI to the rate array
      runningTotal += rate[9];                // add the latest IBI to runningTotal
      runningTotal /= 10;                     // average the last 10 IBI values
      BPM = 60000 / runningTotal;             // how many beats can fit into a minute? that's BPM!
      QS = true;                              // set Quantified Self flag
      // QS FLAG IS NOT CLEARED INSIDE THIS ISR
    }
  }

  if (Signal < thresh && Pulse == true) {  // when the values are going down, the beat is over
//    digitalWrite(blinkPin, LOW);           // turn off pin 13 LED
    Pulse = false;                         // reset the Pulse flag so we can do it again
    amp = P - T;                           // get amplitude of the pulse wave
    thresh = amp / 2 + T;                  // set thresh at 50% of the amplitude
    P = thresh;                            // reset these for next time
    T = thresh;
  }

  if (N > 2500) {                          // if 2.5 seconds go by without a beat
    thresh = 512;                          // set thresh default
    P = 512;                               // set P default
    T = 512;                               // set T default
    lastBeatTime = sampleCounter;          // bring the lastBeatTime up to date
    firstBeat = true;                      // set these to avoid noise
    secondBeat = false;                    // when we get the heartbeat back
  }

  sei();                                   // enable interrupts when youre done!
}// end isr









//////////
/////////  All Serial Handling Code,
/////////  It's Changeable with the 'serialVisual' variable
/////////  Set it to 'true' or 'false' when it's declared at start of code.  
/////////

void serialOutput(){   // Decide How To Output Serial.
 if (serialVisual == true){  
     arduinoSerialMonitorVisual('-', Signal);   // goes to function that makes Serial Monitor Visualizer
 } else{
      sendDataToSerial('S', Signal);     // goes to sendDataToSerial function
 }        
}


//  Decides How To OutPut BPM and IBI Data
void serialOutputWhenBeatHappens(){    
 if (serialVisual == true){            //  Code to Make the Serial Monitor Visualizer Work
    Serial.print("*** Heart-Beat Happened *** ");  //ASCII Art Madness
    Serial.print("BPM: ");
    Serial.print(BPM);
    Serial.print("  ");
    Serial.println("  ");
 } else{
        sendDataToSerial('B',BPM);   // send heart rate with a 'B' prefix
        sendDataToSerial('Q',IBI);   // send time between beats with a 'Q' prefix
 }  
}



//  Sends Data to Pulse Sensor Processing App, Native Mac App, or Third-party Serial Readers.
void sendDataToSerial(char symbol, int data ){
    Serial.print(symbol);

    Serial.println(data);                
  }


//  Code to Make the Serial Monitor Visualizer Work
void arduinoSerialMonitorVisual(char symbol, int data ){    

  /*const int sensorMin = 0;      // sensor minimum, discovered through experiment
const int sensorMax = 1024;    // sensor maximum, discovered through experiment

  int sensorReading = data;
  // map the sensor range to a range of 12 options:
  int range = map(sensorReading, sensorMin, sensorMax, 0, 11);

  // do something different depending on the
  // range value:
  switch (range) {
  case 0:    
    Serial.println("");     /////ASCII Art Madness
    break;
  case 1:  
    Serial.println("---");
    break;
  case 2:    
    Serial.println("------");
    break;
  case 3:    
    Serial.println("---------");
    break;
  case 4:  
    Serial.println("------------");
    break;
  case 5:  
    Serial.println("--------------|-");
    break;
  case 6:  
    Serial.println("--------------|---");
    break;
  case 7:  
    Serial.println("--------------|-------");
    break;
  case 8:  
    Serial.println("--------------|----------");
    break;
  case 9:    
    Serial.println("--------------|----------------");
    break;
  case 10:  
    Serial.println("--------------|-------------------");
    break;
  case 11:  
    Serial.println("--------------|-----------------------");
    break;
  
  }
  
  
   */
}


PaulRB

OP posted this instead of a schematic:

Wawa

How are you powering this Nano, and what else is powered from the 5volt pin.
The USB backflow protection diode will probably go up in smoke when you drive more than eight LEDs full white.
That number is reduced even further if you power the nano from e.g 9volt on the RAW pin.
Leo..

grantf

I'm running off of a USB port connected to an FTDI232 adapter hooked to my PC and I have also ran it with an external 5v supply to pin 27(+5v) and pin 4 (GND)

Luckily I only have to run 3 or 4 led's at max level at a time....  2 for the heartbeat sensor that change red/blue/green based on the HRV interval and 1 at full level for the rotating led and run at half level for the fade effect.


Would the voltage have an effect on the fading color?  The led's that go around in the ring are pink, green, blue, yellow and not white.  Also the two heartbeat LED's should be the same color but one is at one interval (say blue) and the other at a lower interval (say red).



Thanks for everyone's help so far, it's my first post on this forum so thanks for being patient.

Wawa

I'm running off of a USB port connected to an FTDI232 adapter hooked to my PC...
Confused. Why? A Nano has a buildin USB<>Serial chip.
Unless you're not using a Nano.

Would the voltage have an effect on the fading color?
Yes, it's possible.
If the 5volt supply sags too much, then there could be some red shift.
Red LEDs have a lower working voltage, so they are the last one to dim.
Leo..

Grumpy_Mike

The ledFadeToBeat function sets the LEDs to colours other than shaded of white.

Go Up