I have a tuya aubess mini smart switch (Belon2028N)
And I have a 16 channel relay board from aliexpress:
I also have some electronic junk that's useful for something.
I managed to flash OpenBK on the tuya module and it's working well, but the module has only around 9 IO pins...
My idea: use some shift registers, create 16 channels in the module and output these channels status sequentially so the shift registers can control all the relays.
Is this possible? Is there any script that could help?
Hello, I have did a similiar thing in the past with I2C port expander that provides up to 16 GPIO able to drive relays.
I2C port expanders are cheap:
And they are already supported.
Still, I can make that work for you with a shift register as well. Which approach do you prefer?
Thanks for the reply.
Do you have any thread about using those i2c modules?
Still, I would really like to have an option using the shift registers...
You see: I am Brazilian and the new president and his friends fucked up importing things from China for everyone. Shift registers I can buy for cheap in any electronics components store...
And I think that would be a cool option since using shift registers there's theoretically no limit to the number of outputs using only three IO in the processor
Ok. Thanks.
Is there any scripting examples for OBK?
I would like to analyze some to see if I can make some custom scripts
I know a little programming and I think it would be cool trying to make some custom codes for different modules
I am thinking about multichannel modules ...
I am studying the possibility of automating an entire home with only one smart module...
Tomorrow I plan on explaining better my plan, when I am in my shop with some of the modules I already have ..
I already made another thread about using RF 433Mhz modules...
Other things I am studying are:
I2C, UART, or other types of serial communication multichannel PWM controllers (for LED strips and dimmers)
Sending IR signals (to control TVs, and other devices that use IR sensors)
Using multiple buttons in one ADC (I already saw a thread talking about this one)
I am thinking about other options that might be useful while using the limited I/O I have in the Tuya module...
Later I will get some photos of what I have and explain better...
Yes, it should be possible to use one WiFi module to control lots of relays, but keep in mind that you will need a better power supply to driver those relays.
Let's do one feature at time.
I will look into that RF later, remind me if I forget.
For now, I am testing 74hc595:
So far hardcoded blink, but I will add a channels remap to 74HC595 now.
One 74HC595 has 8 outputs, but multiple 74HC595 can be chained. Are you going to chain 2 of them to get 16 IO?
Yes. I understand the need for a power supply that matches the usage of my modules... Doing one feature at a time is the way to go when making this kind of system. At this moment I am going to chain just two registers... But I think it would be a good feature if we could chain more.
I am going to have a general look in openBK source to see if I assimilate how it works... And if I figure it out I could even help coding some of the features I'm throwing here I didn't see much of the documentation on the system too... But I imagine I could help with it too if you want
You can easily fork OpenBeken and get it running with Github online builds on your fork. You don't even have to compile on your PC. It's very easy, you're welcome to help.
Currently port shift out function is working on 32 bit integer, so we can have 4 registers chained together
I have working basic driver, but only for a single register. Tomorrow I will add support to multiple ones.
There is a slight issue with HTML page style:
The current config approach for driver is following:
// startDriver ShiftRegister [DataPin] [LatchPin] [ClkPin] [FirstChannel] [Order] [TotalRegisters]
startDriver ShiftRegister 24 6 7 10 1 1
// If given argument is not present, default value is used
// First channel is a first channel that is mapped to first output of shift register.
// The total number of channels mapped is equal to TotalRegisters * 8, because every register has 8 pins.
// Order can be 0 or 1, MSBFirst or LSBFirst
// To make channel appear with Toggle, please also set the type:
setChannelType 10 Toggle
setChannelType 11 Toggle
setChannelType 12 Toggle
setChannelType 13 Toggle
setChannelType 14 Toggle
setChannelType 15 Toggle
setChannelType 16 Toggle
setChannelType 17 Toggle
More details tomorrow.
What would you like to know when it comes to source code? Do you know that OBK runs on Windows as well?
Since you told it can run in Windows... My first step would be setting it in my Windows machine. The I would figure your style of programming so I can keep the same style of code in my additions.
Assuming you are using C or C: You could set port shift to use a byte pointer so it could be used in any size the user wants.
I discovered OpenBK yesterday half an hour before going home, so I only managed to flash it in my module and didn't really get in the git page yet... Today is a holiday and I had to do the family visiting thing, so I am really limited in my studying. All my electronic and programming stuff is in my shop and I will only come back Thursday... So I will try to read what I can during the weekend so I can get to the shop and start doing hardware tests and building a decent PCB to house the shift registers and fix them in the relay board input.
Added after 9 [minutes]:
>>20530215 I saw that you set the command: startDriver ShiftRegister [DataPin] [LatchPin] [ClkPin] [FirstChannel] [Order] [TotalRegisters]
I think it would be better if you set the number of channels instead of the number of registers. Or set the start and end channels... Like: startDriver ShiftRegister [DataPin] [LatchPin] [ClkPin] [FirstChannel] [last channel][order] Or startDriver ShiftRegister [DataPin] [LatchPin] [ClkPin] [FirstChannel] [TotalChannels] [order]
Also, it should have a parameter to set it to active high or active low. Or can I set this in the channels individually?
Imagine if I have just 6 channels... It should be simpler to manage this way, I think.
And like in the relay board I am using: it is active low... So a parameter for that should be a good option
Assuming you are using c or c++:
You could set port shift to use a byte pointer so it could be used in any size the user wants.
It's C, and it's of course possible. I just have a habit of doing everything as simple as possible because OBK is multiplatform now and so platforms are limited by available flash size. I am trying to reduce the number of instructions in the binary ,etc.
smkassist wrote:
I think it would be better if you set the number of channels instead of the number of registers.
Or set the start and end channels...
Like:
startDriver ShiftRegister [DataPin] [LatchPin] [ClkPin] [FirstChannel] [last channel][order]
Or
startDriver ShiftRegister [DataPin] [LatchPin] [ClkPin] [FirstChannel] [TotalChannels] [order]
Hmm okay I will think about that, the number of registers was for the sake of simplicity, because when shifting out, the number of bits has to be a multiply of 8, and when user gives a number of shift register chips, it's easier to calculate.
smkassist wrote:
Also, it should have a parameter to set it to active high or active low. Or can I set this in the channels individually?
Is there a need to have per-bit swap flags? A global one could be added in a much more simple way.
There is still a lot of memory left on BK7231 platforms, but on WinnerMicro, which has only 1 MB flash, and on BL602 seemingly as well, we are pretty limited. Soon we will have to use the approach common in other firmwares and just create separate builds with separate features.
Some time ago I bought some units of this tuya module: tuya aubess mini smart switch (Belon2028N). I used some of them in my shop for testing and they work well.
Then, one day, I got a lightning strike in one of the external lights that were using the module and it fried.
So, last week I decided to analyse the damage and it turns out just the power supply part of the board is gone, and the wifi chip still works fine.
I decided to remove the wifi module from the relay board and tried to power it and it worked and I figured it had some IO not being used in the original board.
So I googled for some hacking for its chip (BL2028N). That's when I got to the OpenBK guide for the module Since I had one of those 16 channel relay boards laying around, I thought of reprogramming the tuya wifi module to drive it.
But tuya module hadn't enough IO and I remembered of the shift registers... That's when I started this thread.
I was thinking about starting a project using ESP32 to drive the relay board using home assistant and RF controller, but I think OpenBK plus the module from tuya is going to be a better and easier option.
@pkaczmarek262 You mentioned the possibility to run OpenBK in windows. Is there a guide for that?
Nevermind. I found the git page for building
Added after 1 [hours] 8 [minutes]:
So. I started trying to build it and I already see some missing important information on the guide:
First:
new_builtin_devices.c - this file is needed for building and VS gave me a missing file error... I saved a blank file and it stopped.
Second:
windows debug build uses SDL - I am familiar with the lib but it is not installed in my actual system. I will setup SDL in my machine and see if there's something else missing in the guide[/align]
Added after 6 [minutes]:
Third:
Glut lib is being used too
Added after 12 [minutes]:
Fourth:
Native File Dialog lib[/quote]
Added after 3 [minutes]:
Fifth:
Libdevil...
Added after 2 [hours] 8 [minutes]:
So... I managed to set all those dependencies, but I still have some problems to compile the windows test version.
looks like you linked some files that are in paths that are not in the project folder...
I got some undefined symbol errors and some files in solution manager are with the missing icon.
I inspected those files and they are referenced to paths outside of the project folder... So I don't have them...
Hello, sorry for the late reply, but it's 8AM morning in my country and I was sleeping earlier.
I can upload all dependencies to separate repository to make it easier, if you need it.
The important part is here:
You need to select Win32 build. This is because the posted list of files are not needed for Win32. They were just included in project for a reference.
Added after 48 [seconds]:
See how it looks for me:
they are excluded from build
Added after 1 [minutes]:
On windows, MQTT from Beken SDK is not used:
Windows has separate MQTT stub that works with Winsock (non-blocking sockets, single threaded):
There are tools bound to key 1, 2, 3, etc. Unfortunatelly there is no readme about it yet, and no icons for tools. I can try to write one today or tomorrow for you. In general, official release of simulator is on our TODO list. We are hoping to create a simulator tutorial for our Youtube channel someday:
https://www.youtube.com/@elektrodacom I will push shift register update today or tomorrow.
Can you tell me how do you get self test errors? I can see they relate to addClockEvent self test, but how? I tested right now and I get no self test errors.
Yes, I made OpenBeken and I made the simulator. It's my tool used to speed up development of OpenBeken.
I don't get self test errors, so it's strange, it's worth investigating, but maybe we can do it later.
There is no shift register component in the simulator indeed, but you can still play around with all other features of OBK, including MQTT and Hass Discovery. And you can test how scripts behave, etc.
And of course ShiftRegister driver is still running on Windows, so you can put breakpoints, etc, to debug and check how it works. It's very useful for the development.
I think those self test errors are not really important for now... The system seems to be running ok. I see that the simulator part is coded in C. I am reviewing the code and I think I can be useful with it.
I would really want to know why those self test errors happen. Maybe somehow your build is missing "addClockEvent" function?
The main idea of the simulator is to help speed up testing, development and debugging. Most of the issues we encounter are multiplatform and happen even on windows. Only a very tiny fraction of problems is BK7231-specific. That's why we can benefit from running OBK on Windows.
The ShiftRegister can now handle up to 4 registers, it should work well, although I haven't yet changed the number of registers to number of channels. I think that it doesn't give us much difference, especially that we have 64 channels (as far as I know) and I can't imagine a scenario where someone must use non-multiply-of-8 number of channels with shift register because he's running out of channels.... but maybe later I will change it, you can also do the change if you want (open a pull request).
It seems to work well:
I also saw your topic about RF addon, I will look into it.
What else can I do for you now? Is there any other peripheral you've got in mind?
I am focused on your simulator right now. I can try to track those errors and explain them to you later. About the number of registers, I think it's not a really important change. The way it's working seems to be exactly what I had in mind when I started the thread.
About the RF: I used my free time this weekend to understand better the usage of IR and RF and I concluded that the coding and encoding of them is practically the same. I didn't really test the IR option of OpenBK yet. But if it clones the remote codes like I've seen some Arduino examples I think I understand it. So, I think that turning the already existing IR in the system into a "remote-IR" and a "remote-RF", using mostly the same functions could be the way to go. It would be simple and wouldn't generate much more code
Added after 9 [minutes]:
Other than the RF integration, I think that's all for now. I am thinking of making some type of manager for Gate opening motors, but it's priority 0 right now... Maybe make a module to replace the entire board with some extra options, or simply sending the RF signal to mimic its RF remote... But it's just a popped idea with no importance for now
Our IR tries to mimic Tasmota behaviour. You can see an example here:
I don't know about RF behaviour. We would need to look how Tasmota handles it, I assume that it would require a single GPIO and some kind of driver. Probably an interrupt-based one, It's on my TODO list.
From my research, RF receiver sets its data pin the same way IR receiver data pin.
When receiving data, it sends the data through the data pin and the processor decodes it to a specific code that's bound to the pressed button... Really simple. I think it's even possible to just use your IR mode directly. Connecting RF data pin to where it would be the IR data pin.
The simulator seems to be working well. I am tracking the functions to draw things in the code so I can modify some things I see might be better. I had some issues with its resolution (my pc uses 1090x1080) but I found the line that sets the SDL resolution and changed it to fit my case.
The simulation surface is being rendered with an offset that makes part of it render outside my screen but I am already working around it too.
[
Info tool was listing subshapes index from 0 to last-1 and I changed the code so it's from 1 to last too.
Self-test error continues to appear every time I start the simulator. But nothing crashes or gets a strange behavior.
just to be sure: Which one is the root file for the simulator? Is it "sim_sdl.cpp"?
also: I think it would be a good practice to close this thread and start another to discuss the simulator, since shift register is done.
The discussion revolves around integrating a Tuya Aubess Mini Smart Switch (Belon2028N) with a 16-channel relay board using shift registers. The user successfully flashed OpenBK firmware onto the Tuya module but faced limitations due to the limited number of IO pins. Suggestions included using I2C port expanders or shift registers, with a preference for the latter due to local availability. The 74HC595 shift register was identified as a suitable component for expanding IO capabilities. The conversation included technical details on wiring, scripting examples for OpenBK, and the potential for chaining multiple shift registers to control more outputs. The user also expressed interest in exploring other communication protocols and automation possibilities for home systems. Summary generated by the language model.