The baud is 112500 on arduino and on protopie too.
But it says "failed to connect". But I also made sure that the Protopie and Arduino matched ports
I also attach the code (Basically it only measures the heart rate. I used very small units for the heart rate. But if it is High, red light turns on. If it is low, blue light, if it is normal then green and it is measured from a MAX30105 sensor.)
#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include "MAX30105.h"
#include "heartRate.h"
#ifdef __AVR__
#include <avr/power.h>
#endif
// NeoPixel setup
#define PIN 6
#define NUMPIXELS 16
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
// MAX30105 setup
MAX30105 particleSensor;
const byte RATE_SIZE = 4;
byte rates[RATE_SIZE];
byte rateSpot = 0;
long lastBeat = 0;
float beatsPerMinute;
int beatAvg;
#define DELAYVAL 500
bool messageDisplayed = false;
bool startReading = true;
String statusMessage = "";
void setup() {
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
pixels.begin();
Serial.begin(115200);
Serial.println("Initializing...");
if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) {
Serial.println("MAX30102 was not found. Please check wiring/power. ");
while (1);
}
Serial.println("Place your index finger on the sensor with steady pressure.");
particleSensor.setup();
particleSensor.setPulseAmplitudeRed(0x0A);
particleSensor.setPulseAmplitudeGreen(0);
}
void loop() {
if (Serial.available() > 0) {
String command = Serial.readStringUntil('\n');
if (command == "start") {
startReading = true;
}
}
if (startReading && !messageDisplayed) {
long irValue = particleSensor.getIR();
if (irValue < 50000) {
Serial.println("Adjust the wrist.||");
messageDisplayed = false;
delay(1000);
} else {
long delta = millis() - lastBeat;
lastBeat = millis();
beatsPerMinute = 60 / (delta / 1000.0);
if (beatsPerMinute < 255 && beatsPerMinute > 20)
{
rates[rateSpot++] = (byte)beatsPerMinute; //Store this reading in the array
rateSpot %= RATE_SIZE; //Wrap variable
//Take average of readings
beatAvg = 0;
for (byte x = 0 ; x < RATE_SIZE ; x++)
beatAvg += rates[x];
beatAvg /= RATE_SIZE;
}
updateNeoPixels(beatsPerMinute);
messageDisplayed = true;
}
} else if (!startReading) {
Serial.println("Waiting for start command...");
delay(1000);
} else {
long irValue = particleSensor.getIR();
if (irValue < 50000) {
messageDisplayed = false;
}
delay(1000);
}
}
void updateNeoPixels(float beatsPerMinute) {
pixels.clear(); // Clear the pixel buffer
uint32_t color; // Variable to store the color
String statusMessage; // Variable to store the status message
// Adjusted BPM ranges to accommodate lower values
if (beatsPerMinute > 0 && beatsPerMinute < 255) {
if (beatsPerMinute < 2) { // Adjusted for very low readings
color = pixels.Color(0, 0, 255); // Blue for extremely low heart rate
statusMessage = "{\"BPM\": \"Low\", \"value\":" + String(beatsPerMinute) + "}";
Serial.println("Your heart rate is low||");
} else if (beatsPerMinute <= 40) {
color = pixels.Color(0, 150, 0); // Green for low but within a normal range
statusMessage = "{\"BPM\": \"Normal\", \"value\":" + String(beatsPerMinute) + "}";
Serial.println("Your heart rate is normal||");
} else { // Adjusted for BPM above 40
color = pixels.Color(150, 0, 0); // Red for high heart rate
Serial.println("Your heart rate is high||");
statusMessage = "{\"BPM\": \"High\", \"value\":" + String(beatsPerMinute) + "}";
}
} else {
color = pixels.Color(150, 150, 150); // Grey for undefined heart rate
statusMessage = "HeartRateUndefined";
}
// Set color for each pixel
for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, color);
}
pixels.show(); // Update the NeoPixels with the new color
delay(DELAYVAL); // Delay for better visualization
// Send the heart rate status to the serial monitor for debugging
Serial.print("BPM: ");
Serial.print(beatsPerMinute);
Serial.print(", Status: ");
Serial.println(statusMessage);
}