simond

Western Thunderer
Some of you may be aware that I have been trying to help Paul (Focalplane) with his traversers and hoist for his new Moor St layout. I suggested Arduino controlled stepper motors coupled to leadscrews, which is what Paul has adopted. This prompted a brief discussion with Adrian, to enable “.ino” files to be uploaded to the forum, and Adrian asked some questions, which prompt me to post this thread, in trying to answer them, and hopefully, promote some further discussion.

I guess most people have heard of Arduino. It’s an open source project, to produce a cheap & easily-accessible microprocessor control for almost anything, and the project has spawned a massive range of clones & copies, and add-on bits & pieces, some of which are better than others.

The main page is here; Arduino - Home, you’ll find links to the project history, examples, language references, and the officially licence products. A quick www search will yield a huge range of stuff, accessories, connectors, robotic projects, drones, mini CNC milling machines, 3D printers, laser cutter mods, all using Arduino as the core processor. There are others, of course, the Raspberry Pi springs to mind. This is similar but different, and I started with one when they first came out, but it didn’t float my boat. I understand that there are areas in which a Pi is far more capable than an Arduino, but someone else will have to talk about them. There is also the PIC option, which is every bit as capable, but much more faffing about. Again, not my scene.

I started playing with these things about 6 years ago, I think, as I wanted to use r/c servos in place of point motors (servos are dead cheap, Tortoises aren’t, and I’m a cheapskate at heart!), and I kind-of got hooked, and have been playing around ever since.

The main project that I made was to control a turntable, and this is currently in bits, as I’m trying to improve on what I did, the “brains” of it appears in Paul’s thread as the testbed for the sketch I wrote for his applications.

I’m not a specialist, I was lucky enough to start programming at University in 1976 (COBOL, Punch Cards) and got a Sinclair Spectrum when they came out. A little more, in FORTRAN in the late 70’s, I did some programming for my Thesis in 1982, and wrote a suite of lab/machine control programs in 1985/6, all in versions of HP Basic & HPGL, but since then, really nothing apart from fighting MS Dos & Windows, & playing with Excel as a user.

So I guess I have some computing background, but it is not at all necessary to get useful stuff out of Arduinos. There is an excellent support community, and there are some fiendishly clever folks out there, and there is a lot of open source programming available to download, edit, and use.

Please feel free to contribute, the more the merrier.

Back soon with some more bits & pieces, and, as I know we like pictures, some photos.

Atb
Simon
 
Last edited:

Focalplane

Western Thunderer
May I add my support for this thread. I am not a programmer though I did try some Basic in the early 1970s on an IBM PC. I like to design things but don't have the know how to add the electronics to them. This is where Simon came into the equation. I have all these bits of hardware waiting to be connected and a "sketch" which is Arduino-speak for a program. I have looked at the sketch and Simon's comments and it does seem to be simple and straightforward. Seem is my word for "if it works then it must be OK" and Simon's brief youtube videos show that it should and will work when I gain enough courage to solder everything together. Though I still have some doubts. . . . about my capabilities.

I will be showing progress on Moor Street but can also add comments here if they help the greater good.

I also have a 12 year old step grand daughter who is keen to "make things" as part of her D&T classes. She will be visiting the railway room in July so I hope to have some stimulating results to demonstrate to her and her parents (both teachers). I stumbled on a quote from Plato the other day:

"Do not train a child to learn by force or harshness; but direct them to it by what amuses their minds, so that you may be better able to discover with accuracy the peculiar bent of the genius of each"
 

ceejaydee

Western Thunderer
This will be interesting to me as I own and have tinkered a little with a Raspberry Pi but don't know much about the Ardunio :thumbs:
 
Last edited:

simond

Western Thunderer
Photos as promised.

image.jpg

Top left, a Nano as received in an anti-static bag.

Lower left, a Nano, sadly not at all well, had an “oops” with that one.

Right, Pro Mini, with attached USB interface.

Then, something a little more esoteric, last summer I wondered if I could build a driver to replace a non-functional autopilot for a small boat. I got some way down the line but kind-of wobbled to a halt. Anyway, this shows some of the bits and pieces you can interface with an Arduino, in this case, a Mega.

image.jpg

At the top, an LCD display, the Arduino Mega in the middle, and lower left, a GPS receiver, (red board) and its active aerial, (white square thing) and lower right, a fluxgate compass. Just off the top of the picture is a PCB with 5 buttons, and a relay board with two SPCO relays.

I must get around to playing with that again, it was quite promising.

Now, talking of relays...

image.jpg

This is a board with 16 SPCO relays, addressed by the connector central left. The relays can each handle 10A at 250V so a little driver can control great big hefty stuff, if a relay is the appropriate tool for the job. I bought these for a project, to switch points on my Porth Dinllaen locoshed layout, until I discovered the relays took more current than the Tortoises did. This little lot was controlled by a Nano, which plugs into the board on the left, and the Nano was in turn controlled by a Mega, which I have fitted inside the control panel of the layout.

image.jpg

Sorry, rather scruffy, work in progress.

Inside...

image.jpg

The reason for this project is that I wanted to have variable lighting in the buildings, and there were not enough wires within the 2 metre 25-way cable which connects the layout to the panel to achieve that, switch 8 point motors, and control the turntable. So I looked for a means of controlling everything via a bus, which I managed to achieve, and break, on the same day :(.

So, whilst there are a couple of issues, the bones of the system work, and I need to finish it off. Paul’s traverser was an ideal “get yer mojo back” project, as this one had become a bit burdensome, anyway, here’s what I built to replace the 16 relay board above. I was cat-got-the-cream pleased with myself when I made this bit work.

image.jpg

The Nano is plugged in lower left, the smaller board to its left is a voltage regulator to provide 5V for the whole system from the rectified 12V supply coming in through the red & black wires. The two 14 pin chips are “Not Gates” meaning that if the input is high, the output is low, and vice versa. They then feed the four 20- pin chips which are dual H bridge motor drivers, they in turn feed a bridge rectifier and a two-colour led for each of the 8 outputs, which are connected by the pink and white twisted pairs to the Tortoises on the layout.

The turntable controller is this bit

image.jpg

Which those of you following Paul’s thread will have already seen. Again, a Nano, close coupled to an A4988 stepper driver.

The stepper driver is a handy bit of kit, as you arrange for the Arduino to issue step & direction commands, and it looks after the actual outputs to the stepper motor. It also incorporates “microstepping”, a reset, sleep, and enable inputs. Handily, all the inputs are on one side, which means that it’s easy to connect using veroboard.

I get bits from various sources, I’ve found Hobbytronics HobbyTronics | Hobby Electronics Components Supplier for your hobby and education needs to be helpful, with rapid online ordering and reliable delivery, their prices are competitive for some things, less so for others, so do shop around. Usual disclaimers, of course.

These sockets are very useful, to allow the boards to be plugged into a veroboard carrier.

image.jpg

My next step in the project is to replace the red bits with a purpose made PCB, incorporating the mosfets in the bag

image.jpg

I’ll continue to post progress on the control panel project as it develops, meanwhile, anybody with something to add, please do!

Any questions, I’ll try to answer, but, please, I’m a hobby programmer, not a pro!

Atb
Simon
 

Focalplane

Western Thunderer
Here in France I can get most bits from amazon.fr but also the co.uk branch because sometimes it seems to work better that way, please don’t ask me why. There is an electronics parts shop in Montpellier but at the end of April when I went there they had closed for 3 days to celebrate May Day. Karl Marx would be proud.

I do miss the hands on of visiting Radio Shack type shops, an on line photo of a micro switch gives you little idea of its size, build quality, etc.
 

simond

Western Thunderer
Phil

If by “computer” you mean “microprocessor”, Yes.

But to be clear, once the Arduino is programmed, it doesn’t need to be attached to the laptop, it just becomes an automaton, which in this case has a couple of operator buttons and drives a stepper motor.

The approach here is to use a stepper motor to move the traverse table - I guess your laser uses belts (my cheapo one & the Ultimaker 3D printer at work does) to move the head but where a higher force solution is required, the stepper turns a leadscrew, and a ball-nut is driven along it. There’s a photo in Paul’s thread.

Once the processor “knows” where the ends are, ie where the tracks are lined up, it can repeatedly move from one to the other.

It is also possible to incorporate an acceleration profile so it doesn’t start or stop suddenly.

And Arduinos, I should have said earlier, are cheap. Clones are less than a fiver each, genuine ones might be as much as £35 for a Mega, rather less for a Nano.

Does this answer your question?
Atb
Simon
 

michael080

Western Thunderer
Simon,

nice projects! I solved a few model railways related problems with Arduinos. They are easy to program and live in a perfect eco-system.
I discovered
MKS TMC2100 Stepper Motor Driver Ultra-silent With Heatsink Ramps | eBay
these stepper motor driver circuits some time ago that are far superior to the A4988. The have a better efficiency, hi res micro stepping and a lot of other fancy features. That all for about the same price.
Generally, the TMC appear to run the motors with less noise, indicating that their current chopping strategy is better than competition.

Michael
 
Last edited:

Focalplane

Western Thunderer
Here's the stepper motor for the traverser(s), copied from my Moor Street tgread. The travel on the linear screw is 100mm, I need 85mm for the traverser:

index.php
 

simond

Western Thunderer

simond

Western Thunderer
Phil's question prompted me to think that perhaps I've dived a bit deep at the beginning, so I will try to post a short "start at the beginning" overview over the weekend.

Hopefully, it will provide the impetus for others to have a go.

atb
Simon
 
Phil's question prompted me to think that perhaps I've dived a bit deep at the beginning, so I will try to post a short "start at the beginning" overview over the weekend.

Hopefully, it will provide the impetus for others to have a go.

atb
Simon
Simon
Thanks very much for this thread. A "start at the beginning" would be excellent - I can just see you in the distance but not quite over the horizon
Ralph
 

simond

Western Thunderer
In the beginning...

The Arduino board comprises a PCB, a microprocessor, a USB socket, and a bunch of stuff that doesn’t concern anyone who wants only to use it. The actual circuits and the architecture are available via the Arduino website, for anyone who’s interested.

WHY WOULD I WANT ONE?

The Arduino (and the similar alternatives) allows the user to create a custom electro-mechanical system with predictable behaviour. This can be automatic or semi-automatic as required and is often cheaper than commercial alternatives. You will have to program it, but it would be customised to what you want it to do. We are all familiar with automatic washing machines, effectively an Arduino could be coupled up to the various motors, pumps, heaters and valves in a washing machine, and could control them. You could then write your own, specific, wash cycle. What fun!

More pertinently, they have lots of relevance to model railways.

EXAMPLES

A turntable that goes to the angular positions of the entry roads. Programmable to suit the layout rather than fixed intervals. Reprogrammable if the layout is changed.

Traversers - where we came in. Could be “scenic”, like Paul’s, or multi-road for a fiddle yard.

Automatic route setting.

Point & signal control - my example above, controlling Tortoises, but Arduinos also have the capability to control standard R/C servos so offer an alternative to the commercial systems.

Scenic effects - servo controlled crossing gates, loco shed doors, etc. Can be programmed to operate in a specific order, as is typically required for oblique crossings.

Scenic effects - control of lighting digitally, ie turning LEDs on or off. But also, via the ability to output “PWM” - pulse width modulation - a means of controlling brightness. Traffic lights with prototypical sequences are entirely possible., but so are stage effects - sunrise, or twilight, with dimming sky and programmed house and street lights as required.

Signalling - the Arduino can control the servos or Tortoises, but it can also offer interlocking to prevent conflicting routes being set.

DCC interface - the Arduino can be interfaced with the DCC system, thus allowing control of any of the above through most DCC handsets. It’s probably also possible to do the opposite, control the DCC from the Arduino, but I’ve not seen that done.



CONNECTIONS

The boards are typically supplied with a couple of strips of plastic through which are embedded some pins, on a 0.1” pitch - this quasi-imperial spacing is typical of and standard in the electronics industry. The pins are normally soldered to the board, and provide a convenient way of connecting to the inputs and outputs, and of supporting the smaller boards.

This plug-and-socket arrangement allows unplugging of the board for replacement if you too have an “oops”, taking the board out of the project to test it if you think you might have killed it, testing the wiring without the board in place, or swapping boards between projects.

Some boards are supplied with the pins pre-soldered, you can also buy pre-assembled strips of mating sockets which can be soldered to stripboard, Veroboard, custom PCBs, or the Arduino itself. A further alternative is a strip of sockets with extra-long pins, which can be substituted for the standard pin-strip, and which then offers pins on one side, and sockets on the other.

This kind of structure lends itself to the creation of “shields” which are special purpose PCBs with matching pin arrangements, which can then plug directly into an Arduino and offer eg, a screen with buttons, a USB data storage socket, a MIDI interface or many others. Lots on offer from commercial sources. Look on the w3.

A wide range of suppliers offer wires with crimped terminals which suit the pins & sockets on the Arduino. It’s also possible to buy strips of pins, and sockets, the crimping tool, and a wide range of plastic receptacles into which they clip, allowing the assembly of custom connectors.

Many hobbyists use “Breadboard” to try out the hardware for new projects. Probably worth buying a good quality version, as the bad ones are worse than useless. I don’t have one, but if I get a good one, I’ll let you know. MrD-the-younger bought some cheap & nasty ones for a synth project he was playing with, there was some frustration...


More soon.
Atb
Simon
 

simond

Western Thunderer
POWER SUPPLY

Arduinos run off 3.3 or 5 volts. The majority are 5V, and their input will accept up t9 9V. I haven’t bothered with the 3.3V versions, but they would be useful for projects that run off Lithium batteries.

Nearly all versions are equipped with a USB socket, and when they are plugged into a computer, they will run off the 5V supply through the USB lead.

I believe all versions have 3.3 & 5 V stabilised outputs, which can be used to run sensors, peripheral boards, shields, etc. These go live when the Arduino is powered up.

Arduino Mega boards have a barrel socket next to their USB socket. It’s visible in my control panel and autopilot projects above.

So you can power your project from 5-9V from batteries, a wall-wart (phone charger thing), a usb charger, a computer, a purpose-made supply, or one of these beasties:


3A943F92-0BA2-4BA4-878F-BA73C625EB42.jpeg

Sorry, that’s huge... this is a 7805 regulator. It can accept from about 8V to over 30V input and gives 5V out. You can therefore add one to your Arduino project, and just power everything from the layout’s “12V DC” supply . (It’s in inverted commas because it’s pretty much never actually 12V) I do this, using a bench power supply giving around 16V for my Lenz DCC, and simply run my Arduino projects off that. I tend to arrange things so that I can attach the external supply once I’ve got the program working. It doesn’t help to have two parallel power supplies when things are not working properly.

A word about servos. Don’t supply the servo 6V from the Arduino 5V out. It will work, if you have one servo with no load, but as soon as you have more, or any load on them, the servos will pull more current than the Arduino can supply, and it will “brown out” and do strange things... and may be damaged. A brown-out is like a black-out but not as dark. Typically things still work, but not as intended. Servos can pull quite a bit of current through their supply lines, so make sure you provide enough amps for them. The Arduino can easily supply the signal that they require.


COMPUTERS

You’ll need one. It needs a USB socket, screen & keyboard, and ideally, an internet connection. I still use the offline IDE (Integrated Development Environment, the “App” in which you program, and through which you connect to, and monitor your Arduino) but there is an online option for those who prefer. I don’t think there are any limitations to operating system, Windows, Apple and Linux are supported. You could even program your Arduino using a Raspberry Pi, if you’re into self-mortification.

As I said earlier, once you’ve convinced yourself that the project does what you want, you can then disconnect it from the computer, and run it without the USB connection.

If your project requires a means of informing you of something, there is a wide range of screens and displays available, which will interface to the Arduino.

Here endeth...

More soon
Simon
 

BrushType4

Western Thunderer
Simon, I need to switch my laser extraction on and off automatically to save doing it myself.

What would I need to switch a 240 volt supply?
 

simond

Western Thunderer
Hi Phil,

Bit of a “piece of string” question really, because I don’t know the load that your fan will take, nor do I know what outputs etc your computer & laser have, and additionally, there’s always the question of mains safety.

Your laser is really new iirc. I suggest your first port of call should be the supplier, to ask if it doesn’t have fan control built in to the control board - my Smoothie board does, and it’s an aftermarket fix for cheapo Chinese lasers amongst other things - so I’d hope & expect that it’s included in yours. Before modifying your laser, you might want to consider any warranty implications too.

If there isn’t a fan control built in, there may be a logic output available, and this could operate the relays I mentioned earlier which will certainly manage 10A at 240V, so would offer a potential solution. You could operate the relay directly, or via an Arduino which could then incorporate a delay before it switched off.

If there isn’t a logic output that could be used, you’d need to get inventive: two options spring to mind - you could simply fit an extra microswitch that detected the lid being closed*, and that could easily operate the fan, possibly directly, or via a relay or Arduino and relay (directly has the disadvantage of having to put extra mains wiring into the cabinet of your laser), or you could fit some kind of detector to trigger the relay once the head of the laser has moved away from “home”, using a proximity switch or light beam of some sort.

* your laser certainly has microswitches or magnetic switches that prevent the laser firing if the door is open. I would not recommend using this circuit - leave it well alone - your sight might depend on it. Fit an extra switch if you go down this route.

I guess you could also build a “smoke detector” using a led and a phototransistor, but it sounds unnecessarily complicated to me!

Obviously, given that they have 240V feeds, the relays need to be enclosed somehow, so you might build a separate housing, or fit them within the control box of the laser, with an extra socket for the fan to plug into. Something like this would do.
https://www.amazon.co.uk/ARCELI-KY-...0FGFKAH5913&psc=1&refRID=69EG1CNVF0FGFKAH5913
Other suppliers exist, of course.

If you are using a relay, with or without an Arduino, you’ll need to consider a power supply for it, too.

Hope this gives you food for thought, but definitely, Monday morning, speak to your supplier!

Atb
Simon
 

simond

Western Thunderer
SOFTWARE

Is written in a version of C & C++, with some restrictions. I lifted this statement from the Arduino website;

“Arduino is c/c++, so you can read books on c++ and use most of what you learn that is language core. My tip: don't read, but do. If you find yourself with a question just google it, if that does not help, ask here”. (“here” being the Arduino forum, but, hey, try here, as in here, and I’ll try to help!)

C is actually rather like BASIC - there is a rigidly enforced program structure, however, there are no line numbers.

Programs are called “sketches” in Arduino-speak.

“Grammar”, and specifically, punctuation, are hyper-important. If it’s wrong, the compiler will give you an error message, which, in my experience, will bear little relevance to the missing “;” that you have to put at the end of each line.

The program structure requires a “setup” and a “loop”. It’s a good idea to have a “preamble” or “intro” first, in order to specify what the program does, and what the hardware connections are - and maybe a link or two to the wiring diagram, and the instructions for any specific hardware. You can basically put anything you like in here. Entering “//“ anywhere in a line makes all the characters after it into “comments” turns the typeface grey, and ensures that the compiler ignores them.

Entering “/*” does the same for a block of lines, which is ended by “*/“

It’s a great idea to mention stuff like wire colours and functions in the comments!

INPUT & OUTPUT

Kind-of why we’re here. Like the music in the Blues Brothers, we have “both kinds”. In this case, not “Country & Western”, but “Digital & Analog”.

On a Nano, pins A1 to A7 are analog, and can input different signal levels, such as a potentiometer position, or a phototransistor/photodiode (like I use to detect my turntable to set the zero position). They also allow digital, ie on-off input and output.

PWM output, sort of quasi-analog output, is available on a selection of pins; 3, 5, 6, 9, 10, and 11, on most Arduinos, and quite a few more on a Mega.

Digital I/O is available on pins 2 to 13. These are effectively on/off and can accept switch / button inputs, and drive things like lights, LEDs, relays, and other things that are either on, or off.

STRUCTURE

I’m not going to get into programming, but will at least mention the main bits: there is a book about Arduinos and dummies...

For & while loops - allow repeating processes until some limit is reached.
If / then / else / elseif - allow decisions and actions based on values of variables

There are lots of other more esoteric options, but I reckon those will cover 95% of everything that anyone does. (Brave statement!!!)

Maths - just about anything you can do on a calculator or on excel...

Variables - oooh, a little more complicated; you can have integers (ie whole numbers between -32,768 to 32,767 ), long ( lots bigger) & float(floating decimal point) - you only care if you’re strapped for speed (use integers) or memory (ditto) or you need accuracy (float) or big numbers (long).

Define your variables in the setup, along with the the intended functions of the input & output pins.



Rather than rabbiting on, I think it’ll be easier to try to answer questions from here on in, but I will start to post about my turntable, points and lights dimming project.

Best
Simon
 
Top