|
| 1 | +/****************************************************************************** |
| 2 | +MLX90614_Set_Address.ino |
| 3 | +Configure an MLX90614 to use a new I2C address. |
| 4 | +
|
| 5 | +This example demonstrates the setAddress function. |
| 6 | +If an MLX90614 is configured for the default address (0x5A), |
| 7 | +it'll change the address to a new address (0x5B). |
| 8 | +If the Arduino can communicate with an MLX90614 on the new |
| 9 | +address, it'll print the device's ID registers. |
| 10 | +
|
| 11 | +Note: for the new address to take effect, you need to cycle |
| 12 | +power to the MLX90614. |
| 13 | +
|
| 14 | +Hardware Hookup (if you're not using the eval board): |
| 15 | +MLX90614 ------------- Arduino |
| 16 | + VDD ------------------ 3.3V |
| 17 | + VSS ------------------ GND |
| 18 | + SDA ------------------ SDA (A4 on older boards) |
| 19 | + SCL ------------------ SCL (A5 on older boards) |
| 20 | + |
| 21 | +Jim Lindblom @ SparkFun Electronics |
| 22 | +October 23, 2015 |
| 23 | +https://github.com/sparkfun/SparkFun_MLX90614_Arduino_Library |
| 24 | +
|
| 25 | +Development environment specifics: |
| 26 | +Arduino 1.6.5 |
| 27 | +SparkFun IR Thermometer Evaluation Board - MLX90614 |
| 28 | +******************************************************************************/ |
| 29 | + |
| 30 | +#include <Wire.h> // I2C library, required for MLX90614 |
| 31 | +#include <SparkFunMLX90614.h> // SparkFunMLX90614 Arduino library |
| 32 | + |
| 33 | +IRTherm therm; // Create an IRTherm object to interact with throughout |
| 34 | + |
| 35 | +const byte oldAddress = 0x5A; |
| 36 | +const byte newAddress = 0x5B; |
| 37 | + |
| 38 | +void setup() |
| 39 | +{ |
| 40 | + Serial.begin(9600); // Initialize Serial to log output |
| 41 | + Serial.println("Press a key to begin"); |
| 42 | + while (!Serial.available()) ; |
| 43 | + |
| 44 | + therm.begin(oldAddress); // Try using the old address first |
| 45 | + |
| 46 | + byte address; |
| 47 | + if (!therm.readID()) // Try reading the ID registers |
| 48 | + { |
| 49 | + // If the read fails, try re-initializing with the |
| 50 | + // new address. Maybe we've already set it. |
| 51 | + therm.begin(newAddress); |
| 52 | + |
| 53 | + if (therm.readID()) // Read from the ID registers |
| 54 | + { // If the read succeeded, print the ID: |
| 55 | + Serial.println("Communicated with new address."); |
| 56 | + Serial.println("ID: 0x" + |
| 57 | + String(therm.getIDH(), HEX) + |
| 58 | + String(therm.getIDL(), HEX)); |
| 59 | + } |
| 60 | + else |
| 61 | + { |
| 62 | + Serial.println("Failed to communicate with either address."); |
| 63 | + } |
| 64 | + } |
| 65 | + else |
| 66 | + { |
| 67 | + // If the read suceeds, change the address to something |
| 68 | + // new. |
| 69 | + if (!therm.setAddress(newAddress)) |
| 70 | + { |
| 71 | + Serial.println("Failed to set new address."); |
| 72 | + } |
| 73 | + else |
| 74 | + { |
| 75 | + Serial.println("Set the address to 0x" + String(newAddress, HEX)); |
| 76 | + Serial.println("Cycle power to try it out."); |
| 77 | + } |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +void loop() |
| 82 | +{ |
| 83 | + |
| 84 | +} |
0 commit comments