Micromelon Robotics
Platform
Resources
NewsAbout UsDownload
Support
Build Your Kit

Stay in the loop

New activities, teaching guides, and product updates delivered to your inbox.

Micromelon Robotics

Australian-made educational robotics for the next generation of innovators.

contact@micromelon.com.au

Company

  • About Us
  • Privacy Policy
  • Terms and Conditions

Products

  • Micromelon Rover
  • Code Editor
  • Robot Simulator
  • Junior
  • Python Library

Support

  • Resources
  • News
  • Rover Repairs
  • Contact
  • Build Your Kit

© 2026 Micromelon Robotics Pty Ltd. All rights reserved.

ABN 56 623 302 296

← Back to Resources
Advanced Guides

How to use I2C

31 December 2024

How to use I2C

I2C (I-squared-C) is a communication technique used between multiple integrated circuits. The Micromelon Rover can use the I2C protocol to communicate with other I2C-compatible devices, useful for expanding the Rover’s capabilities with external sensors or additional servos.

How I2C Works

Before using I2C on the Rover, it’s helpful to understand how it works at a basic level.

Master and slave devices on an I2C bus (Credit: Scott Campbell, Basics of the I2C Communication Protocol)

Master and slave devices on an I2C bus (Credit: Scott Campbell, Basics of the I2C Communication Protocol)

I2C communication happens between a master and a slave IC. The clock line (SCL) synchronises the timing of the data sent over the data line (SDA). Data can be sent back and forth between master and slave but not simultaneously, this is called half-duplex. Multiple slaves and masters can be used on a bus, but all require a unique address.

7-bit slave addressing on I2C (Credit: Scott Campbell, Basics of the I2C Communication Protocol)

7-bit slave addressing on I2C (Credit: Scott Campbell, Basics of the I2C Communication Protocol)

When a master wants to send a packet to a slave, it starts by sending a 7-bit address over SDA. This establishes which slave is being communicated with. A master can either write data to a slave or read data from a slave; the processes are slightly different.

I2C devices have an address (an identifier) and registers: different locations inside the device that can be read from or written to.

Writing to an I2C Slave

I2C write transaction (Credit: Texas Instruments, Understanding the I2C Bus)

I2C write transaction (Credit: Texas Instruments, Understanding the I2C Bus)

When writing to an I2C device, the master first sends the start signal, followed by the 7-bit address of the slave. Next comes the read/write bit (0 to write, 1 to read). The master waits until the slave sends an acknowledge (ACK) bit on the SDA line. Then the master sends the register address it wishes to write to, the slave acknowledges. The master then transmits the data, with the slave sending an ACK on each byte. The stop condition ends the transmission.

Start and end condition: to signal a start, SDA goes from high to low while SCL stays high. SDA goes from low to high while SCL stays high to signal a stop.

Read/write bit: specifies whether the master wants to read or write. Read = 1, write = 0.

ACK/NACK bit: signals the device has (or hasn’t) received a byte of data. ACK = 0, NACK = 1.

Reading from an I2C Slave

I2C read transaction (Credit: Texas Instruments, Understanding the I2C Bus)

I2C read transaction (Credit: Texas Instruments, Understanding the I2C Bus)

Reading is similar to writing. The master first sends the start signal, followed by the 7-bit slave address. Next comes the read/write bit, and the master waits for the ACK on SDA. The master then sends the register address it wishes to read from and waits for the slave to acknowledge.

The master then sends the start condition again, followed by the slave’s address and a read bit. Once the slave acknowledges, it starts sending a byte of data. The master acknowledges each byte and finally sends a negative acknowledgment (NACK) to signal the slave to stop sending. The stop condition ends the transmission.

I2C on the Rover

Fortunately, the protocols are taken care of when using I2C on the Rover. To wire an I2C device correctly to the Rover, use the pinout below and connect SDA and SCL to the respective pins on the device you’re connecting to.

Micromelon Rover expansion header pinout

Expansion Header Pinout

12-pin header. Pin 1 is top-left; top row reads left-to-right, bottom row reads right-to-left.

Pin 1I2C SCL3.3V logic
Pin 2Battery VoltageInternal
Pin 3I2C SDA3.3V logic
Pin 4UART RX3.3V logic
Pin 5UART TX3.3V logic
Pin 6GND
Pin 12ReservedInternal I2C
Pin 11ReservedInternal I2C
Pin 10ReservedNC
Pin 93.3V300mA
Pin 8ReservedNC
Pin 7USB VoltageFused to 1A

Once connected, the coding is straightforward, there are blocks for reading, writing, and scanning.

I2C Scan

I2C scan block, returns a list of connected I2C addresses

I2C scan block, returns a list of connected I2C addresses

This code returns a list containing the addresses of all I2C devices currently connected to the Rover.

I2C Read

I2C read block, slave address, register, byte count

I2C read block, slave address, register, byte count

This block reads from a slave device. You must specify the slave address, the register to read from, and the number of bytes to read. The block returns a list containing each byte of data read from the slave. The data can be greater than 1 byte.

I2C Write

I2C write block, slave address, register, data, byte count

I2C write block, slave address, register, data, byte count

This block writes to a slave device. You must specify the slave address, the register to write to, the data to write, and the data length in bytes. Data can be greater than 1 byte.

Example Uses

Rover with PCA9685 Servo Driver

Rover with a PCA9685 16-channel servo driver

Rover with a PCA9685 16-channel servo driver

The PCA9685 servo driver allows 16 servos to be controlled over I2C. With this device attached, the Rover can control up to 18 servos.

Rover with Arduino Nano

Rover with an Arduino Nano connected over I2C

Rover with an Arduino Nano connected over I2C

The Arduino Nano is a highly adaptable microcontroller with many I/O ports. The default I2C ports on the Nano are A4 (SDA) and A5 (SCL). The Rover can use I2C to easily communicate with an Arduino, giving it access to all the I/O ports on the Nano as external sensor ports. In the example above, the Rover uses an Arduino Nano to receive data from a line-sensor array.

Showcase: Rover and Arduino Line FollowRelated resourceShowcase: Rover and Arduino Line FollowA showcase of using I2C and an Arduino Nano to drive an 8-channel QTR line sensor array for advanced line following.

Continue Learning

How to Use UARTRelated resourceHow to Use UARTLearn how UART works, how it’s implemented on the Micromelon Rover, and how to connect external devices like Arduino or OpenMV to it.

Getting Started with Arduino and the Micromelon RoverRelated resourceGetting Started with Arduino and the Micromelon RoverConnect an Arduino Uno to the Micromelon Rover and control it over UART using software serial.

How to Connect and Control the Micromelon Rover with OpenMVRelated resourceHow to Connect and Control the Micromelon Rover with OpenMVConnect an OpenMV camera to the Rover over UART and use it to detect objects and drive towards them.

← Return to Resources