Jump to content
 

Arduino Applications and Programs


Simond
 Share

Recommended Posts

Yes - assuming you do mean the IC2 connection, I think this is what the MegaPoints system uses to connect multiple ATMega / Arduino modules with four wires (two being the power rails). The 'siding ladder' video showing Arduino control posted by Simon earlier in this thread was Dave Fenton's prototype for MegaPoints.

 

BTW - I am not trying to promote MegaPoints as such (too expensive for me), but I think it's a good example of what can be achieved for point/signal/crossing control using Arduino. Dave mentions on his site that he's sold 500 boards in one year, showing the rising demand for servo-based point controllers.

Link to post
Share on other sites

  • 2 weeks later...

I have nearly finished my first Arduino project :yahoo: , not counting the many, many tutorials with blinking LEDs.

It is a train speed measuring unit.  Yes, I know there are several of these available but it is just a simple project to see how I go.

Just need to make a couple of mounts for the detectors.

 

Uses IR reflection as detectors/sensors, a pro mini as the CPU, 2 line LCD for output and a 5V regulator.  Development was done with a Uno.

Truely thankful for the cheap electronic modules available from China as it certainly speeds up construction and of course keeps the cost down.  I spent more on the hardware side (plastic case, power connectors, sensor connectors) than the electronics stuff.  The raw cost would be about 10 quid for the major items.  Making it pretty would be at least the same again.

 

Used EEPROM CVs to store the scale (max 1:500), distance between detectors (max 2000mm) and output units (kph or mph).  These can be changed at any idle time using a few push buttons.  Max values can be easily changed in code.  The unit can work from either direction through the IR gates.

 

Was enjoyable, mostly, as I came to terms with the requirements for LCD, strings and C++ math.  The math and units seem rather clumsy.

 

Now am onto making my PECO turntable operational.  Most of the code written, just into debugging.  Using some of the coding I made for the speed unit, especially for editing CVs, adding editing and deleting tracks.  For this project I am going to use a 4 line LCD on I2C, what a struggle to get the right setup for the interface, and an Adafruit motor shield for the stepper motor.

Algorithm for selecting which direction to turn and then how far to move was a right pain, kept making small mistakes (really a bummer getting senile).

After the code, comes the mechanics. :O

 

Regards,

CFJ

  • Like 2
Link to post
Share on other sites

  • 1 month later...

Currently working on my turntable code.

I have a problem in the Ardafruit motor library code for V2 motor shield.

Problem is related to using microstepping and errors in positioning depending on how many full steps are requested.  The worst case is trying for a full rotation, for my 200 step motor calling 1 * 200 steps results in one very accurate rotation but if I do it as 200 * 1step I get 2 complete rotations.  4 * 90degree (50 steps) rotations returns 208 steps, an 8 step overshoot.

If the number of steps requested is a multiple of 4 (200,100,80,....4) then all is ok.  Any other numbers of steps and you get a bonus of 1 to 2 steps for each call.

 

Anyone else getting the same effect?

 

Delete the problem bit of library code and it seems to work perfectly.  A call of 200 * 1step now gives a single accurate rotation. Can't see any use for the problem bit of code; seems to be trying to capture an impossible error (badly).

 

Regards,

CFJ

Link to post
Share on other sites

I would stick with what works, CFJ, since you're coding in a pretty controlled environment. In the worst case, you just put the code back in, assuming you keep a backup, and work out plan B.

Have you asked Adafruit support about this? They seem quite helpful: https://forums.adafruit.com/viewtopic.php?f=31&t=41608

 

Look forward to seeing your progress!

 

Alan

Link to post
Share on other sites

Currently working on my turntable code.

I have a problem in the Ardafruit motor library code for V2 motor shield.

Problem is related to using microstepping and errors in positioning depending on how many full steps are requested.  The worst case is trying for a full rotation, for my 200 step motor calling 1 * 200 steps results in one very accurate rotation but if I do it as 200 * 1step I get 2 complete rotations.  4 * 90degree (50 steps) rotations returns 208 steps, an 8 step overshoot.

If the number of steps requested is a multiple of 4 (200,100,80,....4) then all is ok.  Any other numbers of steps and you get a bonus of 1 to 2 steps for each call.

 

Anyone else getting the same effect?

 

Delete the problem bit of library code and it seems to work perfectly.  A call of 200 * 1step now gives a single accurate rotation. Can't see any use for the problem bit of code; seems to be trying to capture an impossible error (badly).

 

Regards,

CFJ

CFJ-

 

I have not had any problems with my AdaFruit V2 code.  Check out the topic on DCC Controlled Peco Turntable. 

http://www.rmweb.co.uk/community/index.php?/topic/78578-dcc-controlled-peco-turntable-project/

 

The change I made to my table was to put in a 50:1 gearbox to get more torque, but the resolution is great.  I have run the table for hours with multiple operators and the resolution stays 1:1.  Check out my code.  I did switch from microstep to interleave as I didn't need that many steps.  The acceleration and speed controls are great, the torque is fine and I am very happy with the result.  Perhaps your code is calling the target position more than once or you are calling "go to" rather than "target".

 

-Eric

Link to post
Share on other sites

CFJ-

 

I have not had any problems with my AdaFruit V2 code.  Check out the topic on DCC Controlled Peco Turntable. 

http://www.rmweb.co.uk/community/index.php?/topic/78578-dcc-controlled-peco-turntable-project/

 

The change I made to my table was to put in a 50:1 gearbox to get more torque, but the resolution is great.  I have run the table for hours with multiple operators and the resolution stays 1:1.  Check out my code.  I did switch from microstep to interleave as I didn't need that many steps.  The acceleration and speed controls are great, the torque is fine and I am very happy with the result.  Perhaps your code is calling the target position more than once or you are calling "go to" rather than "target".

 

-Eric

I didn't have any problems either just shuffling back and forth between fixed points (errors would mostly cancel) until I wrote some code to "teach" the unit where a track was by stepping from the home (zero) position to the track location and using microstepping to smooth out movement.  Then all went pear shaped.

I spent a couple of hours tracing the library code to find where the problem was.  Blow away a chunk of code and all works ok.  The "problem" is in a bit of code that does microstepping so not executed if you use step, doublestep or interleaved.  Also with a 50:1 gearbox you wouldn't notice an error of two steps.

 

This bit:

if (style == MICROSTEP) {

    while ((ret != 0) && (ret != MICROSTEPS)) {

      ret = onestep(dir, style);

      delay(uspers/1000); // in ms

      steppingcounter += (uspers % 1000);

      if (steppingcounter >= 1000) {

    delay(1);

    steppingcounter -= 1000;

      }

    }

  }

 

More specifically the effect of this statement:  while ((ret != 0) && (ret != MICROSTEPS))

I have written a bug report and will submit to github this week.

 

Now I just need to figure out how to stop the table from occasionally lurching when woken from the released state.

Well at least I now have a better idea on how the library code works. :scratchhead:

 

Not sure what you mean by "go to" or "target", the library code only has a step function.

 

CFJ

Link to post
Share on other sites

I didn't have any problems either just shuffling back and forth between fixed points (errors would mostly cancel) until I wrote some code to "teach" the unit where a track was by stepping from the home (zero) position to the track location and using microstepping to smooth out movement.  Then all went pear shaped.

I spent a couple of hours tracing the library code to find where the problem was.  Blow away a chunk of code and all works ok.  The "problem" is in a bit of code that does microstepping so not executed if you use step, doublestep or interleaved.  Also with a 50:1 gearbox you wouldn't notice an error of two steps.

 

This bit:

if (style == MICROSTEP) {

    while ((ret != 0) && (ret != MICROSTEPS)) {

      ret = onestep(dir, style);

      delay(uspers/1000); // in ms

      steppingcounter += (uspers % 1000);

      if (steppingcounter >= 1000) {

    delay(1);

    steppingcounter -= 1000;

      }

    }

  }

 

More specifically the effect of this statement:  while ((ret != 0) && (ret != MICROSTEPS))

I have written a bug report and will submit to github this week.

 

Now I just need to figure out how to stop the table from occasionally lurching when woken from the released state.

Well at least I now have a better idea on how the library code works. :scratchhead:

 

Not sure what you mean by "go to" or "target", the library code only has a step function.

 

CFJ

CFJ-

 

I think that you are missing out on some of the features of the code and that may be part of your problem.  I was using the micro-step function before I added the gearbox.  Even with code 70 rail I can see a 2 step interleave, and without the gearbox using microstep each step was noticable when trying to program tracks.  The code worked beautifuly.  Run the test program that was offered back on page 3 I think where it just spins 180 deg.  I used tape and a fine line.  After an hour of back and forth there was no drift.  At that point I went nuts on my own code, but the base code is very good.

 

I find that the release function is really neat, but not necessary.  The motor even after being energized for 4+ hours is hot, but not approaching its insulation class.  It would be neat if the realease function could be used.  I have thought about putting in a route code that would return the table to home, back off about a 1/2" and then release, so that when you were ready to use the turntable again you only needed to reset the unit, and the distance wouldn't be that far, so you wouldn't have to wait a while.  I may do that before the upcoming show this summer where the table will be used for 3 days all day.  Just food for thought.

 

I call up  more than just "step".  There are commands in the library that  allow different math operations to occur.  that may be where your error is introduced.   I use the following in my code (from the original code on this forum): 

 

stepper2.moveTo(VALUE);       moves the step number (Value) 0 to 3200 for microstep.

stepper2.move(VALUE);          the stepper moves the value input: + or -. for the total number of steps in (VALUE)

 

stepper2.distanceToGo();        returns the data from the library code (helpful for troubleshooting in serial monitor)

stepper2.targetPosition();        returns the target position from the library

stepper2.currentPosition();      returns what the library thinks the current position is from the library

stepper2.setCurrentPosition(VALUE);  This sets the position value to the integer you put in the (). 

                                                      Useful to re-zero after going around zero- other wise it "unwinds" to get back to the other number.

stepper2.speed();                    returns the speed value from the library. 

 

Speed may also be your problem, you may be trying to rotate too fast for the motor you choose with the current you have available.  I think it is really just that you are calling "step" instead of "move to" or "move"  try my code and see if it works for you.  It is in this post further back.

 

Hope that helps.

-Eric

Link to post
Share on other sites

 

I call up  more than just "step".  There are commands in the library that  allow different math operations to occur.  that may be where your error is introduced.   I use the following in my code (from the original code on this forum): 

 

stepper2.moveTo(VALUE);       moves the step number (Value) 0 to 3200 for microstep.

stepper2.move(VALUE);          the stepper moves the value input: + or -. for the total number of steps in (VALUE)

 

stepper2.distanceToGo();        returns the data from the library code (helpful for troubleshooting in serial monitor)

stepper2.targetPosition();        returns the target position from the library

stepper2.currentPosition();      returns what the library thinks the current position is from the library

stepper2.setCurrentPosition(VALUE);  This sets the position value to the integer you put in the (). 

                                                      Useful to re-zero after going around zero- other wise it "unwinds" to get back to the other number.

stepper2.speed();                    returns the speed value from the library. 

 

-Eric

These functions must be in the AccelStepper library (which I am not using) as I can't find them in the motorshield library.

 

I have submitted an "issue" note so it is in Ardafruit's hands.  My code seems to work ok with the routine deleted so it is forward to writing the last couple of functions and then trying to stop the lurch on stepper reattachment.

 

Something to keep the old brain cells active.

 

Regards,

CFJ

Link to post
Share on other sites

Just got a note from Adafruit.

Reproduced the reported odd behaviour, instituted my fix to solve and submitted an update to Github.

Don't know when it will be available though.

 

Regards,

CFJ

  • Like 2
Link to post
Share on other sites

  • 1 month later...

For general info, some learning references:

 

Online:

http://www.learncpp.com/
http://www.uow.edu.au/~nabg/ABC/ABC.html

Free e-books for arduino stuff:

https://it-ebooks.info/tag/arduino/

 

Some examples from the site:
1. Beginning C for Arduino, 2nd Edition
http://it-ebooks.info/book/5816/

2. Arduino Cookbook

http://it-ebooks.info/book/538/

3. Getting Started with Arduino, 2nd Edition 

http://it-ebooks.info/book/1338/
 

Apologies if posted before or old news.

 

Regards,

CFJ

Edited by NinOz
Link to post
Share on other sites

  • 2 months later...
  • 1 month later...

I have 2 sketches that I am using to control a turntable. One is Tender's DCC Turntable control and one that uses a Bluetooth module connected to

the Arduino and controlled by an Android phone. Both sketches work on their own but when I combine the 2 sketches the Bluetooth sketch is not working.

I have added the Bluetooth control to the Loop as this is only a serial Read but this does not seem to work. I have use pins 0 & 1 for the RX and TX for the Bluetooth and Interrupt 0

for the DCC signal.

 

Can anybody point me in the right direction why the serial read is not working when joined to the DCC Turntable Sketch.

 

Alan

Link to post
Share on other sites

Sorry forgot to add the code

 String t; //create an empty string to store messages from Android
  while(Serial.available()) { //keep reading bytes while they are still more in the buffer
    t += (char)Serial.read(); //read byte, convert to char, and append it to string
  }
  
  if(t.length()) { //if string is not empty do the following
    if(t == "Ton") { //if the string is equal to "on" then turn LED on
      digitalWrite(led, HIGH); //Set digital pin to high to turn LED on
      Serial.write("Moving to Main Track CW"); //Tell the Android app that the LED was turned on
    }
    else if (t == "Toff") { 
      digitalWrite(led, LOW);  
      Serial.write("Moving to Main Track CCW");
    } // turn the LED off by making the voltage LOW
  }

Alan

Link to post
Share on other sites

Andy

 

Please forgive the hypothetical response - I've never tried to do what you are suggesting, but I do believe it is possible.

 

There have been a couple of articles in the MERG mag about this kind of thing. I believe that it would be necessary for your decoder to have the capability of broadcasting its address - the so-called feedback bus. The Arduino would need to be connected to the section in question, I think some form of opto-isolation would be needed so the Arduino doesn't get fried. There are some comments on this thread about connecting to the track bus, which you'd need to arrange. And then it's just software...

 

Hope this gets you started, do please let us know how you get on

 

Best

Simon

Link to post
Share on other sites

Thanks for prompt reply Simon, what got me thinking is that I acquired one of these:

http://www.pricom.com/Trains/DreamPlayerPRO.shtml

It was a bargain from Ebay and I was musing about the possibility of triggering sounds at a point on a layout based on the reporting number of the train somehow embedded in the loco address. So for unfitted mineral train, I could trigger the 10' wheelbase railjoint sound with a longer spaced brakevan at the end.

 

MERG membership beckons methinks.

  • Like 1
Link to post
Share on other sites

A simple solution to this would be an RFID set-up, where each train carries a small unique tag whose information is read out whenever it passes a reader device beside the track. The information stored on the tag can then be interpreted and an appropriate sound produced by whatever means you have for this.

On the MERG demonstration stand we have such an arrangement which works with an Excel spreadsheet to display an image and play sounds as each tag passes.

  • Like 1
Link to post
Share on other sites

  • 2 months later...

Hi everyone 

 

I thought you might like to see my Arduino project. It is called the "Stop the Train Game" and can be seen at https://sites.google.com/site/g7aqkhamradio/stop-the-train .

 

The aim of the game is to stop the train at the station but it is not quite as simple as it sounds. The train runs around an oval of track at a random speed each time the game is played and will take between 1/4 and 3/4 of a lap to stop depending on its speed. 

 

There is a back story relating to escaped dinosaurs and people trapped at the station, so you will rescue more people if you can stop with the carriage completely on the platform. Automatic scoring detection is achieved using light dependent resistors and a 16 x 2 LCD display is used to display the speed and scores.

20160214_162637_resized.jpg?height=180&w

  • Like 1
Link to post
Share on other sites

the Dream Player is a neat bit of kit - but I reckon with an Arduino, a few relays and an SD card reader, you can do it all for maybe £20.

 

card reader here; - http://www.gearbest.com/development-boards/pp_63013.html?currency=GBP&gclid=CLzPpITGq8sCFQ0SGwodpjYLwQ - there are lots more, they cost ~ £1

 

you'll need an audio amp - this is a cheap and cheerful way of doing it - bet there are cheaper ones around - http://uk.rs-online.com/web/p/products/7302732/?grossPrice=Y&cm_mmc=UK-PLA-_-google-_-PLA_UK_EN_Computing_And_Peripherals-_-Audio_And_Video&mkwid=ss2fdYbjN_dc|pcrid|88057058163|pkw||pmt||prd|7302732&gclid=CJ77xLLGq8sCFQo6Gwod_XoKUA

 

RFID if you want, reed switches work for every magnet-equipped loco

 

and if you just want the wheel sound - there was an article in RM many many years ago, you get a tobacco tin or small biscuit tin, mount it under the baseboard, and solder a bit of stiff wire, vertically, from one rail directly to the middle of the tin lid.  You then file a notch in the rail.  and this one works without electrickery!!!

 

best

Simon

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