LoginSignup
0
0

More than 1 year has passed since last update.

STM32L010のMbed2での時計,DS1307で時刻表示OLED,OLED096UNO-A

Last updated at Posted at 2022-08-07

stm32g031,stm32l010用に最軽量化したもの

x 時間合わせは、別

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

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

SSD1306 128x64

o_con626.jpg

過去ログを見よ!!

i2c_oled16x24_64_ds1307_010_1


//i2c_oled16x24_64_ds1307_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[7]; //リードバッファー
    char n1_8[8]; //バッファー


    int oo=0;

    while(1) {

        //時間の読み込み
        i2c.write( (0xD0), "\000", 1);
        i2c.read(  (0xD0) | 1, data_read, 7);

        //温度の表示
        n1_8[0]= '0'+(data_read[2] >> 4);
        n1_8[1]= '0'+(data_read[2] & 0xf);
        n1_8[2]= '.';
        n1_8[3]= '0'+(data_read[1] >> 4);
        n1_8[4]= '0'+(data_read[1] & 0xf);
        n1_8[5]= '.';
        n1_8[6]= '0'+(data_read[0] >> 4);
        n1_8[7]= '0'+(data_read[0] & 0xf);
        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