This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Relay board R421A08
#1
Hello
I've done a short script for controlling cheap relay board from AliExpress Routerboard R421A08

If someone is interested in:
User library named ecl_modbus_rtu
Code:
local lt_modbus = {
 it_rboard_actions={
   close=0x100,
   open=0x200,
   toggle=0x300, -- close/open/close/open
   switch=0x400, -- switch 1 of 8
   impulse=0x0500, -- close one for 1s, open other relays
   close_delay=0x0600 --close, then open with delay[s] 00 - FF - (0x06[00-FF])
 },
 is_port='/dev/RS485-1',
 il_baudrate=9600,
    ecl_modbus_rtu_writeregister=function(self,ll_slave,ll_register,ll_value)
   -- ll_slave =RS485 RTU Number set at relay board DIPs
   -- ll_Register = relay Nr 1-8
   -- ll_value = it_rboard_actions
   require('luamodbus')
   mb = luamodbus.rtu()
   mb:open(self.is_port, self.il_baudrate, 'N', 8, 1, 'H')
   mb:connect()
   mb:setslave(ll_slave)
   mb:writeregisters(ll_register,ll_value)
   mb:close()
 end
}
return lt_modbus

Code for testing:
Code:
local mbus=require('user.ecl_modbus_rtu')
mbus:ecl_modbus_rtu_writeregister(1,4,mbus.it_rboard_actions.close)

mbus:ecl_modbus_rtu_writeregister(1,5,mbus.it_rboard_actions.close)
mbus:ecl_modbus_rtu_writeregister(1,6,mbus.it_rboard_actions.close)

mbus:ecl_modbus_rtu_writeregister(1,6,mbus.it_rboard_actions.open)
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Reply


Messages In This Thread
Relay board R421A08 - by Thomas - 18.05.2018, 14:52
RE: Relay board R421A08 - by JohnTH - 22.05.2018, 07:57

Forum Jump: