LoginSignup
1
4

More than 3 years have passed since last update.

USBサーモグラフィモジュールOTK-THG02をProcessingで使う

Last updated at Posted at 2019-07-03

概要

IMG_1022.jpg

USBサーモグラフィモジュールがシリアル通信できるとのことなのでProcessingで動かしてみます.
参考
* https://oaktree-lab.com/resources/index.html
* https://qiita.com/xshell/items/da3f9f3401898f4b37c8
* https://processing.org/reference/libraries/serial/index.html

環境

MacBookPro Mojave(公式のアプリはwinのみですが,シリアル通信で値をもらうのでMacでもできますね)
サーモグラフィモジュール v1.1.2(ボードに記載)
Processing v3.5.3
serialライブラリ

セットアップ

参考にさせていただいたQiitaの記事とセットアップは同じです
詳細はそちらを参考にしていただければと...
* 裏側をハンダしてシリアルモードに
* ピンソケットもつける
* USBシリアル変換モジュールを利用してArduinoのシリアルモニターで通信確認

IMG_1024.jpg
IMG_1025.jpg

Processingでやってみる

そのままUSBシリアル変換モジュールをつけたまま以下のコードで実行

sketch.pde

import processing.serial.*;

Serial myPort;
boolean serialOK = false;

int [][] temp = new int[16][4];
int tempY = 0;

void setup() { 
  size(320, 80);

  printArray(Serial.list());
  String portName = Serial.list()[2];
  myPort = new Serial(this, portName, 38400);
  myPort.bufferUntil('\n');//"\r"

  frameRate(2);
  noStroke();
}

void draw() {
  if (serialOK == false) {
    myPort.write("\r\n");
  } else {
    myPort.write("READ\r\n");
  }

  for (int yy=0; yy<4; yy++) {
    for (int xx=0; xx<16; xx++) {
      float t = map(temp[xx][yy], 200, 400, 0, 255);
      fill(t);

      rect(xx*20, yy*20, 20, 20);
    }
  }
}

void serialEvent(Serial thisPort) {
  String str = trim(thisPort.readString());

  //println(str);
  //if (str == "OK") { //条件に入らない
  if(str.equals("OK")) {
    serialOK = true;
    //tempY = 0;
  } else {
    //println(str);
    for (int i=0; i<16; i++) {
      temp[i][tempY] = int(str.substring(i*5, (i*5)+5));
    }
    tempY++;
    if (tempY >= 4) {
      tempY = 0;
      //println("---------------");
    }
  }

  //println("---------------");
}

String portName = Serial.list()[2];

この部分をprintArray(Serial.list());によって表示されている「usbserial」から始まっている名前の番号にします
例えば自分は
スクリーンショット 2019-07-03 17.46.52.png
こんな出力がされていたので「2」にしました

実行画面

スクリーンショット 2019-07-03 17.04.25.png

実際のカメラ映像と重ねないとよくわからないですね
実際は天井の蛍光灯の熱が白く縦に伸びています
熱があると白くなっているようにしています...

次からArduino Yunにつけて部屋に常駐させといてAmbientあたりにデータ送って監視&可視化でもしようかなぁ

1
4
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
1
4