# I2C Temperature and Humidity Sensor

**URL:** <https://forum.core-electronics.com.au/t/i2c-temperature-and-humidity-sensor/18339>\
**Category:** Uncategorized\
**Created:** [23 October 2023 05:43 UTC](https://forum.core-electronics.com.au/t/i2c-temperature-and-humidity-sensor/18339 "2023-10-23T05:43:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clint165695](https://avatars.discourse-cdn.com/v4/letter/c/f9ae1b/32.png) [@Clint165695](https://forum.core-electronics.com.au/u/Clint165695)\
**Post date:** [23 October 2023 05:43 UTC](https://forum.core-electronics.com.au/t/i2c-temperature-and-humidity-sensor/18339/1 "2023-10-23T05:43:40Z")

</div>

Hi

Does anyone have code or libraries to get this to work on the RPI Pico using micropython?

> **[I2C Temperature & Humidity Sensor (Stainless Steel Shell)](https://core-electronics.com.au/i2c-temperature-humidity-sensor-stainless-steel-shell.html?gclid=CjwKCAjwkNOpBhBEEiwAb3MvvSSQVe4ouUYQ2Iu-pQt32QkNxZFWMVL-Q0Em8b1LGZ8GJF-KRKpuNBoCs1MQAvD_BwE)**
>
> The I2C Temperature & Humidity Sensor (Stainless Steel Shell) adopts 304 stainless steel for its housing to ensure good impact resistance, heat...

Thanks

---

<div class="post-metadata">

**Author:** ![James](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/james/32/4400_2.png) [@James](https://forum.core-electronics.com.au/u/James)\
**Post date:** [23 October 2023 05:50 UTC](https://forum.core-electronics.com.au/t/i2c-temperature-and-humidity-sensor/18339/2 "2023-10-23T05:50:44Z")

</div>

Hi Clint,

I took a look and it seems no-one has ported this one to MicroPython ☹

Though the product wiki gives some simple example code that could be ported over to a Pico easily:

```auto
#include "Wire.h"
#define address 0x40
char dtaUart[15];
char dtaLen = 0;
uint8_t Data[100] = {0};
uint8_t buff[100] = {0};
void setup()
{
  Serial.begin(9600);
  Wire.begin();
}
uint8_t buf[4] = {0};
uint16_t data, data1;
float temp;
float hum;
void loop()
{
  readReg(0x00, buf, 4);
  data = buf[0] << 8 | buf[1];
  data1 = buf[2] << 8 | buf[3];
  temp = ((float)data * 165 / 65535.0) - 40.0;
  hum = ((float)data1 / 65535.0) * 100;
  Serial.print("temp(C):");
  Serial.print(temp);
  Serial.print("\t");
  Serial.print("hum(%RH):");
  Serial.println(hum);
  delay(500);
}
uint8_t readReg(uint8_t reg, const void* pBuf, size_t size)
{
  if (pBuf == NULL) {
    Serial.println("pBuf ERROR!! : null pointer");
  }
  uint8_t * _pBuf = (uint8_t *)pBuf;
  Wire.beginTransmission(address);
  Wire.write(&reg, 1);
  if ( Wire.endTransmission() != 0) {
    return 0;
  }
  delay(20);
  Wire.requestFrom(address, (uint8_t) size);
  for (uint16_t i = 0; i < size; i++) {
    _pBuf[i] = Wire.read();
  }
  return size;
}

```

All our product design team (the ones that would usually consider making a port) are tied up with our PiicoDev and other ranges, but we’re happy to help with any snags you have if you want to give this a crack yourself 🙂

---

<div class="post-metadata">

**Author:** ![Liam120347](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/liam120347/32/5003_2.png) [@Liam120347](https://forum.core-electronics.com.au/u/Liam120347)\
**Post date:** [23 October 2023 09:20 UTC](https://forum.core-electronics.com.au/t/i2c-temperature-and-humidity-sensor/18339/3 "2023-10-23T09:20:46Z")

</div>

Hi Clint,

ChatGPT is pretty handy for porting small libraries like this (GPT4 ought to work if ChatGPT doesn’t).

---

<div class="post-metadata">

**Author:** ![Clint165695](https://avatars.discourse-cdn.com/v4/letter/c/f9ae1b/32.png) [@Clint165695](https://forum.core-electronics.com.au/u/Clint165695)\
**Post date:** [23 October 2023 10:48 UTC](https://forum.core-electronics.com.au/t/i2c-temperature-and-humidity-sensor/18339/4 "2023-10-23T10:48:15Z")

</div>

Thanks James - I will have a crack.

---

<div class="post-metadata">

**Author:** ![Clint165695](https://avatars.discourse-cdn.com/v4/letter/c/f9ae1b/32.png) [@Clint165695](https://forum.core-electronics.com.au/u/Clint165695)\
**Post date:** [23 October 2023 10:49 UTC](https://forum.core-electronics.com.au/t/i2c-temperature-and-humidity-sensor/18339/5 "2023-10-23T10:49:00Z")

</div>

Thanks Liam - I will try ChatGPT
