AJB2K3 Posted March 10 Posted March 10 17 hours ago, Bliss said: Hello all, So here it is, a first draft of an attempt to make my own Online Blockly programming environment for multiple Lego Interface B's. The requirements? Well no need to install any softwares like python etc but you still need: A Windows PC with Internet access (I don't know if this would work on a Mac, but for a Linux, why not?) A Chromium browser latest version (Chrome or Edge, I used Chrome) usb ports available with USB to RS232 adapters (qty depends how many Lego Interface B you want to try at the same time) Link to my Lego-Blockly page Example Projects to download It seems to work well with one Lego Interface. I can't test multiple. So if anyone could report please? Thank you in advance. On the TOP bar, Connect Lego interface B will open the serial port selector and connect. Once connected you should see LegoB1 - Active in the Device Area on the right. If you press again on Connect Lego interface and select another serial port, you should get LegoB2 - active. (NOT TESTED). Also, you have some logs in the Chrome Console Debug console. Use F12 to open Chrome Console. Check "Debug: Log Device Packets" to see all 19 bytes packets read from Lego Interfaces in the Chrome Console. It takes ressources, so do not leave this checked all the time. Save Project Button does not ask for file name. It saves to defaut file name with a number incrementing in your default download folder. Use the Load Project button to Load json file previously saved. I included an Examples folder in my GiHub that you can downloads and "Load". Please Connect you Interface before loading otherwise, the Device Slot in blocks will show No Device Connected... Press Run to execute a flow, Press Stop to end the program (if in a repeat true, this becomes handy) Press Clear to wipe out the Blocky area. It will ask for confirmation. On the Toolbox on the left, the 2 last category are my custom additions (Not part of the Blockly standard toolbox) The few examples I included in my Github should help to understand how it works. To test with 2 Lego Interface B's, once connected, you could load example LegoB_Out_Follow_Inp: And change the 2 Out block for LegoB2. So Touch Sensor on LegoB1 port 1 pressed, should Activate Output 1 (A) on LegoB2 and Deactivate when touch is released. I also implemented an Output Commands Cache that make sure not to send the same command more than once at a time. So in the previous example where an output follow the status of a touch sensor, we can also make the following Flow: Normally, this flow, when the touch sensor is NOT pressed, would send the command OFF to Output 1 (A) every 0.05 sec but the internal code cache the last command to each port so it sends a same command only once through serial. This allow more flexible coding like industrial PLC (Programmable Logic Controller) code with a scan time :-) There is no cache on Reverse command neither on the ON For Time command. Use those with caution if using the PLC type approach. No problem with Wait Until. BE CARREFUL with using repeat while true block, without the Wait until or Wait time Blocks, you will hang the page... This is a first draft as I said, I will probably add some blocks and features. Do not hesitate to report bugs. Special Thanks to Copilot for the Big Help Works great on chrome in OSX. Still waiting on my second interface Quote
Bliss Posted March 11 Author Posted March 11 I'm starting to have quite some fun programming my Lego Interface B with Blcoky lol. I'm also having lots of fun designing new blocks for more functionalities. So make sure to hard refresh the Lego Blocky web Page (Ctrl-Shift-R on Chrome in windows 11) once in a while to get the changes. Yesterday I added the One Shot Rising and Falling blocks in the Control+Wait Category. And I added the "NOT" block in the Logic Category. Also, I added in the github folder, some examples projects to load in blockly. If you intend to leave your blockly projects running for a while, do not forget to disable your power management or set it to "Performance" (Win 11) because, Power Saving mode de-activates USB ports... There might be some energy saving parameters in the browser as well but might be more important if you run on batteries... Stay tune for more Additions to the Blockly online programming for Lego Interface B (I'll also probably add eventually the RCX communication) Quote
AJB2K3 Posted March 11 Posted March 11 (edited) I wish I could understand bit masking because in my blockly it reads once then show the same value but in raw python it shows the changes in value. I got a second interface now just no mains to plug it in! Edit: Solved it, AI slop strikes again, There was some random code that was added by Gemini that was braking the sensor read but not just that, I defined the wrong port numbers! Edited March 12 by AJB2K3 Quote
Gunners TekZone Posted March 12 Posted March 12 (edited) OK, I finally jury rigged a 3 device multi-Interface-B setup. I rarely use block type programming but it is simple enough, so I successfully toggled ports one ON and OFF, in alternating fashion, on LegoB2 & B3 with each button press on LegoB1. I have noticed that if one of the interfaces is temporarily disabled (due to loose serial connection) then everything stops. Stopping and restarting the sketch will not work. It requires disconnecting/reconnecting ALL Interfaces in order to get back to operational condition. And in the case of one of my Interface-Bs, whenever there is a device issue, even if it is a different one, it throws a BufferOverrunError: And I have to physically disconnect and reconnect it on the USB hub, else it usually connects as the next device number up (AKA LegoB4 when it is normally B3). But as that particular Interface-B is one that I surgically replaced it's internal Serial circuitry with an internal TTL/USB device... who knows... it might be a bit quirky? I'll have to swap them around and see if this issue follows the device or stays with the last one connected. Anyhow, that is all I can work on tonight. And @Bliss I will probably DM you with further troubleshooting posts for the time being, and limit my public posts re: this testing, for more relevant announcements. Edited March 12 by Gunners TekZone Quote
Bliss Posted March 12 Author Posted March 12 (edited) @Gunners TekZone, Thank you for your help testing multiple Interface. We now need to determine if the lost of interface(s) is due to unstable hardware of if it is caused by the limitation of running in a browser window. With only one interface here, I let it run for few hours without problems. I had as I said to disable power saving on the computer of course... the Stop button stops the running program, it does not disconnect. But when you press stop, it tells you in the status window that it does stop the comm. with the Devices... If the comm fails by itself somehow, you have no choice other than press the disconnect all to clean everything and use the connect again. (Disconnect resets the numbering of device name to 1 like LegoB1) The connection must pass though the web serial connect popup window. I will still look if there could be some improvement on this side. But the best is to use healthy interface(s). ALSO Very important, if you use Repeat Until TRUE loop, YOU MUST use a Wait Time inside the loop (generally at the end) like Wait 0.05 sec. Otherwise, you MAY hang the page and communications will eventually fail. (However, I did some output caching to avoid sending same commands consecutively... So this should avoir the com port flooding) Edited March 12 by Bliss Quote
AJB2K3 Posted March 12 Posted March 12 (edited) That’s why I went off line as I had issue with web serial blocking the port, worst case I had was having to hard reboot the computer to reset the serial bus. it’s not just my own version but had the same with other software that accesses the bus like arduino, thonny and python if the bus connection isn’t force closed then a hard reset of the host machine is the only way, removing and reinserting usb devices doesn’t work i have had this with esp32 verities Edited March 12 by AJB2K3 Quote
Bliss Posted March 12 Author Posted March 12 (edited) ESP32 boards have often different FTDI chips that requires different drivers. Sometime I even had to revert to older driver version... So web serial with ESP8266 and ESP32 boards can be painfull sometime. With my interface B, I do not have any serial disconnection from web serial using a very good USB/Serial adapter. (I have another one adapter I bought from local electronic store last year and I did not yet succeeded to maintain a reliable connection with it no matter if it's from the web or not). At the moment, I'm using Win11 on a I7 14e gen small form factor Lenovo Thinkcenter. I have 2 chrome instance with multiple pages opened on each. Everything runs smoothly. But the Idea here is to have an environment easy to use with NO big installation needs and get you up and running with your old interface B project in no time. For me it looks pretty solid but I know I have good hardware (I7 14e gen, Interface B, USB Adapter). So it's reliable for me to have great fun for sure. I do not expect it to be a plateform to make projects that must run 24h/day 365D/year... But if it fails more dans 2 times per hour, it is not acceptable for me either. Now, for multiple interface, the reliability has to be confirmed. Also I wonder if the CPU capability may be a factor... @Gunners TekZone , can you describe the hardware you use (PC CPU, OS version, )? And can you test with 2 interfaces only and see if keeps running for a while without fails? Edited March 12 by Bliss Quote
Gunners TekZone Posted March 12 Posted March 12 2 hours ago, Bliss said: If the comm fails by itself somehow, you have no choice other than press the disconnect all to clean everything and use the connect again. (Disconnect resets the numbering of device name to 1 like LegoB1) OK... That "issue" (one of my interface's Serial connection is very loose) was really the only issue I ran into with my initial and simplistic test, so good to know that it is expected behaviour. 1 hour ago, Bliss said: @Gunners TekZone , can you describe the hardware you use (PC CPU, OS version, )? Microsoft Surface 3 Pro running Windows 10 Pro 64bit. Quote
AJB2K3 Posted March 13 Posted March 13 I tried adding save and load functions to my offline version and ended up braking it and having to restore it. Quote
Bliss Posted March 13 Author Posted March 13 (edited) On 3/12/2026 at 2:23 AM, Gunners TekZone said: ... I have noticed that if one of the interfaces is temporarily disabled (due to loose serial connection) then everything stops. Stopping and restarting the sketch will not work. It requires disconnecting/reconnecting ALL Interfaces in order to get back to operational condition. And in the case of one of my Interface-Bs, whenever there is a device issue, even if it is a different one, it throws a BufferOverrunError: And I have to physically disconnect and reconnect it on the USB hub, else it usually connects as the next device number up (AKA LegoB4 when it is normally B3). Hello, I added some communication error proofing, better Device name re-allocation etc... that should take care of some behaviors observed by @Gunners TekZone. I cannot test multiple Interface B but if a program is running and one device disconnects by itself, it should stop the program, clear the device and let the other good device connected. It should allow you to reconnect a device using the Name that was previously freed up... Let me know. P.S. I also added some multi port output command blocks... https://blissca.github.io/lego-blockly/index.html Edited March 13 by Bliss Quote
Gunners TekZone Posted March 13 Posted March 13 (edited) 3 hours ago, Bliss said: if a program is running and one device disconnects by itself, it should stop the program, clear the device and let the other good device connected. It should allow you to reconnect a device using the Name that was previously freed up... Yes, this seems to work as described. I tested by both disconnecting the Serial end (Disconnecting the Interface-B but leaving USB/Serial adapter "visible" to the O/S) and by just disconnecting the Interface-B from the serial connection. Same results... Program stops and will not run until missing device is physically connected and made active. It did retain the prior device name/number. As an aside... I suggest changing OUTPUT labeling from numerical to the A, B,C... H as indicated on the device (and referenced in Control Lab). Also... As I previously mentions, I generally don't do Block type programming, mainly as they seem to keep changing how they are interpreted, depending on the program implementing it... whereas Python teds to stay a bit more universal (within versions at least). To clarify, I am confused here... There seems to be a way to check for an ON but not an OFF on an Input port? Or am I just misunderstanding the logic flow? Highly probable as I am only on 1st coffee... Edited March 13 by Gunners TekZone Quote
AJB2K3 Posted March 13 Posted March 13 If I recall correctly, there is no need as button function just returns true for pressed and false for not pressed. Quote
Gunners TekZone Posted March 13 Posted March 13 (edited) But in my slapped together test, once activated the port on B3 stays ON... EDIT: Well, that was before my 2nd IF block was added... With which it will turn OFF, if I time it just right Normally I would use something like an IF/THEN/ELSE, but I don't currently understand that equivalent in Blocks. 2nd EDIT: This was just a whimsical test to see what happens to a running program if the STOP button on the device with the button was pressed, then later released.... Turns out it just keeps on keeping on, as expected Edited March 13 by Gunners TekZone Quote
Bliss Posted March 13 Author Posted March 13 (edited) 1 hour ago, Gunners TekZone said: As an aside... I suggest changing OUTPUT labeling from numerical to the A, B,C... H as indicated on the device (and referenced in Control Lab). Hello @Gunners TekZone, and thanks for testing. Blockly is very EASY but still need some training :-) I'm using the official Blockly source V12 from google which has been transfered to RaspberryPiFoundation... I do not want to use labeling A, B, C, for outputs because with numbers, it allows to easlily use a variable in a loop. For example: To check of input is off, you can use a NOT in the Logic category. And by the way, on the IF block, there is a small Blue flower like icon on the top left corner., you can click on it and from the window that appear, you can add ELSE and ELSIF to your IF Block. You will also find One Shut Raising and Falling blocks in the Category Control that can make better programming... For example: This program will continuously print input is off while Input 1 is not pressed. It will continuously print input 1 is ON while pressing the touch sensor. This program will print the touch sensor status only once on every change. By the way, You can check the status of the Red Stop button on the interface B using Input 0: Edited March 13 by Bliss Quote
Gunners TekZone Posted March 13 Posted March 13 (edited) 42 minutes ago, Bliss said: Blockly is very EASY but still need some training :-) I do not want to use labeling A, B, C, for outputs because with numbers, it allows to easlily use a variable in a loop. Hah... This old dog don't like new training for something he isn't likely to use outside of testing... But who knows... "I'm a man, but I can change, if I have to, I guess". As for the output labeling, again not a big concern if others don't care, but I am very use to the alphanumeric distinctions between Interface OUTPUTS and INPUTS. The logic you describe could probably accounted for in the back end, as an "A" label for an Output will always == 1, as will a 1 == "A". HEXADECIMAL does it... But then that is confusion all of its own. However, that is added complexity for the program, while us "meatbags" are somewhat more adaptable... So I will survive 42 minutes ago, Bliss said: One Shut Raising and Falling blocks That said... I do not understand what these do? And your example doesn't even seem use them?? But that falls under "learning blocky" and I might forget how to feed myself if I cram too much "new" through the brainfog Edited March 13 by Gunners TekZone Quote
Bliss Posted March 13 Author Posted March 13 (edited) @Gunners TekZone, you could use letters for output if you can't live without it by creating variables... or The last example is here: https://github.com/BlissCA/lego-blockly/blob/main/Examples/legoB_OutLetters.json Edited March 13 by Bliss Quote
Gunners TekZone Posted March 13 Posted March 13 (edited) 28 minutes ago, Bliss said: you could use letters for output if you can't live without it by creating variables... Ah, yes... Something like that, but in the background code. But again... Please don't stress about it, I'm not I am not your ideal target base. I tend to run out of steam too soon, thus rarely get far in making my own big projects before I have to set them aside... And promptly forget much of what I learned. But I do like smaller ones, like testing for others... So this is that! Edited March 13 by Gunners TekZone Quote
Bliss Posted March 13 Author Posted March 13 (edited) I was being asked on github by @Wapata if this would work on an android phone or tablet... iPhone do not allow webserial :-( So, for Android, I read that it could work with a USB OTG Adapter (On The Go) + Serial USB/RS232 adapter but they also say there are limitations... But google also say that could work better with a Bluetooth to RS232 passthru adapter... I do not have a complete BT / Serial adapter But I found out I ordered in 2023 some BT FTDI board like HC-05, JDY-21 etc... And for the ESP32 project to hook to Interface B, I had to get some TTL to RS-232 adapter... I got some spare too... So I connected the BT / Serial TTL to the TTL - RS232 adapter to make a BT / RS232 adapter and plugged the RS232 port to the Interface B. I opened the Add BT Device on my computer and saw the JDY-21 device and paired it (passkey is 1234 with these little boards). This automatically added Com ports... So in my Blockly page, I click connect, and select the COM Port generated by the BT / Serial board and to my surprised it worked! So I was able to control the Interface B Wireless through BlueTooth! I'm gooing to borrow some old Android phone from my nefew Sunday and let you know if it can work from an android device with chrome and BT... Edited yesterday at 01:30 PM by Bliss Quote
Gunners TekZone Posted March 14 Posted March 14 (edited) 4 hours ago, Bliss said: The last example is here: https://github.com/BlissCA/lego-blockly/blob/main/Examples/legoB_OutLetters.json Ahhh... I see how those One Shot blocks work now. Thanks! To keep with the multi-interface testing, I setup my ON switch on LegoB1, the OFF on LegoB3 and the target outputs on LegoB2. Working just fine! And that variable swap seems to work nicely as well! Perhaps (if easy) just make that variable setup a "built in" function block, so one can use it or not as they chose? 3 hours ago, Bliss said: I was being asked on github if this would work on an android phone or tablet... I is confused ... again... So, this is running the webpage (WiFi) and controlling the Interface-B (BT) solely from a phone/tablet? Well after the whole Rube Goldberg TTL/BT/Serial setup of course. That was some nice jerry-rigging! Not sure how that would work with multiple interfaces?? Alas, I don't believe I have enough bits-n-bobs to set that up for testing. Hmm... Personally, I would just have the same physical PC/Tablet with wired USB and simply VNC to that with a phone. But even that seems unnecessary as your current application is all about the programming of, not the "control" of the program... Not unless you are planning on adding GUI based control/display options as does Control Lab?... Just with Blocks instead of LOGO. Edited March 14 by Gunners TekZone Quote
Bliss Posted March 14 Author Posted March 14 (edited) On 3/13/2026 at 10:16 PM, Gunners TekZone said: I is confused ... again... So, this is running the webpage (WiFi) and controlling the Interface-B (BT) solely from a phone/tablet? Well after the whole Rube Goldberg TTL/BT/Serial setup of course. That was some nice jerry-rigging! Not sure how that would work with multiple interfaces?? Alas, I don't believe I have enough bits-n-bobs to set that up for testing. That's about it. An Android phone or tablet using wifi to access my Lego Blockly Web Page with chrome and use the BT to RS232 adapter that makes com port available to the phone. The BT to RS232 is plugged to the Interface B. On the web page, then press connect and select the com port from the BT adapter and it will connect to the Interface B. This has to be proven to work on Android. IT IS WORKING ON MY LAPTOP (Win11) that has BT... I will have an android phone to test this Sunday. Can it do Multiples Interface? I guess so if you have multiple BT to RS232 adapter :-)... Here is my DIY BT to RS232 adapter that works with my PCs... You probably have all components except the BT to TTL maybe (HC-05 or alike, this one is a JDY-31-SPP) The RS232 port of the TTL-RS232 adapter goes to the interface B. That eliminates the USB/RS232 adapter plugged to a PC. It make the Interface wireless somehow but the program is still running on a PC, not an ESP32 like the last year project... But I di not test it for very long with my PC and I don't know if this wireless method is reliable... Edited yesterday at 01:33 PM by Bliss Quote
Gunners TekZone Posted March 14 Posted March 14 1 minute ago, Bliss said: Can it do Multiples Interface? I guess so if you have multiple BT to RS232 adapter :-)... Hmm, yes, I just might have the parts after all ... I got the same Serial to TTL 3 pack as you probably did, and I am sure I have an HC-05 or similar from back when I messed around with that more often. That said, I'll leave the Multi-Wireless-Serial stuff to whomever really wants it. Most of my testing setup and connections are already cramped and a nuge away from disconnecting themselves as is Quote
AJB2K3 Posted March 14 Posted March 14 OMG this is growing amazingly. You said you didn't want to use port letters because of variables? Oh and BTW the flower Icon is actually a gear. Quote
Bliss Posted March 14 Author Posted March 14 (edited) 10 hours ago, AJB2K3 said: You said you didn't want to use port letters because of variables? Oh and BTW the flower Icon is actually a gear. Well, my mind have seen first a flower but it would have been grey, maybe it would have seen a gear ;-) I made a BIG change for the output port letters haha. (Not that big after some digging). Thanks @Gunners TekZone for "insisting" haha. I also think it is better that way and also, it does not affect at all the possibility to use variables and numbers. Edited March 14 by Bliss Quote
Toastie Posted March 14 Posted March 14 Have been rather busy the last month(s) - our annual mass spectrometry conference has closed its doors on Friday - was rushing back from Leipzig to make it for a birthday party - getting things into the clear, and now !focus! @Bliss I just read this thread from where I lost it - the moment I found "just go to this website" you had me. Learned a bit about "blockly" lost it again, but updated Chrome (I am a Firefox user as long as Firefox exists), installed the essential add-ons (Adblock, etc. pp) and shall try connecting my Interface B (which connects via HC-05 + TTL2SER to my Win11 laptop). I have the feeling that this will be pure fun! I can do all that with DOSBox-X + QBasic, but when it comes to "programming" Interface B in QBasic, a lot of care has to be taken as I need to capture the serial port data along with keeping program control clean - in - well - one Basic program. I am not interested in controlling multiple B's, as I haven't envisioned any stationary >programmable< robotics device having 8 inputs + outputs. Turning things on/off in response to pressing buttons is one thing (and I do that differently in my LEGO world, using RCX driven "electro-mechanical" devices for example). After all, Interface B is a sensor data reporter and light/motor driver, which is principally the same thing Interface A does. The software on the computer does it all, in contrast to the PBricks, which are meant to run autonomously after programming. And here is, where your approach really excels. I know: LOGO is under the hood of the LEGO software, but I am struggling with LOGO a lot. Particularly when mixed with visual controls as in the LEGO software for Interface B. I got somewhat familiar with the (visual) LEGO software for the NXT brick (using all sorts of 3rd party sensors/extension, some were my own), but when I wrote (ok, "wired") more "complex" programs, it became difficult there as well, as the IDE was maybe not expecting such "long" programs. I am really excited - I believe your approach is the way to go, "Interface B software-wise". All the best Thorsten 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.