Mangue Baja Personalized MLX program
Revision 0:b8c679416b97, committed 2019-08-01
- Comitter:
- einsteingustavo
- Date:
- Thu Aug 01 11:41:20 2019 +0000
- Commit message:
- Mangue Baja personalized MLX program
Changed in this revision
my_mlx.cpp | Show annotated file Show diff for this revision Revisions of this file |
my_mlx.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r b8c679416b97 my_mlx.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/my_mlx.cpp Thu Aug 01 11:41:20 2019 +0000 @@ -0,0 +1,83 @@ +/*************************************************** + This is a library for the MLX90614 Temp Sensor + Designed specifically to work with the MLX90614 sensors in the + adafruit shop + ----> https://www.adafruit.com/products/1748 + ----> https://www.adafruit.com/products/1749 + These sensors use I2C to communicate, 2 pins are required to + interface + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + Written by Limor Fried/Ladyada for Adafruit Industries. + BSD license, all text above must be included in any redistribution + ****************************************************/ + +#include "my_mlx.h" + +//Adafruit_MLX90614::Adafruit_MLX90614(uint8_t i2caddr) { +// _addr = i2caddr; +//} + +Adafruit_MLX90614::Adafruit_MLX90614(PinName sda, PinName scl) +{ + i2c_ = new I2C(sda, scl); + i2c_->frequency(400000); +} + +Adafruit_MLX90614::Adafruit_MLX90614(I2C *i2c) : i2c_(i2c) { + } + +Adafruit_MLX90614::~Adafruit_MLX90614() { + delete i2c_; + } + +////////////////////////////////////////////////////// + + +double Adafruit_MLX90614::readObjectTempF(void) { + return (readTemp(MLX90614_TOBJ1) * 9 / 5) + 32; +} + + +double Adafruit_MLX90614::readAmbientTempF(void) { + return (readTemp(MLX90614_TA) * 9 / 5) + 32; +} + +double Adafruit_MLX90614::readObjectTempC(void) { + return readTemp(MLX90614_TOBJ1); +} + + +double Adafruit_MLX90614::readAmbientTempC(void) { + return readTemp(MLX90614_TA); +} + +float Adafruit_MLX90614::readTemp(uint8_t reg) { + float temp; + + temp = read16(reg); + temp *= .02; + temp -= 273.15; + return temp; +} + +/*********************************************************************/ + +uint16_t Adafruit_MLX90614::read16(uint8_t a) { + uint16_t ret; + char cmd[3] = { 0 }; + + //Wire.beginTransmission(_addr); // start transmission to device + i2c_->write(_addr,cmd,1,true); + //Wire.write(a); // sends register address to read from + //Wire.endTransmission(false); // end transmission + + // Wire.requestFrom(_addr, (uint8_t)3);// send data n-bytes read + ret = i2c_->read(_addr,cmd,3); // receive DATA + ret |= i2c_->read(_addr,cmd,3) << 8; // receive DATA + + uint8_t pec = i2c_->read(_addr,cmd,3); + + return ret; +} \ No newline at end of file
diff -r 000000000000 -r b8c679416b97 my_mlx.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/my_mlx.h Thu Aug 01 11:41:20 2019 +0000 @@ -0,0 +1,57 @@ +/*************************************************** + This is a library for the MLX90614 Temp Sensor + Designed specifically to work with the MLX90614 sensors in the + adafruit shop + ----> https://www.adafruit.com/products/1748 + ----> https://www.adafruit.com/products/1749 + These sensors use I2C to communicate, 2 pins are required to + interface + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + Written by Limor Fried/Ladyada for Adafruied in any redistribution + ****************************************************/ + +#include "mbed.h" + +#define _addr 0x5A +#define MLX90614_I2CADDR 0x5A + +// RAM +#define MLX90614_RAWIR1 0x04 +#define MLX90614_RAWIR2 0x05 +#define MLX90614_TA 0x06 +#define MLX90614_TOBJ1 0x07 +#define MLX90614_TOBJ2 0x08 +// EEPROM +#define MLX90614_TOMAX 0x20 +#define MLX90614_TOMIN 0x21 +#define MLX90614_PWMCTRL 0x22 +#define MLX90614_TARANGE 0x23 +#define MLX90614_EMISS 0x24 +#define MLX90614_CONFIG 0x25 +#define MLX90614_ADDR 0x0E +#define MLX90614_ID1 0x3C +#define MLX90614_ID2 0x3D +#define MLX90614_ID3 0x3E +#define MLX90614_ID4 0x3F + +class Adafruit_MLX90614 { + public: + Adafruit_MLX90614(PinName sda, PinName scl); + Adafruit_MLX90614(I2C *i2c); + ~Adafruit_MLX90614(); + bool begin(); + uint32_t readID(void); + + double readObjectTempC(void); + double readAmbientTempC(void); + double readObjectTempF(void); + double readAmbientTempF(void); + + private: + float readTemp(uint8_t reg); + I2C *i2c_; + uint16_t read16(uint8_t addr); + void write16(uint8_t addr, uint16_t data); +}; \ No newline at end of file