Jump to content

Bliss

Eurobricks Citizen
  • Posts

    172
  • Joined

  • Last visited

Everything posted by Bliss

  1. @Toastie, I just read some of your thread about mulpi. Wow, I feel so amateur now haha... Great achievement. I found in your thread quite a few valuable information. I also installed this SDK 2.5 which is great as it contains information about many bricks and the RCX version 2 firmware! That made me add some features in the RCX Python module. (See link in first post, I also updated the README). - I already had the rcx.prg(progno) command but now it has a default value of 1 so you can call rcx.prg() with no argument for prog 1. - I added rcx.start(taskno). default is 0, so rcx.start() start task 0 which if I undersand well, has the same effect as pressing the run button on the brick. taskno can be from 0 to 9. - I added rcx.stop(taskno). default is -1. taskno = 0 to 9 to stop a specific task but any other numbers will stop all task which I think, has the same effect as pressing again on the run button while a program is running. - I added the rcx.msg(msgno). No default value, msgno is mandatory and can be from 0 to 255. Avoid 0 as mentionned in NQC documentation. It sets the IR message buffer with the given value. The set message command is really interesting as it allows, I'm guessing, to have a message sent to RCX program. So more than one RCX could read this message coming from the same IR Tower. But each RCX could have a different program running that waits for different msg numbers to take different actions... I'm gessing again that it might be interesting for train layout to activate remote train switch from a central point ... I also added a small delay between each command, 100 ms (took this number from Toasties thread). Because if you send too much commands in a row, eventually I had to close my serial connection and reopen it... For exemple: for i in range(10): rcx.snd(2) This code before the delay addition, would play sound only once and no more commands were accepted thereafter. With the addition of the 100ms delay between commands, this same for loop plays the snd 10 times. After this 100ms, I now read the reply from the RCX but I do nothing with it yet. For now, this is only to avoid accumulating too much in the read buffer and also it allows me to understand the decoding of the replies.
  2. it should but it would be great to have someone to confirm. I guess the "COM1" port in the examples would rather be something like "/dev/ttyUSB0"... Make sure you have latest version of python...
  3. I updated the legob.py file and corresponding readme.txt. I changed the behavior of off() to brake stop rather than coast to stop. to be consistant with legorcx.py... brk() has been replaced by float() that will coast to stop. (Like rcx...)
  4. I'm testing here the bricksafe file hosting to show images as proposed by @Toastieand @Gunners TekZone. This one shows a Thonny Python session. Left pane show the working directory with the LegoRcx.py file in this folder. LegoRcx.py module is also opened in the editor on the upper right. It also shows the Shell at the bottom and how to test the Lego Rcx module.
  5. Extract from Python discussion: While programming python module for RCX, I wanted to use a function that I saw on Pyton doc for the Queue, it is Queue.shudown(), but it did not work at all. I was using the Thonny integrated Python which is version 3.10.11. Then if you read carefully the Python Doc, here the extract: See the last statement ;-) Then I thought about you and refrain from using this shutdown method lol. So maybe I should reformulate what I said. "Some python function I use MAY not be compatible with Win 7" but I count on you to let me know :-) Python seems to be the trending in script language tofay. But they make some changes from one version to another that are not backward compatible sometime. Like this 10 year old DACTA lego interface B module from Shamlian. Probably done from Python 2.x... or even 1.x... Not working anymore... Anyway, we'll see in 10 years from now :-)
  6. First, here are the links to my dropbox project files that I will keep updated: Lego Demo B to Test multiple Lego Interface B (70909) Lego Script B: an EXE executable C# program that integrates IronPython (No need to install Python separately). Lego Class B: A C# DLL that can be linked to VBA programs (Excel for ex.) or even Python Lego Interface B Python module to be used with Python only. NEW Github for Lego Interface B Python Module: https://github.com/BlissCA/LegoBpy Lego RCX python module that manage serial communication using Serial IR Tower only (Not USB) NEW Github for Lego RCX Python Module: https://github.com/BlissCA/LegoRcxPy I'm now putting my efforts more towards the use of Python. I'm using the latest 3.13. Some python functions are not compatible with windows 7 but until now, I've had some report that my python scripts still works on windows 7... I do not garantee this is going to be always the case but I'll do my best to keep it working on win7... My first goal was to make a simple programming environment that works on modern PC computer and OS and allow the interaction between multiple Lego Interface B, expanding the IO capability... I posted first on the following thread: https://www.eurobricks.com/forum/index.php?/forums/topic/67665-dacta-control-lab-software/ But since I'm now expanding the project to the Lego RCX (After other members ideas), that lead to the creation of this dedicated thread. There are README files in the above links to help you test and integrate these Python modules in your project. Note about the Lego RCX Python Module: This is for sending commands like Start/stop motors through serial link using IR tower. This is not to upload programs in to the RCX. You still need programs like Brickx CC and NQC to make programs that will execute into the RCX. To give you an idea: A python main program user project may import the LegoB pyhton module, and import the LegoRcx python module as well at the same time along with other modules like MQTT etc... The Main python script could have programming that allow interaction between multiple Lego Interface B, multiple RCX, MQTT (External World, Smart Home, etc)... Feel free to comment, report bugs, suggest improvements, share your project on that matter, add other python lego modules like maybe the Interface A. Is there other old forgotten interfaces (Serial)? Bliss NEW NEW NEW 2026: Lego Interface B ONLINE Blockly type Programming: 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) It also works with HC-05 Bluetooth-Serial TTL module and a TTL-RS232 Adapter with a PC or Androîd (NOT IOS) Link to my Lego-Blockly page Example Projects to download Go to the following post for more informations
  7. @Toastie Thanks for feedback on that matter. Is it a driver? maybe more a communication gateway? Right now I just want make a dumb interface with the RCX like the Lego Interface B is. So sending through communication commands to activates outputs basically. For the moment, I do not read any acknowledgement from the RCX but I will probably add this feature, not for the acknowledgement for the commands Python sends when we want to activate outputs but to ask for the status of RCX inputs like we do for Interface B. The basic goal to achieve is allowing interactions between multiple old serial lego interfaces and also interaction with the external world using ethernet (MQTT as an exemple). Example: - A master Python program running on a PC that has many serial ports and have ethernet connectivity and integrates MQTT client "driver" as well as Lego Interface B serial driver and RCX "serial driver" and maybe more (web server etc). - An IKEA zigbee button might send a signal to your smart home hub like Home Assistant that has MQTT broker addon installed. - an automation in the smart home hub could then send a special MQTT topics that your python main program has subscribed to. - Upon receiving the MQTT topic, the Main program could then start some sequence of events that is: - Send commands to RCX1 to activate a sound, then change the position of a lego train switch by sending a command to activate output A of RCX1, and then start a lego Train by sending a command to Lego Interface B #1 to activate its output # H. - Python main program train sequence may wait for a light sensor to be received from Lego Interface B # 2 and than ask the RCX 1 to activate output #2 (antoher train switch or a light ). The Python main program could also ask an RCX to activate an RCX Program that would have been previously loaded into the RCX memory with Brickx / nqc. So for now it is really to make python act like a mindstorm remote control for RCX at some point. But eventually with more features... I have no intent to make another RCX language. This 332 firmware is interesting as it allows to send/receive data with the RCX and also to run programs executing on the RCX (programs writen with nqc from brickx or writen with original lego software)... Many questions remains for me that I will answer through more testing/reading/from other member's help: If there is a program running on the RCX, does it still listen to Remote serial commands (can we still sens motor commands)? Is it possible to stop a program remotely? (haven't seen yet an opcode to stop a running program, but I saw stop task...) Does RobotC firmwares allow the same serial communication protocol than 332 firmware? Maybe the best, would be to create a thread titled: Using python as a hub to communicate with old lego interfaces (RCX, Lego Interface B, and maybe more?) Then, we could talk about Lego Interface B, RCX etc and even maybe other "Driver" in the future provided by others like Interface A etc... (That I do not own unfortunately) EDIT: I just created:
  8. I loaded the firmware firm0332.lgo. I think remote commands do not work without a firmware.
  9. @Gunners TekZone, @Ax4478, and for who might be interested. I got an RCX brick few days ago with its Serial IR Tower and I managed to find in this forum and google some information. The following link seems to be the most complete to explain the serial protocol and list all opcodes etc... https://www.mralligator.com/rcx/ So I started to make a Python driver and right now I have a draft version that takes care of only output commands (Not all yet but some interesting ones). I will refresh the following link as I add features and fix errors that you may find :-) link for LegoRcx.py python driver for RCX brick serial communication. Note that this is not for the USB version. Only the serial RS-232 IR Tower. You can use the shell in Thonny IDE or any other shell like the one that comes with python. I personally use Thonny. Copy the LegoRcx.py in your working folder (that you navigate to in the Files left pane of Thonny for ex). Then in the Shell: >>> from LegoRcx import RCX >>> rcx=RCX("COM1") # use the com port for you IR Tower >>> rcx.snd(1) # should play BEEP BEEP >>> rcx.mot(rcx.A).on() # run motor on output A >>> rcx.mot(rcx.A + rcx.B + rcx.C).on() # run motors A, B, C >>> rcx.mot(rxc.B + rcx.C).off() # stop motors B and C (Brake) >>> rcx.mot(rcx.A).float() # coast to stop motor A >>> rcx.mot(rcx.A).on() >>> rcx.mot(rcx.A).r() # Set reverse direction. >>> rcx.mot(rcx.A).f() # Set forward direction. >>> rcx.mot(rcx.A).flip() # flip direction. >>> rcx.mot(rcx.A).pow(0) # Set speed to minimum pow(7) is the Maximum >>> rcx.prg(5) # Set program #5 (can use 1 to 5) >>> rcx.close() # Shutdown serial communication and any threads gracefully. About the prg method, since I have no program in the brick yet, I can see the program number changing but I do not know of it will actually run the program too. I have not seen a Run program command in the list of opcodes. However I saw commands to start tasks... I do not yet know the structure of the programming of the RCX... I guess I should post further development for the RCX Python driver in another forum thread? Maybe this one?
  10. Thank you both. I removed images from some of my previous posts... Next time I'm going to use bricksafe or other mean.
  11. Well, I often just copy / paste from my screen capture software... or I'll save as a GIF on my pc... Usually it will tell me that the image too big... But now it just tells it encountered a problem ...
  12. I cannot include images anymore in my posts since few days... But in the command codes from this link: https://www.blockcad.net/dacta/, the first 3p 00110ppp will coast to stop a motor (free wheel) 3P 00111ppp will brake stop a motor
  13. this driver does not require the pythonnet (no need to import clr) nor the legoClassB dll... But it is not guaranteed to work on win 7... I like python, but from one version to another, they may change the name of properties and method and makes your program not working...
  14. I had a look to Shamlian 10 years old Python program. It was not working at all. I guess Python versions changed a lot over the years. So I modified it to make it work under Python 3.13. Took few hours of debugging, googling etc... Original Link that has been already posted few time here. Then I decided to rewirte some part of the driver and made quite a few changes and I renamed the dacta.py file to legob file. LINK TO NEW LEGO B Python Driver All you have to do is to put the legob.py file in the same working folder as your project. For example, in Thonny python editor, open your working folder on the left pane and this file should copied there. Then you can test with Thonny Shell by entering the following at the >>> prompt: >>> from legob import LegoB >>> Lego1 = LegoB('COM1') You should get "Got confirmation string." if everything works >>> Lego1.out(1).on() this should Activate output A if you want to use letter for output port then enter the following: >>> A, B, C, D, E, F, G, H = 1, 2, 3, 4, 5, 6, 7, 8 Then: >>> Lego1.out(A).off() should turn off output A To get input states or values etc: >>> Lego1.inp(1).on # will print True or False. >>> Lego1.inp(8).val >>> Lego1.inp(6).rot to reset the rotation count to 0 or other value: >>> Lego1.inp(6).rot=0 There are also temperature: >>> Lego1.inp(3).tempc >>> Lego1.inp(3).tempf >>> Lego1.inp(0).on is the state of the Red Stop Button on the lego box. You can set alias to inp ou out ports: >>> MotorA = Lego1.out(A) Then to start the motor right at power 5: >>> MotorA.pow(5) >>> MotorA.onr All output commands: on(), onl() (on left), onr() (on right), off() (coast to stop), brk() (Brake stop), rev() (reverse), pow(#) set power where #=0 to 7, onfor(t) output will turn on for t tenth of seconds, l() (Set direction left), r() (Set direction right) To stop lego box: Lego1.close() I did not test thoroughly. Let me know if you find any issues.
  15. I did the same observation as I mentionned in a previous post that I suspect you have not seen as we posted almost at the same time.
  16. Congrats! One small step for man, one giant leap for old lego fans ;-) We can now think of using Smart Home Hubs and devices like Home Assistant, Hubitat, SmartThings, name it, that supports MQTT, to start/stop an "Old 9V Train" automatic sequence that uses Lego Interface B. We could add a button on Home Assistant (HA) UI (I'm using Home Assistant) or use HA Automation, or Node-Red Plugin that will use MQTT to interact with the Lego Box... That certainly gives some ideas...
  17. @Gunners TekZone If we forget about win7 for a moment and come back to win10, I think the unknown location problem is related to: https://github.com/pythonnet/pythonnet/discussions/2420 If you put the whole directory of the LegoClassB.zip inside your python working directory, then it appears the PATH starting with the LegoClassB folder is already seen by Python because Python automatically uses the working path in its seach path for modules... The folder named LegoClassB conflicts with the DLL file Name. So in "from LegoClassB import LegoInterfaceB" line, Python prioritize the Folder as a package at first... So, remove the LegoClassB folder from your working directory and leave only the LegoClassb.dll in your working directory along with your .py files and just do like my second previous post. OR, rename the LegoClasB folder to make it different than the Dll file name. >>> import clr >>> clr.AddReference(r"C:\Users\sengx\source\repos\Python\LegoClassB\bin\Release\LegoClassB") <System.Reflection.RuntimeAssembly object at 0x000001B853287740> >>> from LegoClassB import LegoInterfaceB Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: cannot import name 'LegoInterfaceB' from 'LegoClassB' (unknown location) >>>
  18. Just answering my question about python compatibility with windows 7.
  19. @Gunners TekZone I copied the LegoClassB.dll (ONLY This DLL) in a Python work Folder along with the .py file (Same ones than in the dropbox link). In Thonny, on the Files pane on the Left, I selected this Pyton Folder and see listed the Dll and the .py files. This becomes the working directory. In the LegoTrain_01.py, the path was simply the name of the dll: import clr clr.AddReference(r"LegoClassB") from LegoClassB import LegoInterfaceB Lego1=LegoInterfaceB() Then I hit the "Play" button in Thonny and this is working here very well too.
  20. @Gunners TekZone But at some point you said it was working no? Is it working in the Python CLI now or not? Is it only in Thonny that you have problems? Is it working in Windows 10 but not in windows 7 ? (I think I read somewhere, pythonnet would not work well on win 7)
  21. Here is a link with some Python Programs I adapted to Thonny: Sample Lego Interface B Python Files
  22. When I paste the content inside the code box into NotePad++, it shows a stange character at the end of: from LegoClassB import LegoInterfaceB It happens often in the forum Code Window... I have to double check some time... (These character are not visible in the final post but we can see them in notepad++ and sometime, in the code edition window.
  23. I'm guessing it is possible to install the pythonnet library (Which allow the use of import clr) in the thonny environment. First go back in the menu Run, Configure Interpreter and select the Thonny local python.exe as the python executable. In the menu tools, click on open system shell. I think it is possible from there... From the shell, I entered: pip install pythonnet and it did install in thonny libraries... Then from the Thonny local python 3.10, I was able to use import clr etc...
  24. @Gunners TekZone So I installed Python 3.13 and uninstalled older versions and updated manually the PATH system variable in windows (Control Panel, in the serch bar, entre "Path", click modify environment variables, in the next window click at the bottom Env. Variables...) After that I reinstalled with a Dos Window, the python net using pip install pythonnet. I checked with the Python 3.13 CLI that I was able to import clr, AddReference to my LegoClassB and use LegoInterfaceB... Everything was OK... Then in Thonny now - Thonny uses its own Python exe... So, You have to go in menu run, Configure Interpreter, Interpreter Tab and specify the path and exe of the python 3.13 which is the one that has python net installed... - Now, in the Thonny Shell, it will show Python 3.13.1. - If you enter import clr at the >>> prompt it should work
×
×
  • Create New...