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?

STM32L010と温度,S-5851でOLED温度計 (Mbed2)(OLED096UNO-A)

Last updated at Posted at 2022-08-07

x 電源投入直後のOLEDのリセットでまれに失敗する。対策は、電源を入れ直す。
x ライブラリをインストールできる人
x Mbed2のリビジョンを変更できる人
x OLEDのライブラリをインストールしてください(SMALL_SSD1308_128x64_I2C)
x Mbed2リビジョン125

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

SSD1306 128x64

★0.96インチ★OLEDモジュール★I2C★ [OLED096UNO-A]

o_con618.jpg

o_con619.jpg

o_con620.jpg

o_con621.jpg

o_con622.jpg

o_con623.jpg

o_con624.jpg

i2c_oled16x24_64_5851_010_1


//i2c_oled16x24_64_5851_010_1

#include "mbed.h"
#include "SSD1308.h"

//メイン関数
int main()
{
//i2c initialization
#if defined(TARGET_NUCLEO_F767ZI)
    I2C i2c(I2C_SDA, I2C_SCL); //767
#endif
#if defined(TARGET_NUCLEO_L011K4)
    I2C i2c(PA_10, PA_9); //010
#endif

    // Instantiate OLED
    SSD1308 oled = SSD1308( &i2c, SSD1308_SA0);

    char data_read[2];//リードバッファー
    char n1_8[8]; //バッファー

    char  f4_1[4] = {'0',  '2', '5', '7'};
    char  f4_2[4] = {'0',  '5', '0', '5'};

    int oo=0;

    while(1) {

        //初期化
        //set address 0
        i2c.write(0x90, "\000", 1); //addres 0

        //温度の読み込み
        // Read temperature register
        i2c.read(0x90 | 1, data_read,2,false);

        //温度の表示
        n1_8[0]= ' ';
        n1_8[1]= ' ';
        n1_8[2]= '0'+ (data_read[0]/10);
        n1_8[3]= '0'+ (data_read[0]%10);
        n1_8[4]= '.';
        n1_8[5]= f4_1[data_read[1]>>6];
        n1_8[6]= f4_2[data_read[1]>>6];
        n1_8[7]= ' ';
        for(int nn=0; nn<8; nn++) {
            //                y   x
            oled.writeBigChar(0, nn*16,n1_8[nn]);
        } //for


        //リセット対策
        oo++;
        if(oo >= 3) {
            i2c.write( ( 0x3c<<1), "\200\215\200\024\200\257", 6);
            oo=0;
        }

        //1秒待つ
        wait_ms(1000);
    }//while
}//main

//容量削減
void error(const char* format, ...) {}


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?