Asper

Experiment: Using Raspberry PI and SBricks for automatic train control

Recommended Posts

"proof of concept" using one raspberry pi to control two LEGO trains:

The trains are detected by reed switches. The Raspberry PI sends commands over bluetooth to the SBricks mounted on each train. The code on the raspberry PI is based on this code: https://github.com/J...ick-Stress-Test by GitHub user JorgePe. He also has details on the implementation in the SBrick wiki: https://social.sbric...client-scripts.

The only cable-connections are from the raspberry PI to the USB power supply (white box) and to the reed switches. Even at this early stage, this can be helpful on small train layout at exhibitions by adding some random elements in the timing.

Edited by Asper

Share this post


Link to post
Share on other sites

Very nice idea although I don't think the Pi is the best choice. I think an Arduino would be a better choice for detection, maybe connecting them using XBee nodes. The bad thing about SBricks (and in fact all BLE 4.0 solutions) is that meshing is not very good. I'm looking forward to new 4.2/4.3 chips that allow meshing at a hardware level.

I'm currently making a home automation system with about 13 Arduino (in fact Teensy) nodes and a Pi as controller, very effective.

Share this post


Link to post
Share on other sites

Nice work, then I guess you can talk to the raspberry pi via your phone or tablet on the local netowrk?

thank you!

Currently this is just a set of python scripts running on the raspberry pi, so you need something like ssh to connect and start this - I don't think this is what you are thinking of...

But I'm planning to have a web server on the pi, so any device can connect and control the SBricks - without installing custom apps.

Share this post


Link to post
Share on other sites

Very nice idea although I don't think the Pi is the best choice. I think an Arduino would be a better choice for detection, maybe connecting them using XBee nodes. The bad thing about SBricks (and in fact all BLE 4.0 solutions) is that meshing is not very good. I'm looking forward to new 4.2/4.3 chips that allow meshing at a hardware level.

thank you!

I also played with an arduino to control LEGO motors and read in sensors. The major advantages of the SBrick for me are its size and availability - it's a very compact solution to get some remote controlled device into my trains without the need to build my own electronics. So currently this is the only solution I know to achieve something like this with off-the-shelf products. Maybe I need the arduino as I/O device for the pi when it comes to operating the switches or reading in more reed switches. But then size does not matter so much and I can use the available arduino boards.

Share this post


Link to post
Share on other sites

Cool stuff. Does Raspberry PI come with Bluetooth 4 LE?

I did something similar using an Arduino with Infrared LED to talk to Power Functions. No modifications to PF trains are required so anyone can bring an off the shelf train to run. Raspberry PI could be a better choice than Arduino if you plan to run a webserver. Alternatively an ESP8266 can provide a webserver with WIFI plus several GPIOs for around $5 USD.

Share this post


Link to post
Share on other sites

thank you!

I also played with an arduino to control LEGO motors and read in sensors. The major advantages of the SBrick for me are its size and availability - it's a very compact solution to get some remote controlled device into my trains without the need to build my own electronics. So currently this is the only solution I know to achieve something like this with off-the-shelf products. Maybe I need the arduino as I/O device for the pi when it comes to operating the switches or reading in more reed switches. But then size does not matter so much and I can use the available arduino boards.

On the train side I indeed agree that SBricks probably is the best option at this moment! I use IR, have IR poles next to the tracks, does the job but has it's disadvantages (mainly line of sight of course). The Teensies are very small though!

@dr_spock, it has 4 USB ports so one could add a BLE USB stick.

Share this post


Link to post
Share on other sites

Cool stuff. Does Raspberry PI come with Bluetooth 4 LE?

I did something similar using an Arduino with Infrared LED to talk to Power Functions. No modifications to PF trains are required so anyone can bring an off the shelf train to run. Raspberry PI could be a better choice than Arduino if you plan to run a webserver. Alternatively an ESP8266 can provide a webserver with WIFI plus several GPIOs for around $5 USD.

as JopieK mentioned, the raspberry pi has 4 USB ports. So I plugged in a BLE USB stick into one of them. One of the other ports will get a WLAN stick.

I also did experiments with an Arduino and IR LEDs but for me the PF-IR protocol has two major drawbacks. There are only 8 channels, and at exhibitions you will probably find another MOC using your channels. (And it may take some time finding out, that the ferris wheel in the middle of the layout is controlled by PF and that's why your trains start or stop randomly...). And at exhibitions you won't reach your trains at the other end of the layout. There are no reflecting walls and often you have direct sunlight interfering with the remote. So I'm looking for some kind of radio control.

I did not know the ESP8266 - sounds interesting, thank you for this hint.

Share this post


Link to post
Share on other sites

That is true, IR can be a problem at exhibits where others are using the same channel.

Esp8266 is an interesting device for low cost DIY entry into IoT (Internet of Things). You could have one in each of your trains, switches, sensors, track signals, motorized accessories, etc. and control your layout through a WIFI TCP/IP network. It can be programmed using the Arduino IDE if so desired. There are different firmware support. I think it has MESH network support now too. It's constantly evolving and it is hard to keep up all the new information.

Share this post


Link to post
Share on other sites

That is true, IR can be a problem at exhibits where others are using the same channel.

Esp8266 is an interesting device for low cost DIY entry into IoT (Internet of Things). You could have one in each of your trains, switches, sensors, track signals, motorized accessories, etc. and control your layout through a WIFI TCP/IP network. It can be programmed using the Arduino IDE if so desired. There are different firmware support. I think it has MESH network support now too. It's constantly evolving and it is hard to keep up all the new information.

Does beg the question, either on what motor controller combination you would use to step up the voltage, or whether we could just swap out the internal PF motors for ones that could run under 5v so they could be wired directly to the Arduino Micro PWN outputs. Maybe something like http://www.ebay.com/itm/Mabuchi-FC-280SA-Motor-4-5-V-DC-Dual-2mm-Diameter-Shaft-Small-Hobby-Motor-/280812744244 - a new 4.5v era awaits!

Share this post


Link to post
Share on other sites

Hi!

I'm JorgePe at GitHub (ando also Jorge Pereira at Youtube... identity problems, I know). Thanks for giving me the credits, I apreciate a lot.

I'm glad my code worked with the Raspberry Pi. I've been using it mainly with my Linux laptop and my Mindstorms EV3. I had a setup similar to yours but with RFID sensors and tags instead of reed switches and magnets - yours is definitely cheaper than mine :)

Don't want to hijack this thread but I would like to comment things:

- I've been also testint the ESP8266 and agree that Wi-Fi is much better than BTluetooth 4.0( BLE) at the moment, although BLE needs much less power;

- With Arduino and Raspberry Pi I've been using Itead L298 and Pololu drv8835 (dual) /drv8838 (single) motor drivers. You can see later with a grown-up version of the ESP8266 (nodeMCU) here:

Edited by MajorAlvega

Share this post


Link to post
Share on other sites

So that we are not hijacking Asper's thread and being a raspberry, I started a new topic for ESP8266 discussion. Please move ESP8266 related discussion there. Thank you.

Share this post


Link to post
Share on other sites

@Asper nice topic, a year ago i order some Pi's, Sbrick's and reed switches but have no time to make somthing working like you do.

I also backed on kickstarter a Bluz, a cloud connected bluethooth LE kit.

Share this post


Link to post
Share on other sites

Last weekend this ran for two days at Bricking Bavaria. In the youtube video you can see our city/train-layout:

The two trains on the inner ring share one track and are controlled by an raspberry PI.

For the raspberry I built this small hill to hide all the cabling:

29627161622_224b61e2d3_c.jpg

"bricks n bolts" and I are currently working to integrate more options to remote-control trains and work on the user interface.

He has integrated the brickster modules and I could control a train with an ESP8266 with motor-shield. I just did not find time to configure the raspi as wifi hot spot. So only SBricks were used.

Share this post


Link to post
Share on other sites

Hello, great wrok. 

 

Now i am trying to do the same.

unfortunately if i send an command to run port 1 nothing is responding. 

(yes there is an motor on port 1)  

$ gatttool -b 88:6B:0F:77:68:CB -i hci0 --char-write --handle=0x001A --value=01000080

$ gatttool -b 88:6B:0F:77:68:CB -i hci0 --char-write --handle=0x0025 --value=01000080

 

 

do you have aan suggestion.?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.