So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By jimkernsjr
#73678 For the people that are removing the ST microcontroller and running wires and transistors all over the place and to heck and back - you are making this WAY too hard!

-Step 1 - remove the ST microcontroller
-Step 2 - remove R4
-Step 3 - Bridge pin 5 to pin 7 where the ST microcontroller used to be.

Use GPIO 1 (which is the TX pin) to turn the relay on and off.

BAM! - problem solved. Of course you cannot use serial to debug because you took the TX pin, but who cares? Send your serial debug info over wifi.

For what it's worth - sending the hex serial commands for some reason did not work on my board. I have a couple of these from various different sources, so maybe it will work on those...
User avatar
By liderbug
#73801 A) - this post was hard to find - prob because, is your internet slow, what should be 3 pages, how is your mattress, is 17 pages, can we interest you in something else. There is this great product where 20% is posts and the new car, led light bulb and cruises with the other 80% ...

OK, why would anyone create a circuit using a 8266 that requires an external usb-ttl connection to operate - program, yes. Operate, no. Looking at the schmatic the STC14F104 inputs are TX & RX, 5v & Gnd and 1 output to a transistor that drives the relay. Now the question I have - because I've tried - all combinations of TX=0/1 vs RX=0/1 - no luck. But then there is a post where "send a set of 4 hex" on the serial - which I haven't had a chance to try. But that seem to be very ... Rube Goldbergish when GPIO0/2 (or a combination) could drive the transistor. Or the TX/RX lines to the transistor. I've tried to find specs on the STC15F104 (26 different versions) because it's (re)programmable just like the 8266. So exactly what it does internally is ??????

So I will go spend more time ... :roll:
User avatar
By liderbug
#73808 "No trouble mate" - I've got it - it's working - from Android app, from command line, from crontab, browser, program. YaaaHooo! Thanks to the person(s) who did some earlier posting on this subject. Owe ya a beer. Thanks :D

Some of you will look at this and "not like my code" - then modify it. My end goal is to be able to take a standard electrical outlet box, a 110-usb module, this relay board, a duplex outlet and supplement/replace my X10 modules in my hydroponic greenhouse.

Now the STC15F104 (SOP8 = package type) chip works by sending 4 bytes to pin 6(?) saying +voltage on pin 7 or ground to pin 7. But that whole chip, 4k flash, 128 bytes ram .... I'm thinking there's got to be more than just "on"/"off". Status? Delay? There's prob 2 people in the world that know.

My testing: on, sleep 3, off, sleep 3 - works as expected. Changing sleep to 1 works, to .1 works to .01 not so much - think the .01 kinda out runs the relay. :roll:

Code: Select all/*
 *  This sketch demonstrates how to set up a simple HTTP-like server.
 *  The server communicates with the relay board via the Serial port
 *    http://server_ip/on will turn the relay on
 *    http://server_ip/off will turn the relay off
 *    There are no Serial.print lines of code
 */

#include <ESP8266WiFi.h>

  const char* ssid = "MyCasesenSssID";
  const char* password = "mYpassw0rd";
  IPAddress ip ( 192, 168, 0, 131 );  //131=sw1, 132=sw2, etc
  IPAddress gateway ( 192, 168, 0, 1 );
  IPAddress subnet ( 255, 255, 255, 0 );
  WiFiServer server (80);

  //Hex command to send to serial for close relay
  byte relON[]  = {0xA0, 0x01, 0x01, 0xA2};

  //Hex command to send to serial for open relay
  byte relOFF[] = {0xA0, 0x01, 0x00, 0xA1};

void setup ()
{
  delay (10);
  Serial.begin (9600);
 
  WiFi.config (ip, gateway, subnet);
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
 
  // Start the server
  server.begin();
  delay(50);
}

void loop() {
  int val;

  // Check if a client has connected
  WiFiClient client = server.available();
  if ( ! client ) {
    return;
  }
 
  // Wait until the client sends some data
  while ( ! client.available () )
  {
    delay (100);
  }
 
  // Read the first line of the request
  String req = client.readStringUntil ('\r');
  client.flush ();
 
  // Match the request
  if (req.indexOf ("/on") != -1)
  {
    Serial.write (relON, sizeof(relON));
    val = 1; // if you want feedback see below
  } else {
    if (req.indexOf ("/off") != -1)
      Serial.write (relOFF, sizeof(relOFF));
      val = 0; // if you want feedback
  }

  client.flush ();

   // only if you want feedback - see above
  // Prepare the response
  String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
  s += (val)?"on":"off";
  s += "</html>\n";

  // Send the response to the client
  client.print (s);
  delay (10);
}