2
1

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、Grove- I2C ADCで遊ぶ(ADC121C021)

Last updated at Posted at 2024-10-01

参考

o_coq422.jpg

結果

o_coq474.jpg

o_coq475.jpg

o_coq437.jpg

プログラム
(M5Stamp S3と全く同じ)


//Grove_ADC_test1_S3_1


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


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


//初期化
void setup() {

  //I2Cとシリアルポートの初期化
  Wire.begin();
  Serial.begin(9600);
  delay(1);

  //初期化(高速変換)
  //Wire.beginTransmission(Addr);
  //Wire.write(0x02);//CONFIG
  //Wire.write(0x20);
  //Wire.endTransmission();
  //delay(2);

}//setup


//メインループ
void loop() {

  //内部アドレスの設定
  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

  //値の表示
  int adc1 = ((h & 0x0F) << 8) + l;
  int vo = (adc1 * 6000) >> 12; // (adc1*(3/4096))*2
  Serial.print(adc1);
  Serial.print("count");
  Serial.print('\t');
  Serial.print(vo);
  Serial.print("mV");
  Serial.println();
  delay(50);

}//loop


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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?