Teensy 3.2 with Grove Infrared Temp Sensor

Status
Not open for further replies.

pluesss

Member
Hi,

I have a question on how to use a Grove Infrared Temp Sensor ( http://wiki.seeedstudio.com/Grove-Digital_Infrared_Temperature_Sensor/ ) with my Teensy 3.2.
I connected the SDA of the sensor to SDA0 and the SCL to SCL0.

I installed the MLX90615 library and tried to run the singleDevice example:
Code:
#include "MLX90615.h"
#include <I2cMaster.h>

#define SDA_PIN 3   //define the SDA pin
#define SCL_PIN 2   //define the SCL pin

SoftI2cMaster i2c(SDA_PIN, SCL_PIN);
MLX90615 mlx90615(DEVICE_ADDR, &i2c);


void setup()
{
  Serial.begin(9600);
  Serial.println("Setup...");

  //mlx90615.writeEEPROM(Default_Emissivity); //write data into EEPROM when you need to adjust emissivity.
  //mlx90615.readEEPROM(); //read EEPROM data to check whether it's a default one.
}

void loop()
{
  Serial.print("Object temperature: ");
  Serial.println(mlx90615.getTemperature(MLX90615_OBJECT_TEMPERATURE));
  Serial.print("Ambient temperature: ");
  Serial.println(mlx90615.getTemperature(MLX90615_AMBIENT_TEMPERATURE));
  
  delay(1000);
}

I get an "#error unknown CPU" error. So I think the Teensy CPU is not deifned in this library? What would be the best way to read the sensor data? I think I need the calculation in the library to get the correct temperature? But the I2C seems to not be working with the Teensy. Any help would be much appreciated :)

Thank you and best regards,
Stefan
 
the I2cMaster lib is 8-bit AVR specific. In the MLX90615 library you should replace the software I2C with hardware I2c, e.g. teensy Wire.h

you should google and see if someone else has already done a hardware I2C port for Arduino or Teensy

Your first test would be to see if the Teensy detects the device with an I2C scanner from the Wire library
File > Examples > Wire > Scanner
(I didn't find a schematic, but the device photo looks like it has pullup resistors on SDA and SCL. Teensy requires pullups.)

here is an untested proof-of-principle port
Code:
#include <Wire.h>

#define MLX90615_OBJECT_TEMPERATURE     0x27
#define MLX90615_AMBIENT_TEMPERATURE    0x26
#define AccessEEPROM                    0x13
#define Default_Emissivity              0x4000
#define DEVICE_ADDR 0x5B

float getTemperature(int Temperature_kind) {
  float celsius;
  uint8_t dataLow, dataHigh, crc;

  Wire.beginTransmission(DEVICE_ADDR);
  Wire.write(Temperature_kind);
  Wire.endTransmission();

  Wire.requestFrom(DEVICE_ADDR, 3);
  while (Wire.available() < 3) ; // busy wait, no timeout
  dataLow = Wire.read();
  dataHigh = Wire.read();
  crc = Wire.read();

  celsius = (double)(((dataHigh & 0x007F) << 8) | dataLow);
  celsius = celsius * .02  - 0.01;   // temp factor
  celsius = celsius - 273.15;
  return celsius;
}

void setup() {
  Serial.begin(9600);
  Wire.begin();
}

void loop() {
  float tempc;

  tempc = getTemperature(MLX90615_AMBIENT_TEMPERATURE);
  Serial.print("ambient ");
  Serial.println(tempc);
  tempc = getTemperature(MLX90615_OBJECT_TEMPERATURE);
  Serial.print("object ");
  Serial.println(tempc);
  delay(3000);
}
 
Last edited:
Status
Not open for further replies.
Back
Top