Jump to content
THIS IS THE TEST SITE OF EUROBRICKS! ×
THIS IS THE TEST SITE OF EUROBRICKS!

Recommended Posts

Posted (edited)

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.

Lego RCX python module that manage serial communication using Serial IR Tower only (Not USB)

 

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)?

Blis

Edited by Bliss
Posted

Hi @Bliss,

Thanks again for all the work you put in so far. So cool you started with the Python RCX module as well. Your programs make my Lego projects so much easier or even possible at all!
The serial cable of my serial tower broke, so Ill have to get a new one before I can test, but they are easy to get by :)

Looking forward to more updates!

Cheers, Rob

Posted (edited)

@Bliss

Now we are talking! That is one hell of a project - this will be very exciting.

4 hours ago, Bliss said:

Is there other old forgotten interfaces (Serial)?

Whoa - hell NO! Nothing is forgotten! Too many old farts still believing in The Bricks :pir-laugh:. OK, I am joking. No, I am not. Well, sort of not.

Serial protocols: In essence, there are many. For sure, the SCOUT PBrick. This is one is very nice, has only 396 bytes RAM, so you better be smart when programming it, but has a large built-in library of features, e.g., it can control the Code Pilot and MicroScout PBricks via VLL (the LEGO Visible Light Link). Then there are the Cybermaster PBricks. These use essentially the same protocol as the RCX's and SCOUTs do, but via a serial RF tower. Cybermaster PBricks have two built-in motors, and one 9V output that is freely available, plus sensor inputs. Then there are the NXT and EV3 PBricks. They are accessible via serial over BT. The latest line is PoweredUp and Spike (BLE) of course, but I guess this is going too far ...

Some time ago, I made an ESP32 based communication hub for interaction with the old line of PBricks; you may find the protocols interesting (or not). I am trying to keep all that up-and running in my attic - because we do not forget :pir-huzzah2::

https://www.eurobricks.com/forum/index.php?/forums/topic/188584-mulpi-a-multiple-lego-remote-protocol-interface/

Just thinking about it - serial - that may also include #9750, TC control, the 4.5V world. The only thing required to go serial is a little Arduino interface:

https://www.eurobricks.com/forum/index.php?/forums/topic/192941-lego-interface-a-97509771-–-lego-technic-control-1-tc1-referenceideas-thread/&do=findComment&comment=3580886

That would also be very nice to include, as far as I am concerned! The serial protocol is dumb: Serial in -> parallel out, that is all. EDIT: It is also parallel in -> serial back, sorry!

This will be a very exciting development project you have initiated!!! I shall follow your updates closely.

Thank you very much for all your efforts!

All the best,
Thorsten

Edited by Toastie
Posted
2 hours ago, Bliss said:

'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...

Some functions not compatible with Win7?   For my own reference  do you have some additional context?   

 

2 hours ago, Bliss said:

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.

This will help keep things quickly locatable from other topics... Well until we fill it up over the next couple of years as well :excited:

Loving the work you have been doing, bringing a common python base to many vintage LEGO serial devices... And the results that are making it easier for the likes of myself, who can't always bounce around between different programs/languages without losing focus on the task.

Thanks again!

Posted
11 minutes ago, Gunners TekZone said:

Some functions not compatible with Win7?   For my own reference  do you have some additional context?   

Extract from Python discussion:

Quote

It looks like the most recent version of Python that will work on Windows 7 is Python 3.8.15

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:

Quote
Queue.shutdown(immediate=False)

Shut down the queue, making get() and put() raise ShutDown.
By default, get() on a shut down queue will only raise once the queue is empty. Set immediate to true to make get() raise immediately instead.
All blocked callers of put() and get() will be unblocked. If immediate is true, a task will be marked as done for each remaining item in the queue, which may unblock callers of join().

Added in version 3.13.

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 :-)

Posted
2 minutes ago, Bliss said:

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 :-)

Haha... And I thank you for that :P   Silly thing is, I just recently installed Python 3.8.6 after realising it couldn't take the latest... (and being aware of the constant changes they make, version to version) Doh!! 

The focus be foggy after my last batch of thoughtful tinkering :wacko:

I realise that now with Python, I can easily use newer versions of Windows... But the PC I want to use for my LEGO applications (QBOX 2060) can't effectively run Win10 (no display driver... I have tried and tried).  But it is nice and small, and most importantly, has four (4) serial ports... Great for an IR tower and my 2 (soon to be 3) Interface-Bs.  

Makes a nice little corner for me to putter in when the mindset is there... My Commodore setup, including Interface-A, is opposite the QBOX /RPI w/BuildHat station.

I apparently like to "nest" in my old and feeble mid/late 50's :tongue:  But this is where your development efforts are being "Put to the test" :wink:


2025-01-13-13.26.14.jpg?rlkey=d6a02v81yk

2025-01-13-13.35.48.jpg?rlkey=tcp51q845q

Posted (edited)

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.

Thonny-LegoRcxPy.gif

Edited by Bliss
Posted (edited)
49 minutes ago, Gunners TekZone said:

Makes a nice little corner for me to putter in when the mindset is there

Oh, I can so see that - beautiful!!! I happen to have more space, I believe, but that is absolutely not the point, it is - as you said - "when the mindset is there" :pir-love:

49 minutes ago, Gunners TekZone said:

My Commodore setup, including Interface-A, is opposite

Any chance to see that as well? Spotted it! For some silly reason, old Commodore's = C64's for me ... my bad!

(Yes, I am old, forgive me, but this is my world. Never had a C64 then but now. Need to fix it, but that seems to be doable ... I love old stuff, because I am old. New people love new stuff, and that is as it should be)

So nice!

All the best,
Thorsten

Edited by Toastie
Not only color blind, it seems
Posted
9 minutes ago, Toastie said:

Any chance to see that as well?

Was in the 2nd pic (Commodore-128 masquerading as a LEGO workbench :P )... But the table a bit crowded, as I was testing my 1st LEGO capacitor that I had recently received, mostly DOA.

Whie not (yet...???) applicable to this topic, I have some clips of my Interface-A running on LEGO Lines on my YouTube page: www.youtube.com/user/GunnersGarrison

But with your Serial to the Interface-A's "parallel like" interface adapter, it may not be long before we can add it to this topics' "Run ALL the LEGO on Python" goal!

Posted
19 minutes ago, Gunners TekZone said:

Was in the 2nd pic (Commodore-128 masquerading as a LEGO workbench :P )

Yeah - it's me ... edited my post the moment you posted :pir-huzzah2:

Just subscribed to your wonderful channel!

All the best,
Thorsten

Posted

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...)

 

Posted
34 minutes ago, dr_spock said:

Does LegoRCX.py work with Linux? 

I don't see why not... Python is Python (well, assuming not trying to use too old of either version or code ;P )

For me, the issue is more... How to Linux... Hah!   But I have a VM of Mint handy, let me test and see.

Posted (edited)
1 hour ago, dr_spock said:

Does LegoRCX.py work with Linux? 

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...

Edited by Bliss
Posted
2 hours ago, Gunners TekZone said:

For me, the issue is more... How to Linux... Hah!   But I have a VM of Mint handy, let me test and see.

Well that was quick (NOT!!!)  I am not even going to list all the issues... But the one relevant one might be, needing to set user permissions for the port ~$ sudo chmod o+rw /dev/ttyUSB0

And I did use rcx=RCX('/dev/ttyUSB0') in the script.

But, at last... I was able to confirm that YES, it will run in Linux using a Serial IR tower and USB-Serial adapter.

 

Nap time *huh*

 

Posted (edited)

@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.

Edited by Bliss
Posted (edited)
On 1/15/2025 at 5:24 AM, Bliss said:

Wow, I feel so amateur now haha...

Hi @Bliss,

glad you wrote "haha" - first: I am so much more amateur than you (I am a bloody chemist) when it comes to programming, believe me. Second, what you currently achieve with your Python approach is more than amazing!!! So - let us amateurs do what we do: Having fun!:pir-huzzah2:

On 1/15/2025 at 5:24 AM, Bliss said:

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.

Absolutely true. TLG called the enveloped byte along with the byte code "msg" a "message" (3 byte preamble to "heat up" the IR tower LEDs ;) then the byte + complement stream + checksum). You don't need the preamble, works without, but is safer. Such a fully wrapped message (which is net only one byte) which is sent 2400 Baud needs some time to transmit. Thus the delay, as there is no buffer in the RCX; a new message replaces the old one. At least as far as I know.

This is what I do on my train/technic layout: Each RCX/SCOUT (there are may) has an "ID", which is just a number. My control program (VB6 ^^) generates a two byte (sometimes three byte) message: ID + payload. Once an RCX recognizes it is addressed, it tries to do what the payload tells it to do: Turn on/off the headlights of a train, turn on/off PID speed control on a train (the train motor sucks torque-wise at low power; it always bothered me), or changing PID parameters while it is running on the track to optimize speed control when the load changes significantly (carriages added = new optimum PID parameters). If you are interested, I'll simply copy my train control program to my Brickset folders.

On 1/15/2025 at 5:24 AM, Bliss said:

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 ... 

Yeah, see above. Other RCX'/SCOUTs do control bridges (https://www.eurobricks.com/forum/index.php?/forums/topic/156326-lego-train-bridges/), switch drives (https://www.eurobricks.com/forum/index.php?/forums/topic/154740-moc-lego-switch-drive-controller/) and so on and so forth ... MulPI can also emit RF codes for simple 433 MHz home automation devices (e.g., from Intertechno); I just gave the ESP32 controlling MulPI several internal ID's so it can switch on/off lights etc. in the room. I am using very simple IR <-> RF transceivers, which I made 14 years decades ago - well the breadboard version is 2 decades old ;) - they work fine with RCX & Co as well as with PF devices. Here is an old overview regarding my train layout, where an NXT did all the work, not MulPI, as it did not exist back then (https://www.eurobricks.com/forum/index.php?/forums/topic/153260-train-layout-control-nxt-operated-pf-and-rc-trains/) and here is the IR <-> RF transceiver stuff: (https://www.eurobricks.com/forum/index.php?/forums/topic/62616-extending-ir-range-with-rf/). Today, the VB6 program looks even crazier, as I have incorporated BLE as well - the /n software people gave me their BLE stack for VB6 for free - I believe it was in ... 2017?

Here is a post that has (hopefully some links still work) that summarizes how to get old LEGO stuff going on modern computers, but I am sure you have even better links (https://www.eurobricks.com/forum/index.php?/forums/topic/157550-lego-history-programming-20-years-old-mindstorms-rcx%E2%80%99-on-modern-computers/)

I am happy to share any NQC or RobotC programs, if you want them. Here is one example of my RCX train control program (RobotC: https://brickshelf.com/cgi-bin/gallery.cgi?f=340234). Just let me know!

This will be very exciting, when you elevate RCX programming to the next level using Python!!!

Have a nice day and all the best,
Thorsten 

 

 

Edited by Toastie
read twice before pushing submit/send/save ... ^^

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...