Flash/Heart Beat Sensor Query

Hi,

I am getting HRMI data through the arduino serial fine but i need it to read the value from the sensor and then send it as an analog pin value using firmata.....mainly because i am using the firmata sketch to allow my arduino to talk to flash.

I'm having trouble because to get the heart rate data you have to send it a specific request (G1 followed by a carriage return)

The code is below:

/*
* Simple Arduino-based program to read values from the HRMI using the I2C interface
*
* Connections
*    Arduino            HRMI
*    -----------------------
*      +5                +5 (Power for the HRMI)
*      GND               GND
*      Analog In 5       TX (I2C SCL) (recommend 4.7 kOhm pullup)
*      Analog In 4       RX (I2C SDA) (recommend 4.7 kOhm pullup)
*
*/

#include "Wire.h"
#include "hrmi_funcs.h"

/*
* Configuration Information
*
* Change these constants to match your specific configuration.  These
* values are the factory default (no OP1-OP7 jumpers installed).  Jumper
* OP1 should be installed and jumper SJ1 removed.
*
* HRMI_HOST_BAUDRATE should be set to the baudrate the host will use
*   to communicate with the Arduino over the serial interface.
*
* HRMI_I2C_ADDR should be set to the I2C address the HRMI is configured
*   with.
*/
#define HRMI_HOST_BAUDRATE 9600
#define HRMI_I2C_ADDR      127


/*
* Program constants
*/
#define MAX_IN_BUFFSIZE 16


/*
* Global variables
*/
char serInStr[MAX_IN_BUFFSIZE];   // Serial input string array
int numEntries = 1;               // Number of HR values to request
int numRspBytes;                  // Number of Response bytes to read
byte i2cRspArray[34];                // I2C response array, sized to read 32 HR values
byte hrmi_addr = HRMI_I2C_ADDR;   // I2C address to use


/*
* Arduino initialization code segment
*/
void setup()
{
 // Initialize the I2C communication
 hrmi_open();

 // Initialize the serial interface
 Serial.begin(HRMI_HOST_BAUDRATE);
}

void loop()
{
 // Request a set of heart rate values
 hrmiCmdArg(hrmi_addr, 'G', (byte) numEntries);
    
 // Get the response from the HRMI
 numRspBytes = numEntries + 2;
 if (hrmiGetData(hrmi_addr, numRspBytes, i2cRspArray) != -1) {
   // send the results back on the serial interface in ASCII form
   for (int i=0; i<numRspBytes; i++) {
     Serial.print(i2cRspArray[i], DEC);
     Serial.print(" ");
   }
   Serial.println();
  }

 delay(1000);   // Delay 1 second between commands
}

that prints 2 values via the serial command...a number dictating whether or not the data following it is 'good' or not....an incremental number...and the heart rate value itself

Any ideas how i would take the 3rd number printed and convert it into an anlogue pin value? I asked someone a lot smarter than myself and he 'suggested' thats what i needed to do but im not 100% sure i understand him....i am a noob when it comes to Arduinos and would appreciate any help/advice given

thanks

Adam

Analog pins are read only. You can't put a value on an analog pin.

PaulS

Analog pins are read only. You can't put a value on an analog pin.

thanks......that's really helpful......