STM32G031 및 온도, S-5851에서 액정 온도계 (Arduino) (AQM0802A)
2. 전원 연결
3. 아래 소스 코드 작성
4. 컴파일 실행으로 표시되면 종료
5. 끝
i2c의 초기 설정이 UNO와 다릅니다.
  //i2cの初期化
  //Wire.begin(); // initialise the connection //767 UNO
  Wire.begin(sdaPin,sclPin); //STM32G031J6M6
프로그램
#include <Wire.h> //I2C library
//STM32G031J6M6
#define sdaPin PA12    // ArduinoA4
#define sclPin PA11    // ArduinoA5
// I2C temperature sensor - see table 1 of data sheet.  Resistor selects address. 
#define S5851A  0x48
#define I2Cadr  0x3e  // 固定
int     tempval;                //温度
char    data_read[2]={'@','t'}; //i2cバッファー
int     ii;                     //ループカウンター
char INIT_com[]={0x0,0x38,
0x0,0x39,
0x0,0x4,
0x0,0x14,
0x0,0x70,
0x0,0x56,
0x0,0x6C,
0x0,0x38,
0x0,0xC,
0x0,0x1,
0x40,0x41};
char INIT_cls[]={0x0,0x1};
void i2c_led_w(char *buff1){
  Wire.beginTransmission(I2Cadr);
  Wire.write(buff1[0]);
  Wire.write(buff1[1]);
  Wire.endTransmission();
  delay(2);
}//i2c_led_w
void setup()
{  
  delay(3000); //not delete  //031
  //i2cの初期化
  //Wire.begin(); // initialise the connection //767 UNO
  Wire.begin(sdaPin,sclPin); //STM32G031J6M6
  //液晶の初期化
  for(ii=0;ii<11;ii++){
    i2c_led_w(&INIT_com[ii*2]);
  } //for
} //end setup
void loop()
{
  //画面のクリア
  i2c_led_w(INIT_cls);
  //0番目のレジスター
  Wire.beginTransmission(S5851A);
  Wire.write(0);
  Wire.endTransmission();
  delay(1);
  //温度の読み込み
  tempval = 99;
  Wire.requestFrom(S5851A, 1);
  while(Wire.available())  {    // 要求より短いデータが来る可能性あり
    tempval = (int)Wire.read(); // 1バイトを受信
  }//while
  //液晶に表示
  data_read[1] = '0' + (tempval / 10);
  i2c_led_w(data_read);
  data_read[1] = '0' + (tempval % 10);
  i2c_led_w(data_read);
  delay(1000); //1秒待つ
}//loop
 
                Reference
이 문제에 관하여(STM32G031 및 온도, S-5851에서 액정 온도계 (Arduino) (AQM0802A)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/caa45040/items/c7531dff58953d272596텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)