-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESP-01 + 1CH 5V RELAY FROM LC TECHNOLOGY #1130
Comments
I found solution, i dont know why i must send hex command 4 times, but it works.
|
looking at relay.ino providers i noticed RELAY_PROVIDER_STM which uses exact same protocol. have you tried it? espurna/code/espurna/relay.ino Lines 80 to 87 in 4fa1c9d
Edit: and it does implement some workarounds for issues you describe: espurna/code/espurna/relay.ino Lines 500 to 502 in 4fa1c9d
|
Yes, it looks similar and it was first what i have been try. But relay dont work in this case. |
The RELAY_PROVIDER_STM protocol is exactly the same, it should work. But I have noticed the provider does not properly configure the baud rate (it sets it to 115200), maybe setting it to 9600 in the |
xoseperez 100% right! Serial.begin(9600) and Serial.flush() resolve problem. Then
and hardware.h
|
Great. btw you do specify SERIAL_BAUDRATE which would've called this part, but never does (only checks for RELAY_STM device and not just RELAY_PROVIDER_STM): espurna/code/espurna/system.ino Lines 143 to 145 in 373fc53
|
stm-relay okay it seems my LC relay v3 does not have a smt chip but n76e003at20 microprocessor.. don't know where to go from now and debug.. this the modules exactly i have: link for more details: |
Hey i have the same problem as you. (my 2 channel relay uses the Nuvoton N76E003AT20) On the website of lctech you can see some information about the 2 channel relay chip (the website does not seem to work properly at the moment therefore i provide a link to archive.org): https://web.archive.org/web/20180602202511/http://www.chinalctech.com/index.php?_m=mod_product&_a=view&p_id=1261 it writes that you need those hexcodes to switch the relays: an For unknown reason the However, you can see the hexcodes provided by lctech. |
I just use tasmato now with it and some serialsend5 command.. and some “dummy” relays.. and then a rule that listens for switching and then a rule that sendes the command.. |
Hi! |
Edit: Turns out the following patch is not necessary for my LCTech Nuvoton based 4CH relay. See #1130 (comment) Hi, Important: You need to boot the Nuvoton µC in the correct mode by pressing button S1 while powering up the board. If done right the red LED should be on. Otherwise the blue LED will be on, and the Nuvoton won't react to the Serial commands sent by the ESP. Jumpers must be in the original position shorting the pins directed towards the Nuvoton. diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h
index 6068a274..a02570b2 100644
--- a/code/espurna/config/hardware.h
+++ b/code/espurna/config/hardware.h
@@ -1806,6 +1806,23 @@
// Remove UART noise on serial line
#define DEBUG_SERIAL_SUPPORT 0
+// -----------------------------------------------------------------------------
+// NUVOTON 4CH RELAY
+// -----------------------------------------------------------------------------
+
+#elif defined(NUVOTON_4CH_RELAY)
+
+ // Info
+ #define MANUFACTURER "LCTech"
+ #define DEVICE "4CH Relay"
+
+ // Relays
+ #define DUMMY_RELAY_COUNT 4
+ #define RELAY_PROVIDER RELAY_PROVIDER_NUVOTON
+
+ // Remove UART noise on serial line
+ #define DEBUG_SERIAL_SUPPORT 0
+
// -----------------------------------------------------------------------------
// Tonbux Powerstrip02
// -----------------------------------------------------------------------------
diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino
index df01fbc4..34941c93 100644
--- a/code/espurna/relay.ino
+++ b/code/espurna/relay.ino
@@ -86,6 +86,25 @@ void _relayProviderStatus(unsigned char id, bool status) {
Serial.flush();
#endif
+ #if RELAY_PROVIDER == RELAY_PROVIDER_NUVOTON
+ Serial.flush();
+ Serial.write(0x0a);
+ Serial.write(0x2b);
+ Serial.write(0x49);
+ Serial.write(0x50);
+ Serial.write(0x44);
+ Serial.write(0x2c);
+ Serial.write(0x30);
+ Serial.write(0x2c);
+ Serial.write(0x34);
+ Serial.write(0x3a);
+ Serial.write(0xA0);
+ Serial.write(id + 1);
+ Serial.write(status);
+ Serial.write(0xA1 + status + id);
+ Serial.flush();
+ #endif
+
#if RELAY_PROVIDER == RELAY_PROVIDER_LIGHT
// If the number of relays matches the number of light channels
@@ -537,7 +556,7 @@ void _relayBoot() {
_relays[i].current_status = !status;
_relays[i].target_status = status;
- #if RELAY_PROVIDER == RELAY_PROVIDER_STM
+ #if RELAY_PROVIDER == RELAY_PROVIDER_STM || RELAY_PROVIDER == RELAY_PROVIDER_NUVOTON
_relays[i].change_time = millis() + 3000 + 1000 * i;
#else
_relays[i].change_time = millis();
diff --git a/code/espurna/system.ino b/code/espurna/system.ino
index c988c6cd..1cd75e57 100644
--- a/code/espurna/system.ino
+++ b/code/espurna/system.ino
@@ -144,7 +144,7 @@ void _systemSetupSpecificHardware() {
// These devices use the hardware UART
// to communicate to secondary microcontrollers
- #if defined(ITEAD_SONOFF_RFBRIDGE) || defined(ITEAD_SONOFF_DUAL) || (RELAY_PROVIDER == RELAY_PROVIDER_STM)
+ #if defined(ITEAD_SONOFF_RFBRIDGE) || defined(ITEAD_SONOFF_DUAL) || (RELAY_PROVIDER == RELAY_PROVIDER_STM || RELAY_PROVIDER == RELAY_PROVIDER_NUVOTON)
Serial.begin(SERIAL_BAUDRATE);
#endif
diff --git a/code/platformio.ini b/code/platformio.ini
index 9d81cf13..d55fd344 100644
--- a/code/platformio.ini
+++ b/code/platformio.ini
@@ -72,7 +72,7 @@ extra_scripts = extra_scripts.py
# Please note that we don't always use the latest version of a library.
# ------------------------------------------------------------------------------
lib_deps =
- ArduinoJson
+ https://github.com/bblanchon/ArduinoJson#v5.13.5
https://github.com/marvinroger/async-mqtt-client#v0.8.1
Brzo I2C
https://github.com/xoseperez/debounceevent.git#2.0.4
@@ -1962,6 +1962,18 @@ upload_flags = ${common.upload_flags}
monitor_speed = ${common.monitor_speed}
extra_scripts = ${common.extra_scripts}
+[env:nuvoton-4ch-relay]
+platform = ${common.platform}
+framework = ${common.framework}
+board = ${common.board_1m}
+board_build.flash_mode = ${common.flash_mode}
+lib_deps = ${common.lib_deps}
+lib_ignore = ${common.lib_ignore}
+upload_speed = ${common.upload_speed_fast}
+build_flags = ${common.build_flags_1m0m} -DNUVOTON_4CH_RELAY
+monitor_speed = ${common.monitor_speed}
+extra_scripts = ${common.extra_scripts}
+
[env:heygo-hy02]
platform = ${common.platform}
framework = ${common.framework} |
hi, i have relay 2ch with Nuvoton N76: n76e003at20 |
You have to build espurna yourself using PatformIO. Before building you have to include the changes i made from the diff above in the following files:
After adding my changes you can use |
i never succeed on using platformIO to compile espurna :( |
@he-leon see #1610 (comment) about the webui problem. You can check the 1.13.5 with those changes
|
@mcspr Thanks for the hint.
@megamarco833, @xoseperez I'm not sure if it's okay for the maintainers to upload unofficial binaries here. Generally it's not a good idea to run binaries from random people on a device in your private network. |
hi he-leon btw, I did an original sw backup with the command you mention above but I cannot restore it now, it keeps on giving me an error command after the flash is completed, something about the header.... |
hi, Hm, I don't really know what went wrong with your backup. Maybe you have a 512K version of the esp-01. The commands i posted should work for the 1M version. I'm not sure what would happen with a 512K version. |
hi he-leon, Regarding the backup I made sure it was a 1M version with command "esptool.py --port /dev/ttyUSB0 flash_id", do not know what happened because I used the very same command you posted... |
@he-leon If you do not mind, I'll add the patch you provided to the dev tree. |
I am neither an esp8266 expert nor a nuvoton expert and i did not try switching the relays faster than 240ms but maybe interrupts could help. This code runs fine: noInterrupts();
Serial.flush();
Serial.begin(SERIAL_BAUDRATE);
Serial.write(...); // send commands
Serial.write('\n');
Serial.flush();
interrupts();` |
Maybe this is the reason?
Bytes from #1130 (comment) above: >>> bytes([0xa, 0x2b, 0x49, 0x50, 0x44, 0x2c, 0x30, 0x2c, 0x34, 0x3a, 0x01, 0x01, 0xa3])
b'\n+IPD,0,4:\x01\x01\xa3' There's newline, but it is at the start. Maybe device thinks that is an empty command? |
Maybe, since I tried what Enteponez suggested above and now it works with both the STM approach and the he-leon one, .... |
@mcspr Sure you can add the patch. Apparently the different boards behave slightly different, because my relay works fine with my patch. Maybe we can find a solution working for all versions. |
Hi there, I tested the \n solution without the interrupts and it works for me. I have the impression that once the NUVOTON works once it does always work because it is working with both the STM and the NUVOTON approach
and the STM approach
it not clear to me whether this solution would work in every version of the board or not, this both are working now for me.... Regards |
Hi, hardware.h
platformio.ini
Here are the working HEX sequences for my LCTech 4CH Nuvoton based Relay
|
Arduino Code: Drive of the 04 relays running in sequence. time #define CH_PD 44 //sinal de controle de CH_PD Serial.begin(115200); } void loop() {
delay(1000); |
Hi, `#include <ESP8266WiFi.h> #define LED1_PIN 1 const char* ssid = "qwerty"; WiFiServer server(2323); const byte relNO[] = {0xA0, 0x01, 0x01, 0xA2}; //Hex command to send to serial for open relay void setup() { // Connect to WiFi network WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { // Start the server } void loop() { char request; // Check if a client has connected symbolToSend='x'; // Wait until the client sends some data //// Read the first line of the request
} }` Thx |
May be somebody find it useful. I think it is better too late, than never in this case. |
Hi!
I try to modificate some parts of code to make it work. I have ESP-01 + 1CH 5V RELAY FROM LC TECHNOLOGY, https://www.az-delivery.de/products/esp8266-01s-mit-relais?ls=de , https://www.hackster.io/makerrelay/esp8266-wifi-5v-1-channel-relay-delay-module-iot-smart-home-e8a437
This board does not use GPIO0 or GPIO2 in order to activate the relay, it use the serial communication instead it.
First: you need to open Serial port communication at 9600B, any other speed does not works fine.
Ex. : Serial.begin(9600);
Second:
To enable the Relay send it by serial port:
const byte miBufferON[] = {0xA0, 0x01, 0x01, 0xA2};
Serial.write(miBufferON, sizeof(miBufferON));
To disable the Relay send it by serial port:
const byte miBufferOFF[] = {0xA0, 0x01, 0x00, 0xA1};
Serial.write(miBufferON, sizeof(miBufferOFF));
I add in hardware.h
in platfomio.ini
in relay.ino
here i just try to put relay in on mode, but unfortunately its not working. Simple arduino sketch work fine, but i want to make it work with espurna.
Here is simple sketch
The text was updated successfully, but these errors were encountered: