1
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?

M5NanoC6、I2C経由でマイクの音を拾って遊ぶ

Last updated at Posted at 2024-10-07

過去ログを見よ!!

結果

o_coq493.jpg

o_coq494.jpg

プログラム



//Grove_I2C_ADC_MIC_M5NanoC6_1

// test code for Grove - Sound Sensor
// loovee @ 2016-8-30


//ヘッダーファイル
#include <Arduino.h>
#include <Wire.h>
#include "nana_Grvove_ADC.h"


void setup()
{

  //I2Cとシリアルポートの初期化
  Wire.begin();
  Serial.begin(115200);
  //Serial.println("Grove - Sound Sensor Test...");
  delay(1);

}//setup


void loop()
{

    //電圧を求める
    float Voltage = 0; //電圧
    for(int i=0; i<32; i++){

      Voltage = Voltage + nana_Grvove_ADC();

    }//for

    Voltage = Voltage * 0.03125; // Voltage / 32

    Serial.println((int)(Voltage * 1000.0));
    delay(10);

}//loop

nana_Grvove_ADC.h



//インクルド
#include <Arduino.h>
#include <Wire.h>

//I2Cのアドレス
#define Addr 0x50

float nana_Grvove_ADC() {

  //内部アドレスの設定
  Wire.beginTransmission(Addr);
  Wire.write(0x00);
  Wire.endTransmission();
  delay(2);

  //データの読み込み
  Wire.requestFrom(Addr, 2);
  delay(1);
  int h, l;
  if (Wire.available() == 2) {
    h = Wire.read();
    l = Wire.read();
  }//endif
  delay(1);

  //値の変換
  int adc1 = ((h & 0x0F) << 8) + l;
  int vo = (adc1 * 6000) >> 12; // (adc1*(3/4096))*2

  return( ((float)vo) * 0.001 );
  
}


1
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
1
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?