Bliss Posted February 1, 2025 Author Posted February 1, 2025 Here is a preview of the UIFlow 2 blocky LegoB blocks and a working sample program. (nothing fancy motor port A follow state of Touch sensor input 1). (On a M5 Core 2 but same has worked on a M5Stick CPlus) Quote
Gunners TekZone Posted February 2, 2025 Posted February 2, 2025 (edited) Well, a bit of fiddling around (I still don't really understand the webrepl aspect?? I just use Thonny to run a program) I got an older ESP32 DevKit board to work with demob.py (press button on 1 see light on A) Baby steps Edited April 11, 2025 by Gunners TekZone Quote
Bliss Posted February 2, 2025 Author Posted February 2, 2025 2 hours ago, Gunners TekZone said: Well, a bit of fiddling around (I still don't really understand the webrepl aspect?? I just use Thonny to run a program) I got an older ESP32 DevKit board to work with demob.py (press button on 1 see light on A) Baby steps ESP32 devkit are still the best. very stable. I like also the mini version of the ESP Wroom 32... The webrepl is really to use the Wifi to access the "Shell" so you can access remotely with no USB link to your ESP32... But it is slow. I think, for a particular project, someone will use the USB to test and when fully functionnal, the user will rename his final project file main.py so that it will be executed automatically when you apply power... Right now, I made provision to power my esp using the lego box power connector on the front but I do not use it because I prefer to use USB link to test. It is faster. But for a final project, I would disconnect the usb and use the 9vdc link to power the ESP... I'm glad you you managed to test the setup... I feel less lonely now ;-) Quote
Gunners TekZone Posted February 2, 2025 Posted February 2, 2025 (edited) On 2/1/2025 at 7:52 PM, Bliss said: I'm glad you you managed to test the setup... I feel less lonely now ;-) And I finally got the MQTT part working. Took a bit to realise that, and where in the code, I needed to set the TX/RX pins... Silly me :P That app looks interesting... But looked like it was going to take me a bit to set it up, so I fell back to my Node-Red setup for some basic tests to confirm proper action. Edited April 11, 2025 by Gunners TekZone Quote
Bliss Posted February 2, 2025 Author Posted February 2, 2025 (edited) On 2/1/2025 at 11:13 PM, Gunners TekZone said: And I finally got the MQTT part working. Took a bit to realise that, and where in the code, I needed to set the TX/RX pins... Silly me :P That app looks interesting... But looked like it was going to take me a bit to set it up, so I fell back to my Node-Red setup for some basic tests to confirm proper action. Indeed in every demo programs I offer, there are few settings to change (Described in the README). tx rx pin in the lego.start method and for the mqtt demo, the ip address of the broker. In addition, the secret.py should be updated as well for using the network features (MQTT and WebREPL)... If someone does not not need the network at all in his project, he does not need to replace the boot.py file and he only needs to copy the legob.py and his project file like demob.py or demob02.py that's all. No need to copy the boot.py, the lib folder, secret.py etc... The phone app IoT MQTT Panel is really just another alternative for those who wants to have a nice UI (User Interface or HMI Human Machine Interface) to control their Lego Interface B outputs from their phone a bit like the https://www.controllab.io/ which is using a webbrowser... I found myself this IoT MQTt Panel app very easy to setup and fun to play with. But since IoT MQTT panel is configurable, it is more flexible. You can also make Home Assistant Dashboard and custom "Cards" etc. Many solutions. Node-Red is great to test and make programs to interact between IoT devices... It a favorite for many in the IoT world. I update the demob_mqtt_v2.py to make all sensors avail to mqtt. I also put comments at the beginning to describe the topic to use. EDIT 2025-02-02 17h16: I made a correction in the demob_mqtt_v2 for the reset of rotation count and I also uploaded a demob_mqtt_plc_v1.py in the LegoB "PLC" version folder... The demob_mqtt_plc_v1 file uses the built-in umqtt.simple since there is no asyncio in this version... We'll see if it runs reliably... Have fun! Edited February 3, 2025 by Bliss Quote
Bliss Posted February 3, 2025 Author Posted February 3, 2025 @Gunners TekZone I found out that the IoT MQTT app on the phone allows to backup the configuration. So, I just uploaded a backup (json) of my IoT MQTT Panel configuration. You will still need to configure your broker info. I don't know if the backup will work on an Android phone though... Quote
Gunners TekZone Posted February 3, 2025 Posted February 3, 2025 3 hours ago, Bliss said: I don't know if the backup will work on an Android phone though... It's JSON so not a problem there. Worked great! Thanks! I had started on a couple of settings of my own with that app... as well as some more Node-Red, but between normal grogginess and stuffed sinuses due recent weather change... I fear the more GUI/HMI interfaces I struggle to learn, the greater my chances of forgetting where I live Quote
Gunners TekZone Posted February 3, 2025 Posted February 3, 2025 4 hours ago, Bliss said: oT MQTT app on the phone allows to backup the configuration Woops... Be aware, not sure if due to the free or Android version, but apparently restoring will wipe out all other connections that were there? Odd. And having almost installed advertised programs when meaning to hit the save button at the bottom, and not willing to spend $12CAD for this at the moment, I might stick with the Virtuino IoT and Node-Red interfaces I already have and understand Quote
Bliss Posted February 5, 2025 Author Posted February 5, 2025 (edited) I removed the "plc" version and replaced it with LegoB micropython V2 folder. I updated Post #1 too. Lego Interface B MicroPython ESP32 V2 Now I use MCU Timers for both the keep alive and Inputs Byte Frame readings... Using Timers creates constant periodic interrupts. (There are 4 of these Timers available on the ESP32) (Should have done this before...) So we can do slow sequences or non blocking fast logic (like an industrial PLC). The V2, i believe, is the simplest to use and I hope, the most stable version of the MicroPython ESP32 Lego Interface B driver. UPDATE 2025-02-05 9h47: I left the V2 running overnight with the MQTT demo and when I checked this morning it was stopped with an OS Error (Error from the umqtt.simple)... ESP32S3-zero mcu... (It seems stable with no mqtt demos) I will let the V1 running the whole day with its MQTT demo... UPDATE 2025-02-05 20h38: I left V1 MQTT demo running all day and no fail but maybe this version of mqtt has some auto reconnect feature. I'm trying LegoB V2 again since few hours with the umqtt.robust rather than umqtt.simple and it does not fail, but robust version of umqtt uses the .simple with some auto reconnects on fail... UPDATE 2025-02-06 01:06: The LegoB V2 eventually failed. Now it was a Checksum mismatch lf the LegoB continuous inputs reading... I suspect that when there is mqtt.robust auto reconnects, it takes ressources and bothers to reading on serial... idk... Anyway, I made (and uploaded in dropbox of the LegoB V2) another mqtt demo (demobv2_mqtt_2.py) that uses the same "mqtt_as" library that I used for the V1 LegoB. Now let's see if the LegoB V2 demobv2_mqtt_2.py will run overnight with no fail... UPDATE 2025-02-06 11h47: LegoB V2: demobv2_mqtt_2.py has run overnight no fail... This mqtt_as library is really solid... Edited February 6, 2025 by Bliss Quote
Gunners TekZone Posted February 8, 2025 Posted February 8, 2025 (edited) On 2/4/2025 at 7:37 PM, Bliss said: UPDATE 2025-02-06 11h47: LegoB V2: demobv2_mqtt_2.py has run overnight no fail... This mqtt_as library is really solid... Well, after many days of 1st snow, 6 hour power outage (in freezing cold and all electric heat), dead camera server (faulty UPS??) computer revival/replacement, and even issues with micropython behaviour that just messed up my thinking... (PS, I belatedly realised that there is NO reason to try this on the Win 7 PC, as due it's very nature, a ESP32/Micropython controlled Interface-B needs no serial ports... Doh!)... I can finally concur :D I am running an Pi400 with Mosquitto MQTT broker and Node-Red. And using Node-Red to handle the logic, the Micropython Interface-B has been running over 24 hours. With temp, rotation, button and light (the button and bulb control and indicate the status of a 120v lamp, via Sonoff switch). Edited March 2 by Gunners TekZone Quote
Bliss Posted February 11, 2025 Author Posted February 11, 2025 Just added the UIFlow2 Blocky version for M5Stack Devices in the drop box (Link also in post #1). I tested only on M5 Core2 ESP32 device. Not fully tested and it was very painful to make the custom block... Also, I find the blocky can be very ugly sometimes. UIFlow2 demo project LegoInterfaceB.m5f2 and also the Custom Block for Lego Interface B driver Lego9751.m5b2. Quote
Gunners TekZone Posted March 2 Posted March 2 (edited) UPDATE: March 1, 2026... And my In-B/ESP32/MQTT hookup is still working, easily for many months at a time in between power/reset. I have seen some interested parties in other forums, working on their own ways of running the Interface-B via Python, and I have referred them to this topic. Unfortunately... I seem to have forgotten how I even did this (as in how I programmed the MQTT sketch) "Ahh, brain fog, let me give you a piece of my min... Hmm, now where was I going with that??" I can log into the ESP... but none of the files seem to make sense to what I know is happening... The switch on input 1 sends an MQTT SUB command to toggle an AC Relay and the lamp on output A responds to any incoming PUB command to show the state of said external AC Relay. This Int-B is just one of a total of 5 totally different button/indicator systems , including the AC relay itself, and they all update whatever display method they use based on the actions of the others. Oh well... at least it remembers what to do and how to do it. Edited March 2 by Gunners TekZone Quote
Gunners TekZone Posted March 2 Posted March 2 (edited) 4 hours ago, Gunners TekZone said: Unfortunately... I seem to have forgotten how I even did this (as in how I programmed the MQTT sketch) "Ahh, brain fog, let me give you a piece of my min... Hmm, now where was I going with that??" Ahhh... now I got it... again. This was a "Generic" sketch that covered all the Interface-B inputs and outputs and basic sensors. It is using Bliss's V1 version which uses uasyncio. It has an imported micropython MQTT-Client, and all it does is send a "1" on the PUB channel, when switch is pressed (or whatever signals are relevant for rotation and temp, etc.) and listens for a "0/1" for the outputs (and "1 through 8 " for whatever output power is specified) at SUB reception . All the "heavy lifting" code for this particular "relay switch" is in my Node-Red server. That is where I handle the toggle code and SUB/PUB protocols for this one, as well as other testing I was doing. I still have settings there to read rotation and temp sensors as well as control a bunch of the outputs that I had motors and other lamps on... Back when I was more actively messing around with this. That is what happens when you don't play ALL your toys more often You have to post stuff on forums... In my case, not so much for others, but so I can find out how I did whatever I did at that time when the brainfog wasn't as heavy Edited March 2 by Gunners TekZone Quote
AJB2K3 Posted March 2 Posted March 2 3 hours ago, Gunners TekZone said: Ahhh... now I got it... again. This was a "Generic" sketch that covered all the Interface-B inputs and outputs and basic sensors. It is using Bliss's V1 version which uses uasyncio. It has an imported micropython MQTT-Client, and all it does is send a "1" on the PUB channel, when switch is pressed (or whatever signals are relevant for rotation and temp, etc.) and listens for a "0/1" for the outputs (and "1 through 8 " for whatever output power is specified) at SUB reception . All the "heavy lifting" code for this particular "relay switch" is in my Node-Red server. That is where I handle the toggle code and SUB/PUB protocols for this one, as well as other testing I was doing. I still have settings there to read rotation and temp sensors as well as control a bunch of the outputs that I had motors and other lamps on... Back when I was more actively messing around with this. That is what happens when you don't play ALL your toys more often You have to post stuff on forums... In my case, not so much for others, but so I can find out how I did whatever I did at that time when the brainfog wasn't as heavy I’ve uploaded the source to the latest version of my ULI using Bliss’ RCX on GitHub. you wouldn’t be interested in trying to add your code to it would you? Quote
Gunners TekZone Posted March 2 Posted March 2 (edited) 10 hours ago, AJB2K3 said: you wouldn’t be interested in trying to add your code to it would you? I am using @Bliss's code (also in the link I provided above). I have no code of my own in this... That's part of the reason it took me a moment to realise why it seems so confusing. I was getting my memory recall mixed up between how I got this Int-B/ESP32 combo going, compared to a Raspberry Pi LEGO-Hat that I also have running as part of my MQTT test setup. Edited March 2 by Gunners TekZone Quote
AJB2K3 Posted March 2 Posted March 2 Yeh I asked him to upload to GitHub so I could include and credit him Quote
Gunners TekZone Posted March 2 Posted March 2 (edited) Actually, I am not sure he has a GitHub repository... I barely do. But all the links are already here to download (beginning of topic)... Why not save him the trouble and copy it over yourself? (with credit) Edited March 2 by Gunners TekZone Quote
AJB2K3 Posted March 2 Posted March 2 42 minutes ago, Gunners TekZone said: Actually, I am not sure he has a GitHub repository... I barely do. But all the links are already here to download (beginning of topic)... Why not save him the trouble and copy it over yourself? (with credit) https://github.com/BlissCA/LegoRcxPy https://github.com/BlissCA/LegoBpy My own if you are interested. https://github.com/Ajb2k3/ULI Quote
Bliss Posted March 2 Author Posted March 2 (edited) I finally created 2 gitub repo's for the "PC" version of the Lego IntB and RCX python modules and examples. I added the link to these repos in the first post of the thread: Lego RCX, Int B Programs I might as well create some Repo's for the ESP32 Mycropython eventually Edited March 2 by Bliss Quote
Gunners TekZone Posted March 2 Posted March 2 (edited) 18 minutes ago, AJB2K3 said: https://github.com/BlissCA/LegoRcxPy https://github.com/BlissCA/LegoBpy My own if you are interested. https://github.com/Ajb2k3/ULI Yup... I can be totally clueless when it comes to navigating GitHub. Thanks for the links 12 minutes ago, Bliss said: I finally created 2 gitub repo's Ah... good... I am not (totaly) clueless after all... I was just searching in the wrong year, last year (for the LEGO stuffs... I wasn't searching by name). 1 hour ago, Gunners TekZone said: I barely do And since we are sharing... https://github.com/Gun-neR/MQTT-Example-for-RPi-BuildHat No, it has nothing to do with the Interface-B. But at least it is LEGO...ish Edited March 2 by Gunners TekZone Quote
AJB2K3 Posted March 3 Posted March 3 8 hours ago, Gunners TekZone said: Yup... I can be totally clueless when it comes to navigating GitHub. Thanks for the links Ah... good... I am not (totaly) clueless after all... I was just searching in the wrong year, last year (for the LEGO stuffs... I wasn't searching by name). And since we are sharing... https://github.com/Gun-neR/MQTT-Example-for-RPi-BuildHat No, it has nothing to do with the Interface-B. But at least it is LEGO...ish Oh cool, that's something I would like to incorporate into the RPI version. I have one sat on my RPI 4 but not got around to using it yet. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.