Wire (using member functions))
Wire (using member function)
The method using member functions has a relatively low level of abstraction and follows the general API system as provided by the C library. The procedures for operating the two-wire serial bus are more intuitive.
However, it is necessary to be explicitly aware of the start and end of bus usage.
Read
requestFrom()
Reads the specified number of bytes at once. Since the result of reading is stored in a queue, call the .read()
method immediately afterward until the queue is empty.
Parameters | Description |
---|---|
| I2C address to be read |
| Number of bytes read |
| When |
return type | Number of bytes read. |
Code Example
Writing
Writing is performed by the write()
method after executing beginTransmission()
. Call endTranmission()
after a series of writing is finished.
beginTransmission()
Initialize the export transfer. Call endTransmission()
as soon as the writing process is finished.
Parameters | Description |
---|---|
| I2C address to be written out |
write(value)
Writes one byte.
Parameters | Description |
---|---|
Return value | Bytes to be written. |
Return value | Number of bytes written. A value of |
write(*value, quantity)
Writes a byte sequence.
Parameters | Description |
---|---|
| the byte sequence to be written |
Return value | Number of bytes to be written. |
Return value | Number of bytes written. 0 is an error. |
endTransmission()
Processes the end of the export.
Parameters | Description |
---|---|
| Issue the STOP bit. |
Return value | 0: Success 4: Failure |
最終更新