-
Notifications
You must be signed in to change notification settings - Fork 0
/
SM324-field-temp.ino
25 lines (25 loc) · 1.17 KB
/
SM324-field-temp.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/***********************************************************************************
Reads magnetic field and temperature from an SM324 smart sensor with an Arduino Uno.
Connect sensor power to Arduino 3.3 V and connect I²C SDA and SCL.
Demo at: https://youtu.be/PDNVEmkQcs0
www.nve.com * www.YouTube.com/NveCorporation * [email protected] * Rev. 12/14/20
***********************************************************************************/
#include <Wire.h> //I²C Library
long data[7]; //Data array
byte i; //Byte counter
void setup() {
Serial.begin(57600); //Initialize serial port
Wire.begin(); //Join I²C bus as master
}
void loop() {
Wire.beginTransmission(0x10); //Sensor I²C address
Wire.write(0xAA); //Write command (0xAA = read magnetic field and temperature)
Wire.endTransmission();
Wire.requestFrom(0x10,7); //Status + 3 magnetic field bytes + 3 temperature bytes
for (i=0; i<7; i++) {data[i]=Wire.read();} //Read 7 bytes
Serial.print(float((data[1]<<16)|(data[2]<<8)|data[3])/0x400000-2,4);
Serial.print(" mT ");
Serial.print(float((data[4]<<16)|(data[5]<<8)|data[6])/0xFFFFFF*165-40,1);
Serial.print(" C \r"); //Print units
delay(100);
}