Using PyBricks to control Lego trains

  Рет қаралды 6,065

BatteryPoweredBricks

BatteryPoweredBricks

7 ай бұрын

I've wanted to make this tutorial for quite some time. I had covered PyBricks in previous videos but they were very outdated. I want to give a huge thanks to Eurobricks user Lok24 for writing the original program and @mpersand from our discord for adding the functionality for lights. If you spot any errors or problems with the links please let me know.
Pybricks
code.pybricks.com/
note when loading the firmware disconnect any "smart devices" from the hub. You shouldn't have an issue with train motors or lights but sensors or non-train motors can cause issues
Github link to @mpersand's modified program
github.com/and-ampersand-and/...
Eurobricks discussion thread for this program
www.eurobricks.com/forum/inde...
‪@blockjunction2230‬ builds shown in @ampersand's clips
blockjunction.co.uk/downloads...
blockjunction.co.uk/downloads...
blockjunction.co.uk/downloads...
Join my discord channel! / discord
Follow me on Twitter for updates / bpbricks
Instagram: / batterypoweredbricks
Music: "Sandviken Stradivarius" by Wintergatan
This track can be downloaded for free at www.wintergatan.net
Free License to use this track in your video can be downloaded at www.wintergatan.net
LEGO® is a trademark of the LEGO Group of companies which does not sponsor, authorize or endorse this content

Пікірлер: 45
@Gamersforlive
@Gamersforlive 7 ай бұрын
Thank you for this explanation i was having a hard time trying to get this program to work for my train
@BatteryPoweredBricks
@BatteryPoweredBricks 7 ай бұрын
No problem, glad to help!
@AFOLKFOLBricks
@AFOLKFOLBricks 6 ай бұрын
Excellent video tutorial; we followed your steps, and in a matter of minutes, we were able to control our modified Orient Express with a large Lego motor and a standard Lego remote instead of the PoweredUp phone app. Thank you very much!
@BatteryPoweredBricks
@BatteryPoweredBricks 6 ай бұрын
Thanks! Glad to help. Couldn't have done it without the programmers in the Lego community 😁
@technicmaster0tutorials
@technicmaster0tutorials 7 ай бұрын
Nice video. Disconnecting the sensors/motors from the city hub is required for "smart" devices like sensors and motors with rotation sensors. The firmware contains a bug which blocks the update process if these "smart" UART devices are connected.
@BatteryPoweredBricks
@BatteryPoweredBricks 7 ай бұрын
Shoot, I don't think I tested that. I know it used to have issues with train motors when loading the firmware and turning the hub off. After those problems were fixed I thought it would apply to other motors. I'll make a not in the description, thanks for the heads up!
@PurgatoryIndustries
@PurgatoryIndustries 7 ай бұрын
Thanks for you help mate great vid
@Tekytek
@Tekytek 7 ай бұрын
Thanks again for this, I have added it to my Orient Express running SevBricks PU large motor modification… works great 😎
@pybricks
@pybricks 7 ай бұрын
Great video. And we now have block coding too, so you can experiment with code without Python experience!
@BatteryPoweredBricks
@BatteryPoweredBricks 7 ай бұрын
Thanks! I haven't had a chance to check out the block coding myself but I am glad to see it implemented. I imagine it will be less intimidating to lots of Lego fans
@pybricks
@pybricks 7 ай бұрын
@@BatteryPoweredBricks and we just added our first train demo. I guess a demo with the remote needs to be next! And maybe an automated switch controlled by an approaching train? So many options 😃
@JLaxx13
@JLaxx13 5 ай бұрын
Thank you so much! I tried this out and it worked flawlessly on my custom loco! I was so happy to finally have smooth acceleration and braking!
@BatteryPoweredBricks
@BatteryPoweredBricks 5 ай бұрын
Happy to be the messenger! The programmers and the PyBricks team are the real heroes 😁
@JLaxx13
@JLaxx13 4 ай бұрын
They sure are! I wish I had founds this years ago! I just had a quick question. What would you recommend a dual motored locomotive or a single motered loco with lights? I also was a little concerned about my motor making a high pitched beep noise. Is that normal?
@BatteryPoweredBricks
@BatteryPoweredBricks 4 ай бұрын
@@JLaxx13The way the motors are powered it's perfectly normal to have a whine to them. For most of my trains I use dual motors but I did upload a video recently where I made a Y adapter to power two motors which left the other plug for lights.
@JLaxx13
@JLaxx13 4 ай бұрын
@@BatteryPoweredBricksOk thanks!
@paulsbricks
@paulsbricks 7 ай бұрын
I am totally a newb when it comes to do this sort of stuff. I take it you need a PC with Bluetooth to do this? Which unfortunately my archaic PC does not have.😀👍
@BatteryPoweredBricks
@BatteryPoweredBricks 7 ай бұрын
For most of my PCs I use a USB bluetooth adapter. As long as it's Bluetooth 4.0 LE compatible it should work just fine. They go for about $15 online. PyBricks is supposed to work from mobile devices or tablets but I haven't done much testing with it myself.
@robvanleeuwen3885
@robvanleeuwen3885 6 ай бұрын
This is great. Thanks for showing how it's done, made it worth the try, and I succeeded. Just one things I might be missing.. When using this program, can you still connect a second hub to the controller?
@BatteryPoweredBricks
@BatteryPoweredBricks 6 ай бұрын
Yes and no. There is a branch of the program on GitHub that allows for multi-hub operation. It's still being tested but has worked great for me. I've shown it off in some upcoming videos but probably won't make a full video tutorial for a while. It's meant for controlling trains with multiple locomotives, not multiple individual trains. It could probably be converted to such a use case but it would take a fair bit of programming to do so.
@FalconWing1813
@FalconWing1813 7 ай бұрын
After you load the program onto the locomotive do you half to have the PC or laptop every time you want to run a train? My son just got his first Lego train and thinking about using bricks. We have a laptop but cant have it in his room at all times. Thanks for your help!
@BatteryPoweredBricks
@BatteryPoweredBricks 7 ай бұрын
Nope, that's the beauty of it. Once it's loaded there is no need for a mobile device or PC. Press the button on the hub to turn it on, press it again to start the program and then connect the controller 👍
@FalconWing1813
@FalconWing1813 7 ай бұрын
@@BatteryPoweredBricks That sounds great. Huge thanks for your response! have a good one!
@ChristianLopezanime
@ChristianLopezanime 24 күн бұрын
@@FalconWing1813 @batterypowerbricks Do I have to have 2 controllers in order to have the front and rear Engines work together or can I just use 1 controller for the front and rear. I tried to connect two hubs and they just didn't
@BrickTrains
@BrickTrains 7 ай бұрын
One of these days. 😂
@davemiller2306
@davemiller2306 7 ай бұрын
Thanks for the tutorial which is very useful. FYI the github link to mpersand's code doesn't work directly, but if you click on "Go to default branch" the code is there. One issue with this approach seems to be that you have to start the program running from your PC, pity the code won't "self start". Or have I missed something? Thanks, Dave
@BatteryPoweredBricks
@BatteryPoweredBricks 7 ай бұрын
Fixed the link, thanks for the heads up. The code will self start, you press the button on the hub to turn it on and then press it again to start the program. Now I'm wondering if I ever actually said that in the video 😅
@davemiller2306
@davemiller2306 7 ай бұрын
@@BatteryPoweredBricks I watched it again and at about 4m40s you showed starting the program by pressing the button again so my bad 🙂
@BatteryPoweredBricks
@BatteryPoweredBricks 7 ай бұрын
Still it's something I should have said in the voice over, I'm glad it was brought to my attention. I may have further videos in the future on PyBricks and this should be mentioned as it isn't immediately obvious
@paulharris4256
@paulharris4256 6 ай бұрын
Hi: will Pybricks work on an Apple Computer? If so, what will I need?
@BatteryPoweredBricks
@BatteryPoweredBricks 6 ай бұрын
I don't see any reason why it wouldn't as long as the computer has Bluetooth built-in or a Bluetooth dongle. I had issues with Firefox and had to use Chrome using a PC. I have never used an Apple device in my life but if you have any issues feel free to ask and I'll try to find an answer
@paulharris4256
@paulharris4256 6 ай бұрын
@@BatteryPoweredBricks blue tooth is built in. Reading from Pybricks the information they supply is ambiguous as to which browser I need. I’ll keep working on it
@legogonegaming
@legogonegaming Ай бұрын
PROBLEM!!! I have done everything described in this video which was very helpful btw, but when I press the button on the hub again it turns red and when I turn the controller on it connects and turns green like it’s supposed to, but then when I press the forward or reverse button on the controller it does nothing and starts flashing blue and I have redownloaded the program fully several times but it still doesn’t work it keeps saying the requested operation is not valid in the current state and to check the traceback and gives errors on code lines 268, 95, and 464. Can someone please help me fix this. Thanks very much.
@BatteryPoweredBricks
@BatteryPoweredBricks Ай бұрын
What kind of motor are you using? If you have a train motor I would try that and see if it works, just as a test. If I remember correctly the other motors can be temperamental but I haven't done a lot of testing myself. If you are a discord user we have some folks in there that may be able to help better than I can. Side note, you only need to comment once. It won't make me see them any fast, I deleted the other ones.
@legogonegaming
@legogonegaming Ай бұрын
@@BatteryPoweredBricks I’m so sorry for bugging you I don’t mean to come off as rude I’m used to larger channels not being as responsive or polite as you. Thanks for responding and being helpful but I’m using two brand new technic large motors to motorize the Orient Express with danjo trains instructions. I unplugged both ports when setting it up and plugged them in after I installed the software and it worked only once but when I turned it off and back on again to check if it was actually working it went back to doing what I previously described. Thanks for responding and trying to help. And sadly I don’t have discord or I would def join yours. Thanks
@BatteryPoweredBricks
@BatteryPoweredBricks Ай бұрын
I'll ask @mpersand, he's had this issue before but I'm not sure if he ever got to the bottom of it. It was kind of intermittent
@Mpersand914
@Mpersand914 Ай бұрын
I've seen this issue intermittently but haven't been able to fix it. It only seems to happen in this script and only with L motors. It also doesn't seem to happen in older versions of Pybricks. The most recent time I tried to look into it, I couldn't even get it to happen. What's happening is the hub seems to forget the motor, and trying to set the speed of the motor causes the script to crash. When this happens and the light starts flashing blue, the program is still installed on the hub. You don't need to re-install. You can start the program again by hitting the hub's green button and reconnecting the remote. It might crash again, it might not. I've found unplugging and replugging the motor to the hub helps. Once it starts working, it usually keeps working for a while if you turn the hub off and on. And it never crashes after the first controller press. So if you hit forward or reverse and it works, then it will keep working until you stop the script. What I ended up doing for my L-motor locomotive is rolling back the Pybricks firmware to a version that this didn't happen. I'll post instructions for how to do that in another comment.
@legogonegaming
@legogonegaming Ай бұрын
@@Mpersand914 thanks for the help and explanation. The problem is exactly as you described and as many times as I rebooted the battery box it only worked once. Thanks for trying to help and I hope you can try to fix this issue because it wouldn’t be very easy for me to go through the process of removing the battery box and hoping it works every time I try to run the Orient Express. Thanks again for your help.
What is the best Lego train control system?
13:43
BatteryPoweredBricks
Рет қаралды 265 М.
Best Toilet Gadgets and #Hacks you must try!!💩💩
00:49
Poly Holy Yow
Рет қаралды 21 МЛН
Gym belt !! 😂😂  @kauermtt
00:10
Tibo InShape
Рет қаралды 17 МЛН
Mama vs Son vs Daddy 😭🤣
00:13
DADDYSON SHOW
Рет қаралды 46 МЛН
He secretly changed this freeway sign, helped millions of drivers
9:30
Revolutionizing LEGO RC Control with Pybricks & Xbox
12:01
RacingBrick
Рет қаралды 31 М.
How to make smart Lego Train layouts
11:41
Pybricks
Рет қаралды 17 М.
Building my Computer Controlled Lego Monorail Layout
10:30
BatteryPoweredBricks
Рет қаралды 14 М.
Control+ Pybricks Tutorial #1 - Getting Started
12:07
Vizonex Builds
Рет қаралды 4,4 М.
solving the LEGO city train problem (no room for loops!)
9:31
eggybricks
Рет қаралды 305 М.
TrixBrix switch machine by @novakasa5011
11:07
BatteryPoweredBricks
Рет қаралды 4,4 М.
Controlling Lego train switch tracks remotely (part 2)
7:13
BatteryPoweredBricks
Рет қаралды 10 М.
Lego Maersk Train is complete!  Dark Azure mod of the 10219 set
25:01
BatteryPoweredBricks
Рет қаралды 24 М.
КРУТОЙ ТЕЛЕФОН
0:16
KINO KAIF
Рет қаралды 6 МЛН
Какой ноутбук взять для учёбы? #msi #rtx4090 #laptop #юмор #игровой #apple #shorts
0:18
iPhone socket cleaning #Fixit
0:30
Tamar DB (mt)
Рет қаралды 18 МЛН
Как бесплатно замутить iphone 15 pro max
0:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 8 МЛН