Jump to content

Bliss

Eurobricks Citizen
  • Posts

    107
  • Joined

  • Last visited

Everything posted by Bliss

  1. Just added the UIFlow2 Blocky version for M5Stack Devices in the drop box (Link also in post #1). I tested only on M5 Core2 ESP32 device. Not fully tested and it was very painful to make the custom block... Also, I find the blocky can be very ugly sometimes. UIFlow2 demo project LegoInterfaceB.m5f2 and also the Custom Block for Lego Interface B driver Lego9751.m5b2.
  2. I removed the "plc" version and replaced it with LegoB micropython V2 folder. I updated Post #1 too. Lego Interface B MicroPython ESP32 V2 Now I use MCU Timers for both the keep alive and Inputs Byte Frame readings... Using Timers creates constant periodic interrupts. (There are 4 of these Timers available on the ESP32) (Should have done this before...) So we can do slow sequences or non blocking fast logic (like an industrial PLC). The V2, i believe, is the simplest to use and I hope, the most stable version of the MicroPython ESP32 Lego Interface B driver. UPDATE 2025-02-05 9h47: I left the V2 running overnight with the MQTT demo and when I checked this morning it was stopped with an OS Error (Error from the umqtt.simple)... ESP32S3-zero mcu... (It seems stable with no mqtt demos) I will let the V1 running the whole day with its MQTT demo... UPDATE 2025-02-05 20h38: I left V1 MQTT demo running all day and no fail but maybe this version of mqtt has some auto reconnect feature. I'm trying LegoB V2 again since few hours with the umqtt.robust rather than umqtt.simple and it does not fail, but robust version of umqtt uses the .simple with some auto reconnects on fail... UPDATE 2025-02-06 01:06: The LegoB V2 eventually failed. Now it was a Checksum mismatch lf the LegoB continuous inputs reading... I suspect that when there is mqtt.robust auto reconnects, it takes ressources and bothers to reading on serial... idk... Anyway, I made (and uploaded in dropbox of the LegoB V2) another mqtt demo (demobv2_mqtt_2.py) that uses the same "mqtt_as" library that I used for the V1 LegoB. Now let's see if the LegoB V2 demobv2_mqtt_2.py will run overnight with no fail... UPDATE 2025-02-06 11h47: LegoB V2: demobv2_mqtt_2.py has run overnight no fail... This mqtt_as library is really solid...
  3. @Gunners TekZone I found out that the IoT MQTT app on the phone allows to backup the configuration. So, I just uploaded a backup (json) of my IoT MQTT Panel configuration. You will still need to configure your broker info. I don't know if the backup will work on an Android phone though...
  4. Indeed in every demo programs I offer, there are few settings to change (Described in the README). tx rx pin in the lego.start method and for the mqtt demo, the ip address of the broker. In addition, the secret.py should be updated as well for using the network features (MQTT and WebREPL)... If someone does not not need the network at all in his project, he does not need to replace the boot.py file and he only needs to copy the legob.py and his project file like demob.py or demob02.py that's all. No need to copy the boot.py, the lib folder, secret.py etc... The phone app IoT MQTT Panel is really just another alternative for those who wants to have a nice UI (User Interface or HMI Human Machine Interface) to control their Lego Interface B outputs from their phone a bit like the https://www.controllab.io/ which is using a webbrowser... I found myself this IoT MQTt Panel app very easy to setup and fun to play with. But since IoT MQTT panel is configurable, it is more flexible. You can also make Home Assistant Dashboard and custom "Cards" etc. Many solutions. Node-Red is great to test and make programs to interact between IoT devices... It a favorite for many in the IoT world. I update the demob_mqtt_v2.py to make all sensors avail to mqtt. I also put comments at the beginning to describe the topic to use. EDIT 2025-02-02 17h16: I made a correction in the demob_mqtt_v2 for the reset of rotation count and I also uploaded a demob_mqtt_plc_v1.py in the LegoB "PLC" version folder... The demob_mqtt_plc_v1 file uses the built-in umqtt.simple since there is no asyncio in this version... We'll see if it runs reliably... Have fun!
  5. ESP32 devkit are still the best. very stable. I like also the mini version of the ESP Wroom 32... The webrepl is really to use the Wifi to access the "Shell" so you can access remotely with no USB link to your ESP32... But it is slow. I think, for a particular project, someone will use the USB to test and when fully functionnal, the user will rename his final project file main.py so that it will be executed automatically when you apply power... Right now, I made provision to power my esp using the lego box power connector on the front but I do not use it because I prefer to use USB link to test. It is faster. But for a final project, I would disconnect the usb and use the 9vdc link to power the ESP... I'm glad you you managed to test the setup... I feel less lonely now ;-)
  6. Here is a preview of the UIFlow 2 blocky LegoB blocks and a working sample program. (nothing fancy motor port A follow state of Touch sensor input 1). (On a M5 Core 2 but same has worked on a M5Stick CPlus)
  7. I played a bit with the M5Stack ESP32 devices I have in hands. Notably the M5Stick CPlus. But I did not yet installed a bare micropython firmware in it. I was wondering if I could implement a LegoB Block in their UIFlow Blocky... I found out that their blocky thing is a bit limited and does not allow ASYNCH tasks really... ASYNCH allows to simulate some multitasking... (Micropython does not have real mutli-threading... not yet). So in blocky, you have a setup and a loop. But behind the scene they use micropython. They allow us to make our own Blocky custom blocks... I decided to try to make a LegoB blocky block that do not use asynchio... It works. I'm not finished implementing, but the basic works... If anyone is interested to my blocky LegoB code, let me know and I will finish implementing the methods and make it available in dropbox. That made me think it could be interesting to have a version of LegoB module that does not use ASYNCHIO as an alternative to the version using ASYNCHIO. So here it is: UPDATED 2025-02-04: LegoBv2 : LegoB Driver not using Asyncio. The main difference, is that your program is now responsible of the reading of the IO's. (see demob_plc01 et demob_plc02). It acts somewhat like an industrial PLC (Programmable Logic Controller which is my field of work). The code to achieve the same think as the multi tasking version seems bigger but for me it is more "logic" but I'm not objective cause I worked with PLC for over 30 yrs... So you always have to put your program in a FAST forever loop and ALWAYS include the lego.readinputs in the loop. And you have to think differently when you want to implement a sequence cause you cannot block the code for too long or you will miss input frames and might become totally un sync with the serial comm. demob_plc02 implements a sequence some how with delays between output commands... Let me know what version you prefer... The LegoB V2 is using Machine (ESP32 MCU) Timers to achieve separates tasks for KeppAlive and Read Inputs. Now the user program does not need to worry to much about timings...
  8. The M5Stack series of ESP32 products (Atom, Stick, Core) can be also a great options for those NOT wanting to solder... And their products are often LEGO compatible (HW Size, studs...) I will order for fun: ATOMIC RS232 Base TTL-RS232 ATOM Lite ESP32 IoT Dev Board I have a M5Stack Core2 already. M5Stack Core2 But I'm missing: RS232 Module 13.2 with DB9 Male Connector (Expensive, I will rather use Grove cable to a DB9 RS232/TTL converter module. But good to know it exists) Grove2Dupont Conversion Cable 20cm (5Pairs) I also have a M5Stick CPlus: M5StickC PLUS ESP32-PICO Mini IoT Development Kit . I might try it this weekend. I have grove connector cable with a bare end that I will adapt with dupont wires somehow... This small M5Stick has a small battery and a OLED screen and it also has some IR transmitter (maybe could interface the RCX?) and buttons and 6-Axis IMU, RED Led, RTC, Passive Buzzer, Microphone...
  9. Did you also buy some gender changer like: https://www.amazon.ca/DKARDU-Changer-Transfer-Adapter-Connector/dp/B09BQ4HF53 ? (Unless you aready have some...)
  10. What is Fritzing? I just picked up some pictures over the internet that looked cool. I was wondering though how these very easy to understand schematics were done. So thank you for the hint. I usually buy this kind of electronic stuff on Aliexpress. There are also on amazon of course but more expensive. I have no particular projects in mind beside this project of making these "Modern Drivers" for interface B hoping it might interest some people.
  11. Just updated the legob.py file. I added retries if it does not succeed to connect within 5 sec. (Will print a message asking to check serial connection and power to the box). Also, if the connection is lost while it's reading inputs, it will proceed to stop (shutdown) the box... EDIT: I updated again, more proofing and changed the version number...
  12. 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...
  13. 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.
  14. 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
  15. 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...
  16. 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).
  17. 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.
  18. 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.
  19. Buck step down converter board I used to convert 9v to 5v: https://www.aliexpress.com/item/1005005105181120.html
  20. 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.
  21. 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...
  22. I just created a new topic about Lego Interface B and ESP32. I thought it would be better in a new thread.
  23. 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.
  24. 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
  25. 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.
×
×
  • Create New...