Help 4-Channel Relay 13.2 Modbus
-
Hello,
I have purchased the 4-Channel Relay 13.2 module and I need an example to activate and deactivate the relays using Modbus, both as a master and as a slave. Could you please provide me with a sample code or guide on how to achieve this?
Thank you!
-
Hello @Robertof
which M5Core / Modbus hardware are you panning to use?
Documentation about the 4-Channel Relay module can be found here.
The required libraries (and examples) can be found here:
I suggest you start with controlling the four relays from the M5Core first (w/o Modbus). Then learn about Modbus master and slave. And finally combine Modbus with the relays.
Thanks
Felix -
@felmue Hi Felix, the problem is that I only know how to use Uiflow. I followed an example that was available to read multiple records, and it worked with qmodmaster. I am using an M5Core 2.7. The information for Uiflow Modbus V1 and V2 is under construction, and I am frustrated because I can’t solve it. I appreciate your comment, regards.
-
Hello @Robertof
from what I can tell Modbus Slave (Server) blocks have not yet been implemented in UIFlow2.
That said, please find below a Modbus Slave (Server) example in UIFlow1:
from m5stack import * from m5ui import * from uiflow import * from modbus.slave.rtu import ModbusSlave setScreenColor(0x222222) myVal = None label0 = M5TextBox(20, 31, "label0", lcd.FONT_Default, 0xFFFFFF, rotate=0) label1 = M5TextBox(19, 69, "label1", lcd.FONT_Default, 0xFFFFFF, rotate=0) label0.setText('Coil 0 : off') label1.setText('Coil 1 : off') modbus_s = ModbusSlave(2, tx=17, rx=16, baudrate=9600, data_bits=8, stop_bits=1, parity=None, slaveID=4) modbus_s.function_init(5, 0, 2) while True: myVal = modbus_s.receive_req_create_pdu() if (modbus_s.find_function) == (5): if modbus_s.find_address==0: if myVal == 0: label0.setText('Coil 0 : off') else: label0.setText('Coil 0 : on') elif modbus_s.find_address==1: if myVal == 0: label1.setText('Coil 1 : off') else: label1.setText('Coil 1 : on') else: pass modbus_s.create_slave_response(myVal) wait_ms(2)
Thanks
Felix -
-
@felmue
This has worked perfectly thanks to your help.
Your comments helped me understand the code and adapt it to my needs.
If there's any way to mark this post as resolved, I would appreciate it if you could let me know how to do it.
I am very grateful for your help.
Thank you so, so, so much.
Roberto. -
Hello @Robertof
You are welcome. I am glad to hear you got it working to your liking.
I don't know of an official way to mark a post as resolved. Sometimes people change the title and prepend it with [Solved], but I haven't seen that in a while. I'll leave that up to you.
Thanks
Felix -
@felmue
Hi Felix, I haven’t been able to change the title.
I saw your GitHub page, it’s clear that C++ is your language.
Thanks for providing me with the UIflow example.
Roberto. -
Hello @Robertof
if you edit your first post it should allow you to change the title. Have you tired that?
Thanks
Felix -
Hola @felmue
Now I did it but it can't be done!