Jump to content
 

Arduino Applications and Programs


Simond
 Share

Recommended Posts

  • RMweb Gold
2 hours ago, -missy- said:

Hello.

 

This is a bit of a plea for help! I have been building a machine to cut my own gears. It uses 2 stepper motors to drive the 2 axis I need.

 

image.png.0cc50d114cddb6ea063ab1a0d5a546b4.png

 

The idea was to use an arduino to drive the 2 motors. They need to drive one motor at a set ratio to the other which is defined by the number of required teeth of the gear.

 

image.png.95321c789d8fff36f5b477938f5f881d.png

 

The thing is, I have been working on trying to work out the arduino drive of the machine for a few months now and to be honest, I have got nowhere after trying out several different types of drive etc. I have limited knowledge of coding and this is stressing me out!

 

Is there anyone able and willing to help me out or point me in the right direction?

 

Thanks

 

Missy.

 

Stepper motors only move in steps ideally if the one shaft drove another throught a 20:1 ration

Then each motor could do the same no of steps per second and it would work with the same steps being sent to each motor.

However if you need to have the difference controlled by the arduino there is no easy way to have them running at the same time. but if the steps are small enough they can be run it turn.

 so  motor 1 tunrs 20 steps to motor 2 1 step.

Assuming motor 1drives the workpiece and motor2 drives the cutter and the cutter does one turn at each position create a loop

 

 

int motor1stepcount=0;

for (int motor1srepcount=0, motor1stepcount<20, motor1tepcountcount++?) {

//code to step motor 1 18degs

// code to step  motor 2 one revolution

}

 

this will work with a shaped cutter which can cut the tooth shape . It may need to do a number of cuts to reach full depth  assume it take 5 steps to reach full depth the code becomes

 

Int depthcount=0

While (depthcount<5){

  int motor1stepcount=0;

  for (int motor1srepcount=0, motor1stepcount<20, motor1tepcountcount++?) {

     //code to step motor 1 18degs

     // code to step  motor 2 one revolution

  }

  // code to move cutter one step deeper

  depthcount++;

}

 

This is intended to work with a cutter that has a gap to allow the workpiece to move to the next step without contact.  If you are cutting skewed teeth it would be slightly different 

 

Don 

  • Craftsmanship/clever 1
Link to post
Share on other sites

Hi Julia,

 

Driving tow or more steppers simultaneously is not that hard; after all your friendly CNC machine or extrusion 3D printer manages it.  For these there as to be X steps on one motor to Y steps on the where X and Y are unrelated.  It is errors in the timing of the steps that causes errors in the position of the cutter/extruder and hence the accuracy of the workpiece.

 

In your case the two step rates are related by a simple integer N. In the simplest case where the step angles of the motors is the same and the motors have no gearing (or the same gearing) then N is the number of teeth.

The hob stepper is the faster motor and its step rate can be set to give the required cutter speed. The workpiece is stepped once each N steps of the hob. The  workpiece will have an error in position of -1/2 to +1/2 step so it is necessary to make the steps as small as possible so you must count steps not revolutions of the hob. If this does not give enough accuracy then you will need to micro-step. Alternatively gearing the steppers  increases the number of steps and thus reduces their size.

  

 

Driving a stepper with an Arduino is easy enough but will need an interface circuit as the Arduino cannot deliver the required current.  The circuit depends on the particular stepper motors and this impacts on the Arduino code.  Start with a simple sketch to step the hob motor with a timer or delay to control its speed. when this is working then add code to count its steps up to some hard-coded value of N and use this to step the workpiece motor. Then try it with a different value of N.  At this stage you should be able to decide  how much you want/need to optimise the code you have.

 

Regards Roger

 

 

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

Ok, this is a new challenge..  I tried to post this yesterday, but finger trouble intervened.

 

Just to understand the machine you have, there is a stepper controlling the horizontal spindle on the left, on which I guess you mount your blank and presumably one to control the main horizontal lead screw?  Is there a stepper for the vertical lead screw?  And presumably the cutter is mounted in the ER collet on the vertical feed?  So that is powered by a motor for the cutter?

 

Next, are you cutting a worm wheel, a helical gear or spur gears?

 

And further, please can you post pictures of the hob and the gear you’re trying to cut.

 

I really don’t think a stepper will be suitable for driving the cutter spindle.  I’d be more than happy to be proven wrong!  
 

Stepper drivers/controllers available on eBay, at Hobbytronics, and others.  “A4988” will get you a basic one (which will do plenty!) though I tend to view them as somewhat consumable, like fuses, so buy a couple more than you think you’ll need!  In particular, a work test-rig project required a motor to drive a large disc, which acted as a flywheel, and which got expensive.  It also yielded almost no useful data...


atb

Simon

 

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

  • 2 weeks later...

Morning everyone

 

I'm looking to build an auto shuttle with Arduino, purely on a cost basis compared with an s88 board.  It'll be run using the shuttle feature of an ECoS (don't have yet but plan to buy).

Looking to buy an Arduino Uno from AliExpress, along with some dupont cables.

 

The videos I've seen refers to there being 16 ports available on an Uno but I only count 13.  I read further back in the thread that the analogue ports on the Uno can be used but that bumps the port numbers up to 19.  I'm not really sure how there's 16 ports.

The method uses reed switches.  Are there any ones that are recommended to use?

 

And for this, I don't need a breadboard or anything?

 

Finally, I am no good with schematic diagrams.

 

Does each end of the reed switch go into the same port on the Uno? (there would be two switches for the shuttle)
And then the other reed switch will go into another port?

 

I run an accessory bus under my layout, which feeds point motors (seep motors using DC + toggle switches) and LED signals (using their own control boards / sensors).  Can I tap into this 12v (or maybe it's 16v) supply to power the Auduino?  I guess not.  Is there some sort of converter I can get to put between them or should I just get a separate 5v supply?  If I added other Auduinos in the future, could I run these from that same power supply?

 

I understand I connect the s88 port from the back of the ECoS to the Auduino?  Is there a cable for this, or it is a case of some duponts?  If the latter, does it matter on the order I plug them in?

 

Finally, the "ground" thing.  That's 0v, correct?  Where do I connect this to?  Would it be to one of the power bus wires under my layout?  How do I know which one? (for added info, don't really know how to use a multimeter as I've not really needed to use it before, but do have one).

 

Thanks

Edited by Sir TophamHatt
Link to post
Share on other sites

  • RMweb Gold

You are obviously a real novice and this is not the place for a proper tutorial so I would look for some tutorials on getting started with Arduinos.

However a few points

The terminal points on an Arduino are referred to as Pins.  Some are Digital only, Some are Analogue and most of them can be used as digital instead. How the pins are used whether input or output is determined by the code you write and upload to the processor on the Arduino. 

If you really need a lot of pins the Mega has a lot more pins.

A digital pin is either High or Low  Low is 0v High is 5v on a 5v Arduino. When used a input the pin is expecting either a voltage applied or 0v applied . Depending on which way you have set the logic. You would never connected both ends of a switch to a Pin it would do nothing. One end of the reed switch could be connected to the pin the other to either the 5v or the 0v  depending on how the pin is set there may need to be resistances in the circuit.

As for the breadboard  well you may need something to connect up external components while you test and develop your code.  Ifyou are following someone elses project they may be able to supply PCBs.

I would suggest you follow some basic tutorials learn how they work and how to read schematics. You will also need to understand a bit of the C language to write or adapt code. Otherwise I think you would be better off buying an autoshuttle from a supplier.

 

Don   

  • Agree 2
Link to post
Share on other sites

1 hour ago, Sir TophamHatt said:

Morning everyone

 

I'm looking to build an auto shuttle with Arduino, purely on a cost basis compared with an s88 board.  It'll be run using the shuttle feature of an ECoS (don't have yet but plan to buy).

Looking to buy an Arduino Uno from AliExpress, along with some dupont cables.

 

The videos I've seen refers to there being 16 ports available on an Uno but I only count 13.  I read further back in the thread that the analogue ports on the Uno can be used but that bumps the port numbers up to 19.  I'm not really sure how there's 16 ports.

The method uses reed switches.  Are there any ones that are recommended to use?

 

And for this, I don't need a breadboard or anything?

 

Finally, I am no good with schematic diagrams.

 

Does each end of the reed switch go into the same port on the Uno? (there would be two switches for the shuttle)
And then the other reed switch will go into another port?

 

I run an accessory bus under my layout, which feeds point motors (seep motors using DC + toggle switches) and LED signals (using their own control boards / sensors).  Can I tap into this 12v (or maybe it's 16v) supply to power the Auduino?  I guess not.  Is there some sort of converter I can get to put between them or should I just get a separate 5v supply?  If I added other Auduinos in the future, could I run these from that same power supply?

 

I understand I connect the s88 port from the back of the ECoS to the Auduino?  Is there a cable for this, or it is a case of some duponts?  If the latter, does it matter on the order I plug them in?

 

Finally, the "ground" thing.  That's 0v, correct?  Where do I connect this to?  Would it be to one of the power bus wires under my layout?  How do I know which one? (for added info, don't really know how to use a multimeter as I've not really needed to use it before, but do have one).

 

Thanks

 

I think you're heading to a crash  ( " I'm no good with schematic diagrams" ,   "dont really know how to use a multimeter" and others ). 

 

However,  if wanting to learn Arduino, buy a beginner's box of bits from somewhere like Elegoo for about £30.  That will have a Uno, breadboard, load of cables, various components and accessories, and a CD containing a load of lessons/tutorials to follow to learn the basics of how it works.  

 

Connecting to the s88 port:  Unless you've code from somewhere to generate valid s88 messages, you'll get nowhere.  Its not just "connect a few wires".    There's scope to destroy a £600 command station here.  

 

 

 

  • Agree 2
Link to post
Share on other sites

48 minutes ago, Donw said:

Otherwise I think you would be better off buying an autoshuttle from a supplier.


I thought this but the Lenz BM1 didn't seem to work when I rigged a test line.

I then found an s88 board which seems to be the thing I need but at £60 odd (or £80 for the newer version!), that's quite a lot.

I think my research let me to some s88 boards that are about £40 and I think someone makes some for around the same price out of the Auduino but when I could follow a tutorial and pay less than £15 for everything, I'm obviously interested.

 

I do have a tutorial / diagram to follow and it seems fairly simple but the above questions are just the missing pieces to the build :P @RudyB may be able to help?

 

I'll take a look at the starter kit but would be great to learn from a model rail point of view.

Edited by Sir TophamHatt
Link to post
Share on other sites

I tend to agree with the advice above.  You need to walk before running, what you’re trying to do is not intrinsically difficult, but it’s far beyond basic.  You’ll end up frustrated, and worse off.

 

if you want to learn Arduino, please do, and join the Merry throng who do enjoy the capabilities it offers, but get some experience with simple stuff first.  Make a servo open a gate, flash a few leds, use buttons, switches and pots as inputs, and break the cheap stuff before connecting wires to expensive things!


goodluck

Simon

 

  • Agree 2
Link to post
Share on other sites

1 hour ago, Simond said:

I tend to agree with the advice above.  You need to walk before running, what you’re trying to do is not intrinsically difficult, but it’s far beyond basic.  You’ll end up frustrated, and worse off.

 

if you want to learn Arduino, please do, and join the Merry throng who do enjoy the capabilities it offers, but get some experience with simple stuff first.  Make a servo open a gate, flash a few leds, use buttons, switches and pots as inputs, and break the cheap stuff before connecting wires to expensive things!


goodluck

Simon

 

That's what I intend to do, before moving onto a traverser.......

Link to post
Share on other sites

53 minutes ago, leopardml2341 said:

That's what I intend to do, before moving onto a traverser.......

 

Heres my current O Gauge project. DCC Controlled by Arduino Nano with A4988 Stepper Driver and DCC optically isolated interface.

 

 

 

  • Like 2
  • Thanks 1
Link to post
Share on other sites

  • RMweb Premium
On 09/01/2021 at 17:38, tender said:

 

Heres my current O Gauge project. DCC Controlled by Arduino Nano with A4988 Stepper Driver and DCC optically isolated interface.

 

 

 

Here's my non Arduino DCC controlled traverser I made a few years ago:

1010242842_detailview.jpg.e7de7dc6bc478d85ae3528e696149652.jpg

 

Controlled by this:

underside.jpg.374f400e8316d85e1d77a87a435d3f8e.jpg

 

It's actually a dismantled Traintronics point motor & decoder, using the motor and some of the gears.

However it is very noisy and I would like to replace it with a nice quiet brushless motor, which I have a few.

 

So has anybody used a brushless motor in a Railway Project like this?

I have a couple of ex VHS recorder motors, one is a slow revving capstan motor which is 24 pole 3 phase (with a 3.5mm shaft and a pulley for a belt) and works off 12v, the other is a smaller 12 pole 3 phase and is also12v which is the head drum motor but needs some work to remove the head drum itself.

I also have a couple of 12v HDD motors, one has a star connection (4 wires) and the other a delta (3 wires).

I will use a Nano + some other bits, I've plenty of mosfets and hall devices to go with them.

 

 

  • Craftsmanship/clever 1
Link to post
Share on other sites

4 hours ago, Simond said:

Keith

 

I'd take the easy route and put a 4 wire stepper directly onto your leadscrew. 

 

atb

Simon

 

Or better still (if you want it really quiet) use a stepper with toothed belt and a TMC2208 driver chip.

 

IMG_0508.jpeg.313f69816ed770de71b1082d0ba6c4ba.jpeg

 

 

A big improvement on my original post above with the old A4988 driver.

  • Like 2
Link to post
Share on other sites

  • RMweb Premium
4 minutes ago, tender said:

 

Or better still (if you want it really quiet) use a stepper with toothed belt and a TMC2208 driver chip.

 

 

 

A big improvement on my original post above with the old A4988 driver.

That TMC 2208 looks useful.

I already have a couple of stepper motors, one with a matching toothed belt (from a printer)

 

 

  • Like 1
Link to post
Share on other sites

Just now, melmerby said:

That TMC 2208 looks useful.

I already have a couple of stepper motors, one with a matching toothed belt (from a printer)

 

 

Yeh, its a plug-in replacement for the A4988 apart from the direction which is reversed.

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

  • RMweb Premium

Our club layout and two others that I'm associated with use NCE equipment including the NCE Mini-Panels.

 

The Mini-Panel has a limit of 30 inputs each of which can be used to generate up to 4 dcc commands. Unfortunately the Mini-Panel appears to have been designed to work with push buttons thus requiring the use of 2 inputs per On-Off switch.

 

I've assembled an Arduino circuit that can read and act upon dcc commands sent via the accessory (or track) bus and was wondering if it was possible to effectively do the reverse i.e. produce an Arduino sketch that will ascertain whether the state of an On-Off switch has changed and send x number of pre-programmed dcc commands out on the accessory/track bus to be complied with (primarily) by accessories although doing similar with/for the occasional loco would be a bonus.

Link to post
Share on other sites

34 minutes ago, Ray H said:

Our club layout and two others that I'm associated with use NCE equipment including the NCE Mini-Panels.

 

The Mini-Panel has a limit of 30 inputs each of which can be used to generate up to 4 dcc commands. Unfortunately the Mini-Panel appears to have been designed to work with push buttons thus requiring the use of 2 inputs per On-Off switch.

 

I've assembled an Arduino circuit that can read and act upon dcc commands sent via the accessory (or track) bus and was wondering if it was possible to effectively do the reverse i.e. produce an Arduino sketch that will ascertain whether the state of an On-Off switch has changed and send x number of pre-programmed dcc commands out on the accessory/track bus to be complied with (primarily) by accessories although doing similar with/for the occasional loco would be a bonus.

 

I don't think you can use an Arduino to output commands directly to the Track/Accessory bus as it would be in conflict with the DCC command Station. You could theoretically program an arduino to output commands to the Cab Bus though in response to an input, although you will probably need some sort of interface (RS485 maybe for the NCE system). I'm sure i've seen something along these lines somewhere. A quick google might bring up something.

 

Try this:

 

https://mrrwa.org/2019/05/25/nce-cab-bus-supported/

 

Edited by tender
added link
  • Like 1
Link to post
Share on other sites

1 hour ago, Ray H said:

Our club layout and two others that I'm associated with use NCE equipment including the NCE Mini-Panels.

 

The Mini-Panel has a limit of 30 inputs each of which can be used to generate up to 4 dcc commands. Unfortunately the Mini-Panel appears to have been designed to work with push buttons thus requiring the use of 2 inputs per On-Off switch.

 

I've assembled an Arduino circuit that can read and act upon dcc commands sent via the accessory (or track) bus and was wondering if it was possible to effectively do the reverse i.e. produce an Arduino sketch that will ascertain whether the state of an On-Off switch has changed and send x number of pre-programmed dcc commands out on the accessory/track bus to be complied with (primarily) by accessories although doing similar with/for the occasional loco would be a bonus.

 

I'm fairly sure someone has published an Arduino sketch for putting commands onto the NCE Cab Bus.  So, could build a DIY equivalent to a MiniPanel where it did respond to a switch going to "off".  

 

Sticking with the NCE MiniPanel, it would be possible to build a processing unit which responded to the first "on" event in one way, and the second "on" event in a different way.  Thus a push button on the minipanel would be "first push = on,  second push = off" or whatever the processing unit was doing.   The question is where to insert the processing unit into the system.   The two easier places, to my mind, are either on the Cab Bus, or on the computer connection to the NCE system.    For the latter, its a fairly trivial task to setup the rules in JMRI, and as JMRI will run on a £40 Raspberry PI computer, its also a cheap option.   

 

 

- Nigel  

 

Link to post
Share on other sites

  • RMweb Gold

Nigel suggestion of using JMRI  with a Pi is probably the simplest answer. 

 

There is a way of inputting commands directly into the track bus. A scheme was developed by Julian Coles amember of MREG . It works by interrupting the DCC signal to insert properly formatted DCC comands.  He used a PIC microcontroller coded in assembler. While it may be possible to use an Arduino the coding would be difficult. Julian has been kind enough to post me a couple of boards to try out. My intention is to use a lever frame with micro switches rather than a panel. Things like this are not really suited to club layouts where on going support is problematic. The JMRI solution is better suited as there is some on going support from the JMRI community.

 

Don 

Link to post
Share on other sites

  • RMweb Premium

Thanks chaps. I do sometimes get my kn*ckers in a twist! The Arduino sketch we're using is picking the data it needs off the accessory/track bus. I'd completely forgot that the Mini-Panel outputs to the Control Bus so apologies for that.

 

I'll take a look at the interface in the link above.

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...