Catching Heartbeats with the Gadgeteer


I reckon the Gadgeteer has more interfaces than just about any other embedded framework. Including neat things like this Pulse Oximeter from Seeed. They make the point on the product description that you should not use this as a medical instrument but, what with the theme of GlobalGameJam being heartbeats, and me having one to play with, the temptation to use it in our game was very hard to resist.

Using it is very easy indeed. You can bind to events that fire when connected (i.e. someone has put their finger into the sensor), disconnected (when someone has pulled their finger out, so to speak) and on a pulse detected event. You can also read the sensor object to find out pulse rate, blood oxygen levels and signal strength.

This is my code to bind methods to the sensor events:

pulseOximeter.ProbeAttached += 
   new PulseOximeter.ProbeAttachedHandler(pulseOximeter_ProbeAttached);
pulseOximeter.ProbeDetached += 
   new PulseOximeter.ProbeDetachedHandler(pulseOximeter_ProbeDetached);
pulseOximeter.Heartbeat += 
    new PulseOximeter.HeartbeatHandler(pulseOximeter_Heartbeat);

The handlers then do all the work:

void pulseOximeter_Heartbeat(PulseOximeter sender, 
PulseOximeter.Reading reading) { sendMessage("P" + reading.PulseRate.ToString()); }

The sendMessage method takes a string and sends it on to the game via a serial port interface that is also connected to the Gadgeteer device. The sensor has proved to be quite sensitive and works rather well. It is quite unnerving to be playing a game and find that the gameplay matches your heartbeat.