Jump to content
 

Fun with Arduino - how to get started, and more


RudyB
 Share

Recommended Posts

If you are a MERG member, then there are a number of train detectors in the pocket money project section.

 

I've not controlled points but use an Arduino to set signals based on occupation and points settings. Code is on this topic if there is anything that helps

 

  • Thanks 1
Link to post
Share on other sites

2 hours ago, melmerby said:

Those IMHO are the same as the Megapoints ones

 Which are a little cheaper on Aliexpress but take longer to arrive:

 

I don't have the patience to wait for stuff from China. And those devices are several times larger than an LDR

 

...R

Link to post
Share on other sites

Have a look here. These are the servos and optical sensors I used, acquired at Aliexpress.

 

The transmitter and receiver were cut lose and placed opposite each other along the track to detect the train by obstructing the IR beam.

 

https://rudysarduinoprojects.wordpress.com/2019/03/07/fun-with-arduino-19-railway-crossing-train-detection-optical-sensor/

  • Thanks 1
Link to post
Share on other sites

  • RMweb Premium
1 hour ago, Robin2 said:

I don't have the patience to wait for stuff from China. And those devices are several times larger than an LDR

 

...R

 

You obviously don't have the patience to look through the components either.:no:

:jester:

Link to post
Share on other sites

6 hours ago, melmerby said:

 

You obviously don't have the patience to look through the components either.:no:

:jester:

I already have the components I want - LDRs. I don't have the patience to construct an equivalent from parts. I had the impression from your earlier Post that you had found a supplier of a ready-made IR detector that is smaller than an LDR. Apologies if I misunderstood.

 

...R

Link to post
Share on other sites

  • RMweb Premium
26 minutes ago, Robin2 said:

I already have the components I want - LDRs. I don't have the patience to construct an equivalent from parts. I had the impression from your earlier Post that you had found a supplier of a ready-made IR detector that is smaller than an LDR. Apologies if I misunderstood.

 

...R

I was indeed suggesting using separate components to produce a smaller footprint and individual IR devices are very cheap and can be connected directly to an Arduino.

I wouldn't use the pre-assembled board, IMHO it is huge and the on board components are unnecessary but10 can be bought for £3.84 (inc P&P) and I have found AliExpress delivery is often no slower than some e-bay sellers.

 

I never liked using LDRs due to ambient light problems.

Link to post
Share on other sites

  • 2 weeks later...
  • RMweb Premium

 

On 20/06/2020 at 09:19, 47137 said:

It would be a shame to clutter this excellent topic with discussions of preferences for particular hardware, and so I will report back after I have something which works or I have given up.

 

On 20/06/2020 at 09:54, melmerby said:

Well the topic is "Fun with an Arduino" and an Arduino will do all you want without employing a Megapoints board.:jester:

 

 

Keith,

I have made some servo mounts, and there is write-up of these and some notes on controlling the frogs here:

 

To be honest with you, I am not sure if I will ever equate "software" with "fun"; and I probably should not have made my original post here. But if you wish to follow my link, you will see my present thinking.

 

- Richard.

Link to post
Share on other sites

One of the easyest ways to mount a servo for a turnout is shown in video 30:

https://rudysarduinoprojects.wordpress.com/2019/05/13/fun-with-arduino-30-dcc-servo-decoder/

 

As far as frog polarization is concerned I would like to point to the free Arduino software on this website:

www.arcomora.com

It's a further evolution of the Arduino DCC decoder and it's fully configurable via USB, servo angles, frog polarization and more.

  • Like 1
Link to post
Share on other sites

  • 7 months later...
  • RMweb Gold
On 30/12/2018 at 23:12, RudyB said:

Hi 'Theakerr'. If you have any specific Arduino task to be resolved, with no answer yet as to how to do it, who knows if you'd post it here there might be readers who can offer a solution.

 

This is a very interesting thread RudyB thanks for starting it.

 

Re the quoted post I am looking for any article about the automation of passing  sidings.  I have  a continuous run double track main line.  In a hidden section of the main line, each track splits into three loops.  I want to design a means of having a train arrive into the first loop and stop. Then the train in the second loop would depart and do one circuit, then the train in the third loop, then the first train and so on.

 

The layout is DCC.

Link to post
Share on other sites

Colin,

 

I wonder whether the automation that you're looking for might be achieved using a Raspberry Pi running software like JMRI or RocRail, rather than using an Arduino. If you used an Arduino, I think that you would have to implement a lot of software yourself, both on the detection side, since you need to know where trains are located dynamically, and also on the control side, since you have to set routes on the layout and drive trains. I am sure that this could be done using an Arduino, but from what I know about available software, it looks like a lot of work.

 

Yours, Mike

  • Agree 1
  • Informative/Useful 1
Link to post
Share on other sites

  • RMweb Premium

One thing to remember about dcc is that you need to address each "loco" specifically to get it to do something - e.g. move, whistle.

 

You'll either need to restrict the number of locos that you use so that you know which one is where (assuming you don't get a power failure midway during a running session), have the "locos" carry a tag that can be read from lineside/in track apparatus or input the loco's details at the (re)start of each session.

  • Informative/Useful 1
Link to post
Share on other sites

  • RMweb Premium

Arduinos are ideal for such things as point decoders and signal operation, but to control a layout something more sophisticated is needed

 

How about the Raspberry Pi 400?

It's a complete computer (less display) for under £70:

https://shop.pimoroni.com/products/raspberry-pi-400?variant=32280738005075

  • Informative/Useful 1
Link to post
Share on other sites

5 hours ago, KingEdwardII said:

Colin,

 

I wonder whether the automation that you're looking for might be achieved using a Raspberry Pi running software like JMRI or RocRail, rather than using an Arduino. If you used an Arduino, I think that you would have to implement a lot of software yourself, both on the detection side, since you need to know where trains are located dynamically, and also on the control side, since you have to set routes on the layout and drive trains. I am sure that this could be done using an Arduino, but from what I know about available software, it looks like a lot of work.

 

Yours, Mike

 

1 hour ago, melmerby said:

Arduinos are ideal for such things as point decoders and signal operation, but to control a layout something more sophisticated is needed

 

How about the Raspberry Pi 400?

It's a complete computer (less display) for under £70:

https://shop.pimoroni.com/products/raspberry-pi-400?variant=32280738005075

 

In the past I've used a Pi2 B with JMRI and a SPROG3 and the sort of 7" screen sold for reversing cameras in cars and found it a very effective, flexible and "inexpensive"* DCC controller setup.  With a wireless dongle** (Not needed if you use a Pi 4B or possibly a Pi Zero W ) and a surplus Android phone or tablet with Engine Driver, you can have walkabout controllers too!

 

Of course, no Arduinos would be harmed in this setup...

 

* I know I said "inexpensive", but then I looked up how much a Sprog 3 was nowadays... A Pi3B+, SPROG and 7" monitor comes out as over £120+, it works out as more cost effective if you have a spare Pi and other bits to hand already.

** Or you can use an obsolete wireless hub, which saves having to set up the wireless on the Pi correctly...

 

Edited by Hroth
  • Like 2
Link to post
Share on other sites

1 hour ago, Hroth said:

A Pi3B+, SPROG and 7" monitor comes out as over £120+,

Well, I view it a bit differently. You are going to need some kind of DCC controller, like it or not - I would not lump the cost of that into the equation here, since it is table stakes for having a DCC enabled layout in the first place.

 

So the extra cost for automation is really the Pi - and you don't have to have the monitor for the Pi, since it can be run "headless".

 

OK, in my case I have a Digikeijs DR5000 controller and I use a Pi400 with a large touchscreen monitor (22", not 7" !), but I regard that as a replacement for a "traditional" mimic panel. You don't have to go that far to get software automation running.

 

One of the big questions is what mechanisms you are going to use to detect and report the location of trains. Especially if you care about knowing the identity of a particular loco or train. These mechanisms need to fit in to the overall solution.

 

Yours, Mike

Link to post
Share on other sites

  • RMweb Gold

I hope you don’t mind me dropping this question in here but it seems related to ‘getting started.

 

I am thinking about dipping my toe into the Arduino world, not necessarily for railway modelling use yet, just out of general interest. I was looking at starter kits and  I came across this, what I assume is a clone,  by Elegoo.

 

Basic Kit

 

I appreciate it doesn’t contribute to the Arduino project but the could be solved by a donation.  
 

Has anyone come across and used this?  If so any thoughts on your experience?

 

Will it/should it operate using the software from the Arduino website?  (This is where the donation could come in).

 

 

 

Link to post
Share on other sites

  • RMweb Premium
16 minutes ago, BoD said:

I hope you don’t mind me dropping this question in here but it seems related to ‘getting started.

 

I am thinking about dipping my toe into the Arduino world, not necessarily for railway modelling use yet, just out of general interest. I was looking at starter kits and  I came across this, what I assume is a clone,  by Elegoo.

 

Basic Kit

 

I appreciate it doesn’t contribute to the Arduino project but the could be solved by a donation.  
 

Has anyone come across and used this?  If so any thoughts on your experience?

 

Will it/should it operate using the software from the Arduino website?  (This is where the donation could come in).

 

 

 

All Arduinos, real or cloned are electrically the same, as the circuit diagram is published by Arduino for all to use. Hence all software will work.

You have to bear in mind that some software is written for a particular type of Arduino, so there are some differences.

e.g. The Mega has a lot more input/output pins so if they are used the program is quite clearly not suitable for a Uno.

I started whit Uno clones and have moved onto Nanos as they are easier to fit to a custom PCB.

 

Whether the assembly quality is the same for all the various clones is another matter, although the ones I have bought (various makes) have been fine.

 

  • Agree 1
  • Thanks 1
Link to post
Share on other sites

  • RMweb Gold
3 minutes ago, melmerby said:

You have to bear in mind that some software is written for a particular type of Arduino, so there are some differences.

e.g. The Mega has a lot more input/output pins so if they are used the program is quite clearly not suitable for a Uno.


Thank you for your reply.  I was thinking more about compatibility of the software for connecting and uploading the sketches rather than specific sketches.

Link to post
Share on other sites

  • RMweb Premium
5 minutes ago, BoD said:


Thank you for your reply.  I was thinking more about compatibility of the software for connecting and uploading the sketches rather than specific sketches.

No problem with sketches written for "genuine" Arduinos.

That kit has plenty to get you going and could be a good way to get started without hunting for various bits, one by one.

I can see a servo, a DC motor, stepper motor, keypad, 7 segment display, LCD display, various sensors etc. so plenty to get on with.

I assume there is software online to be used as "lessons"

 

EDIT just spotted programs are on a supplied CD as well.

Edited by melmerby
  • Thanks 1
Link to post
Share on other sites

The kits that you reference look like an excellent choice to get started.  They all have a good selection of accessories to play with.  That is exactly how I got started.

 

Don’t forget that there are many excellent videos available on YouTube aimed at both beginners and more advanced users.  In particular I would recommend the series produced by Ralph Bacon.  He aims his particularly at beginners and I found them very useful.  To start with go back to his earlier productions (he now has over 200 to choose from).

 

Regards,

 

ColinM.

  • Agree 1
  • Thanks 1
Link to post
Share on other sites

  • 3 months later...
  • RMweb Premium

I hope I am posting this in the right place.

 

I have had a go with Rudy's train describer:

https://rudysarduinoprojects.wordpress.com/2019/09/23/fun-with-arduino-40-station-platform-departure-display-with-analog-clock/

 

I have kept the clock but changed the messages. The idea is to make a fun thing and for me the important thing is to make sure the platform display never relates to what is really going on. The default message is a quote from the charity shop where I work.

 

I am using an Arduino Nano on an expansion shield, and a 0.91 inch OLED display, this is the only hardware needed. I bought a real time clock module for it but I think a random time on the clock face is best for me.

 

- Richard.

 

TramPlatformDisplay_0.1.ino

  • Like 2
Link to post
Share on other sites

  • RMweb Premium

20210527_171640a.jpg.8e9b2657da51f4bfa8961cef00af2e9f.jpg

 

I don't suppose anyone knows - can we connect two of these mini OLED displays in parallel? So with both displays having the same I2C address, they would both show the same information.

 

This would let me have one display in a prototypical position for my model passengers to read, and another where I can see the message without having to look round a corner to see it.

 

- Richard.

  • Like 1
Link to post
Share on other sites

  • RMweb Premium
2 hours ago, 47137 said:

20210527_171640a.jpg.8e9b2657da51f4bfa8961cef00af2e9f.jpg

 

I don't suppose anyone knows - can we connect two of these mini OLED displays in parallel? So with both displays having the same I2C address, they would both show the same information.

 

This would let me have one display in a prototypical position for my model passengers to read, and another where I can see the message without having to look round a corner to see it.

 

- Richard.

 

You can use a bus multiplexer to run several I2C devices off one Arduino

https://coolcomponents.co.uk/products/tca9548a-i2c-multiplexer

 

Then just send the same info to each device but at different addresses

see this sketch where I used 8x VL6180 on I2C bus.

 

TCA9548_multi_VL6180X.ino

 

EDIT

The other thing to check before buying a bus multiplexer, is to see whether the OLED display has any jumpers to change the address.

Some devices do, others the address is in the firmware and cannot be changed (as with the VL6180Xs

 

AFAIK you can't parallel two devices with the same address, hence the multiplexer.

Edited by melmerby
  • Like 1
  • Thanks 1
Link to post
Share on other sites

  • RMweb Premium

I have found and downloaded the "specification and user manual"(!) for I2C

https://www.i2c-bus.org/specification/

and to be honest with you, it is really good. I think it is easier to understand than the tutorials I've seen on the subject.

 

Yes - a bus multiplexer is ideal to connect multiple identical slaves to the bus. And indeed, the address of the displays I have is hard-coded into their firmware.

 

Having glanced at the pictures and a few of the words in the spec for I2C, it is pretty clear I can have multiple masters sharing the same slave(s). So if I decided my layout was going to have a real time clock module, then every master on the bus could poll the same module. And if I decided to have a character-based display to show (say) a simple narrative description of the layout, I could use the same display with a configuration menu running on a different Arduino.

 

Of course, now I can see how to provide a second platform display, I'm not sure if I really want one. This is because I have realised, with a tram in the platform, I would not be able to see either display.

 

- Richard.

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
 Share

×
×
  • Create New...