2018-11-16 06:57:39 +01:00
# i2c Read Number
2016-07-05 21:40:04 +02:00
2017-12-12 07:34:33 +01:00
Read one number from an I2C address using a specified number format.
2016-07-05 21:40:04 +02:00
```sig
2017-04-03 19:30:25 +02:00
pins.i2cReadNumber(0, NumberFormat.Int8LE, false);
2016-07-05 21:40:04 +02:00
```
2017-12-12 07:34:33 +01:00
### ~hint
2018-11-16 06:57:39 +01:00
2017-12-12 07:34:33 +01:00
**Simulator**
This function needs real hardware to work with. It's not supported in the simulator.
### ~
2017-09-07 22:42:08 +02:00
## Parameters
2016-07-05 21:40:04 +02:00
2017-12-12 07:34:33 +01:00
* **address**: the 7-bit I2C address of the device you want to read a number from.
* **format**: the [NumberFormat ](/types/buffer/number-format ) of the number value to read.
2018-11-16 06:57:39 +01:00
* **repeated**: if `true` , don't send a stop condition after the read. Otherwise, a stop condition is sent when `false` (the default).
### ~ hint
A [repeated start condition ](http://www.i2c-bus.org/repeated-start-condition/ ) is set to help make sure that when you want to read multiple numbers from the device at one time, it can happen without interruption. A start conditon is sent (if **repeated** is `true` ) each time a number is read without a matching stop condition. When the last number is read, the stop conditon can be sent by setting **repeated** to `false` . For single reads, don't use **repeated** or set it to `false` .
### ~
2017-12-12 07:34:33 +01:00
## Returns
* a number from the device with the [NumberFormat ](/types/buffer/number-format ) you asked for.
2016-07-05 21:40:04 +02:00
2018-11-16 06:57:39 +01:00
## Examples
### Read a big endian number from a device
2016-07-05 21:40:04 +02:00
The following example reads a number in big-endian, 16-bit, unsigned integer
format from the 7-bit I2C address `32` .
2017-12-12 07:34:33 +01:00
Read a number from the device at a 7-bit I2C address as a 16-bit number. The `16` , big-endian, and integer chosen for the format.
2016-07-05 21:40:04 +02:00
```blocks
2018-11-16 06:57:39 +01:00
let inValue = pins.i2cReadNumber(32, NumberFormat.UInt16BE, false);
```
### Repeated reads
Read three bytes from a device at address `33` at one time.
```blocks
let nums: number[] = []
nums[0] = pins.i2cReadNumber(33, NumberFormat.UInt8LE, true)
nums[1] = pins.i2cReadNumber(33, NumberFormat.UInt8LE, true)
nums[2] = pins.i2cReadNumber(33, NumberFormat.UInt8LE, false)
2016-07-05 21:40:04 +02:00
```
2017-09-07 22:42:08 +02:00
## See also
2016-07-05 21:40:04 +02:00
2018-11-16 06:57:39 +01:00
[i2c write number ](/reference/pins/i2c-write-number )
2017-12-12 07:34:33 +01:00
[What's I2C? ](http://www.i2c-bus.org/ ), [number format ](/types/buffer/number-format )