# Programming with MicroPython: I2C Device

### Import FutureBoard Library

Import the Library to make use of its functions.

```
from future import *
```

### 13: I2C

### Initiate I2C Device

```
i2c = I2C(0)  #Default I2C Port
i2c = I2C(1, scl=Pin(5), sda=Pin(4), freq=400000) #Define own i2c pins
```

### I2C Scan Address

```
i2c.scan()
```

### I2C Read

```
i2c.readfrom(address,nbytes)
```

Returns data from the memory address. Parameter nbytes define length of data.

### I2C Read into Buffer

```
I2C.readfrom_into(addr, buf)
```

Reads data from the memory address. The data sill be stored in parameter buf, which must be a bytearray.

### I2C Write

```
i2c.writeto(address,buf)
```

Write data to a memory address. The data in buf will be written to the device, buf must be a bytearray.

### I2C Write Vector

```
i2c.writevto(address,vector)
```

Write a vector to a memory address.

### I2C Read from Memory

```
I2C.readfrom_mem(address, memaddr, nbytes, *, addrsize=8)
```

Reads data from the I2C device address represented by address. Reads data from the memory address represented by memaddr. Parameter nbytes define length of data being read. Parameter addrsize define the size of the memory.

### I2C Read from Memory into Buffer

```
I2C.readfrom_mem_into(address, memaddr, buf, *, addrsize=8)
```

Reads data from the I2C device address represented by address. Reads data from the memory address represented by memaddr. The data sill be stored in parameter buf, which must be a bytearray. Parameter addrsize define the size of the memory.

### I2 Write Buffer to Memory

```
I2C.writeto_mem(address, memaddr, buf, *, addrsize=8)
```

Writes data to the I2C device address represented by address. Writes data to the memory address represented by memaddr. The data in buf will be written to the device, buf must be a bytearray or byte. Parameter addrsize define the size of the memory.

[ Previous](https://kittenbothk-eng.readthedocs.io/en/latest/futureboard/micropython/api12.html)[Next ](https://kittenbothk-eng.readthedocs.io/en/latest/futureboard/micropython/api14.html)<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sharinghub-eng.kittenbot.hk/main-controllers/futureboard/futureboard-micropython-programming-tutorial/programming-with-micropython-i2c-device.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
