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?

More than 3 years have passed since last update.

STM32F103C8と温度,S-5851でOLED温度計 (Arduino)(AL12832AWWB)

Last updated at Posted at 2021-08-21

1.SCLとSDAを接続、プルアップも忘れずに
2.電源の接続
3.下記のソースコードを書き込む
4.コンパイル実行で表示されたら終了
5.おわり

x プログラムは、unoと同じ
x ハードは、BluePill 設定は、BluePillF103C8

b6 swd-clk
b7 swd-io

h_con13.jpg

stm32のボードを選択している

h_con14.jpg



# include <Arduino.h>
# include <U8x8lib.h>
# include <Wire.h> //I2C library

// I2C temperature sensor - see table 1 of data sheet.  Resistor selects address. 
# define S5851A  0x48

//#ifdef U8X8_HAVE_HW_SPI
//#include <SPI.h>
//#endif

U8X8_SSD1306_128X32_UNIVISION_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);   // Adafruit ESP8266/32u4/ARM Boards + FeatherWing OLED

int     cursor1;      //カーソルの位置
char    data_read[8]; //i2cバッファー

void i2c_oled_w(char *s)
{
            //文字の表示
            u8x8.drawString(
            ((cursor1-0) & 0x07  )*2, // x
            (cursor1>>3)*2,           // y
            s);
            
            while(s[0] != 0) {
              s++;
              cursor1++;
            }
            
            //cursor1=cursor1 + 3; 
} //i2c_oled_w

//初期化
void setup(void) {

  delay(2000); //oledのリセット時間

  u8x8.begin();

  u8x8.setFont(u8x8_font_px437wyse700a_2x2_r);

  //スタートロゴ
  cursor1 = 0;
  i2c_oled_w("START");
  delay(500);

  //画面の初期化
  u8x8.drawString( 0,0,"        ");
  u8x8.drawString( 0,2,"        ");
  cursor1 = 0;

  //Wire.begin(sdaPin,sclPin); //f103
  Wire.begin(); //uno

} //setup

int tempval;          //温度
int n0;               //温度 小数点以上
int nt[] = {0,2,5,7}; //温度

void loop(void) {

//  //画面の初期化
//  u8x8.drawString( 0,0,"        ");
//  u8x8.drawString( 0,2,"        ");
  //カーソルのクリア
  cursor1 = 0;

  //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

  //温度をセット
  int n0 = tempval;

  //n0=20; //debug
  
  //画面に表示
  i2c_oled_w("TMP=");
  data_read[0] = '0' + n0/10;;
  data_read[1] = '0' + (  n0-(  (n0/10)  *10)  );
  data_read[2] = '.';
  data_read[3] = '0' + 0;
  data_read[4] = 0; 
  i2c_oled_w(data_read);

  //1秒待つ
  delay(1000);
} //loop




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?