Pybricks Posted July 20, 2022 Author Posted July 20, 2022 Yes, or try the very latest version using the instructions linked above if you can’t wait for the next beta in a few weeks :) It would still be very useful if someone wants to try that experiment above with the Powered Up app, to find out what the values really are. Quote
BatteryPoweredBricks Posted July 22, 2022 Posted July 22, 2022 (edited) Forgive me if the answer is somewhere staring me in the face. I've spent hours trying to find out how to use Pybricks to control two train motors (in opposite directions) simultaneously for the same locomotive using the official remote. I would think this would be a popular use case, but I haven't been able to find anything. Edited July 22, 2022 by BatteryPoweredBricks Quote
vascolp Posted July 22, 2022 Posted July 22, 2022 There are lots of examples. You can, for instance, peek this zetros example and remove the stuff related with steering and locking. Since you want the motors in the opposite direction, change the creation of one of the motors to: drive_motor2 = Motor(Port.B, Direction.COUNTERCLOCKWISE) You could also try my Remote Bla Bla which allows you to configure a hub without a mobilephone. But you will need a TechnicHub even to configure a CityHub (not enough memory on the CityHub...). Quote
Lok24 Posted July 22, 2022 Posted July 22, 2022 my_motorA = Motor(Port.A) my_motorB = Motor(Port.B) #use any code here to set s to desired Speed s= 300 # and then run both motors: my_motorA.run(s) my_motorB.run(s*-1) Does this answer your question completely? Quote
BatteryPoweredBricks Posted July 22, 2022 Posted July 22, 2022 6 hours ago, Lok24 said: my_motorB.run(s*-1) This answers my question, but only because I had already found an example train control code on rebrickable. That worked in a quick test so I tried to include the program in a firmware download. I've been trying for over an hour to load the firmware and keep getting errors ``` GATT operation failed for unknown reason. ``` ``` GATT Server is disconnected. Cannot retrieve services. (Re)connect first with `device.gatt.connect`. ``` After several attempts I tried loading official Lego firmware and it downloads just fine. Try again with Pybricks and keep getting errors. I've tried two different PC's. I'm using a "Plugable USB Bluetooth 4.0 Low Energy Micro Adapter" which has worked fine in the past. I can try my Laptop later which has integrated low power bluetooth and see if that works. I must warn you I am a "hardware guy", software has always had it out for me. I have very simple demands for programs I use but always end up having the craziest issues. When first testing the program with the play button it kept failing and citing line 21 and an error 21 remote = Remote(timeout=10000) and the remote would not connect. After including the program in a firmware download and not changing anything else it worked just fine. Please send help or an exorcist Quote
BatteryPoweredBricks Posted July 24, 2022 Posted July 24, 2022 Update It seems my bluetooth adapter is to blame, works fine with my laptop. Odd that it worked dozens of times before and then stopped working (again on multiple PC's). My goal is to use Pybricks exclusively with my Lego trains. I dislike the official Lego app and I use my phone for recording video, phone calls, work etc. I do not want it tied up in my trains. My dual motor train is now working thanks to @Lok24. My next project is to convert my dual hub passenger train to Pybricks, Is it possible to connect multiple hubs to a single controller using Pybricks currently? Again if there is any website / resource out there with example programs for use with trains I'd love to find it. I'm hardly the person suited for this task but will do it if no one else will. I'm also interested in a better power curve than adding 20 for each button press if anyone has any ideas there as well. Quote
Lok24 Posted July 24, 2022 Posted July 24, 2022 4 minutes ago, BatteryPoweredBricks said: Is it possible to connect multiple hubs to a single controller using Pybricks currently? No. 5 minutes ago, BatteryPoweredBricks said: Again if there is any website / resource out there with example programs for use with trains I'd love to find it. I'm hardly the person suited for this task but will do it if no one else will. I'm also interested in a better power curve than adding 20 for each button press if anyone has any ideas there as well. yes, you can press the button once and in 5 sec add 1 every 250ms. For non-train-motors you can use acceleration-limit. A program you find here http://www.kinderbahn.de/MotorControl2.7.zip You can set min, max, step, acceleration, auto-acc and other parameters. Quote
BatteryPoweredBricks Posted July 24, 2022 Posted July 24, 2022 Ah bummer, back to official firmware for my passenger train until I can find something better. Thanks for the link to the program I'll check it out! Quote
Lok24 Posted July 24, 2022 Posted July 24, 2022 What type of motors do you use? For the train motors it is very simple to cut the cable and add some extension, its only two wires! How do you use it now? Powered Up App, smart device and remote? Quote
BatteryPoweredBricks Posted July 24, 2022 Posted July 24, 2022 I'm using the official PU train motors, I don't have any train mocs that use other PU motors atm. I prefer to use the PU remote to control my trains until hub to hub communication is implemented in Pybricks. I don't do any programming with the Powered Up app, I just use it to load the official firmware. I run multiple trains at once, which is another reason I don't use the app at all. My passenger train is made up of three 60197 sets minus one locomotive so it would be quite long to extend the wires through 6 coaches to the other end. It's doable, the wire I use to repair 9v connectors would be great for it, but not something I'm interested in doing. For now the Lego firmware unofficially supports connecting multiple hubs to a single remote, it's just the initial pairing that is a pain. I make videos / tutorials of most of my projects so I try to keep the cutting / modifying to a minimum so anyone can follow along. Quote
Lok24 Posted July 24, 2022 Posted July 24, 2022 (edited) 6 minutes ago, BatteryPoweredBricks said: For now the Lego firmware unofficially supports connecting multiple hubs to a single remote, it's just the initial pairing that is a pain. It is not "unofficial", it's intend to do that. Just pair hub 1, then hub 2 and set the channel on Hub 2 accordingly. Edited July 24, 2022 by Lok24 Quote
BatteryPoweredBricks Posted July 24, 2022 Posted July 24, 2022 1 minute ago, Lok24 said: It is not "unfiicial", it's intend to do that. Just pair hub 1, the Hub 2 and set the channel on Hub 2 accordingly. I may be misunderstanding, I meant two hubs on the same channel. I use the buttons on one side of a single remote to control motors on two hubs simultaneously (I physically reversed the motor on one end of the train). I'm also able to pair a third hub for an entirely separate train with the buttons on the other side of the remote. I never have to change channels to control them. I haven't been able to find any documentation from Lego on this, that is why I described it as "unofficial". I found the info buried in various YouTube videos, it's a series of button presses on the remote and hubs to get them to pair like this. If there is an easier method I'd be very interested Quote
Gimmick Posted July 25, 2022 Posted July 25, 2022 11 hours ago, BatteryPoweredBricks said: I may be misunderstanding, I meant two hubs on the same channel. I use the buttons on one side of a single remote to control motors on two hubs simultaneously (I physically reversed the motor on one end of the train). I'm also able to pair a third hub for an entirely separate train with the buttons on the other side of the remote. I never have to change channels to control them. I haven't been able to find any documentation from Lego on this, that is why I described it as "unofficial". I found the info buried in various YouTube videos, it's a series of button presses on the remote and hubs to get them to pair like this. If there is an easier method I'd be very interested You can create a network with up to 5 hubs/remotes and any channel-hub-combination you like. But every A and every B on the same channel (color) will react simultaneously. The only "documentation" for this is, as far as I know, a Q&A: Powered UP AFOL Community Answers - News - LEGO Ambassador Network Quote
Lok24 Posted July 25, 2022 Posted July 25, 2022 As I wrote: Pair hub 1, Pair Hub2. Hub 1: Remote press and relaese green Button Hub press and release green Button -> connected Hub 2: Remote press and hold green Button Hub press and release green Button -> connected If the hubs show different channels (colors): Hub 2 press an release green Button multiple times, till it shows same color as 1 Quote
BatteryPoweredBricks Posted July 28, 2022 Posted July 28, 2022 On 7/25/2022 at 5:29 AM, Lok24 said: Hub 2: Remote press and hold green Button Hub press and release green Button -> connected This exact method does not work for me. The second hub must be blinking before being held down. Again that's my major gripe with Lego that the procedure isn't a little more intuitive and has to be exact. At least have some feedback like color coded errors with the LED would be nice and not require any additional hardware. Beyond that I'm having trouble even getting the initial connection sometimes, which has me completely baffled, but it is not an issue for this thread since it is using official firmware. Also either I am completely blind or Lego has recently added the procedure for connecting multiple hubs directly on their help page. I feel I checked it recently and didn't see it but I could be wrong. As for Pybricks and Lok24's motor control program everything is working great. I have two engines running two motors each. But I do have one more question, I'm having issues turning hubs off when running Pybricks firmware and trying to figure out the exact procedure. Sometimes it takes me 5 to 10 tries holding down the button before it turns off, and every once in a while it just turns off first try. I've tried a range of 6-10 seconds, counting from how long the button is pressed or counting from when the light stops flashing. But I can't figure it out. Also curious if it is possible to turn the hub off when the remote is disconnected for a specified time. That would make it easier for me when I'm done with the layout. When using official firmware I just turn off the remote and the hubs timeout and shutdown after 10 seconds or so. Quote
AVCampos Posted July 28, 2022 Posted July 28, 2022 7 hours ago, BatteryPoweredBricks said: I'm having issues turning hubs off when running Pybricks firmware and trying to figure out the exact procedure. I have always done it by short-pressing the button to stop the program, then long-pressing to turn the hub off. Doesn't that work for you? 7 hours ago, BatteryPoweredBricks said: Also curious if it is possible to turn the hub off when the remote is disconnected for a specified time. It's possible to detect a remote control disconnect by catching an exception (I don't remember which). Then it's a matter of existing a method that turns off the hub. Quote
Lok24 Posted July 28, 2022 Posted July 28, 2022 (edited) And it is possible to reconnect the remote after loss of connection. Using this as a watchdog, for cars it might be useful stop , for trains to continue and then reconnect if train returns. It is OSError, and the method is hub.system.shutdown() And yes: you can't turn the hub off while programming is running. Push button stop program (-> blue blinking), the press and hold to turn off. Edited July 28, 2022 by Lok24 Quote
AVCampos Posted July 28, 2022 Posted July 28, 2022 9 minutes ago, Lok24 said: Using this as a watchdog, for cars it might be useful stop , for trains to continue and then reconnect if train returns. I wanted to use that feature in a boat, to put it in reverse in case of loss of control and hopefully get back to me. But gave up, not because of Pybricks, but rather the short range of the controller-hub link... I ended up using a Chinese controller and receiver instead of official LEGO stuff. Quote
BatteryPoweredBricks Posted July 28, 2022 Posted July 28, 2022 (edited) Yes I am stopping the program from running before trying to turn off the hub. I either hold down the button too long or not long enough, it just starts blinking again. I'm not sure if I should be counting for how long I press the button and ignore the LED or start counting after the LED goes out. Again thanks for the help, problems seem to follow me around everywhere I go, but I always share my experiences for others that are cursed Edit: If the video fails to play you can click "view on YouTube" in the bottom right. I've shared unlisted YouTube several times before with no issues but this one refuses to play for me. Edited July 28, 2022 by BatteryPoweredBricks Quote
Pybricks Posted July 28, 2022 Author Posted July 28, 2022 @BatteryPoweredBricks, it looks like you might have found a bug. Would you mind posting a message here? https://github.com/pybricks/support/issues It would be great if you want to share your connectivity issues in a separate issue. There's a chance this affects other people too. Thanks for the help! @Lok24 and @vascolp: We have made some progress in regards to saving data on the hub. How much space would you need to make this a useful feature? 10 bytes? 100? 256? more? Quote
vascolp Posted July 28, 2022 Posted July 28, 2022 3 hours ago, Pybricks said: : We have made some progress in regards to saving data on the hub. How much space would you need to make this a useful feature? 10 bytes? 100? 256? more? Cool! I am currently living with the 14 bytes of the remote but only with a lot of enconding. 128 or 256 bytes seems enough for most cases I think. Quote
BatteryPoweredBricks Posted July 28, 2022 Posted July 28, 2022 Done and done, thank @Pybricks I rarely submit bugs since I always just assume I'm doing something wrong In the mean time does anyone have a recommendation of a known working BT adapter to use with Cityhubs? After more testing it seems my "plugable" BT adapter will program Technic hubs but not Cityhubs. I'd rather not use my laptop since it usually stays in my car for use at work and has a really small screen. Quote
Pybricks Posted July 29, 2022 Author Posted July 29, 2022 Thanks for submitting the bugs! That really helps us keep track of things, and mark them as done when they are fixed. Quote
Lok24 Posted July 29, 2022 Posted July 29, 2022 7 hours ago, BatteryPoweredBricks said: In the mean time does anyone have a recommendation of a known working BT adapter to use with Cityhubs? I use without any problems: ASUS Micro Bluetooth USB-Stick V4.0 USB-BT400 13 hours ago, Pybricks said: @Lok24 and @vascolp: We have made some progress in regards to saving data on the hub. How much space would you need to make this a useful feature? 10 bytes? 100? 256? more? Oh, good to hear, I thought that was cancelled. I use the remote-name meanwhile (which isn't really nice......) Below some code from MotorContol 2.7. 10 isn't really useful. If you want to store the name of a remote you need 14 bytes....... Of course you could pack two or more values in one bytes, but makes the pogram hard ro read . So I count 20 parms with my proggy, +14 makes 35. Double would be 70. 50 - 100 should be suffiicient, who needs more has to pack..... Profil_A = (20,100,10,100) #min,max,step,acc Profil_B = (10,500,5,200) #min,max,step,acc # define direction of motors dirMotorA = 1 # Direction 1 or -1 dirMotorB = -1 # Direction 1 or -1 autoacc = False # accelarate continously when holding butten # ----------------------------------------------- # Set general values # ----------------------------------------------- # assign buttons to function1 # syntax: function = "name" # name may be "A+","A-","A0","B+","B-","B0","CENTER" UP = "A+" DOWN = "A-" STOP = "A0" SWITCH = "CENTER" mode=1 # start with function number... watchdog = False # "True" or "False": Stop motors when loosing remote connection remoteTimeout =10 # hub waits x seconds for remote connect after starting hub remoteName = "" # connect this remote only # Color and brightness of Hub LEDs LEDconn = Color.GREEN*0.3 # if Hub connected, color * brightness LEDnotconn = Color.RED*0.5 # if Hub is not connect, color * brightness LED_A = Color.GREEN*0.3 # Remote Profil_A, color * brightness LED_B = Color.RED*0.5 # Remote Profil_B, color * brightness Quote
BatteryPoweredBricks Posted August 1, 2022 Posted August 1, 2022 (edited) On 7/29/2022 at 3:50 AM, Lok24 said: I use without any problems: ASUS Micro Bluetooth USB-Stick V4.0 USB-BT400 Thanks for the recommendation! Initially I had the same issue but after manually downloading the latest driver from ASUS it works like a charm. Unfortunately Plugable does not offer any driver updates besides what Windows update provides due to some conflict with another windows update, so it's a no-go for use with Cityhubs. Glad to have answers and a good recommendation for anyone that needs it. Spoke too soon, I got one good firmware download but it hasn't worked since then. I'll keep testing for science I set up an Intel NUC with LInux and Windows and added an internal wireless card that has BT 4.0 LE and that works fine, just like my laptop. I would like to get to the bottom of it so I can have a good USB BT adapter recommendation to give others who don't have any devices with compatible internal BT. Also was able to help solve the power off issue over on the Pybricks github Edited August 2, 2022 by BatteryPoweredBricks Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.