0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

M5StickC Plus2 で MAX3012によって 脈拍を測定する

Last updated at Posted at 2025-05-01

M5StickC Plus2と MAX3012を使って脈拍を測定するコードの検索に苦労しました。
最後にようやく成功したのが下記サイトです。7

[参考にさせて頂いたサイト]

ここの
12行目の
Wire.begin(32, 33);
だけを書き換えました。

#include <Wire.h>
#include "MAX30105.h"
// doc https://learn.sparkfun.com/tutorials/max30105-particle-and-pulse-ox-sensor-hookup-guide/all
MAX30105 particleSensor;

void setup()
{
  Wire.begin(32, 33); 
  Serial.begin(115200);
  
  Serial.println("");
  Serial.println("Initializing...");
 
  // Initialize sensor
  while(!particleSensor.begin(Wire, I2C_SPEED_FAST)){
    Serial.print(".");
  }
  Serial.println("OK!");
  
  //Setup to sense a nice looking saw tooth on the plotter
  byte ledBrightness = 0x1F; //Options: 0=Off to 255=50mA
  int sampleRate = 800; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
  byte sampleAverage = 4; //Options: 1, 2, 4, 8, 16, 32
  // 結果的に800/4でサンプルレートは200になります
  // redとirが逆になっていて, ここが1だと赤外線LEDが発光します(見えない)
  byte ledMode = 1; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green
  int pulseWidth = 411; //Options: 69, 118, 215, 411
  int adcRange = 4096; //Options: 2048, 4096, 8192, 16384
 
  particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange); //Configure sensor with these settings
 
  Serial.println("red");  
}
 
void loop()
{
  //redとirが逆になっているらしく, getRed()でirの強度をとってきています 
  //uint32_t sensor_ir = particleSensor.getIR();
  uint32_t sensor_red = particleSensor.getRed();

  Serial.println(sensor_red);
}

M5StickC Plus2の場合、本来は:

Pin  GPIO
SDA  32
SCL  33

ですので、Wire.begin()の時にピン指定が必要ということです

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?