1.SCLとSDAを接続、プルアップも忘れずに
2.電源の接続
3.下記のソースコードを書き込む
4.コンパイル実行で表示されたら終了
5.おわり
x プログラムは、unoと同じ
x ハードは、BluePill 設定は、BluePillF103C8
b6 swd-clk
b7 swd-io
stm32のボードを選択している
# 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