Notes on I2C protocol (Relay Expansion)

Expansion modules and attachments

Posts: 5
Joined: Mon Nov 05, 2018 1:25 pm
PostPosted: Sat May 04, 2019 5:47 pm
Here are a few observations that may be helpful to anyone trying to interface with the Relay Expansion over I2C without using the main RA controller:

  • You can control the Relay Expansion over I2C using the protocol you'll find in Relay.cpp, but there are a few caveats that aren't documented in the source code.
  • The pinning of the USB connector is: Pin 1 (VBUS) +5V; Pin 2 (D-) SDA; Pin 3 (D+) SCL; Pin 4: GND. By the way, this is not the recommended pinning for I2C over USB; see page 28 of the I2C bible: (Remove space in URL, because phpBB.)
  • If you're using a logic level shifter like the PCA9508 in the RA, don't use 10k pull-up resistors like the datasheet shows (and the RA uses); that's too high for a relatively high-capacitance bus like a USB cable. Texas Instruments has a nice document on computing the correct pull-up resistor value: (Remove space in URL, because phpBB.) At a high level, that suggests that a value around 2k would be the most flexible if the bus capacitance is high, which it likely is. I used an oscilloscope to look at 5V I2C signals from a PCA9508 over a normal USB cable connected the Relay Expansion, and found that the rise time was very long with a 10k pull-up, barely reaching full voltage before the next pulse began. A 4.7k pull-up looked much more like a square wave.
  • I would also recommend trying lower pull-up resistor values for people having bus lock issues with the Reef Angel itself, although refitting a Reef Angel with a different resistor would be a little bit tricky. You could maybe bodge something on to the USB port itself. You don't have to remove the existing pull-up; just add resistors between 5V and each of SCL_5_1 and SDA_5_1
  • Speaking of bus lock: The Relay Expansion has its own RANet controller inside it. Roberto posted the source code here: ... 1f1#p44743. (Remove space in URL, because phpBB.) When the expansion turns on, the RANet controller first determines whether the USB (I2C) cable is connected. It does this the same way the RA detects bus lock: by seeing whether it can communicate with the real-time clock module inside the RA controller, which has I2C address 0x68. If there isn't an I2C slave on address 0x68, the RANet module in the expansion will act as an I2C master on its own and will send its own control messages every few seconds, overriding all the ports to whatever it thinks are their fallback states. If you're implementing your own controller, this is not helpful. You'll need to have an I2C slave on the bus with address 0x68. You may be able to do this in your own microcontroller. If you have an unlimited budget, you could just include the same RTC that the Reef Angel uses, the DS3231 from Maxim Integrated, but it's like a $7 part, which is probably almost as much as your microcontroller costs. You could also just open up the relay box and remove the RANet module, which is probably what I'll do for my personal use.
  • Your attempt to control the Relay Expansion will fail unless you deal with the previous bullet, so go back and read that if you got bored and skipped it.

Return to Addons

Who is online

Users browsing this forum: No registered users and 0 guests