Jump to content
THIS IS THE TEST SITE OF EUROBRICKS! ×
THIS IS THE TEST SITE OF EUROBRICKS!

Recommended Posts

Posted (edited)

Hello everybody, I'm starting this topic because I want to start automating my Lego Train layout. 

I am new to this so I have questions you might have the answer to and with that I hope this topic will help other newbies in the future. 

For starting off I'm thinking of buying:

  • 1 arduino mega 2560. To control everything.
  • 2 L298n modules to control 4 pf motors, for as many track switches. 
  • 6 (or more) lm393 lightsensetive optical sensors for train detection.
  • 1 HC05 bluetooth module for communication with bluetooth devices. 

I think I am all set for hardware. Maybe a 12v powerline to power the L298n's. 

I have two powered up trains, which I hope to be able to control with the arduino too, didn't find anything about it yet (didn't look hard either though).

Is this the right way to go Or do I miss something?

Thank for you help.

 

 

Edited by Venderwel
  • Replies 92
  • Created
  • Last Reply

Top Posters In This Topic

Posted

It's not simple to answer to your question because there are a lot of things to take in consideration.

For example: why use a HC-05 when you use an ESP32 with a Legoino library?

 

Posted
15 minutes ago, GianCann said:

For example: why use a HC-05 when you use an ESP32 with a Legoino library?

 

Am I using an ESP32?? Or do you mean I better use one?

Posted

Oh no problem, English is not my native language either. 

ESP32 is a board on it's own right? So no need of the arduino mega 2560 board anymore then. Is there an ESP32 with as many ports as the mega?

Posted

No. The ESP32 has a minor I/O respect to the Arduino 2560. I think, however, that you don't need so many I/O port.

Note: there are many dev-board based on ESP32 chip.

Start to explain how many (and the type of) trains/switch/sensor you want to be using.

Posted (edited)
30 minutes ago, GianCann said:

Start to explain how many (and the type of) trains/switch/sensor you want to be using.

There you have a good point! :thumbup:

For a motor I need 2 digital ports and a pwn port. 4 motors make 8 digital ports and 4 pwn

These LM393 need Analog output, or can I put those on digital too? Need at least 6 of those. So if I can put these on digital I only need 14 digital and 4 pwn for the moment. 

And I recon I can put multiple ground and 5v together right?

Edited by Venderwel
Posted
2 minutes ago, JintaiZ said:

I'd go with power functions it I were you. You probably also need some tracks.

And why PF??? I already have the Powered Up trains.

Already have the tracks smart megablocks! :pir-laugh: 

 

Posted

PF runs at 9V.  You could probably run them at 12V.  Excess voltage/lheat may not be good for the motor windings in the long run. 

ESP32 is a 3.3V device if I am not mistaken.  You'll have to do 3.3V/5V translation for your 5V sensors and motor drivers. 

The HC05 is a 3.3V device if I recall, you could probbably run it with a simple voltage divider between it and the Arduino. 

Posted (edited)
42 minutes ago, dr_spock said:

PF runs at 9V.  You could probably run them at 12V.  Excess voltage/lheat may not be good for the motor windings in the long run. 

ESP32 is a 3.3V device if I am not mistaken.  You'll have to do 3.3V/5V translation for your 5V sensors and motor drivers. 

The HC05 is a 3.3V device if I recall, you could probbably run it with a simple voltage divider between it and the Arduino. 

All true.

However, many of the ESP32 dev boards have a "Vin" output pin. That is connected to the (micro) USB V+ input = 5V. So there you have a 5V power feed right away. The ESP32 board I am using is tolerating +5V as logic high on appropriately configured GPIOs - but this may need closer attention; may have been lucky.

I am taking the 3.3V route - so when I am ordering sensors, they need to match that requirement as the ESP32 boards are really powerful (BT, BLE, WiFi, PWM on almost all GPIOs, at least 8 touch sensor compatible GPIOs, I2C and more - at about the price of an Arduino Uno R3 clone. 

The HC05 can be powered from the 3.3V output pin of any Arduino board providing it (Uno for sure). The HC05s I am using tolerate 5V as well - so not sure if this is generally the case.

Best
Thorsten

 

Edited by Toastie
Posted

The 12v is to power the L298n modules. At least that is what I read everywhere. As I read it, the L298n converts it to 9v for powering the connected 9v motors that I use for the trackswitches.

I'll use lightsensors that run on 3,3-5v to detect a train passing by. 

Can I use connect ground pins of multiple sensors to one ground pin on the board? 

Same question goes for the 3,3v connections. 

Posted (edited)
1 hour ago, Venderwel said:

Can I use connect ground pins of multiple sensors to one ground pin on the board? 

Same question goes for the 3,3v connections. 

You can connect all 3.3 and ground connections to one pin as they will be brought together at smeplace anyways. can you send me a link or a picture of the hc 05 you are using? i have one where the actual hc 05 board is soldered onto another board where the levelshifting (ie converting 3.3v to 5 and vice versa) is done. im not shure if you have a similar one to me.

HC-05_2.png

I would try running the l298n with 9v first as the actual driver chip is a so called h-bridge ich basicly just directly connects the supply voltage to the motor

H-Bridge-Working-Motor-Direction-Control

XG BC

 

Edited by XG BC
Posted (edited)

I don't have a HC05 yet...and probably not going to, since I decided to buy an ESP32 instead of an Android Mega. 

Okay, so have to see where I find a decent 9v power source.

On 8/26/2020 at 4:36 PM, Venderwel said:

For starting off I'm thinking of buying:

  • 1 arduino mega 2560. To control everything.
  • 2 L298n modules to control 4 pf motors, for as many track switches. 
  • 6 (or more) lm393 lightsensetive optical sensors for train detection.
  • 1 HC05 bluetooth module for communication with bluetooth devices. 

I think I am all set for hardware. Maybe a 12v powerline to power the L298n's. 

 

 

So after the advice of you guys what did I buy:

  • 1 38 pin ESP32 board with WiFi and Bluetooth on board. To control everything.
  • 2 L298n modules to control 4 9v motors, for as many track switches. 
  • 6 (or more) lm393 lightsensetive optical sensors for train detection.

And a bunch of cable stuff, waiting for it to come in, so I can start. 

Edited by Venderwel
Posted
36 minutes ago, Venderwel said:

2 L298n modules to control 4 9v motors, for as many track switches. 

That is where I am lost. The ESP32 is supposed to do "everything". That is fine. As well as the sensors are - these will be hooked up to the ESP32 right? But what are the L298n motor controllers for? These are H-bridge drivers ... so they go on the train(s), right? But they need a controlling device that they drive - is this the ESP32 board? I am a bit lost here.

I have an ESP32 "controlling" my Crocodile. There are four optical sensors on the track attached to the ESP - detecting the Croc's position. But the ESp32 is not >on< the Crocodile - that is a 2I/O Hub. The ESP is residing somewhere near the track. To control not everything, but the Crocodile. The sensors are used for: Endpoint detection and acceleration/deceleration triggers.

I am still unclear where your ESP32 will be: On the train or on the layout? And then: Where do the L298n's go? On the train of course ... but why do you want to control 4 9V motors? And what thing drives the 298's?

Sorry - may be entirely me not getting this!!!

All the best
Thorsten 

Posted (edited)

Ha, I may not have been clear on that. No. Noting goes on the trains, they are Powered Up hubs, they have Bluetooth, I can connect with that and hopefully find out how to control them in my script.

The ESP32 will be the center control in the layout. The light sensors will be connected to it, so they will detect were there is/was a train on that piece of track. I want to use them to make sections. 

The l298 will also be connected to the ESP32, and they will run the engines that will operate my track switches.

Let's say section one is connected with a switch to section two and three....Train A arrives in section one and I want it to go to section two and stop there. The sensor in section one detects a train and the program flips the switch to turn to section 2. The sensor in section two notices the train and the program stops the train. 

The sensor in section one notices an other train, but Train A is still in section two, so to avoid a collision, the program switches the track to section three and everybody is happy. 

Edited by Venderwel
Posted
27 minutes ago, Venderwel said:

and they will run the engines that will operate my track switches.

Ahhh - that is what I was missing. Sorry for that. Makes total sense.

Just in case: There are very nice tutorials on the usability of ESP32 dev board GPIOs regarding I/O. I am using jOYiT node MCU ESP32 dev boards - and here not all GPIOs actually work as "expected". PWM appears to be fine on most GPIOs. Using the PULL_UP configuration in the Arduino IDE (avoiding the application of pull up resistors to digital inputs) may not work on all designated/configurated I/O pins. Took me a while to figure that out. This is mostly only an issue when using open collector type sensors.  

Sounds like a very cool project you have going!!!

Best
Thorsten

 

Posted
18 minutes ago, Venderwel said:

I ordered this one, I hope it's any good.

Looks really good! Particularly the documentation is very nice. My jOYiT dev boards are the smaller 30 pin version - and virtually no documentation other than pin-out and installation.

On the pin out for your board as well as on the data sheet document they tell you exactly what GPIO pins you can use for what purposes! Very nice.

In case you want to use the internal pull up feature for digital in, I'd first test it. Took me quite some time to find out what was going on, as the input I used was simply floating around, regardless what setting I used. (It is always a good idea to tie the inputs up/down with resistors, when you know what you are going to do).

Best
Thorsten

Posted

That reminds me, I still need to pick up breadboard somewhere, Forgot to order that one.

9 minutes ago, Toastie said:

Looks really good! Particularly the documentation is very nice. My jOYiT dev boards are the smaller 30 pin version - and virtually no documentation other than pin-out and installation.

On the pin out for your board as well as on the data sheet document they tell you exactly what GPIO pins you can use for what purposes! Very nice.

See the Noob I am, I didn't even notice the documentation yet!! And have no idea yet what all that means. :pir_laugh2:

Posted (edited)
12 minutes ago, Venderwel said:

breadboard

... and maybe pre-configured female - male wires. They come in very cheap. The ESP boards do have pins whereas the Arduino boards have the "sockets" (well - as you know of course. I was just not prepared when switching form Arduino to ESP dev boards.

You then don't need to push the ESP into the breadboard but rather only use it on the side and do only your wiring (LEDs, motors, etc.) on the breadboard. I found it to be much more flexible this way.

Best
Thorsten

Edited by Toastie
Posted

can you send me a link to the motor drivers you bought so i could take a look at it. running 12v is probably fine as long as you are only runnung the 9v motors for a short time.

 

XG BC

Posted
49 minutes ago, XG BC said:

running 12v is probably fine as long as you are only runnung the 9v motors for a short time

True.

Plus depending on the switch's throwing mechanism @Venderwel is going to implement, he may well get off with a low PWM duty cycle on the outputs. It is my understanding that the PWM outputs of the ESP32 will interface to the drivers.

One more question: Why 12V? 9V does not work? Or are there 12V motors in the throwing mechanism?

Best
Thorsten 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.

Announcements

  • THIS IS THE TEST SITE OF EUROBRICKS!

×
×
  • Create New...