Author Topic: Anyone integrate Arduino/Raspberry Pi into your model trains?  (Read 6879 times)

0 Members and 3 Guests are viewing this topic.

peteski

  • Crew
  • *
  • Posts: 32958
  • Gender: Male
  • Honorary Resident Curmudgeon
  • Respect: +5343
    • Coming (not so) soon...
Re: Anyone integrate Arduino/Raspberry Pi into your model trains?
« Reply #15 on: October 26, 2014, 11:44:31 PM »
0
I'm not sure if I understand the problem correctly.  The pulse width tells the servo the requested final position, not whether it moves in some direction.

No matter what the current position of the servo ar is, a 1.5ms pulse will direct it to go to the center, 2ms pulse will make it go to the positive 90 degree position (off center) and 1ms pulse will make it go to negative 90 degrees position (from the center).
http://en.wikipedia.org/wiki/Servo_control
. . . 42 . . .

Mark W

  • Crew
  • *
  • Posts: 1988
  • Respect: +2125
    • Free-moNebraska
Re: Anyone integrate Arduino/Raspberry Pi into your model trains?
« Reply #16 on: October 27, 2014, 12:00:10 AM »
0
Right.  So my servo responds to .5ms (-90), 1.5ms(0), and 2.5ms(+90).  When I just run a simple raw servo script, .5ms sends it toward -90, the raw 2.5 sends it toward +90. 
However, when embedded in the turnout control script, the .5ms and 2.5ms both send it toward +90.



Contact me about custom model building.
Learn more about Free-moNebraska.
Learn more about HOn3-mo.

peteski

  • Crew
  • *
  • Posts: 32958
  • Gender: Male
  • Honorary Resident Curmudgeon
  • Respect: +5343
    • Coming (not so) soon...
Re: Anyone integrate Arduino/Raspberry Pi into your model trains?
« Reply #17 on: October 27, 2014, 12:50:51 AM »
0
Right.  So my servo responds to .5ms (-90), 1.5ms(0), and 2.5ms(+90).  When I just run a simple raw servo script, .5ms sends it toward -90, the raw 2.5 sends it toward +90. 
However, when embedded in the turnout control script, the .5ms and 2.5ms both send it toward +90.

Ah, then it must be a buggy code somewhere.  :D   The servo and the other hardware seems to be verified as working correctly.
. . . 42 . . .

babbo_enzo

  • Crew
  • *
  • Posts: 200
  • Gender: Male
  • Respect: +12
    • Experience IT!
Re: Anyone integrate Arduino/Raspberry Pi into your model trains?
« Reply #18 on: October 27, 2014, 07:00:58 AM »
0
Right.  So my servo responds to .5ms (-90), 1.5ms(0), and 2.5ms(+90).  When I just run a simple raw servo script, .5ms sends it toward -90, the raw 2.5 sends it toward +90. 
However, when embedded in the turnout control script, the .5ms and 2.5ms both send it toward +90.
Yes I agree about some sw problem, but ...
Which servo brand/model you use?
How you're sure about milliseconds you refer?

I can suggest you invest on a proper Frequency meter or better on a cheap oscilloscope.
You don't need to cut one hand for this: search on ebay ( mainly sellers from China) one of these, depends on your budget:

PC based ( use the PC screen for display ) = $20-30
http://www.ebay.com/itm/2-Channel-PC-Computer-Digital-Storage-USB-Oscilloscope-/330731251939?pt=BI_Oscilloscopes&hash=item4d011e68e3

Hantek 6022BL PC Based USB Digital Portable Oscilloscope + 16 CHs Logic Analyzer = $45-50
http://www.ebay.com/itm/Hantek-6022BL-PC-Based-USB-Digital-Portable-Oscilloscope-16-CHs-Logic-Analyzer-/351203459905?pt=BI_Oscilloscopes&hash=item51c55b8341

DSO201 Portable Digital Storage Oscilloscope = $60...
http://www.ebay.com/itm/ARM-DSO-DSO201-Portable-Digital-Storage-Oscilloscope-DIY-Kit-/151408511070?pt=LH_DefaultDomain_0&hash=item2340a6885e

DSO203 Nano V2 / Quad Pocket Digital Oscillo​scope = $150
http://www.ebay.com/itm/ARM-DSO203-Nano-V2-Quad-Pocket-Digital-Oscillo-scope-with-Aluminum-Black-Case-/161385925584?ssPageName=ADME:X:AAQ:US:1123


railnerd

  • Crew
  • *
  • Posts: 764
  • Gender: Male
  • Respect: +230
Re: Anyone integrate Arduino/Raspberry Pi into your model trains?
« Reply #19 on: October 27, 2014, 12:42:59 PM »
0
I'm using software based PWM on the GPIO to drive the servo, but having trouble.  When I send a raw .005 pulse it moves one way, and the .025 pulse moves the opposite.  But when I send each pulse via the control program, both widths turn the servo the same direction.  Will keep experimenting.

Mark,

Try using the "servo" library, although I'm not sure it won't screw up the other PWMs.

-Dave

Mark W

  • Crew
  • *
  • Posts: 1988
  • Respect: +2125
    • Free-moNebraska
Re: Anyone integrate Arduino/Raspberry Pi into your model trains?
« Reply #20 on: October 27, 2014, 05:46:35 PM »
0
Yes I agree about some sw problem, but ...
Which servo brand/model you use?
How you're sure about milliseconds you refer?

Ultimately, it's just a guess based on trial/error sending various pulses to it.  The 0.5-2.5ms range seemed to be the sweet spot. 
Its just a cheap thing that came in a RadioShack electronics starter kit bundle, which lists no other specs beside "mini servo". 
 

Looking at it closer, the range is actually about 250 degrees.  Now I'm starting to wonder, if we split the 250 degree range and assign pulse width as follows:

-125 (.5ms)
 0(1.5ms)
+125(2.5ms)

Starting at 0, I send a few 2.5ms pulses and move the servo to +56, at that point, it's less distance on the 360 degree circle to reach -125 by continuing the servo in the same direction toward +125.  Would that cause the servo then interpret both .5 and 2.5 as a move toward +125, even though the gear limits would prevent .5ms pulse from reaching -125 traveling in that direction? 

I'm going to try adding a 'reset' command to first send the servo back to 0 before then continuing on toward -125 and see if that makes a difference.
Contact me about custom model building.
Learn more about Free-moNebraska.
Learn more about HOn3-mo.

peteski

  • Crew
  • *
  • Posts: 32958
  • Gender: Male
  • Honorary Resident Curmudgeon
  • Respect: +5343
    • Coming (not so) soon...
Re: Anyone integrate Arduino/Raspberry Pi into your model trains?
« Reply #21 on: October 27, 2014, 07:08:25 PM »
0
Ultimately, it's just a guess based on trial/error sending various pulses to it.  The 0.5-2.5ms range seemed to be the sweet spot. 
Its just a cheap thing that came in a RadioShack electronics starter kit bundle, which lists no other specs beside "mini servo". 
 

Looking at it closer, the range is actually about 250 degrees.  Now I'm starting to wonder, if we split the 250 degree range and assign pulse width as follows:

-125 (.5ms)
 0(1.5ms)
+125(2.5ms)

Starting at 0, I send a few 2.5ms pulses and move the servo to +56, at that point, it's less distance on the 360 degree circle to reach -125 by continuing the servo in the same direction toward +125.  Would that cause the servo then interpret both .5 and 2.5 as a move toward +125, even though the gear limits would prevent .5ms pulse from reaching -125 traveling in that direction? 

I'm going to try adding a 'reset' command to first send the servo back to 0 before then continuing on toward -125 and see if that makes a difference.

Does the routine provide correct spacing between the pulses?  It should be 20 ms.  All the RC servos should adhere to the same standard (since they are supposed to be interchangeable).  There might be some minor variations but they all should be close in their operation.

You shouldn't need and resets between changing directions. In their as-intended application they receive and respond (in real time) to a continuous stream of control pulses.  When a model pilot moves the control joystick on the transmitter the servo responds immediately and the arm position continuously tracks the position of the transmitter's joystick.

Does the routine you use send continuous stream of pulses (with 20ms between them) or just sends a single pulse, then goes quiet unless a change in position is needed?  The pulse stream should be continuous (see the Wiki page I mentioned earlier).
. . . 42 . . .

Mark W

  • Crew
  • *
  • Posts: 1988
  • Respect: +2125
    • Free-moNebraska
Re: Anyone integrate Arduino/Raspberry Pi into your model trains?
« Reply #22 on: October 28, 2014, 01:17:02 AM »
0
Figured it out!  That was pretty close Peteski.  I was changing the length of time the output was on instead of the length of the duty cycle of the pulse.   :facepalm:

Here's the prototype.

Contact me about custom model building.
Learn more about Free-moNebraska.
Learn more about HOn3-mo.

peteski

  • Crew
  • *
  • Posts: 32958
  • Gender: Male
  • Honorary Resident Curmudgeon
  • Respect: +5343
    • Coming (not so) soon...
Re: Anyone integrate Arduino/Raspberry Pi into your model trains?
« Reply #23 on: October 28, 2014, 01:53:04 AM »
0
Figured it out!  That was pretty close Peteski.  I was changing the length of time the output was on instead of the length of the duty cycle of the pulse.   :facepalm:


Excellent!
. . . 42 . . .

Baronjutter

  • Crew
  • *
  • Posts: 509
  • Respect: +11
Re: Anyone integrate Arduino/Raspberry Pi into your model trains?
« Reply #24 on: October 28, 2014, 10:18:03 AM »
0
I'm making an arduino controlled tram system, or at least I'm designing it and my electronics friend is helping me build and program it.

Mark W

  • Crew
  • *
  • Posts: 1988
  • Respect: +2125
    • Free-moNebraska
Re: Anyone integrate Arduino/Raspberry Pi into your model trains?
« Reply #25 on: October 29, 2014, 11:58:56 PM »
0
I bought an Arduino Uno yesterday and have been trying to play around with it.  It has a much steeper learning curve than the Pi, but it looks like it will be more apt as stand alone automation driver, whereas the Pi will be more useful for interactive automation.
Contact me about custom model building.
Learn more about Free-moNebraska.
Learn more about HOn3-mo.

railnerd

  • Crew
  • *
  • Posts: 764
  • Gender: Male
  • Respect: +230
Re: Anyone integrate Arduino/Raspberry Pi into your model trains?
« Reply #26 on: October 30, 2014, 02:31:59 PM »
0
I bought an Arduino Uno yesterday and have been trying to play around with it.  It has a much steeper learning curve than the Pi, but it looks like it will be more apt as stand alone automation driver, whereas the Pi will be more useful for interactive automation.

Interesting perspective…  I've always considered the Pi to be significantly more complex than Arduino.

-Dave

John

  • Administrator
  • Crew
  • *****
  • Posts: 13396
  • Respect: +3256
Re: Anyone integrate Arduino/Raspberry Pi into your model trains?
« Reply #27 on: October 30, 2014, 05:21:29 PM »
0
nice article in MR about using Arduino to read data from micro chips ..

Mark W

  • Crew
  • *
  • Posts: 1988
  • Respect: +2125
    • Free-moNebraska
Re: Anyone integrate Arduino/Raspberry Pi into your model trains?
« Reply #28 on: October 31, 2014, 10:49:49 PM »
0
Interesting perspective…  I've always considered the Pi to be significantly more complex than Arduino.

-Dave

I'd say the Pi has significantly more and better quality tutorials on YouTube which helped me get up and running very fast (Specifically https://www.youtube.com/user/updowndown).  I've now found some great Arduino tutorials also (https://www.youtube.com/channel/UC4KXPjmKwPutGjwFZsEXB5g) and would now say Arduino is a lot easier and faster to experiment with. 

I received 40 micro LEDs from China today and am wiring up a test warehouse.  I must say, for how much simply lighting up a building improves a model, adding a random flicker to even just a single light really makes things come alive!  This is incredibly fun!
Contact me about custom model building.
Learn more about Free-moNebraska.
Learn more about HOn3-mo.

railnerd

  • Crew
  • *
  • Posts: 764
  • Gender: Male
  • Respect: +230
Re: Anyone integrate Arduino/Raspberry Pi into your model trains?
« Reply #29 on: November 01, 2014, 08:06:36 PM »
0
I received 40 micro LEDs from China today and am wiring up a test warehouse.  I must say, for how much simply lighting up a building improves a model, adding a random flicker to even just a single light really makes things come alive!  This is incredibly fun!

Lighting effects is one of the cooler things you can do with Arduino right out of the box. I put a few examples in my clinic back in 2011:

http://www.x2011west.org/handouts/ModelRailroadingWithArduino.pdf

-Dave