Jump to content

Bliss

Eurobricks Citizen
  • Posts

    164
  • Joined

  • Last visited

Everything posted by Bliss

  1. @Toastie, I made some tests and found out that the Blockly Functions were actually asynchronous since I'm using an Async approach to my coding. That means that each function you define CAN BE a separate task. However, it can be dangerous. In a MAIN Forever loop, if you keep calling the same function over and over and this function has its own forever loop that never ends, each call will create a new instance of that function... It is not a problem for your example since your functions have no loops. Look at the following simple example: In this example, the main program is not a loop, it just call Test1 and prints END OF Main. The Function Test1 has a repeat loop that wait 1 seconds every loop then prints END OF Test1 task. In the time line, END OF Main will print as soon as you RUN the program. Actually, the Program RUNs and ENDs immediately. But 5 sec later, you will see in the status window: END OF Test1 task... Another example: In this example, 2 independant task for flashing Output 1 and output 2 independantly. And in the main loop, I made sure I "start" the task only once! Because those tasks have their own forever loop. Then in the main loop, I also make the Output C to follow the Touch sensor on Input 1. and it is still very responsive. We have clearly here, parallelism... HOWEVER, This is NOT the behaviour we wish for simple functions. Functions should be sub routines WITH NO forever loop. Functions SHOULD be synchronized with their Main loop. In the next versions, I will synch the built-in blockly functions. So in the first example above, the result is that the program will run, wait for 5 sec, then it will print END OF Test1 task and then print END Of Main, and Program will finish. The second example will not work anymore as the main loop will wait for the firt function call to return will never happens... The forever loop in this function would become the main loop... Also, I will add a new block TASK similar to functions but with a bit more features... Task will be Asynch from each other. Stay tuned...
  2. I added RCX Motor (Output) command caching into the code so it will send the Same consecutive command through serial only once. I did not cache the "Flip" command. I struggled a bit with the auto update again so if your page does not update by itself, use ctrl-shift-r to force the browser to update... You should get the following in the footer bar: Version: 2026-03-30-2250
  3. A blockly page is actually only one task or THREAD as they call it but it so fast that you can emulate somehow multitasking. I come from Industrial world, and in this world they have PLC's (Programmable Logic Controller) which is used to automate processes that involve often hundreds of sensors, motors, valves etc. They now have the notion of tasks but often, we use one task only with many "Routines", "sub-Routines" (Like Functions). The PLC are so fast and they do a forever loop... (Scan time is microseconds to milliseconds) It's like an Arduino type of programming that has a Setup routine and a Main Loop. So in a forever loop, as much as possible, you do not use "blocking" instructions like other repeat forever or Wait until, or Wait x seconds... those just blocks everything and if you want to monitor some touch sensors as quickly as possible, this is not the way to go. (That is the reason why I created non blocking timers. Moreover, I programed the timer so on completion, they can do an independant code.) (I might also implement more events eventually.) So if we take your exemple where you monitor 3 sensor inputs, since you use a fast forever loop, it behaves like you have 3 independant tasks... - Task 1: Monitor Sensor 2 continuously and do actions accordingly, - Task 2: Monitor Sensor 3 continuously and do actions accordingly, - Task 3: Monitor Sensor 4 continuously and do actions accordingly, And everything looks to be running independant . That is the way industrial PLC works. One fast forever loop, non blocking instructions, everything, input monitoring (polling), activating, deactivating outputs, everything looks independant... But with PLC, when a condition is true, they can keep energizing an output every scan. With Interface B, we cannot write the same command through serial every scan of the forever loop. That is why PLC philosophy is not ideal in this case but I did some caching for most output commands to make sure same commands are sent once.
  4. @Toastie, I think you'll have your Blockly Expert Certificate very soon ;-) You're progressing fast! You will become our Blockly teacher and teach to Wapata! Do you speak French? (I do as I'm french canadian if you didn't notice my accent in my writing lol) The new version should fix the blocking dialog window problem now. (I replaced the built in prompts and confirm dialog with new custom ones) Version: 2026-03-30-1519
  5. I just noticed that if you take too long to create a variable with its Dialog window, or using the confirm diablog window , it actually blocks the background programs and eventually, the Lego Interface disconnects. As soon as we connect a Lego Interface B, it starts reading continuously the 19 bytes streams... So this is interrupted by those modal dialog window... I'll try to find a fix for this and let you know.
  6. @Toastie No, I don't think so. The Sensor variable appears in the variable category, so it must be global. Don't forget that the basic of blockly is to make it easy for children. But still, doing it this way makes the program neat... I'm suprised that "3", "7" is working... As I said, they made it very simple so you don't need to think about conversion etc... You cannot use a Text directly in the Set Output ON block. But using a variable before might do the conversion internally of text number into number... But it will not convert a Letter to a number. However, if you still want to assign output port letters to your OutFwd and OutRev variable, you can still use the "Constant" variable that I provide for you to use anywhere in your program. They are in the Lego B -> Output Single Port Category at the top.
  7. @Gunners TekZone, @Toastie, @Wapata and all the others, I added the "Save As" button. The "clear" button has been replaced by a "New" button. (New Project). Which will clear the area and put back the project name to default. The last Folder used should be retain in a same session only. If you close and open the lego blockly page, it will revert to default folder (Downloads) until you save as or load a project... The save button will always now overwrite the same project file name. I also added the "New Edits" detection since the last save and you will have an "unsaved changes exist" indicator (Black Dot) on the left of the file name. When Unsaved edits exist, you will be asked for confirmation when you click on Load or New button... Latest Version: 2026-03-30-1212
  8. This function you gave in example, does not make a lot of sense though. The input variable should be "Sensor", then when you call the function, you connect Sensor_3 to Sensor, and later in your code, you may call again you function but this time, Sensr_4 connects to Sensor... Inside your function, you whould then only use "Sensor" variable.If you want to explictely use Sensor_3 inside the function, there is no need to use input variable... just use Sensor_3 variable already available as a global anyway. For the USB Tower, since I don't own one yet, I did not check what work has been done already to get it working on modern OS... The code area, I mean the Blockly code area where you drag blocks from the toolbox to make you blockly program.
  9. @Gunners TekZone, @Toastie, I do check for replies and even have three retries... But after 3 retries, if I do not get any reply, well, I just send an error to the chrome console (Press F12 to see the console) and keep going... I'll check if I display an error in the status window, might not do it at the moment. But the thing is, I do not stop the program for this. For the Rcx Input Value block, it does not return a boolean as I showed in a previous post, if the Input is configured as a touch sensor, it will return 0 or 1. See the example in post:
  10. Hello @Gunners TekZone, glad to see you back testing! - No Save As. Indeed, for now I wanted to keep it VERY simple. But I take good note of that... - A saved program doesn't retain and reconnect device connections. But the Name is retained as long as you connect your device BEFORE loading your saved code. As fas as I know, there are no UNIQUE ids for connections and Chrome does not provide the "Com" port number used... I've heard they might give more flexibility in a future version of the web serial api... Anyway, for now, the procedure is, you need to connect to a device to use its Auto generated Device Name in Lego Blocks. For RCX, actually, the Brick does not have to be powered really but the IR tower has to be connected. I still have a note to improve eventually the Device Naming and connect etc. But again, for now, it is VERY simple, Device Name are generated when you connect them, and the Device you select in Lego Blocks are retained in the saved files... But if you load your file when no device connected, the blocs will select no device... It may become difficult if you have many devices, so you may have to take notes LegoB1 is COM19, Rcx1 is COM5, LegoB2 is COM12 etc... - I tried having two RCX's online at the same time: I do not think 2 RCX with the same IR Tower can work... in parallel... I cannot test as I have only one but I do not see the gain... However, 2 IR tower, opposite direction, might work independantly. The MSG instruction trick here is the best I think. Thank you very much for your observations and suggestions. Always VERY appreciated!
  11. @Toastie, I think I fixed the issue with the Function blocks. I tested the following with success: I added a FOOTER and the version should now be: Version: 2026-03-29-1947
  12. I'm glad to see this thread a bit busier ;-) @Toastie, It appears that the function blocks (part of blockly internals) are not working anymore. I must have broken something and will look into that. I don't know much about blockly functions yet but it is a great way to make more object oriented programming. So if your main repeat forever loop becomes more complex, you can use function to modularize your program. When you drag a function block into the code area, you can rename it and it creates automatically in the toolbox, category Functions, a calling block for your function. You can the use the called block into your Main Repeat loop. I don't know but I doubt there is the notion of local variable. I would believe that all variables are Global... I have to test more... Also, when you create input variable for the function, it creates X by default and you can see this x variable in the Variable Category of the toolbox. If you right click on the variable in the toolbox, you can rename it... I think you're right, ChangeOutputA(value or variable) would be the same as a Function with no return value. Let me fix the Function blocks so you can test it without issues.
  13. Both USB to Serial and BT to Serial adapters are seen the same for the online Lego Blockly and it uses the webserial API for both (BT serial adapter generates a "COM" port in the windows device manager for example). I had to do a little something in the code though to have it run on ANDROID phone/tablet as there is no "COM" ports. But it still use the webserial API...
  14. @Wapata, The "Power" must be a number from 0 to 7 (3 bits, 000 to 111 binary), the program "AND"'s your number with 7 (111) whatever number you give, so 8 = 1000 binary AND 0111 = 0000= pwr 0 the lowest power. I just added tooltip on the Lego B power Block to inform about the range 0-7 of the power. As @Toastie said, the LegoBx name is saved with your project (if you use the save button) but you have to "load" back your program after reconnecting your com port(s) that generates the Device Name automatically. I might try to change this in the future but for now, it was for me the simplest way to do things.
  15. Now the Updates should be automatic when you go on the web page. I removed the update button and banner... (But for now, there is not new important updates) Thanks for CC info!
  16. This is good programming. Your first version is intuitive too, but it could send same commands to serial every scan we might think. But I also did some output commands caching in the code (FOR LEGO INTERFACE B ONLY NOT RCX YET) that prevents sending same consecutive commands. There are a couple of exceptions like the REVERSE command which I cannot cache, so care must be taken when using it. I added the "Is Between" block in the logic category. To update, you must go online with chome on my page. Check in the logic category if you see the new [ ] <= [ ] <= [ ] block. If not, To force page refresh, press Ctrl-Shift-R. A banner should appear at the bottom with update button. I'm improving this update thing (the bottom banner that appear gets the blockly scroll bars over it... will be fixed soon). It does (Sensor_2) > 20 AND (Sensor_2 < 200) Note that the first number can be > than the last number. for example, 200 < Sensor_2 < 20 which is equivalent to Sensor_2 >200 OR Sensor_2 < 20.
  17. @Toastie, That makes me very happy to know that my Blockly project can help some people realize some dreams :-) I think you did a very good program. It's intuitive and visually tells what it does. You're right about forever loops, a small wait is required to leave the UI some time to manage things I guess... I'll look after that if it could be implicit... But for now, it's the way to do. And actually, your program gave me the idea to add a new comparison block: A block that outputs True if Input number between min and max number which would replace the bunch of <= and >= and the "AND" blocks you merged to achieve this result. You talk about the Control Center CC and got me curious about this... I don't know what it does... So I'm going to read about this equipment. So, do I understand you tested quite a few things with the Lego Blockly? : - You used the installable feature to install the standalone version to work offline? - You used a BT to Serial Converter? Thanks for the good words.
  18. Ok, here is a little something new: The Lego Interface B Online Blockly is now Installable on your PC (Windows, Linux, OSX etc). It should run offline, without internet (have not tested it without internet yet). It runs as a standalone app without address bar etc. But to install, you must at least connect to internet once to go to the my blockly page and click on this little icon in the address bar:
  19. As I tested previously and successfully, it is very possible with a bluetooth to serial adapter. See: and:
  20. I think I added in my online Blockly for Lego Interface B all the RCX blocks I had previously implemented in my Python RCX module equivalent. The Input Value block returns a number, not a boolean. I have not done a special "boolean" block for the touch sensor inputs. An input configured as a touch sensor will have the inp value block returning 0 or 1. Then in blocks that needs a true false boolean condition, you can always use a "comparison" block. See the following example: first block configures input 2 as touch sensor.
  21. About my problem with the Serial connection, the port with the CH340 adapter was already opened with my other web serial project... So the CH340 adapter is working just great and I manage to use web pbrick IDE to download the program to the RCX successfully. The prolific adapter for some reason gives me problems but anyway, I use it now for the Interface B. It would be neat to have a wait until block but the repeat until empty loop is working very well. That's too bad not much people use RCX anymore cause web Blockly RCX makes programming the yellow brick so much easier and intuitive and time saving! I think Interface B is even less popular now and I feel a bit lonely sometime :-) while developping drivers and IDE for it. Some website are "installable" when you see at the right of the address bar this icon: . This is not the case with @maehw websites and neither with my blockly project. I'll look after what it takes to make a website "installable"... Thanks @maehw for this great peace of work! I will look at your code as I want to have a bottom bar like yours :-)
  22. @maehw, I just discovered your work here. That is great! I tried both Blockly NQC and WebPBrick IDE. Is it me or there is no "UNTIL" in the blockly? in NQC, I had the following line: until(Message() == 11 ); . And I do not find a matching block for until. I had to use repeat until which is not the same...
  23. While adding RCX communication to the Online Blockly project, I have broken something yesterday for the connection of Lego B but it should be fixed now. So as I said, I am trying to add RCX comm (IR Tower) to the project. It is not to upload programs into the RCX. For this, you still need to use Not Quite C (BricxCC?) or other means. It is only to send basic commands to RCX. This allow interacting betweens multiple Lego B's and RCX's somehow using my Lego Blockly Online UI... For now I did only the Motor commands and Sound and Check if Alive Blocks. I will add more blocks in the next days... The web serial API is more sensitive/picky compared to the pyserial module for python. Python ignores parity errors etc but not the web serial so I had to adjust some timing and even then, I still get parity errors but I ignore them and allow 3 retries (resend the command if no replies detected after parity error.). Communication with the IR hub is only 2400 bauds and is half duplex. It is not the most reliable... But it is working. Example:
  24. MQTT is a very popular protocol in IoT world especially smart homes... I find it very relevant even for Lego controllers to allow them to communicate with external world... So while developping "Drivers" for old lego stuff, if it is possible, why not integrate MQTT client as well. I find myself this "add-on" to be great. I have a small PC that runs Home Assistant with MQTT and Node-Red Addons... I could use an IKEA Zigbee button to interact with my lego interface B and RCX through MQTT. So yes, it is relevant for some of us but not mandatory to operate the Lego Bricks. Just an amazing addon that is worth to talk about, at least a little ;-) . And since I'm doing some Javascript for the Online Blockly project, I'm thinking maybe eventually to bring the Lego Interface B JS driver into Node-Red ... But this is another project...
  25. Ok, good news. After many trials and gemini/copilot incomplete replies to my request, I managed to have a code to connect to android through an HC-05 BT/serial adapter (As my picture few post behinds). It should still work on the other plateforms like windows, osx, linux as usual with a serial adapter or HC-05 but I had to use some filters in the JS code to allow connections on android with a BT device. So for Android, for the moment, YOU MUST use a HC-05 or alike board. HC-05 uses standard Bluetooth. HM-10 board is a BLE board and should be compatible with Chrome but I think I would need to use another API in my code like WebBluetooth or something like that which I'm not ready for now... IMPORTANT: You must update your Chrome on Android with the latest version. 1- Make sure your Chrome is updated above version 137... 2- Pair your HC-05 Board using the key pass 1234. 3- You must use a TTL to RS232 as shown in my setup few posts before. Connect RX from HC-05 to RX on the TTL/RS232 adapter, and TX to TX... 4- Connect your RS-232 to TTL DB9 to the Interface B. You may need a sex changer. 5- Go in chrome on you android device / tablet and open my blockly page: https://blissca.github.io/lego-blockly/index.html 6- Click connect. It may ask you for permission which you should allow. Then it will show you the HC-05 that you select and connect. I tested on an Android phone, it's working but it would be way better on a tablet.
×
×
  • Create New...