Jump to content

Bliss

Eurobricks Citizen
  • Posts

    171
  • Joined

  • Last visited

Everything posted by Bliss

  1. If you want to test the ESP32 micropyton legob without soldering, there are easy solutions: You will still need to get ESP32 board and a RS232 / TTL converter... and bread board or scew terminal breakout board. Those ESP32 board are easily available with pin headers already soldered...
  2. Here it is: Powered from the Power port on the front of the Interface B. So I added a Rectifier bridge to be independant of lego connector orientation. The ESP32-S3-Zero is tricky to setup micropython. Had to try with different firmwares. Had to choose the 4Mb version on the ESP32-S3 page. Also, once micropython installed and working, when enabling the wifi, the ESP32-S3 was crashing and reseting itself. After lots of readings I finally tried the trick of adding a 1000uF cap between 3.3v and GND... Those extra mini versions of ESP32 are missing some noise filtering and shielding I think... Now it works great with the demob_mqtt_v2.py file... I also put the folder "lib" on the dropbox that you can copy on your esp32 micropython device. With this, you will not need to install the improved mqtt async I talked before... It will be already there.
  3. I updated demob_mqtt_v2.py the file in the dropbox. The mqtt is now more responsive and I added few more published inputs. Will add more eventually. I tested the phone app called IoT MQTT Panel (I used the free app) with which you can easily make your own dashboard based on mqtt topic: (Also available on android device) *** WITH AN IPHONE 14, IT DOES NOT CONNECT TO MY LOCAL MQTT BROKER BUT WORKS WITH test.moquitto.orq broker... IT WORKS LOCALY WITH AN OLD IPHONE SE *** It is very responsive and the switch to start the motor on output A is quite fast. We could also configure the demo program to start a lego interface b sequence... UPDATE 2025-01-29: Updated the demob_mqtt_v2.py again and updated the image above as well
  4. Indeed, a 78L05 could probably do the job to bring the lego 9vdc to 5vdc which is safe for the ESP32 and Max 3232 board. I did not have any... But I have a bunch of buck converter boards. You also could do a more compact design with more soldering for sure. Double face tape the ESP32 on the back of the Max board and have the 5v voltage regulator also there... I might give it a try with a ESP32-S3-Zero super mini board...
  5. For some people having a big project involving interaction between many Lego Interface B Boxes, another protocol that might be interesting to implement that seems to be built-in the MicroPython for ESP, is the ESP-NOW protocol. This would allow direct communication between Lego Interface B boxes even without the need of wifi access point. Extract from MicroPython web site: ESP-NOW is a connection-less wireless communication protocol supporting: Direct communication between up to 20 registered peers: Without the need for a wireless access point (AP), Encrypted and unencrypted communication (up to 6 encrypted peers), Message sizes up to 250 bytes, Can operate alongside Wifi operation (network.WLAN) on ESP32 and ESP8266 devices. It is especially useful for small IoT networks, latency sensitive or power sensitive applications (such as battery operated devices) and for long-range communication between devices (hundreds of metres).
  6. Ok for the MQTT demo, I added the file demob_mqtt_v2.py which is using another mqtt library (https://github.com/peterhinch/micropython-mqtt)... It appears to be more stable. To use it, you will have to install the library. To do so, in Thonny, while you are connected to your ESP32 with the USB port and the content of the MocroPython Device is shown on the left pane, in the Shell (>>>) type one line at a time: (You obviously need internet connectivity) import mip mip.install("github:peterhinch/micropython-mqtt") This will install the necessary files in a "lib" folder on your ESP32. Then, you should be able to execute the demob_mqtt_v2.py with no problems. EDIT: I put the "lib" folder on the dropbox. The lib folder contains this mqtt library so you do not need to install. Just copy the folder on your ESP32 using Thonny.
  7. Let's add some fun! I updated the Dropbox for this project. I added the file: demob_mqtt.py Since a simple MQTT client is built-in Micropython, I decided to make a small demo. In this demo, you can activate motor on output A by publishing a 1 payload to the topic lego/outa. Stop the motor by publishing a 0 in the payload of the same topic. Each time you press a touch sensor connected to input 1, it publishes 1 or 0 in the payload of the topic lego/inp1 for anyone subscribing to this topic. I use my Home Assistant to test. I also use the excellent MQTT Explorer (https://mqtt-explorer.com/). MQTTX is also very simple to make test. (https://mqttx.app/) I also modified the secret.py where you can put your MQTT user and password if you have any. This MQTT demo is working but not for very long as it eventually throws an OS Error... This might be because I'm using asyncio for the lego interface B and the mqtt module is not asynch... I wanted to make a separate task for the Lego Interface B input frame continuous reading to make sure no data is loss... There might be some solutions to this problem with MQTT... There are other mqtt libraries that could be more compatible like: https://github.com/peterhinch/micropython-mqtt I'll investigate.
  8. Buck step down converter board I used to convert 9v to 5v: https://www.aliexpress.com/item/1005005105181120.html
  9. For the serial board, (RS232), I took mine on amazon for fast delivery. https://www.amazon.ca/dp/B09L1BB6F8 But they are cheaper on aliexpress obviously.
  10. Hey @Gunners TekZone, My intent was to not modifiy the Interface B at all. But since you already have a modified one, you could indeed use the internal 5V to power the ESP. The ESP could even be put inside the box but I would leave the USB port available and accessible from the outside. However, I think you cannot use both Vcc external supply on an ESP and a 5V coming from USB... So pluggin a USB cable to a PC while ESP is powered from the B Box might not work... Unless you modify the ESP... I used directly the 9V from lego to power my ESP32-S2 and it seems to work fine with no heating but I might rather sugest to use a buck step down converter to bring the voltage to 5V...
  11. I just created a new topic about Lego Interface B and ESP32. I thought it would be better in a new thread.
  12. First, here are links to dropbox folders for this project that I will update once in a while. MicroPython files for the V1 version which uses uasyncio to achieve Reading of inputs in a separate task. The MQTT (using mqtt_as library) example appears to be reliable. Most reliable. MicroPython files for the V2 version which is not using uasyncio so it is simpler. It is using Timer's interrupt only. Seems reliable with mqtt_as too. Not stable with built-in umqtt.simple. UIFlow2 Demo (LegoInterfaceB.m5f2) and Custom block (Lego9751.m5b2). The demo should already include the custom block for the LegoB blocky blocks.  Tested only on M5Stack Core2. I talked about this project not long ago in the thread: https://www.eurobricks.com/forum/forums/topic/67665-dacta-control-lab-software/page/12/#comment-3739089 The project goal is to control the Lego Interface B using a micropython program running on an ESP32 microcontroller (MCU). I made a class module to interface with the Control Lab serial Box to read the inputs and write to the outputs. It's basically the same commands as in the Pyton Module I created for a PC. see : https://www.eurobricks.com/forum/forums/topic/200778-project-programs-to-allow-interactions-between-old-lego-control-interfaces-rcx-lego-interface-b-others/ So once setup, you only need to power the Interface B. (I powered the ESP32 MCU with the 9V DC port on the front on the Interface B ) An image is worth thousand words: I used a small rectifier Bridge to be independant of the orientation of the lego connector which would reverse polarity. You also need a TTL to RS232 converter because an ESP32 has uarts (Serial communication intrface) but the voltage level is 0-3.3v. RS232 is like -12 to +12. So this little converter can run at 3.3v and generate rs232 signals! (Using the chip MAX3232 not the MAX232). https://www.amazon.ca/dp/B09L1BB6F8 You might also need gender changers too. https://www.amazon.ca/DKARDU-Changer-Transfer-Adapter-Connector/dp/B09BQ4HF53 I tested on ESP32 Mini (WROOM) and ESP32-S2 (Cheap). I did not managed have a working ESP32-S3-Zero in Thonny. I did not try ESP32-C3 and C6 but I suspect it might work well. I recommand using Thonny : https://thonny.org/ Because you can install micripython on you ESP32 directly from there. And you can make and test your micropythons programs from there. Setup procedure with Windows: 1- First thing first, you plug your ESP32 to you computer with its usb port. 2- Open Device Manager to identify the COM port. (But you can also find it in Thonny if you don't have too much device connected) 3- In Thonny, menu Run -> Configure Interpreter, at the bottom right of this windows, there is a link for Install or Update MicroPython (esptool). Click on this link. (Not UF2). 4- Choose your ESP32 com port in Target Port., In MicroPython family, choose yout board (ESP32 for ex.), variant (Expressif ESP32 / WROOM), in version, choose the latest. Click install. 5- Once the ESP32 is flashed successfully with MicroPython, reboot the board. 6- In Thonny, menu Run -> Configure Interpreter, in Which kind of interpreter... choose MicroPython (ESP32) 7- In Thonny, menu Run -> Configure Interpreter, in port or WebREPL, choose the com port for your ESP32. Click OK. Eventually, once the whole setup is completed, we will be able to use the WebREPL which is the access to the Python Shell in Thonny through wifi, no more USB cable to the ESP... 8- You should now have the MicroPython device folder that appears on the left side and Thonny should create a boot.py file automatically 9- Always in the left pane of Thonny, you should also open the folder where you have put all the file downloaded from my dropbox (Link at the beginning of this post). 10- There are 3 files you have to modifiy from the files you downloaded from dropbox. secret.py : you have to specify your wifi SSID and Passord. webrepl_cfg.py : this is a password for the WebREPL. in the demob.py and demob_02.py, (and also the demob_mqtt_v2_) in the line: lego.start(17,16), 17 is the Tx Pin, 16 is the Rx Pin. This is what I used for the serial comm but you can use other pins. (If using ESP32-C3, 17, 16 are not allowed) 11. Once you modified the files, Select all files in you working folder (even the lib sub-folder for the mqtt demo, see notes at the bottom) on you computer in Thonny Left Pane, Right click on your selection and choose "upload to/" to copy the files on your device. (Overwrite boot.py) 12. if everything goes well, you might need to press red STOP in Thonny so it reboot the ESP. It should show in the shell window that it is connecting to your wifi and give you the IP address. 13. you can test the WebREPL now. Go in menu Run -> Configure Interpreter, Port or WebREPL: choose WebREPL and make sure it has the right IP address and WebREPL Password (See step 10) The hardware: 1. I soldered some Dupont pins to my ESP to use Dupont wires... But you can do whatever you want. There are ESP32 NodeMcu board with Pins already soldered and some socket board with screw terminals if you prefer. 2. From the ESP32 to the RS232 converter: ESP 3V3 goes to Converter Vcc, ESP Pin 17 (Tx) goes to Converter Tx pin, ESP pin 16 (Rx) goes to Converter Rx pin, ESP G (GND) pin goes to Converter GND pin. 3. You have to power the ESP32. You have many choice. From the USB port on the ESP32 Board to a Charger or PC USB port. OR you can use the 9V DC port on the front of the Interface B (Using an olf Lego cable you will cut at one end) and connect the +9v on the ESP32 Vcc Pin (NOT 3V3), and the - (0v) to the ESP32 G (GND) Pin. Usually there are many GND pins available on the ESP32. I personnaly used as I said earlier, a smal Rectifier bridge to protect againg reverse polarity of the 9V lego plug. There is a 3.3v regulator on these ESP32 Board that can take the 9V as an input voltage. (However, see update below) ***WARNING*** Do not plug USB cable to ESP32 and 9V on the external Vcc pin at the same time. UPDATE I finally used a buck step down converter to convert the 9V to 5V. Since I will not change the orientation of the Lego connector, I also removed the Rectifier (Well, I broke it and I did not have others)... 9v was working just fine on this ESP32-S2 board but might not be the case for all board... The external Vcc on the ESP is also used I believe for the FTDI chip and not sure what 9v can do to it... Notes on using the demob_mqtt_v2.py: I'm using asynchio for the legob module. The built-in MQTT module is not async friendly. I found an async mqtt library and installed it. It is in the lib folder that I copied in the dropbox link. using Thonny, copy the whole lib folder on your ESP32 device. Then, you should be able to run the demob_mqtt_v2.py. UPDATE: how ever, in the legobplc version, since i'm not using asyncio in this version, I might be able to implement the built-in mqtt... I'll keep you informed... Please do not hesitate to ask questions. Bliss.
  13. I updated the legorcx.py. (version 2025.01.21.0) Added "alive" command (rcx.alive()) which returns True if RCX detected, False otherwise. But I also rewrote the Read / Write engine. It was originally taken from lego interface B python module that is using multithreading. This is not needed for RCX as it is a Send command, read reply sequence. Commands/Replies must execute one after the other as I can see. So I had to syncronize between threads and I concluded that multithreading was not relevant for remote comm. with this brick. The code is simplified so might be more efficient... Let me know how this version works for you... Thank you! Bliss
  14. I updated again cause I added the following commands: rcx.pwroff() # Powers off the brick rcx.sensor(rcx.inp3).clear() # clear the counter associated with the sensor. A rotation sensor for exemple.
  15. @Gunners TekZone I updated again to version 2025.01.21. You may try it again in win 7 who knows...
  16. @Gunners TekZone, Could you please try the new version I just put in the dropbox? I modified the getval method with a little more proofing and it's not dependant of a fixed delay for the reply reading. Also added some timeout if it does not find the correct reply and will return "None" if it does not find a match. (Meaning that you could check the value return == None to make some actions) I modified the version numbering. I adjusted it to 2025.01.20 and fits with the acutal day for now but the last number is really an incrementing number. So if I put another updated file today, this number will be 21... Let me know how it goes. Thank you! I guess that means that I used some python functions that are not anymore compatible with the python version that works on Win7... I'll try to find which functions... I'm using the Thonny's default python version 3.10.11 to achieve my tests...
  17. Hello, Thanks for testing. By the way, in your first bloc of code, while not v will always loop no matter what because you are not refreshing the variable v inside the loop. You could do v = 0 before the loop and v= rcx.getval... inside the loop. Your last statement though should work. You do not have to use time.sleep I think cause there is already a delay of 100 ms in the getval... while not rcx.getval(rcx.SrcSb,0): pass Should do it. As for your error msg, can you tell me what firmware you are using? is it an RCX 1.0? I tried the following with success on my side: from legorcx import RCX r=RCX("COM4") v=r.getval(r.SrcSv,1) # making a first dummy call as the first call seems to be 1 sometimes even if the sensor is at 0 state while not r.getval(r.SrcSv,r.inp2): pass print("Input 2 = ON") r.close() In the legorxc.py, could you add the following "print" before the line 173 (if f>=0:) ... print(r.hex(), s.hex(), f) if f>=0: ... And then execute your test, it should print some variable values that you could send to me to help debugging. I found out also that the first getval SrcSv or SrcSb for a touch sensor I do after opening the com port, is often 1 even if the touch is 0... I'll investigate. After sending the getval command, I wait 100ms before a read the reply. It might not be long enough. Maybe you could try to increase this delay at line 171 (time.sleep(0.1) => time.sleep(0.15)? Thank you again.
  18. Right, python RCX module is not to make and download program into the RCX... Remotely controling the Inputs/Outputs of RCX is not as efficient as with the Interface B as the latter has a faster communication and response time (around 25 ms) There is a 100 ms delay between rcx remote commands which is a bit slow for some kind of automation logics like stopping at a precise position... But it can still be interesting in some projects where speed is not an issue. 100ms is stil fast enough in many cases. Like trigger an RCX autonomous program when something hit a touch sensor on an interface B or when someone press a button on a Smart Home UI interface (MQTT)... RCX autonomous program could send MSG that Python program would read and make some actions accordingly and python would then send back an ack msg for the RCX for it to continue its job... So yes the RCX can stay autonomous but can also interact with the external world through a main python program used as a gateway somehow.
  19. Hello, I updated legob.py cause there was a bug in my last update I did not see before... ------------ I also updated legorcx.py. Please have also a look to the Readme file. I added rcx.sensor(inputno).type(typeno) to set the sensor type for a given input number (1 to 3). >>> rcx.sensor(rcx.inp1).type(rcx.TypeTouch) # configue input 1 as a touch sensor. Other choices: TypeRaw, TypeTemp, TypeLight, TypeRot. Choosing a sensor type also set a default "mode". TypeTemp will give temperature in celsius by default. You can then change the mode for degree F with the flowing command. >>> rcx.sensor(rcx.inp2).type)rcx.TypeTemp) # value of input 2 will be in degree C. >>> rcx.sensor(rcx.inp2).mode(rcx.ModeTempF) # value of input 2 will be in degree F. (More on the mode command and mode codes in the readme.) I added the getval command: rcx.getval(sourceno, argno) # Reads the value corresponding to the source. Argument depends on the source and defaut is 0. Sources are listed in the readme. It is a command implemented like the original opcode... The most usefull are probably get value on sensors and get value of msg buffer. Get value of msg buffer could be use to interact with multiple RCX bidirectionally. ex.: >>> rcx.getval(rcx.SrcSv, rcx.inp1) # will return the value of sensor 1. Depending ot the sensor type, value might be 0 or 1, raw 0..1023, percent (Light), Degree (Temp sensor), Angle step count (Rotation Sensor) >>> rcx.getval(rcx.SrcSb, rcx.inp2) # will return boolean value of sensor 2. no matter what type of sensor, returns 0 or 1... >>> rcx.getval(rcx.SrcMsg) # will return the actual message in the message buffer. sending command rcx.msg(123) first, for ex., rcx.getval(rcx.SrcMsg) will return 123 if no other rcx changed it in their running programs...
  20. I see so 4A total for 8 outputs, but the box must allow it. So is there a main protection at the power intput of the interface?
  21. Is there a fuse or other protection inside? I'm certain that with the original PSU, 8 outputs of interface B cannot power 8 X 9v lego train. But could it do it if we use bigger PSU? Of course, the thin board power trace must be able to take it... (I'm pretty sure it cannot take 10A though)... But maybe 2Amps?
  22. The original Lego PSU is 12VAC 7VA so we talk basically of 600mA at 12 VAC for the whole box... It not much... Can the Box use more amps if we connect a bigger PSU say 12VAC at 2A (24VA)? No matter USB-C or USB-A, from a computer port it is not like a PD Charger I think... I would use the USB from a computer to have both DATA and Power. But anyway, saying this, google tell me: Most computer USB ports supply 5V of electricity with a maximum current of 0.5A. So maybe not enough to use the interface at least like the spec... but still...
  23. What would be great is to have an easy solution to get rid of the Serial data cable and the PSU 12VAC 7VA. So removing the RS232 circuit and replace by a FTDI USB input USB-C or USB-A. And, use the 5V from the USB with a step up board to provide 9vdc at about 1A or less. I don't know what the lego outputs capacity... but 7VA is not much... I think a USB port on a computer should be able to supply the whole thing no?
  24. @Gunners TekZone, wow you're da man! Not much people still play with those Interface B but they are quite unique in some way as they offer the most quantity of inputs and outputs in one box... And if you can connect 3 or more on a same PC interface, it offers 24/32 Inputs and same for outputs all available in one programming environment to achieve big projects. I have an EV3 kit but never opened it yet... So I don't really know how it can expand itself and interact with other EV3 or other systems... But I see these RCX, EV3, NXT more like small standalone controller that have there own independant program and very limited IO capability... I understand that like the RCX, EV3's probably have a way to send messages between each other but it's not the same... Can one EV3 expands its IO capacity somehow? Did lego completely stopped production of mindstorm? I see today in their education line some spike and BricQ ? technic hub? EV3 is marked retired. I'm clearly behind on this :-) Are they working on a new version? That would be great if they could enter the IoT world making wireless sensors using battery button like zigbee and BLE stuff... (Touch, light, temperature, IR motion sensors). (Wires can be a pain in projects) Is there a thread about what would be the best new Lego Smart System for you ? I think I saw on TikTok, lego projects using motors and electronics I've never saw in a lego store... Third party bricks?
  25. @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.
×
×
  • Create New...