-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Dingtian relay board driver #17032
Dingtian relay board driver #17032
Conversation
I can confirm this also works correctly for this board on the DTWONDER store (request for programmable board because the seller has his own firmware flashed and locked the esp32 for reading and writing) : One question, how can I invert the inputs? Now they are 1 when the contact is open en 0 when the contact is closed, I prefer 1 for closed, 0 for open. |
I found an issue with this, the output relays are clicking every 50ms because the output shift register latches every 50ms also when there is no change in the outputs. |
Looks like it is the same board What I was thinking is that we can now implement such input as virtual switches, fully support Switchmode command which could be convenient. The click issue you are encountering is due to the hardware.
|
I was trying this unfortunately I couldn't save the 595 so I ordered some 595's for replacement. I understand the state, the inputs of the 165 are pulled-up and the input has to be connected to GND in order to pull it down on this board to "activate" the input. If you want to implement it as virtual switches, I will test it as soon as I fixed my board. I will also create the documentation page on https://tasmota.github.io/docs/Supported-Peripherals/#expanding-specific-devices if desired. |
Is it possible to use the inputs in rules when you implement this? |
Like any native "Switch" gpio |
Isn't it an idea to change this code
to something like:
In this case the latch takes the minimum of time (about 122ns according to https://www.esp32.com/viewtopic.php?t=11678) and it decreases the output tri-state time which is probably less or even not triggering the enabled relais to fall off. Unfortunately I can't test it because I broke my board and I'm waiting for a new 74HC595 to arrive. |
No |
Thank you for explaining. |
@jeroenst
DINGTIAN_INPUTS_INVERTED mostly interresting for Buttons (it also works with switches but you already have SwitchMode to invert Switch behavior) Only one of DINGTIAN_USE_AS_BUTTON or DINGTIAN_USE_AS_SWITCH If you own a 32 in/out board, beware that Tasmota is limited to 28 switches so last 4 inputs wouldn't be usable in that case. There is not such limitation with Buttons If you already have switches or button on native GPIO, index for 1st Dingtian input is shifted (check the logs at level 3) As soon as you have tested on the real hardware, I will PR |
18:36:22.004 MQT: 0006/TASMOTA-DTWONDER01/tele/SENSOR = {"Time":"2023-03-19T18:36:21","Switch1":"OFF","Switch2":"OFF","Switch3":"OFF","Switch4":"OFF","Switch5":"OFF","Switch6":"OFF","Switch7":"ON","Switch8":"ON","DINGTIAN":{"IN1":0,"IN2":0,"IN3":0,"IN4":0,"IN5":0,"IN6":0,"IN7":1,"IN8":1}} (retained) Seems to work in the console, inputs are inverted, and switches do follow state of the inputs. Also switchmode seems to work. The only thing that doesn't work is using inverted inputs in a berry script, they are not inverted unfortunately: the second line is the output of printing tasmota.get_switches(): 19T18:46:59","Switch1":"OFF","Switch2":"OFF","Switch3":"OFF","Switch4":"OFF","Switch5":"OFF","Switch6":"OFF","Switch7":"OFF","Switch8":"OFF","DINGTIAN":{"IN1":0,"IN2":0,"IN3":0,"IN4":0,"IN5":0,"IN6":0,"IN7":0,"IN8":0}} (retained) |
Ah, and I forgot to remove the original DINGTIAN key in the SENSOR message When you say the inversion works but not in Berry, did you used the DINGTIAN_INPUTS_INVERTED or is it based on SwitchMode ? |
I did use DINGTIAN_INPUTS_INVERTED, changing switchmode doesn't seem to do anything for the berry script |
ok, I'm looking into it |
Just tried, when using DINGTIAN_INPUTS_INVERTED, I get all switches to "false" in Berry and when not using I get all to "true" I will now PR thanks |
Strange, in my berry script print(tasmota.get_switches()) prints: While the inputs on the main screen are inverted: My defines are: |
When I compile with INVERTED: I see "1" in the Web UI, and Berry gives "false" Berry considers "True" when the signal is to GND (Low) |
New PR : #18223 |
When console says 1 berry should be true imo... I also see this behavior, Berry is always inverted comparing to the console. That was not the case before your change for what I remember. |
Before today's change Berry was not able to report the inputs as Switches state as they were not Switches You can compare with native GPIO Switches. It should be exactly the same. |
You're right, I remember. Still imo when the console says 0 berry should also report false. Tha #define DINGTIAN_INPUTS_INVERTED does also changes berry behaviour but in different direction. |
You can address that to s-hadinger but I wouldn't expect a breaking change now |
Ok, I leave it this way, I can use it although it is a bit misleading. Thank you very much for your effort! Mayby @s-hadinger can take a look at this sometime. |
Possible this explains the inverted behaviour: tasmota.get_switches | () -> list(bool)Returns as many values as switches are present. true means PRESSED and false means NOT_PRESSED. (Warning: this is the opposite of the internal representation where PRESSED=0)Note: if there are holes in the switch definition, the values will be skipped. I.e. if you define SWITCH1 and SWITCH3, the array will return the two consecutive values for switches 1/3. |
You shouldn't have "holes" in your switches/buttons/relays indexes. |
for Dingtian Relay 8/16/32 channel 74hc165 and 74hc595 below is python driver source code for Tasmota
notice: |
this ESP-IDF C source code example 74hc165 and 74hc595 for Dingtian relay gpio.h key code snippets for 8/16/32 channel
|
@dtlzp this tasmota driver already reads and writes the shift registers at the same time. The problem is that the latch pin (PL in code) of the input shift register 74hc165 is also connected to the output enable pin of the output shift register 74hc595, causing the outputs of the 74hc595 to go to tristate while reading and writing (also at the same time). This is also the problem in your example code. Only connecting output enable of the 74hc595 to gnd solves this problem. |
What about changing ButtonSetVirtualPinState(Dingtian->key_offset +i, inputs &1); To ButtonSetVirtualPinState(Dingtian->key_offset +i, !(inputs &1) ); And the same for switch. In this way the switch state is the same as the input state. Of course the real issue is that switch is inversed but changing this would cause serious issues when people upgrade to a version without this inversion. |
the ESP-IDF demo source code shows read(74hc165) and write(74hc595) REFRESH by task "gpio_task" every 20ms , not only refresh when in use.
is very important
create task "gpio_task"
"gpio_task" refresh every 20ms
From: Jeroen
Date: 2023-03-20 14:23
To: arendst/Tasmota
CC: Dingtian; Mention
Subject: Re: [arendst/Tasmota] Dingtian relay board driver (PR #17032)
@dtlzp this tasmota driver already reads and writes the shift registers at the same time.
The problem is that the latch pin (PL in code) of the input shift register 74hc165 is also connected to the output enable pin of the output shift register 74hc595, causing the outputs of the 74hc595 to go to tristate while reading and writing at the same time. This is also the problem in your example code.
Only connecting output enable to gnd solves this problem.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
This is already done in Tasmota. So every 20ms the OE pin of the 74hc595 and the SH pin of the 74hc165 become high for a few microseconds, because they are interconnected. The latch input (SH) of the 74hc165 has to be high when shifting out the bits. This causes the relays to make noise. The OE pin of the 74hc595 has to be connected to gnd to prevent the outputs to go tristate. |
I soldered the 74HC595 today with OE connected to GND and the relays don't make noise anymore. The only remaining issue is that the relais are on during power on boot but I received an email from dingtian that they made a hardware revision that solves this issue and they also connected OE to GND. |
Pin 10 of the 595 is a master reset |
Possible RST can be connected to a GPIO of the ESP32, they are low on boot afaik. I don't have the board available for testing anymore because it's now in use on a remote location to control a heat pump and corresponding valves. Maybe Dingtian can provide me a test version of the new hardware revision flashed with tasmota to test in the nearby future. Just buying a board for testing and modifying is a bit expensive with no purpose for it at this moment. Thank you for all the effort. My final berry script for controlling this board is on https://github.com/jeroenst/dingtian-heatpump-control Used template: {"NAME":"Dingtian 8CH Relay Board","GPIO":[1,9408,1,9440,1,1,1,1,1,9760,9728,9856,9792,1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,9824,9952,1,1,1,0,0,1],"FLAG":0,"BASE":1} |
Description:
Related issue (if applicable): fixes #16797
Dingtian relay boards are ESP32 based boards with 8, 16, 24 or 32 relays and inputs.
Relays are driven through x595 shift registers and inputs are read from x165 shift registers
Because the design is using some GPIO for both '595 and '165, those are not independant and could not be managed through the existing Shift595 driver
This driver is not included in any official Tasmota build. You must compile your own build by adding the following line in your
user_config_override.h
:The driver define 5 News GPIOs (from here):
The CLK GPIO supports index 1 to 4 to specifiy the number of shift registers:
Exemple for the 8 relay board:
WebGUI:
Inputs state are reported through SENSOR message at teleperiod like for PCF8574/MCP230xx port extenders:
And changes are reported to DINGTIAN_CHG topic:
The driver is limited to ESP32 as the Dingtian boards only use ESP32, however if needed the limit could be removed in order to use the same principle on a ESP8266 custom board.
Checklist:
NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass