esp32 调试温度传感器LM75
时间:2023-08-26 21:37:01
采用的是vs code 的arduino进行调试
导入lib包I2C Temperature Sensors derived from the LM75
添加到项目后
代码如下
#include #include //1001A2A1A0 Generic_LM75 temperature(0x48); Generic_LM75 temperature2(0x4A); static const uint8_t TEMP_SDA = 22; static const uint8_t TEMP_SCL = 23; static const uint32_t TEMP_FREQUENCY = 400000L;//400khz void setup() { Serial.begin(9600); Wire.setPins(TEMP_SDA, TEMP_SCL); Wire.setClock(TEMP_FREQUENCY); Wire.begin(); } void loop() { Serial.print("Temperature = "); Serial.print(temperature.readTemperatureC()); Serial.println(" C"); delay(500); Serial.print("Temperature2 = "); Serial.print(temperature2.readTemperatureC()); Serial.println(" C"); delay(1000); }
需要连接VCC,GND,SDA,SCL四条线,
LM75默认地址是0x48,即1001 000
后三位是A2 A1 A0共8种组合,A与VCC连接为1,不连则为0。