-->
Page 1 of 1

LCTech 16ch relay board with 8266-12F and 2 x 74HC595

PostPosted: Wed Feb 02, 2022 3:38 am
by Matt SegFault
Hi all,

I have a 16 channel relay controller (12v version) with an inbuilt wifi and 8266 processor, you've probably seen them around
https://www.aliexpress.com/item/1005003319135693.html

The board has 2 x 74HC595 units to control which relay(s) to turn on and off
I have managed to deduce that the pins defined in code below work and I can turn on a few of the relays.

What I don't understand is how the data needs to be formatted to send to the 74HC595 shift registers. For example I get different outcomes based on which relays I trigger first, which maybe says to me I am sending too much data and getting overflow into the next request.

I don't have a schematic for this board, but I am assuming they are wired something like the dual 74HC595 setup on this page, but I do not know. https://protostack.com.au/2010/05/intro ... g-16-leds/

Code: Select all// LCTech 16ch Relay board with 2x74HC595 shift registers - replicates close to out of box relay testing function
int latchPin = 12;  // Latch pin of 74HC595 is connected to Digital pin 5
int clockPin = 13; // Clock pin of 74HC595 is connected to Digital pin 6
int dataPin = 14;  // Data pin of 74HC595 is connected to Digital pin 4
int oePin = 5;    // oePin - not using this

void setup()
{
  // Set all the pins of 74HC595 as OUTPUT
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT); 
  pinMode(clockPin, OUTPUT);
  pinMode(oePin, OUTPUT);

  // Setup serial comms
  Serial.begin(115200); 
}

void loop()
{

      Serial.println("Relay #16 = 0b0000");       
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, 0b0000);
      digitalWrite(latchPin, HIGH);
      delay(3000);

      Serial.println("Relay #8 = 0b0001");       
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, 0b0001);
      digitalWrite(latchPin, HIGH);
      delay(3000);

}


Only other conversation around this board and 8266's I can find are here on the Home Assistant board
https://community.home-assistant.io/t/1 ... /368544/29

Any help would be grately appreciated.

The board:
Image

Re: LCTech 16ch relay board with 8266-12F and 2 x 74HC595

PostPosted: Thu Feb 03, 2022 5:55 pm
by Matt SegFault
Matt SegFault wrote:Hi all,

I have a 16 channel relay controller (12v version) with an inbuilt wifi and 8266 processor, you've probably seen them around
https://www.aliexpress.com/item/1005003319135693.html

The board has 2 x 74HC595 units to control which relay(s) to turn on and off
I have managed to deduce that the pins defined in code below work and I can turn on a few of the relays.

What I don't understand is how the data needs to be formatted to send to the 74HC595 shift registers. For example I get different outcomes based on which relays I trigger first, which maybe says to me I am sending too much data and getting overflow into the next request.

I don't have a schematic for this board, but I am assuming they are wired something like the dual 74HC595 setup on this page, but I do not know. https://protostack.com.au/2010/05/intro ... g-16-leds/

Code: Select all// LCTech 16ch Relay board with 2x74HC595 shift registers - replicates close to out of box relay testing function
int latchPin = 12;  // Latch pin of 74HC595 is connected to Digital pin 5
int clockPin = 13; // Clock pin of 74HC595 is connected to Digital pin 6
int dataPin = 14;  // Data pin of 74HC595 is connected to Digital pin 4
int oePin = 5;    // oePin - not using this

void setup()
{
  // Set all the pins of 74HC595 as OUTPUT
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT); 
  pinMode(clockPin, OUTPUT);
  pinMode(oePin, OUTPUT);

  // Setup serial comms
  Serial.begin(115200); 
}

void loop()
{

      Serial.println("Relay #16 = 0b0000");       
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, 0b0000);
      digitalWrite(latchPin, HIGH);
      delay(3000);

      Serial.println("Relay #8 = 0b0001");       
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, 0b0001);
      digitalWrite(latchPin, HIGH);
      delay(3000);

}


Only other conversation around this board and 8266's I can find are here on the Home Assistant board
https://community.home-assistant.io/t/1 ... /368544/29

Any help would be grately appreciated.

The board:
Image


Here is the end result, some working code that replicates the boards test function when it comes out of the box

Code: Select allint latchPin = 12;  // Latch pin of 74HC595 is connected to Digital pin 5
int clockPin = 13; // Clock pin of 74HC595 is connected to Digital pin 6
int dataPin = 14;  // Data pin of 74HC595 is connected to Digital pin 4
int oePin = 5;    // oePin - not using this

uint16_t Data ;

void setup()
{
  // Set all the pins of 74HC595 as OUTPUT
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT); 
  pinMode(clockPin, OUTPUT);
  pinMode(oePin, OUTPUT);

}

void loop()
{

            Data = 0b0000000000000001;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000000000000011;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000000000000111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000000000001111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000000000011111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000000000111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000000001111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000000011111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000000111111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000001111111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000011111111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000111111111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0001111111111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0011111111111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0111111111111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b1111111111111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);               
            Data = 0b1111111111111110;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b1111111111111100;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b1111111111111000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b1111111111110000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b1111111111100000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b1111111111000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b1111111110000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b1111111100000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b1111111000000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b1111110000000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b1111100000000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b1111000000000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b1110000000000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b1100000000000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b1000000000000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000000000000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
}

Re: LCTech 16ch relay board with 8266-12F and 2 x 74HC595

PostPosted: Fri Feb 04, 2022 5:43 am
by rpiloverbd