File tree 3 files changed +37
-16
lines changed
examples/Example1_Basic_Readings
3 files changed +37
-16
lines changed Original file line number Diff line number Diff line change 24
24
25
25
MAX30105 particleSensor;
26
26
27
+ #define debug Serial // Uncomment this line if you're using an Uno or ESP
28
+ // #define debug SerialUSB //Uncomment this line if you're using a SAMD21
29
+
27
30
void setup ()
28
31
{
29
- Serial .begin (115200 );
30
- Serial .println (" Initializing..." );
32
+ debug .begin (115200 );
33
+ debug .println (" Initializing..." );
31
34
32
35
// Initialize sensor
33
36
if (!particleSensor.begin (Wire, I2C_SPEED_FAST)) // Use default I2C port, 400kHz speed
34
37
{
35
- Serial .println (" MAX30105 was not found. Please check wiring/power. " );
38
+ debug .println (" MAX30105 was not found. Please check wiring/power. " );
36
39
while (1 );
37
40
}
38
41
@@ -41,13 +44,13 @@ void setup()
41
44
42
45
void loop ()
43
46
{
44
- Serial .print (" R[" );
45
- Serial .print (particleSensor.getRed ());
46
- Serial .print (" ] IR[" );
47
- Serial .print (particleSensor.getIR ());
48
- Serial .print (" ] G[" );
49
- Serial .print (particleSensor.getGreen ());
50
- Serial .print (" ]" );
51
-
52
- Serial .println ();
47
+ debug .print (" R[" );
48
+ debug .print (particleSensor.getRed ());
49
+ debug .print (" ] IR[" );
50
+ debug .print (particleSensor.getIR ());
51
+ debug .print (" ] G[" );
52
+ debug .print (particleSensor.getGreen ());
53
+ debug .print (" ]" );
54
+
55
+ debug .println ();
53
56
}
Original file line number Diff line number Diff line change @@ -619,19 +619,19 @@ uint16_t MAX30105::check(void)
619
619
_i2cPort->write (MAX30105_FIFODATA);
620
620
_i2cPort->endTransmission ();
621
621
622
+ // We may need to read as many as 288 bytes so we read in blocks no larger than I2C_BUFFER_LENGTH
623
+ // I2C_BUFFER_LENGTH changes based on the platform. 64 bytes for SAMD21, 32 bytes for Uno.
622
624
// Wire.requestFrom() is limited to BUFFER_LENGTH which is 32 on the Uno
623
- // We may need to read as many as 288 bytes so we read in blocks no larger than 32
624
- // BUFFER_LENGTH should work with other platforms with larger requestFrom buffers
625
625
while (bytesLeftToRead > 0 )
626
626
{
627
627
int toGet = bytesLeftToRead;
628
- if (toGet > BUFFER_LENGTH )
628
+ if (toGet > I2C_BUFFER_LENGTH )
629
629
{
630
630
// If toGet is 32 this is bad because we read 6 bytes (Red+IR * 3 = 6) at a time
631
631
// 32 % 6 = 2 left over. We don't want to request 32 bytes, we want to request 30.
632
632
// 32 % 9 (Red+IR+GREEN) = 5 left over. We want to request 27.
633
633
634
- toGet = BUFFER_LENGTH - (BUFFER_LENGTH % (activeLEDs * 3 )); // Trim toGet to be a multiple of the samples we need to read
634
+ toGet = I2C_BUFFER_LENGTH - (I2C_BUFFER_LENGTH % (activeLEDs * 3 )); // Trim toGet to be a multiple of the samples we need to read
635
635
}
636
636
637
637
bytesLeftToRead -= toGet;
Original file line number Diff line number Diff line change 25
25
#define I2C_SPEED_STANDARD 100000
26
26
#define I2C_SPEED_FAST 400000
27
27
28
+ // Define the size of the I2C buffer based on the platform the user has
29
+ #if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
30
+
31
+ // I2C_BUFFER_LENGTH is defined in Wire.H
32
+ #define I2C_BUFFER_LENGTH BUFFER_LENGTH
33
+
34
+ #elif defined(__SAMD21G18A__)
35
+
36
+ // SAMD21 uses RingBuffer.h
37
+ #define I2C_BUFFER_LENGTH SERIAL_BUFFER_SIZE
38
+
39
+ #else
40
+
41
+ // The catch-all default is 32
42
+ #define I2C_BUFFER_LENGTH 32
43
+
44
+ #endif
45
+
28
46
class MAX30105 {
29
47
public:
30
48
MAX30105 (void );
You can’t perform that action at this time.
0 commit comments