Skip to content

Commit 984a341

Browse files
committed
Add i2c example to read temperature from LM75B IC
1 parent 157331e commit 984a341

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Breakout Carrier - LM75BTemperature
3+
4+
The sketch shows how to read temperature from LM75B using I2C bus of the BreakoutCarrier.
5+
6+
The circuit:
7+
- Portenta H7
8+
- Breakout Carrier
9+
10+
This example code is in the public domain.
11+
*/
12+
13+
#include <Arduino_PortentaBreakoutCarrier.h>
14+
15+
void setup() {
16+
Serial.begin(9600);
17+
while (!Serial);
18+
19+
// Join I2C_1 bus
20+
Breakout.I2C_1.begin();
21+
22+
}
23+
24+
void loop() {
25+
26+
// Transmit to device 0x48 LM75B default address and select register 0x00
27+
Breakout.I2C_1.beginTransmission(0x48);
28+
Breakout.I2C_1.write(0x00);
29+
Breakout.I2C_1.endTransmission();
30+
31+
// Read 2 bytes from temperature register 0x00
32+
Breakout.I2C_1.requestFrom(0x48, 2);
33+
34+
// Convert data into human readable format
35+
word regdata = (Breakout.I2C_1.read() << 8) | Breakout.I2C_1.read();
36+
float temp = (float(regdata) / 256);
37+
38+
// Print temperature
39+
Serial.println(temp);
40+
41+
delay(1000);
42+
}

0 commit comments

Comments
 (0)