Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

1
1

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.

3分プログラミング~mbed体温計~

Posted at

体温計が手に入りづらいので
img.jpg
作業時間180分 熱量 0.67W 塩分 0.0g

材料(1台分)
mbed LPC1768 1台
mbed application board 1台
THERMO K click (MCP9600) 1台
K熱電対 1つ
mini USBケーブル 1本

作り方

  1. 開発用PCを起動し、開発環境を整えておく。
  2. プロジェクトを作成する。プロジェクト内に移動してLCD用ライブラリをインポートする。
mbed new ondokei
cd ondokei
mbed add http://os.mbed.com/users/chris/code/C12832/
  1. main.cppを作成して、以下のコードを保存する。
main.cpp
# include "mbed.h"
# include "C12832.h"

// LCD
C12832 lcd(p5, p7, p6, p8, p11);

// MCP9600
I2C i2c(p9, p10);
int addr8bit = 0xC0;

int main()
{
    char cmd[2];

    // Initialize the MCP9600
    i2c.frequency(50);

    cmd[0] = 0x05;	// Sensor configuration.
    cmd[1] = 0x07;	// K, Filter max
    i2c.write(addr8bit, cmd, 2);

    cmd[0] = 0x06;	// Device configuration.
    cmd[1] = 0x00;	// 0.0625 degree C, 18 bit resolution, 1 sample, Normal op.
    i2c.write(addr8bit, cmd, 2);

    float temperature;

    while (true) {
        ThisThread::sleep_for(1000);

        cmd[0] = 0x00;
        i2c.write(addr8bit, cmd, 1);
        i2c.read(addr8bit, cmd, 2);

        if ((cmd[0] & 0x80) == 0x80) {
            temperature = (cmd[0] * 16.0 + cmd[1] / 16.0) - 4096.0;
        }
        else {
            temperature = (cmd[0] * 16.0 + cmd[1] / 16.0);
        }

        lcd.cls();
        lcd.locate(0, 3);
        lcd.printf("%.1f degree C", temperature);
    }
}
  1. ビルドする。
mbed compile -t GCC_ARM -m LPC1768
  1. binファイルが出来上がる間に、材料をすべてつなげてPCと接続する。
  2. binファイルが出来上がったらストレージへドラッグ&ドロップしてLPC1768へフラッシュする。
  3. リセットボタンを押す。
  4. 液晶画面に温度が表示されることを確認する。

アドバイス

  • 精度が±0.5℃と低いので、あくまで目安として使用する。
1
1
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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?