Smart-Home am Beispiel der Präsenzerkennung im Raum Projektarbeit Lennart Heimbs, Johannes Krug, Sebastian Dohle und Kevin Holzschuh bei Prof. Oliver Hofmann SS2019
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Example1_BasicReadings.ino 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. Read the temperature pixels from the MLX90640 IR array
  3. By: Nathan Seidle
  4. SparkFun Electronics
  5. Date: May 22nd, 2018
  6. License: MIT. See license file for more information but you can
  7. basically do whatever you want with this code.
  8. Feel like supporting open source hardware?
  9. Buy a board from SparkFun! https://www.sparkfun.com/products/14769
  10. This example initializes the MLX90640 and outputs the 768 temperature values
  11. from the 768 pixels.
  12. This example will work with a Teensy 3.1 and above. The MLX90640 requires some
  13. hefty calculations and larger arrays. You will need a microcontroller with 20,000
  14. bytes or more of RAM.
  15. This relies on the driver written by Melexis and can be found at:
  16. https://github.com/melexis/mlx90640-library
  17. Hardware Connections:
  18. Connect the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
  19. to the Qwiic board
  20. Connect the male pins to the Teensy. The pinouts can be found here: https://www.pjrc.com/teensy/pinout.html
  21. Open the serial monitor at 9600 baud to see the output
  22. */
  23. #include <Wire.h>
  24. #include "MLX90640_API.h"
  25. #include "MLX90640_I2C_Driver.h"
  26. const byte MLX90640_address = 0x33; //Default 7-bit unshifted address of the MLX90640
  27. #define TA_SHIFT 8 //Default shift for MLX90640 in open air
  28. static float mlx90640To[768];
  29. paramsMLX90640 mlx90640;
  30. void setup()
  31. {
  32. Wire.begin();
  33. Wire.setClock(100000); //Increase I2C clock speed to 400kHz
  34. Serial.begin(9600);
  35. while (!Serial); //Wait for user to open terminal
  36. Serial.println("MLX90640 IR Array Example");
  37. if (isConnected() == false)
  38. {
  39. Serial.println("MLX90640 not detected at default I2C address. Please check wiring. Freezing.");
  40. while (1);
  41. }
  42. Serial.println("MLX90640 online!");
  43. //Get device parameters - We only have to do this once
  44. int status;
  45. uint16_t eeMLX90640[832];
  46. status = MLX90640_DumpEE(MLX90640_address, eeMLX90640);
  47. if (status != 0)
  48. Serial.println("Failed to load system parameters");
  49. status = MLX90640_ExtractParameters(eeMLX90640, &mlx90640);
  50. if (status != 0)
  51. Serial.println("Parameter extraction failed");
  52. //Once params are extracted, we can release eeMLX90640 array
  53. }
  54. void loop()
  55. {
  56. for (byte x = 0 ; x < 2 ; x++) //Read both subpages
  57. {
  58. uint16_t mlx90640Frame[834];
  59. int status = MLX90640_GetFrameData(MLX90640_address, mlx90640Frame);
  60. if (status < 0)
  61. {
  62. Serial.print("GetFrame Error: ");
  63. Serial.println(status);
  64. }
  65. float vdd = MLX90640_GetVdd(mlx90640Frame, &mlx90640);
  66. float Ta = MLX90640_GetTa(mlx90640Frame, &mlx90640);
  67. float tr = Ta - TA_SHIFT; //Reflected temperature based on the sensor ambient temperature
  68. float emissivity = 0.95;
  69. MLX90640_CalculateTo(mlx90640Frame, &mlx90640, emissivity, tr, mlx90640To);
  70. }
  71. for (int x = 0 ; x < 10 ; x++)
  72. {
  73. Serial.print("Pixel ");
  74. Serial.print(x);
  75. Serial.print(": ");
  76. Serial.print(mlx90640To[x], 2);
  77. Serial.print("C");
  78. Serial.println();
  79. }
  80. delay(1000);
  81. }
  82. //Returns true if the MLX90640 is detected on the I2C bus
  83. boolean isConnected()
  84. {
  85. Wire.beginTransmission((uint8_t)MLX90640_address);
  86. if (Wire.endTransmission() != 0)
  87. return (false); //Sensor did not ACK
  88. return (true);
  89. }