From 9334564f34df871e3524fdc936106b22d586fc0f Mon Sep 17 00:00:00 2001 From: Drew Fustini Date: Mon, 2 May 2011 11:25:24 -0500 Subject: [PATCH] Update from Shawn temp integartion --- ps1biosensor_arduino/ps1biosensor_arduino.pde | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/ps1biosensor_arduino/ps1biosensor_arduino.pde b/ps1biosensor_arduino/ps1biosensor_arduino.pde index 55e8ac3..c24677a 100644 --- a/ps1biosensor_arduino/ps1biosensor_arduino.pde +++ b/ps1biosensor_arduino/ps1biosensor_arduino.pde @@ -5,9 +5,8 @@ * The code reads analog inputs and sends the data in an Open EEG * Modular EEG 17 byte packet format back to the computer. */ - -#include //from http://www.arduino.cc/playground/Code/Timer1 - +#include //from http://www.arduino.cc/playground/Code/Timer1 +#include int ledPin = 13; // pin for the LED int chan1 = 0; // analog pin for chan 1 int chan2 = 1; // analog pin for chan 2 @@ -15,11 +14,15 @@ int ledStatus = LOW; // we use a variable to toggle the LEDs state int ekg, oxy = 0; // variable to store the analog reading char cnt =0; int i; - -byte packet[17] = { +int temperature; +int sensorAddress = 0x91 >> 1; // From datasheet temp sensor address is 0x91 +// shift the address 1 bit right, the Wire library only needs the 7 +// most significant bits for the address +byte packet[17] = { 0xa5, 0x5a, 0x02, cnt, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 0 }; - +byte msb; +byte lsb; void setup() { pinMode(ledPin, OUTPUT); // declare the ledPin as an output Serial.begin(57600); // initialize the serial port @@ -27,9 +30,20 @@ void setup() { Timer1.initialize(3906); Timer1.pwm(9, 512); Timer1.attachInterrupt(ReadData); + Wire.begin(); // join i2c bus (address optional for master) } -void loop () { +void loop () { + Wire.requestFrom(sensorAddress,2); + if (2 <= Wire.available()) // if two bytes were received + { + msb = Wire.receive(); // receive high byte (full degrees) + lsb = Wire.receive(); // receive low byte (fraction degrees) + temperature = ((msb) << 4); // MSB + temperature |= (lsb >> 4); // LSB + //temperature = temperature * 0.0625; + } + delay(500); } void ReadData() { @@ -40,8 +54,10 @@ void ReadData() { packet [3] = cnt; packet [5] = ekg; packet [4] = ekg>>8; - packet [7] = oxy; - packet [6] = oxy >>8; + packet [6] = temperature; + packet [7] = temperature>>8; + //packet [8] = oxy; + //packet [9] = oxy >>8; for (i=0; i< 17; i++) { Serial.print ( packet [i], BYTE); } @@ -50,5 +66,5 @@ void ReadData() { // change the state of the LED (if HIGH, then LOW, and viceversa) ledStatus = cnt >> 7; digitalWrite(ledPin, ledStatus); - } +