Skip to content

Commit 3e59f68

Browse files
author
Joice TM
committed
added support for new Open-ox board, moved pin configurations to src file
1 parent cc8a199 commit 3e59f68

File tree

6 files changed

+143
-101
lines changed

6 files changed

+143
-101
lines changed

examples/Example-1-Raw-PPG-plot-openview/Example-1-Raw-PPG-plot-openview.ino

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424

2525
const int SPISTE = 7; // chip select
2626
const int SPIDRDY = 2; // data ready pin
27-
const int RESET =5; // data ready pin
28-
const int PWDN =4; // data ready pin
27+
const int PWDN =4;
28+
const int DRDY_INTNUM =0; //digital pin2 interrupt num = 0. Please pass correct interrupt number if you are using any boards otherthan arduino uno
2929

3030
int datalen = 10;
3131

3232
volatile char DataPacket[10];
33-
volatile char DataPacketFooter[2];
34-
volatile char DataPacketHeader[6];
33+
volatile char DataPacketFooter[2]={0x00, CES_CMDIF_PKT_STOP};
34+
const char DataPacketHeader[6] = {CES_CMDIF_PKT_START_1, CES_CMDIF_PKT_START_2, datalen, ((uint8_t)(datalen >> 8)), CES_CMDIF_TYPE_DATA};
3535

3636
AFE4490 afe4490;
3737

@@ -71,33 +71,17 @@ void sendDataThroughUart(afe44xx_output_values * afe4490Data){
7171
void setup()
7272
{
7373
Serial.begin(57600);
74-
Serial.println("Intilazition AFE44xx.. ");
74+
Serial.println("Intilaziting AFE44xx.. ");
7575

7676
delay(2000) ; // pause for a moment
7777

7878
SPI.begin();
79-
80-
// set the directions
81-
pinMode (SPISTE,OUTPUT);//Slave Select
82-
pinMode (SPIDRDY,INPUT);// data ready
83-
84-
attachInterrupt(0, afe44xx_drdy_event, RISING ); // Digital2 is attached to Data ready pin of AFE is interrupt0 in ARduino
85-
// set SPI transmission
8679
SPI.setClockDivider (SPI_CLOCK_DIV8); // set Speed as 2MHz , 16MHz/ClockDiv
8780
SPI.setDataMode (SPI_MODE0); //Set SPI mode as 0
8881
SPI.setBitOrder (MSBFIRST); //MSB first
8982

90-
//Packet structure
91-
DataPacketHeader[0] = CES_CMDIF_PKT_START_1; //packet header1 0x0A
92-
DataPacketHeader[1] = CES_CMDIF_PKT_START_2; //packet header2 0xFA
93-
DataPacketHeader[2] = datalen; // data length 9
94-
DataPacketHeader[3] = (uint8_t)(datalen >> 8);
95-
DataPacketHeader[4] = CES_CMDIF_TYPE_DATA;
96-
DataPacketFooter[0] = 0x00;
97-
DataPacketFooter[1] = CES_CMDIF_PKT_STOP;
98-
99-
afe4490.afe44xxInit (SPISTE);
100-
Serial.println("intilazition is done");
83+
afe4490.afe44xxInit (SPISTE, SPIDRDY, DRDY_INTNUM, PWDN);
84+
Serial.println("intilazition done");
10185
}
10286

10387
void loop()

examples/Example-2-computed-spo2/Example-2-computed-spo2.ino

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Copyright (c) 2018 ProtoCentral
66
//
77
// This software is licensed under the MIT License(http://opensource.org/licenses/MIT).
8-
//
8+
//
99
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
1010
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
1111
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
@@ -19,57 +19,53 @@
1919
#include "Protocentral_AFE4490_Oximeter.h"
2020

2121
const int SPISTE = 7; // chip select
22-
const int SPIDRDY = 2; // data ready pin
23-
const int RESET =5; // data ready pin
24-
const int PWDN =4; // data ready pin
25-
26-
int datalen = 10;
22+
const int SPIDRDY = 2; // data ready pin
23+
const int PWDN =4;
24+
const int DRDY_INTNUM =0; //digital pin2 interrupt num = 0. Please pass correct interrupt number if you are using any boards otherthan arduino uno
2725

2826
AFE4490 afe4490;
2927

28+
int32_t heart_rate_prev=0;
29+
int32_t spo2_prev=0;
30+
3031
void setup()
3132
{
3233
Serial.begin(57600);
33-
Serial.println("Intilazition AFE44xx.. ");
34-
34+
Serial.println("Intilaziting AFE44xx.. ");
35+
3536
delay(2000) ; // pause for a moment
36-
37-
SPI.begin();
38-
39-
// set the directions
40-
pinMode (SPISTE,OUTPUT);//Slave Select
41-
pinMode (SPIDRDY,INPUT);// data ready
42-
43-
attachInterrupt(0, afe44xx_drdy_event, RISING ); // Digital2 is attached to Data ready pin of AFE is interrupt0 in ARduino
44-
// set SPI transmission
37+
38+
SPI.begin();
4539
SPI.setClockDivider (SPI_CLOCK_DIV8); // set Speed as 2MHz , 16MHz/ClockDiv
4640
SPI.setDataMode (SPI_MODE0); //Set SPI mode as 0
4741
SPI.setBitOrder (MSBFIRST); //MSB first
48-
49-
afe4490.afe44xxInit (SPISTE);
42+
43+
afe4490.afe44xxInit (SPISTE, SPIDRDY, DRDY_INTNUM, PWDN);
5044
Serial.println("intilazition is done");
5145
}
5246

5347
void loop()
54-
{
48+
{
5549
afe44xx_output_values afe4490Data;
5650
boolean sampled_value = afe4490.getDataIfAvailable(&afe4490Data,SPISTE);
57-
51+
5852
if(sampled_value == true)
5953
{
6054
if(afe4490Data.spo2 == -999){
61-
55+
6256
Serial.println("Probe error!!!!");
63-
}else{
57+
}else if ((heart_rate_prev != afe4490Data.heart_rate) || (spo2_prev != afe4490Data.spo2)){
58+
59+
heart_rate_prev = afe4490Data.heart_rate;
60+
spo2_prev = afe4490Data.spo2;
6461

6562
Serial.print("calculating sp02...");
6663
Serial.print(" Sp02 : ");
6764
Serial.print(afe4490Data.spo2);
68-
Serial.print("% ,");
65+
Serial.print("% ,");
6966
Serial.print("Pulse rate :");
70-
Serial.print(afe4490Data.heart_rate);
71-
Serial.println(" bpm");
67+
Serial.print(afe4490Data.heart_rate);
68+
Serial.println(" bpm");
7269
}
7370
}
7471
}
75-

examples/Example-3-Raw-PPG-plot-Arduino-Plotter/Example-3-Raw-PPG-plot-Arduino-Plotter.ino

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,26 @@
2323

2424
const int SPISTE = 7; // chip select
2525
const int SPIDRDY = 2; // data ready pin
26-
const int RESET =5; // data ready pin
27-
const int PWDN =4; // data ready pin
28-
29-
int datalen = 10;
26+
const int PWDN =4;
27+
const int DRDY_INTNUM =0; //digital pin2 interrupt num = 0. Please pass correct interrupt number if you are using any boards otherthan arduino uno
3028

3129
AFE4490 afe4490;
3230

3331
void setup()
3432
{
3533
Serial.begin(57600);
36-
Serial.println("Intilazition AFE44xx.. ");
34+
Serial.println("Intilaziting AFE44xx.. ");
3735
delay(2000) ; // pause for a moment
3836

3937
SPI.begin();
40-
// set the directions
41-
pinMode (SPISTE,OUTPUT);//Slave Select
42-
pinMode (SPIDRDY,INPUT);// data ready
43-
attachInterrupt(0, afe44xx_drdy_event, RISING ); // Digital2 is attached to Data ready pin of AFE is interrupt0 in ARduino
4438

45-
// set SPI transmission
4639
SPI.setClockDivider (SPI_CLOCK_DIV8); // set Speed as 2MHz , 16MHz/ClockDiv
4740
SPI.setDataMode (SPI_MODE0); //Set SPI mode as 0
4841
SPI.setBitOrder (MSBFIRST); //MSB first
4942

50-
afe4490.afe44xxInit (SPISTE);
51-
Serial.println("intilazition is done");
43+
//NOTE: usually the DRDY_INTNUM is same as the pin but the interrupt number for arduino uno pin2 is 0.
44+
afe4490.afe44xxInit (SPISTE, SPIDRDY, DRDY_INTNUM, PWDN);
45+
Serial.println("intilazition done");
5246
}
5347

5448
void loop()
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//////////////////////////////////////////////////////////////////////////////////////////
2+
//
3+
//
4+
// This example is for the new Open-Ox board.
5+
//
6+
// This software is licensed under the MIT License(http://opensource.org/licenses/MIT).
7+
//
8+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
9+
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
10+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
11+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
12+
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13+
//
14+
// For information on how to use, visit https://github.com/Protocentral/protocentral-afe4490-arduino
15+
/////////////////////////////////////////////////////////////////////////////////////////
16+
17+
18+
#include <SPI.h>
19+
#include "Protocentral_AFE4490_Oximeter.h"
20+
21+
const int SPISTE = 25; // chip select
22+
const int SPIDRDY = 13; // data ready pin
23+
const int PWDN =4;
24+
25+
AFE4490 afe4490;
26+
27+
void setup()
28+
{
29+
Serial.begin(57600);
30+
Serial.println("Intilaziting AFE44xx.. ");
31+
delay(2000) ; // pause for a moment
32+
33+
SPI.begin();
34+
35+
SPI.setClockDivider (SPI_CLOCK_DIV8); // set Speed as 2MHz , 16MHz/ClockDiv
36+
SPI.setDataMode (SPI_MODE0); //Set SPI mode as 0
37+
SPI.setBitOrder (MSBFIRST); //MSB first
38+
39+
afe4490.afe44xxInit (SPISTE, SPIDRDY, SPIDRDY, PWDN);
40+
Serial.println("intilazition done");
41+
}
42+
43+
void loop()
44+
{
45+
afe44xx_output_values afe4490Data;
46+
boolean sampled_value = afe4490.getDataIfAvailable(&afe4490Data,SPISTE);
47+
48+
if (afe4490Data.calculated_value == true)
49+
{
50+
Serial.println(afe4490Data.red);
51+
//Serial.println(afe4490Data.ir);
52+
}
53+
}

src/Protocentral_AFE4490_Oximeter.cpp

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ boolean AFE4490 :: getDataIfAvailable (afe44xx_output_values *sensed_values,cons
115115
{
116116
if (drdy_trigger )
117117
{
118-
detachInterrupt(0);
118+
detachInterrupt(intrrpt_num);
119119
afe44xxWrite(CONTROL0, 0x000001,pin);
120120
IRtemp = afe44xxRead(LED1VAL,pin);
121121
afe44xxWrite(CONTROL0, 0x000001,pin);
@@ -155,7 +155,7 @@ boolean AFE4490 :: getDataIfAvailable (afe44xx_output_values *sensed_values,cons
155155
sensed_values->calculated_value = true;
156156
afe44xx_data_ready = false;
157157
drdy_trigger = false;
158-
attachInterrupt(0, afe44xx_drdy_event, RISING );
158+
attachInterrupt(intrrpt_num, afe44xx_drdy_event, RISING );
159159

160160
}else{
161161

@@ -164,44 +164,57 @@ boolean AFE4490 :: getDataIfAvailable (afe44xx_output_values *sensed_values,cons
164164
}
165165

166166

167-
void AFE4490 :: afe44xxInit (const int pin)
167+
void AFE4490 :: afe44xxInit (const int cs_pin, const int drdy, const int interrupt_num, const int pwdn )
168168
{
169-
afe44xxWrite(CONTROL0, 0x000000,pin);
170-
afe44xxWrite(CONTROL0, 0x000008,pin);
171-
afe44xxWrite(TIAGAIN, 0x000000,pin); // CF = 5pF, RF = 500kR
172-
afe44xxWrite(TIA_AMB_GAIN, 0x000001,pin);
173-
afe44xxWrite(LEDCNTRL, 0x001414,pin);
174-
afe44xxWrite(CONTROL2, 0x000000,pin); // LED_RANGE=100mA, LED=50mA
175-
afe44xxWrite(CONTROL1, 0x010707,pin); // Timers ON, average 3 samples
176-
afe44xxWrite(PRPCOUNT, 0X001F3F,pin);
177-
afe44xxWrite(LED2STC, 0X001770,pin);
178-
afe44xxWrite(LED2ENDC, 0X001F3E,pin);
179-
afe44xxWrite(LED2LEDSTC, 0X001770,pin);
180-
afe44xxWrite(LED2LEDENDC, 0X001F3F,pin);
181-
afe44xxWrite(ALED2STC, 0X000000,pin);
182-
afe44xxWrite(ALED2ENDC, 0X0007CE,pin);
183-
afe44xxWrite(LED2CONVST, 0X000002,pin);
184-
afe44xxWrite(LED2CONVEND, 0X0007CF,pin);
185-
afe44xxWrite(ALED2CONVST, 0X0007D2,pin);
186-
afe44xxWrite(ALED2CONVEND, 0X000F9F,pin);
187-
afe44xxWrite(LED1STC, 0X0007D0,pin);
188-
afe44xxWrite(LED1ENDC, 0X000F9E,pin);
189-
afe44xxWrite(LED1LEDSTC, 0X0007D0,pin);
190-
afe44xxWrite(LED1LEDENDC, 0X000F9F,pin);
191-
afe44xxWrite(ALED1STC, 0X000FA0,pin);
192-
afe44xxWrite(ALED1ENDC, 0X00176E,pin);
193-
afe44xxWrite(LED1CONVST, 0X000FA2,pin);
194-
afe44xxWrite(LED1CONVEND, 0X00176F,pin);
195-
afe44xxWrite(ALED1CONVST, 0X001772,pin);
196-
afe44xxWrite(ALED1CONVEND, 0X001F3F,pin);
197-
afe44xxWrite(ADCRSTCNT0, 0X000000,pin);
198-
afe44xxWrite(ADCRSTENDCT0, 0X000000,pin);
199-
afe44xxWrite(ADCRSTCNT1, 0X0007D0,pin);
200-
afe44xxWrite(ADCRSTENDCT1, 0X0007D0,pin);
201-
afe44xxWrite(ADCRSTCNT2, 0X000FA0,pin);
202-
afe44xxWrite(ADCRSTENDCT2, 0X000FA0,pin);
203-
afe44xxWrite(ADCRSTCNT3, 0X001770,pin);
204-
afe44xxWrite(ADCRSTENDCT3, 0X001770,pin);
169+
pinMode (cs_pin,OUTPUT);//Slave Select
170+
pinMode (pwdn,OUTPUT);
171+
pinMode (drdy,INPUT);// data ready
172+
173+
intrrpt_num = interrupt_num;
174+
attachInterrupt(intrrpt_num, afe44xx_drdy_event, RISING );
175+
176+
digitalWrite(pwdn, LOW);
177+
delay(500);
178+
digitalWrite(pwdn, HIGH);
179+
delay(500);
180+
181+
afe44xxWrite(CONTROL0, 0x000000,cs_pin);
182+
afe44xxWrite(CONTROL0, 0x000008,cs_pin);
183+
afe44xxWrite(TIAGAIN, 0x000000,cs_pin); // CF = 5pF, RF = 500kR
184+
afe44xxWrite(TIA_AMB_GAIN, 0x000001,cs_pin);
185+
afe44xxWrite(LEDCNTRL, 0x001414,cs_pin);
186+
afe44xxWrite(CONTROL2, 0x000000,cs_pin); // LED_RANGE=100mA, LED=50mA
187+
afe44xxWrite(CONTROL1, 0x010707,cs_pin); // Timers ON, average 3 samples
188+
afe44xxWrite(PRPCOUNT, 0X001F3F,cs_pin);
189+
afe44xxWrite(LED2STC, 0X001770,cs_pin);
190+
afe44xxWrite(LED2ENDC, 0X001F3E,cs_pin);
191+
afe44xxWrite(LED2LEDSTC, 0X001770,cs_pin);
192+
afe44xxWrite(LED2LEDENDC, 0X001F3F,cs_pin);
193+
afe44xxWrite(ALED2STC, 0X000000,cs_pin);
194+
afe44xxWrite(ALED2ENDC, 0X0007CE,cs_pin);
195+
afe44xxWrite(LED2CONVST, 0X000002,cs_pin);
196+
afe44xxWrite(LED2CONVEND, 0X0007CF,cs_pin);
197+
afe44xxWrite(ALED2CONVST, 0X0007D2,cs_pin);
198+
afe44xxWrite(ALED2CONVEND, 0X000F9F,cs_pin);
199+
afe44xxWrite(LED1STC, 0X0007D0,cs_pin);
200+
afe44xxWrite(LED1ENDC, 0X000F9E,cs_pin);
201+
afe44xxWrite(LED1LEDSTC, 0X0007D0,cs_pin);
202+
afe44xxWrite(LED1LEDENDC, 0X000F9F,cs_pin);
203+
afe44xxWrite(ALED1STC, 0X000FA0,cs_pin);
204+
afe44xxWrite(ALED1ENDC, 0X00176E,cs_pin);
205+
afe44xxWrite(LED1CONVST, 0X000FA2,cs_pin);
206+
afe44xxWrite(LED1CONVEND, 0X00176F,cs_pin);
207+
afe44xxWrite(ALED1CONVST, 0X001772,cs_pin);
208+
afe44xxWrite(ALED1CONVEND, 0X001F3F,cs_pin);
209+
afe44xxWrite(ADCRSTCNT0, 0X000000,cs_pin);
210+
afe44xxWrite(ADCRSTENDCT0, 0X000000,cs_pin);
211+
afe44xxWrite(ADCRSTCNT1, 0X0007D0,cs_pin);
212+
afe44xxWrite(ADCRSTENDCT1, 0X0007D0,cs_pin);
213+
afe44xxWrite(ADCRSTCNT2, 0X000FA0,cs_pin);
214+
afe44xxWrite(ADCRSTENDCT2, 0X000FA0,cs_pin);
215+
afe44xxWrite(ADCRSTCNT3, 0X001770,cs_pin);
216+
afe44xxWrite(ADCRSTENDCT3, 0X001770,cs_pin);
217+
205218
delay(1000);
206219
}
207220

src/Protocentral_AFE4490_Oximeter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ class AFE4490
101101
{
102102
public:
103103
void afe44xxInit (const int pin);
104+
void afe44xxInit (const int cs_pin, const int drdy, const int interrupt_num, const int pwdn );
104105
boolean getDataIfAvailable (afe44xx_output_values *sensed_values,const int pin);
105106

106107
private:
108+
char intrrpt_num=0;
107109
void afe44xxWrite (uint8_t address, uint32_t data,const int pin);
108110
void estimate_spo2(uint16_t *pun_ir_buffer, int32_t n_ir_buffer_length, uint16_t *pun_red_buffer, int32_t *pn_spo2, int8_t *pch_spo2_valid, int32_t *pn_heart_rate, int8_t *pch_hr_valid);
109111
void find_peak( int32_t *pn_locs, int32_t *n_npks, int32_t *pn_x, int32_t n_size, int32_t n_min_height, int32_t n_min_distance, int32_t n_max_num );

0 commit comments

Comments
 (0)