I'm currently developing an Android Application which connects via Bluetooth Low Energy to an Arduino which has the nRF8001 Bluetooth Low Energy Module with a connect the SEN-11574 Pulse Rate Sensor available at Spark Fun ( https://www.sparkfun.com/products/11574 ).
I have been trying to implement a graph which plots the data on the graph every time I tap on 'Get Heart Rate' button but I'm only managing the following:
I've researched a number of different resources which include the following yet unfortunately they don't answer my question:
I am using the Android Graph View Library to try and solve my problem as it offers the best integration with Android Studio.
I am struggling with three main things:
- Labelling the X and Y-Values properly
- Appending the Heart Rate Sensor Data to the Graph
The full project is available at : Arduino Pulse Rate
I seem to be struggling the most with these two sections of code:
private void writeSensorData(final CharSequence text) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Log.e(LOG_TAG,text.toString());
output=text.toString().trim();
if (output.length() > 0 && output.length() <=3) {
pulseRateView.setText(output);
rateSeries.appendData(new GraphView.GraphViewData(graph2LastXValue,Double.parseDouble(output)),AutoScrollX,maxDataCount);
}
else {
return;
}
}
});
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pulse);
//Connect U.I Elements
getPulseRate = (Button)findViewById(R.id.heartRateBtn);
pulseRateView = (TextView) findViewById(R.id.pulseValueView);
connectionStsView = (TextView) findViewById(R.id.connectionStsView);
refreshButton = (Button) findViewById(R.id.refreshBtn);
// init heart rate series data
rateSeries = new GraphViewSeries(new GraphView.GraphViewData[] {
});
GraphView graphView = new LineGraphView(this, "Pulse Rate Sensor");
graphView.addSeries(rateSeries);
graphView.setScrollable(true);
graphView.setScalable(true);
LinearLayout layout = (LinearLayout) findViewById(R.id.graph1);
layout.addView(graphView);
getPulseRate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String setOutputMessage = "/bpm /";
tx.setValue(setOutputMessage.getBytes(Charset.forName("UTF-8")));
if (gatt.writeCharacteristic(tx)) {
writeConnectionData("Sent: " + setOutputMessage);
} else {
writeConnectionData("Couldn't write TX characteristic!");
}
}
});
refreshButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
restartScan();
}
});
}
Would appreciate any help and thank you for your time.