Breadboard Serial-I2C Bridge

USART-I2C Bridge

Serial-I2C Bridge
A breadboard friendly Serial-I2C Bridge. Good for low speed devices, up to about 19,200 baud, and works in 3.3V and 5V systems.
It comes in handy when you're out of hardware serial ports, don't want to use SoftwareSerial, but you do have an I2C port available.
The Bridge module I2C address and communication speed is configurable so several of them can be used to add multiple serial ports.

Design Documents

Schematic Diagramusart_i2c_bridge_schematic.pdf
PCB Gerbersusart_i2c_bridge_gerbers.zip
PIC12F1822 Source Codeusart_i2c_bridge_code.asm
Example Arduino Library CodeLibrary.zip
Configuration Setup Program CodeSetup.zip

USART-I2C Bridge

The PCB for this project can be ordered at OSHpark.
PCB   Hookup
The PIC12F1822 chip programming requires a Microchip programmer such as PICKIT and a POGO attachment.

Configuration
The default I2C address is 8 and the speed is 9600 baud. To change the settings use the Setup example program. The Settings program sends settings into the bridge module using encoded strings; it's very unlikely that these patterns will be encountered normally but it's possible. To lock out settings changes once it's configured the way you want it, solder the Lock jumper.

Sending
To send serial data out simply write to the bridge I2C address. The bridge has a 32 byte transmit buffer. Attempting to write when the buffer is full will return an I2C NAK.

Example Arduino code...

  Wire.beginTransmission(USART_BRIDGE_I2C_ADDR);
    Wire.write('A');
  uint8_t error = Wire.endTransmission();
  if (error) wait and retry (see the library example code)

A code library is provided that makes sending data pretty easy. The library takes care of buffering (blocking while waiting for serial data to go out), and leverages the Arduino print() functionality.
Example Arduino code...

  #include "SerialI2Cbridge.h"
  SerialI2Cbridge mySerial; // create a serial bridge
  void setup() { mySerial.begin(); }
  void loop() { mySerial.println("Hello world"); }

Receving
Read serial data by reading from the bridge I2C address. If there is no data ready an I2C NAK is returned. In order to read data only when it's ready (thus avoiding unnecessary I2C bus activity) a digital pin is provided that indicates when data is ready.

Example Arduino code using a ready pin...

  if (digitalRead(RDY_PIN))
  {
    Wire.requestFrom(BRIDGE_I2C_ADDR,1);
    byte b = Wire.read();
    Serial.println(b,HEX);
  }

Example Arduino code without a ready pin...

  int result = Wire.requestFrom(BRIDGE_I2C_ADDR,1);
  if (result) { byte b = Wire.read(); Serial.println(b,HEX); }

The Bridge library provides Serial compatible functions available() and read() to read from the serial bridge.

Putting it Together - A simple Terminal application

Example Arduino terminal program using the Serial-I2C Bridge library.
Connect the serial bridge transmit and receive to your serial device and talk to it using the Arduino Serial Monitor...


  #include "SerialI2Cbridge.h"
  SerialI2Cbridge mySerial; // create a serial bridge instance
  void setup()
  {
    // serial monitor
    Serial.begin(115200); 

    // serial bridge on I2C
    //   serial speed and address is configurable using the setup program
    //   for this example we will use the default settings
    mySerial.begin();    // defaults to I2C address 8, ready pin 2
  }
  void loop()
  { 
    // read incoming serial and show on Serial Monitor
    if (mySerial.available()) Serial.write( mySerial.read() );

    // send from Serial Monitor to outgoing serial
    if (Serial.available()) mySerial.write( Serial.read() );
  }

Build Pictures

Front View    Front View