# "requestFrom" --Wire.cpp

**URL:** <https://forum.arduino.cc/t/requestfrom-wire-cpp/385649>\
**Category:** 3rd Party Boards\
**Created:** [May 13, 2016, 12:08pm UTC](https://forum.arduino.cc/t/requestfrom-wire-cpp/385649 "2016-05-13T12:08:51Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![HamingBird](https://avatars.discourse-cdn.com/v4/letter/h/73ab20/32.png) [@HamingBird](https://forum.arduino.cc/u/HamingBird)\
**Post date:** [May 13, 2016, 12:08pm UTC](https://forum.arduino.cc/t/requestfrom-wire-cpp/385649/1 "2016-05-13T12:08:51Z")

</div>

Hallo,  
I am using "Arduino UNO" with "HDC1000" . And in "Adafruit\_HDC1000.cpp" file , there is

" Wire.requestFrom((uint8\_t)\_i2caddr, (uint8\_t)4);" .. I dont understand, what does it do ?

* * *

uint32\_t Adafruit\_HDC1000::read32(uint8\_t a, uint8\_t d) {

* * *

Wire.requestFrom((uint8\_t)\_i2caddr, (uint8\_t)4);///wire.cpp ---\> requestFrom

* * *

}  
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_--

is it taking the address of internal Register and reading the data from that internal Register ? ? ?

Thanks

---

<div class="post-metadata">

**Author:** ![Koepel](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/koepel/32/637546_2.png) [@Koepel](https://forum.arduino.cc/u/Koepel)\
**Post date:** [May 13, 2016, 2:54pm UTC](https://forum.arduino.cc/t/requestfrom-wire-cpp/385649/2 "2016-05-13T14:54:19Z")

</div>

This is the reference of the Wire.requestFrom : [Wire - Arduino Reference](https://www.arduino.cc/en/Reference/WireRequestFrom)

If you use something, please give links or photos.  
This file ? [Adafruit\_HDC1000\_Library/Adafruit\_HDC1000.cpp at master · adafruit/Adafruit\_HDC1000\_Library · GitHub](https://github.com/adafruit/Adafruit_HDC1000_Library/blob/master/Adafruit_HDC1000.cpp)

They have put the I2C address of the HDC1000 in a variable \_i2caddr.  
They cast the \_i2caddr to a uint8\_t, and they cast the number 4 to a uint8\_t. I don't know why, I think that is not needed.

The default for a number (for example number 4) is an integer. They cast it to a 8-bits unsigned byte.

---

<div class="post-metadata">

**Author:** ![DrAzzy](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@DrAzzy](https://forum.arduino.cc/u/DrAzzy)\
**Post date:** [May 13, 2016, 3:03pm UTC](https://forum.arduino.cc/t/requestfrom-wire-cpp/385649/3 "2016-05-13T15:03:23Z")

</div>

```cpp
uint32_t Adafruit_HDC1000::read32(uint8_t a, uint8_t d) {
  Wire.beginTransmission(_i2caddr);
  Wire.write(a);
  Wire.endTransmission();
  delay(50);
  Wire.requestFrom((uint8_t)_i2caddr, (uint8_t)4);
  uint32_t r = Wire.read();
  r <<= 8;
  r |= Wire.read();
  r <<= 8;
  r |= Wire.read();
  r <<= 8;
  r |= Wire.read();
  //Serial.println(r, HEX);
  return r;
}

```

Wire.requestFrom() tells it to read the specified number of bytes from the device (and it then gets them with Wire.read() one at a time, and reassembles them into a 32-bit unsigned integer).

Prior to the request from, it sends a single byte (a, the first argument to the function) - this probably sets the address (within the device's internal memory map) that the subsequent requestFrom() will read starting at. (while the I2C standard doesn't specify it, this convention is very common in I2C devices)

---

<div class="post-metadata">

**Author:** ![bperrybap](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/bperrybap/32/605367_2.png) [@bperrybap](https://forum.arduino.cc/u/bperrybap)\
**Post date:** [May 16, 2016, 8:33pm UTC](https://forum.arduino.cc/t/requestfrom-wire-cpp/385649/4 "2016-05-16T20:33:21Z")

</div>

> Koepel:  
> They have put the I2C address of the HDC1000 in a variable \_i2caddr.  
> They cast the \_i2caddr to a uint8\_t, and they cast the number 4 to a uint8\_t. I don't know why, I think that is not needed.
> 
> The default for a number (for example number 4) is an integer. They cast it to a 8-bits unsigned byte.

C++ treats **int** and **uint8\_t** (unsigned char) as different so unless you do the cast, there is no function with the proper arguments if the function is declared with **uint8\_t** arguments and the caller arguments are **int**

The **int** is too big for the **uint8\_t** so it is not a match.

--- bill

---

<div class="post-metadata">

**Author:** ![Koepel](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/koepel/32/637546_2.png) [@Koepel](https://forum.arduino.cc/u/Koepel)\
**Post date:** [May 16, 2016, 9:10pm UTC](https://forum.arduino.cc/t/requestfrom-wire-cpp/385649/5 "2016-05-16T21:10:45Z")

</div>

The requestFrom is declared 5 times, also one with: uint8\_t requestFrom ( int , int) ;  
[https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/libraries/Wire/src/Wire.h](https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/libraries/Wire/src/Wire.h)

---

<div class="post-metadata">

**Author:** ![HamingBird](https://avatars.discourse-cdn.com/v4/letter/h/73ab20/32.png) [@HamingBird](https://forum.arduino.cc/u/HamingBird)\
**Post date:** [May 21, 2016, 10:55am UTC](https://forum.arduino.cc/t/requestfrom-wire-cpp/385649/6 "2016-05-21T10:55:26Z")

</div>

Thanks Guys for the info.

I would like to ask you again, the HDC1000 sensor is sending data to the microcontroller as a "Temperature / Humidity".

But is HDC1000 sensor sending "hex value or Binary value" to the microcontroller ? or it is sending Decimal value ?

Thanks

---

<div class="post-metadata">

**Author:** ![Koepel](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/koepel/32/637546_2.png) [@Koepel](https://forum.arduino.cc/u/Koepel)\
**Post date:** [May 21, 2016, 11:32am UTC](https://forum.arduino.cc/t/requestfrom-wire-cpp/385649/7 "2016-05-21T11:32:16Z")

</div>

The I2C communication is almost always binary data. But it depends on the sensor what it is sending.

---

<div class="post-metadata">

**Author:** ![bperrybap](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/bperrybap/32/605367_2.png) [@bperrybap](https://forum.arduino.cc/u/bperrybap)\
**Post date:** [May 21, 2016, 4:16pm UTC](https://forum.arduino.cc/t/requestfrom-wire-cpp/385649/8 "2016-05-21T16:16:20Z")

</div>

"hex", "binary", and "decimal" are not encoding formats, but rather display formats.  
that are determined by how you choose to display a value not by what the contents is.  
For example, a byte in memory can be displayed as hex, binary, or decimal. The actual value never changes.

What you really may be asking, perhaps, is how is the data encoded.  
The TI HDC1000 datasheet describes the data encoding in section 8.1

But since you seem to be using the Adafruit library, you don't have to concern yourself with such details.  
You can use the API functions provided by the library to read the humidity and temperature and you can look in the library header file to see what those functions are and what they return.

--- bill

---

<div class="post-metadata">

**Author:** ![HamingBird](https://avatars.discourse-cdn.com/v4/letter/h/73ab20/32.png) [@HamingBird](https://forum.arduino.cc/u/HamingBird)\
**Post date:** [May 21, 2016, 11:25pm UTC](https://forum.arduino.cc/t/requestfrom-wire-cpp/385649/9 "2016-05-21T23:25:32Z")

</div>

Thanks again.

I would like to ask again a small question regarding "Adafruit\_HDC1000" . the both prog ( .cpp and .h) can be found here

> **[GitHub - adafruit/Adafruit\_HDC1000\_Library: Arduino library for HDC1000 and...](https://github.com/adafruit/Adafruit_HDC1000_Library)**
>
> Arduino library for HDC1000 and HDC1008 sensors. Contribute to adafruit/Adafruit\_HDC1000\_Library development by creating an account on GitHub.

Problem is in "Adafruit\_HDC1000.cpp" file The Method " read32(uint8\_t a, uint8\_t d)" . the full Method is like this:

* * *

```cpp
uint32_t Adafruit_HDC1000::read32(uint8_t a, uint8_t d) {

 
  Wire.beginTransmission(_i2caddr); ///uint8_t _i2caddr = addr;

  Wire.write(a);  ///uint32_t read32(uint8_t a, uint8_t d=0); -->
                          /// float hum = (read32(HDC1000_TEMP, 20) & 0xFFFF);
                    ///HDC1000_TEMP  0x00
                    /// SO its sending command/Internal Register address, write(a)... a = 0x00

  Wire.endTransmission();
  delay(50);

 
  Wire.requestFrom((uint8_t)_i2caddr, (uint8_t)4);///wire.cpp  

  uint32_t r = Wire.read(); ///wire.cpp ---> read(void)
                                      ///Lets say, r = Wire.read() = 2... decimal value

  r <<= 8;      ///r = r << 8;  --> r = 2 << 8= 512

  r |= Wire.read();    ///r = r | Wire.read();  --> r = 512 | 2 = 514

  r <<= 8;      /// r= 514 << 8 = 332800

  r |= Wire.read();    /// r = 332800 | 2 = 332802

  r <<= 8;            ///r = 332802 << 8 = 858259968

  r |= Wire.read();        ///r = 858259968 | 2 = 858259970

  ///Serial.println(r, HEX);

  return r;
}

```

* * *

I really don't understand, why we need this :

* * *

r \<\<= 8;

r |= Wire.read();

* * *

and really what does it do ? ? ?

if possible try to look here also --\> [HDC1000 --\>Humidity problem - Microcontrollers - Arduino Forum](http://forum.arduino.cc/index.php?topic=402026.0)

I really appreciate your help....

Thanks

---

<div class="post-metadata">

**Author:** ![bperrybap](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/bperrybap/32/605367_2.png) [@bperrybap](https://forum.arduino.cc/u/bperrybap)\
**Post date:** [May 22, 2016, 5:53pm UTC](https://forum.arduino.cc/t/requestfrom-wire-cpp/385649/10 "2016-05-22T17:53:19Z")

</div>

Again, don't confuse the human readable output formats of hex,binary,decimal with data encoding.  
The two are different.  
To say a value is "decimal" in this context doesn't mean anything as any value communicated is hex, decimal, octal, and binary all at the same since those are simply output formats not encoding/storage formats  
It is the data encoding format that matters.

The shift \<\<=8 and the OR |= are being used to construct a value that is larger than 8 bits.  
This because the values from the part being read that are used to calculate the final temperature and humidity values are larger than 8 bits but are read 8 bits at a time.

To understand how the part works and the size and encoding of the data values for humidity and temperature you will need to read the datasheet and focus on section 8.  
Section 8.1 explains the data encoding.

As to why you may be getting incorrect results from the adafruit readTemperature() and readHumidity() functions goes, that is probably best discussed in your other thread:  
[http://forum.arduino.cc/index.php?topic=402026.0](http://forum.arduino.cc/index.php?topic=402026.0)

--- bill

---

<div class="post-metadata">

**Author:** ![HamingBird](https://avatars.discourse-cdn.com/v4/letter/h/73ab20/32.png) [@HamingBird](https://forum.arduino.cc/u/HamingBird)\
**Post date:** [May 23, 2016, 10:32am UTC](https://forum.arduino.cc/t/requestfrom-wire-cpp/385649/11 "2016-05-23T10:32:47Z")

</div>

Thank you bperrybap .........

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 5:05pm UTC](https://forum.arduino.cc/t/requestfrom-wire-cpp/385649/12 "2021-05-06T17:05:04Z")

</div>


