Christian
Published © GPL3+

9-Bit Multidrop Communications

Connect multiple IO Expanders together using a 9-bit multidrop communications.

BeginnerFull instructions provided1 hour1,407

Things used in this project

Story

Read more

Schematics

9-bit Wiring Diagram

Connect the Arduino Uno to multiple IO Expanders using 9-bit communications

Code

Relay 9-bit with IO Expanders

C/C++
Use 9-bit communications to control multiple IO Expanders with x16 relays.
/* IO Expander sketch optimized
 *  
 * Relay 9-bit with IO Expanders!
 *
 */

#include <HardwareSerial9Bit.h>
#include "IOExpander9Bit.h"
#include <avr/wdt.h>

#define MAX_BOARDS    2

char cmd[10];

void setup()
{
  Serial9Bit.begin(115200, SERIAL_9N1);

  delay(100);                               // Wait 100 ms for IO Expander Title
  while (Serial9Bit.available()) Serial9Bit.read(); // Flush RX buffer
 
  Serial9Bit.write(0);                      // Set IO Expanders to 9-bit by sending zero
  delay(1);
 
  wdt_enable(WDTO_8S);

  // Turn off all the relays on all the boards
  for (int board = 1; board <= MAX_BOARDS; board++) {
    SerialCmdDone(board, "esffff");         // Clear all the relays
  }
}

void loop()
{
  static int board = 1;
  static int relay = 1;

  if (board <= MAX_BOARDS) {
    sprintf(cmd, "e%do", relay);            // Turn on the relay
    SerialCmdDone(board, cmd);
 
    delay(200);                             // Delay, must be less than 8 sec or add a loop.
 
    sprintf(cmd, "e%df", relay);            // Turn off the relay
    SerialCmdDone(board, cmd);
 
    if (++relay > 16) {                     // Select the next relay
      relay = 1;
      if (++board > MAX_BOARDS)             // Select the next board
        board = 1;
    }
  }
  wdt_reset();
}

Credits

Christian

Christian

24 projects • 134 followers
Senior Embedded Engineer

Comments