NCIR_MLX90614.ino 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. Description: Use NCIR Unit to measure the temperature without contact and display the value on the screen.
  3. */
  4. #include <M5Stack.h>
  5. #include <Wire.h>
  6. void setup() {
  7. M5.begin();
  8. M5.Power.begin();
  9. M5.Lcd.setTextColor(WHITE);
  10. M5.Lcd.setTextSize(3);
  11. M5.Lcd.clear(BLACK);
  12. M5.Lcd.setCursor(120, 100);
  13. }
  14. uint16_t result;
  15. float temperature;
  16. void loop() {
  17. Wire.beginTransmission(0x5A); // Send Initial Signal and I2C Bus Address
  18. Wire.write(0x07); // Send data only once and add one address automatically.
  19. Wire.endTransmission(false); // Stop signal
  20. Wire.requestFrom(0x5A, 2); // Get 2 consecutive data from 0x5A, and the data is stored only.
  21. result = Wire.read(); // Receive DATA
  22. result |= Wire.read() << 8; // Receive DATA
  23. temperature = result * 0.02 - 273.15;
  24. M5.Lcd.fillRect(120,100,120,100,BLACK);
  25. M5.Lcd.setCursor(120, 100);
  26. M5.Lcd.print(temperature);
  27. Serial.println(temperature);
  28. delay(500);
  29. M5.update();
  30. }