Mangue Baja Personalized MLX program
my_mlx.cpp@0:b8c679416b97, 2019-08-01 (annotated)
- Committer:
- einsteingustavo
- Date:
- Thu Aug 01 11:41:20 2019 +0000
- Revision:
- 0:b8c679416b97
Mangue Baja personalized MLX program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
einsteingustavo | 0:b8c679416b97 | 1 | /*************************************************** |
einsteingustavo | 0:b8c679416b97 | 2 | This is a library for the MLX90614 Temp Sensor |
einsteingustavo | 0:b8c679416b97 | 3 | Designed specifically to work with the MLX90614 sensors in the |
einsteingustavo | 0:b8c679416b97 | 4 | adafruit shop |
einsteingustavo | 0:b8c679416b97 | 5 | ----> https://www.adafruit.com/products/1748 |
einsteingustavo | 0:b8c679416b97 | 6 | ----> https://www.adafruit.com/products/1749 |
einsteingustavo | 0:b8c679416b97 | 7 | These sensors use I2C to communicate, 2 pins are required to |
einsteingustavo | 0:b8c679416b97 | 8 | interface |
einsteingustavo | 0:b8c679416b97 | 9 | Adafruit invests time and resources providing this open source code, |
einsteingustavo | 0:b8c679416b97 | 10 | please support Adafruit and open-source hardware by purchasing |
einsteingustavo | 0:b8c679416b97 | 11 | products from Adafruit! |
einsteingustavo | 0:b8c679416b97 | 12 | Written by Limor Fried/Ladyada for Adafruit Industries. |
einsteingustavo | 0:b8c679416b97 | 13 | BSD license, all text above must be included in any redistribution |
einsteingustavo | 0:b8c679416b97 | 14 | ****************************************************/ |
einsteingustavo | 0:b8c679416b97 | 15 | |
einsteingustavo | 0:b8c679416b97 | 16 | #include "my_mlx.h" |
einsteingustavo | 0:b8c679416b97 | 17 | |
einsteingustavo | 0:b8c679416b97 | 18 | //Adafruit_MLX90614::Adafruit_MLX90614(uint8_t i2caddr) { |
einsteingustavo | 0:b8c679416b97 | 19 | // _addr = i2caddr; |
einsteingustavo | 0:b8c679416b97 | 20 | //} |
einsteingustavo | 0:b8c679416b97 | 21 | |
einsteingustavo | 0:b8c679416b97 | 22 | Adafruit_MLX90614::Adafruit_MLX90614(PinName sda, PinName scl) |
einsteingustavo | 0:b8c679416b97 | 23 | { |
einsteingustavo | 0:b8c679416b97 | 24 | i2c_ = new I2C(sda, scl); |
einsteingustavo | 0:b8c679416b97 | 25 | i2c_->frequency(400000); |
einsteingustavo | 0:b8c679416b97 | 26 | } |
einsteingustavo | 0:b8c679416b97 | 27 | |
einsteingustavo | 0:b8c679416b97 | 28 | Adafruit_MLX90614::Adafruit_MLX90614(I2C *i2c) : i2c_(i2c) { |
einsteingustavo | 0:b8c679416b97 | 29 | } |
einsteingustavo | 0:b8c679416b97 | 30 | |
einsteingustavo | 0:b8c679416b97 | 31 | Adafruit_MLX90614::~Adafruit_MLX90614() { |
einsteingustavo | 0:b8c679416b97 | 32 | delete i2c_; |
einsteingustavo | 0:b8c679416b97 | 33 | } |
einsteingustavo | 0:b8c679416b97 | 34 | |
einsteingustavo | 0:b8c679416b97 | 35 | ////////////////////////////////////////////////////// |
einsteingustavo | 0:b8c679416b97 | 36 | |
einsteingustavo | 0:b8c679416b97 | 37 | |
einsteingustavo | 0:b8c679416b97 | 38 | double Adafruit_MLX90614::readObjectTempF(void) { |
einsteingustavo | 0:b8c679416b97 | 39 | return (readTemp(MLX90614_TOBJ1) * 9 / 5) + 32; |
einsteingustavo | 0:b8c679416b97 | 40 | } |
einsteingustavo | 0:b8c679416b97 | 41 | |
einsteingustavo | 0:b8c679416b97 | 42 | |
einsteingustavo | 0:b8c679416b97 | 43 | double Adafruit_MLX90614::readAmbientTempF(void) { |
einsteingustavo | 0:b8c679416b97 | 44 | return (readTemp(MLX90614_TA) * 9 / 5) + 32; |
einsteingustavo | 0:b8c679416b97 | 45 | } |
einsteingustavo | 0:b8c679416b97 | 46 | |
einsteingustavo | 0:b8c679416b97 | 47 | double Adafruit_MLX90614::readObjectTempC(void) { |
einsteingustavo | 0:b8c679416b97 | 48 | return readTemp(MLX90614_TOBJ1); |
einsteingustavo | 0:b8c679416b97 | 49 | } |
einsteingustavo | 0:b8c679416b97 | 50 | |
einsteingustavo | 0:b8c679416b97 | 51 | |
einsteingustavo | 0:b8c679416b97 | 52 | double Adafruit_MLX90614::readAmbientTempC(void) { |
einsteingustavo | 0:b8c679416b97 | 53 | return readTemp(MLX90614_TA); |
einsteingustavo | 0:b8c679416b97 | 54 | } |
einsteingustavo | 0:b8c679416b97 | 55 | |
einsteingustavo | 0:b8c679416b97 | 56 | float Adafruit_MLX90614::readTemp(uint8_t reg) { |
einsteingustavo | 0:b8c679416b97 | 57 | float temp; |
einsteingustavo | 0:b8c679416b97 | 58 | |
einsteingustavo | 0:b8c679416b97 | 59 | temp = read16(reg); |
einsteingustavo | 0:b8c679416b97 | 60 | temp *= .02; |
einsteingustavo | 0:b8c679416b97 | 61 | temp -= 273.15; |
einsteingustavo | 0:b8c679416b97 | 62 | return temp; |
einsteingustavo | 0:b8c679416b97 | 63 | } |
einsteingustavo | 0:b8c679416b97 | 64 | |
einsteingustavo | 0:b8c679416b97 | 65 | /*********************************************************************/ |
einsteingustavo | 0:b8c679416b97 | 66 | |
einsteingustavo | 0:b8c679416b97 | 67 | uint16_t Adafruit_MLX90614::read16(uint8_t a) { |
einsteingustavo | 0:b8c679416b97 | 68 | uint16_t ret; |
einsteingustavo | 0:b8c679416b97 | 69 | char cmd[3] = { 0 }; |
einsteingustavo | 0:b8c679416b97 | 70 | |
einsteingustavo | 0:b8c679416b97 | 71 | //Wire.beginTransmission(_addr); // start transmission to device |
einsteingustavo | 0:b8c679416b97 | 72 | i2c_->write(_addr,cmd,1,true); |
einsteingustavo | 0:b8c679416b97 | 73 | //Wire.write(a); // sends register address to read from |
einsteingustavo | 0:b8c679416b97 | 74 | //Wire.endTransmission(false); // end transmission |
einsteingustavo | 0:b8c679416b97 | 75 | |
einsteingustavo | 0:b8c679416b97 | 76 | // Wire.requestFrom(_addr, (uint8_t)3);// send data n-bytes read |
einsteingustavo | 0:b8c679416b97 | 77 | ret = i2c_->read(_addr,cmd,3); // receive DATA |
einsteingustavo | 0:b8c679416b97 | 78 | ret |= i2c_->read(_addr,cmd,3) << 8; // receive DATA |
einsteingustavo | 0:b8c679416b97 | 79 | |
einsteingustavo | 0:b8c679416b97 | 80 | uint8_t pec = i2c_->read(_addr,cmd,3); |
einsteingustavo | 0:b8c679416b97 | 81 | |
einsteingustavo | 0:b8c679416b97 | 82 | return ret; |
einsteingustavo | 0:b8c679416b97 | 83 | } |