LoginSignup
0
0

More than 1 year has passed since last update.

備忘録MLX90614 M5Stack Ambient wifi

Posted at

#MLX90614とM5stackを使いLCDに表示しながらAmbientにデータ送信使用目的はモーターの温度上昇計測とクラウドに上げ記録をする。
##MLX90614のライブラリはAdafruitのモノを使用した。
その他のものを使用したらうまく動かなかった。
##この次はSDカードにCVSを収納できるように改造予定。

#include <M5Stack.h>
#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <Ambient.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();
WiFiClient client;
Ambient ambient; // Ambientオブジェクトを定義


const char* ssid = "*********";
const char* password = "********";

unsigned int channelId = ~~~~~~~~; // AmbientのチャネルID
const char* writeKey = "========"; // ライトキー


void setup() {
  M5.begin();
  Wire.begin();
  Serial.begin(74880);
  delay(100);

  Serial.println("MLX90614 test10sec");  

  WiFi.begin(ssid, password);  //  Wi-Fi APに接続
    while (WiFi.status() != WL_CONNECTED) {  //  Wi-Fi AP接続待ち
        delay(100);
    }
      
      Serial.print("WiFi connected\r\nIP address: ");
      Serial.println(WiFi.localIP());

 
  ambient.begin(channelId, writeKey, &client); // チャネルIDとライトキーを指定してAmbientの初期化
  mlx.begin();  
  /* M5stackの
   *  画面の使い方はhttps://wak-tech.com/archives/1770を参照
   */
  M5.Lcd.setBrightness(127);//照度調整最高255
  M5.Lcd.setTextSize(3);//LCDテキストサイズ指定
  M5.Lcd.setCursor(5,10);
  M5.Lcd.setTextColor(WHITE);
  M5.Lcd.print("MLX90614");//表示させる文字(常時表示)
  M5.Lcd.setTextSize(2);
  M5.Lcd.setCursor(5,40);
  M5.Lcd.print("Object Temp Sensor");  
  M5.Lcd.setCursor(5,60);
  M5.Lcd.print("wifi Iot device");
  delay(5000);
  
  M5.Lcd.clear(BLACK);
  
  M5.Lcd.setTextSize(2);//LCDテキストサイズ指定
  M5.Lcd.setCursor(5,10);
  M5.Lcd.print("WiFi connected\r\nIP address: ");
  M5.Lcd.print(WiFi.localIP());
  delay(5000);
}

void loop() {
  M5.Lcd.clear(BLACK);
  M5.Lcd.setTextColor(WHITE);
  M5.Lcd.setTextSize(2);
  M5.Lcd.setCursor(5,10);
  M5.Lcd.print("Ambient Object temp");
  
  M5.Lcd.setTextSize(3);
  M5.Lcd.setCursor(5,80);
  M5.Lcd.setTextColor(ORANGE);
  M5.Lcd.print("Ambient:");
  M5.Lcd.setTextColor(WHITE);
  M5.Lcd.print(mlx.readAmbientTempC());
  M5.Lcd.setTextColor(YELLOW);
  M5.Lcd.print(" ^C");
  M5.Lcd.setCursor(5,110);
  M5.Lcd.setTextColor(ORANGE);
  M5.Lcd.print("Object: ");
  M5.Lcd.setTextColor(WHITE);
  M5.Lcd.print(mlx.readObjectTempC());
  M5.Lcd.setTextColor(YELLOW);
  M5.Lcd.print(" ^C");

  
  Serial.print("周囲温度 = ");
  Serial.print(mlx.readAmbientTempC()); 
  Serial.print("℃");
  Serial.print("  対象物温度 = "); 
  Serial.print(mlx.readObjectTempC());
  Serial.println("℃");

  ambient.set(1,mlx.readAmbientTempC());
  ambient.set(2,mlx.readObjectTempC());

  ambient.send();
  
  delay(10000);//1000ms=1秒 5000ms=5秒 10000ms=10秒 60000ms=1分  600000=10分
}
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