Jump to content
 

Much cheaper servo control for points


Grinkle
 Share

Recommended Posts

thanks guys for the interest

I have no doubt that the arduino will do a similar job to the RPi

I already have several RPi's for another job so I will use what I have

If someone else is working on something similar using the arduino the code should be very similar

 

I will get there

I have talked to a couple of people about help with the code

just have not spoken to the right one yet

 

I want to keep it so anyone can reproduce it easily

People with more experience can complicate it as far as there imagination can take them

 

It does not just have to control points

Link to post
Share on other sites

Just a quick pic showing a mock up of how the frog switching connects

It was mentioned in a post on the previous page

there are only 8 servos shown

by using servo boards from china adding the extra hardware does not increase the price from when i stared the thread

 

post-19064-0-94567000-1525280002_thumb.jpg

 

I have both merg and megapoint controllers myself

I use code55 electrofrog points (with the springs removed)

They are also slightly modified with live blades

  • Like 1
Link to post
Share on other sites

feeling like I am getting there with python

I will still do it even if you guys cant give me a short cut

so long as you keep this thread going I will let you know how I get on

look a bit like I am relying on the guys down under

 

thats not a problem

I intend buying in southern QLD in the next few years

I might bump into you guys down the mens shed

Link to post
Share on other sites

feeling like I am getting there with python

I will still do it even if you guys cant give me a short cut

In spite of asking you a few times you have never said what you need help with.

 

...R

Link to post
Share on other sites

I need help with python

Update

I have buttons on screen

 

post-19064-0-69323700-1525460621.png

 

this is only a picture

I can attach the html file but not the css

 

If anyone is interested I will post the html as a file and the css as plain text then you can create your own file

 

In the screen shot buttons 2,6,7,8 have been pressed

It does not actually do anything yet except change the text from main to branch

I need a variable which each button will add a number to or subtract the number from

 

The number is then sent to the python script and if it has changed the servos move

 

this is the simplest form of control

If you want your own layout plan with routes changing colours keep watching

Link to post
Share on other sites

feeling like I am getting there with python

I will still do it even if you guys cant give me a short cut

 

I can't help feeling you're not asking the right question.  If your problem is with Python coding, why not create a topic about Python coding and ask whether anyone can assist, rather than post multiple threads about point control as though you are trying to market a lower cost point control system.  Cost isn't everything and whilst the DIY route will often be cheaper, some of us are willing to pay a premium to have a tried and tested system that someone else has created and avoid all the 'development work' that you are trying to undertake.  The reason that 'off the shelf' products cost more, is to pay for the time spent developing them - ie the writing of the code.

 

If that is what is holding you back, start a Python topic, post the code that you have already written, explain where it goes wrong and see if someone can help you to debug it.

 

I don't have any knowledge of Python, so can't help on the syntax, but I'm sure that the logic must be similar to many other programming languages.  

Link to post
Share on other sites

the Gui will run in a browser

So simple HTML, css, Java

 

I did consider alternatives like VNC but anyone can use a browser

 

the RPi can run apache

I just need to interface the hardware

 

There are 3  parts
 Part 1
          The browser
Basically this would just be a pic on the screen with some icons (radio buttons)
when you click them they plus or minus a number from a variable
since there will be no more than 16 icons in a group the variable can be a 2hex pair or a decimal 0-65365
   There can be more than one variable
when ever this value changes it should be sent to the main program
   I think this is a job for json (I do not know how to do this)        HELP HERE please

 Part 2
          User settings
A simple editable file (probably a .py)
this file contains 33 values
How far a servo travels clockwise x16
How far a servo travels anticlockwise x16
and one to set the speed the servos travel

something like this:-
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  servo_limits.py
#  
# Changes in this file will not take effect until you restart the interpreter
 
# Set the speed at which the servos move
# Bigger number is slower
# servo_speed = 10   # For later use


# Configure min and max servo pulse lengths
servo_0_min = 150  # Min pulse length out of 4096
servo_0_max = 600  # Max pulse length out of 4096
servo_1_min = 150  # Min pulse length out of 4096
servo_1_max = 600  # Max pulse length out of 4096
servo_2_min = 150  # Min pulse length out of 4096
servo_2_max = 600  # Max pulse length out of 4096
servo_3_min = 150  # Min pulse length out of 4096
servo_3_max = 600  # Max pulse length out of 4096
servo_4_min = 150  # Min pulse length out of 4096
servo_4_max = 600  # Max pulse length out of 4096
servo_5_min = 150  # Min pulse length out of 4096
servo_5_max = 600  # Max pulse length out of 4096
servo_6_min = 150  # Min pulse length out of 4096
servo_6_max = 600  # Max pulse length out of 4096
servo_7_min = 150  # Min pulse length out of 4096
servo_7_max = 600  # Max pulse length out of 4096
servo_8_min = 150  # Min pulse length out of 4096
servo_8_max = 600  # Max pulse length out of 4096
servo_9_min = 150  # Min pulse length out of 4096
servo_9_max = 600  # Max pulse length out of 4096
servo_10_min = 150  # Min pulse length out of 4096
servo_10_max = 600  # Max pulse length out of 4096
servo_11_min = 150  # Min pulse length out of 4096
servo_11_max = 600  # Max pulse length out of 4096
servo_12_min = 150  # Min pulse length out of 4096
servo_12_max = 600  # Max pulse length out of 4096
servo_13_min = 150  # Min pulse length out of 4096
servo_13_max = 600  # Max pulse length out of 4096
servo_14_min = 150  # Min pulse length out of 4096
servo_14_max = 600  # Max pulse length out of 4096
servo_15_min = 150  # Min pulse length out of 4096
servo_15_max = 600  # Max pulse length out of 4096


# DON'T FORGET TO RESTART THE INTERPRETER

  Part 3
           The main program
A: setting up

It' something like this:-
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  first.py
#  

#def main(args):
#    return 0

#if __name__ == '__main__':
#    import sys
#    sys.exit(main(sys.argv))


# Simple demo of of the PCA9685 PWM servo/LED controller library.
# This will move channel 0 from min to max position repeatedly.
# Author: Tony DiCola
# License: Public Domain
from __future__ import division
import time

# Import the PCA9685 module.
import Adafruit_PCA9685

# Import servo_limits
# This sets the end points of the servo sweep
import servo_limits

# Uncomment to enable debug output.
#import logging
#logging.basicConfig(level=logging.DEBUG)

# Initialise the PCA9685 using the default address (0x40).
pwm = Adafruit_PCA9685.PCA9685()

# Alternatively specify a different address and/or bus:
#pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2)

(  # Configure min and max servo pulse lengths
(  servo_min = 150  # Min pulse length out of 4096               THIS BIT IS WRONG
(  servo_max = 600  # Max pulse length out of 4096   IT NEEDS TO GET ITS SETTINGS FROM THE USER FILE

# Helper function to make setting a servo pulse width simpler.
def set_servo_pulse(channel, pulse):
    pulse_length = 1000000    # 1,000,000 us per second
    pulse_length //= 60       # 60 Hz
    print('{0}us per period'.format(pulse_length))
    pulse_length //= 4096     # 12 bits of resolution
    print('{0}us per bit'.format(pulse_length))
    pulse *= 1000
    pulse //= pulse_length
    pwm.set_pwm(channel, 0, pulse)

# Set frequency to 60hz, good for servos.
pwm.set_pwm_freq(60)

B: The loop
     This is the bit that does the work
first
      print('Moving servo on channel 0, press Ctrl-C to quit...') some kind of stop function
While (start loop)
    next get input from json (if it is there)
                                                                  this is the bit where my logic gets confused (oh to be vulcan)
first time around this is chanel 0
                                                if position=>min pos (from servo_limits) servo pos = min
                                                if position=>min pos (from servo_limits) and bit1 (from json) =1 then servo positoin+1

ok this is where I get confused
 if the coresponding digit from the json is 1 add 1 until max (from servo_limits is reached)
 if the servo is at max and json is 0 then keep reducing  position by -1 until min(from servo_limits is reached)
at the end of the loop
                               add 1 to the channel number
                               If chanel number < 15 channel number =0
loop back
              HELP HOW DO I DO THIS?

Link to post
Share on other sites

the RPi can run apache

I just need to interface the hardware

With Bottle (see Reply #58) there is no need for Apache and the Bottle code is in a single .py file that is easy to distrubute if you want to give your program to others.

 

This Python - Arduino demo should help you with the interface between Python and your Arduino. See also Serial Input Basics - simple reliable ways to receive data on an Arduino. It was written more recently.

 

...R

Edited by Robin2
Link to post
Share on other sites

I do not want technical issues to put people of this thread

when we get them ironed out I intend to post simple instructions anyone can follow

 

If your question is why haven't you heard of this before the answer is the RPi  zero W has only been available since mid march

and still only in limited numbers

 

I had a supplier limit me to one per coustomer

 

P.S. stupid questions will keep this thread going

Link to post
Share on other sites

thank you robin2

I am not using an arduino

My apologies, I got confused.

 

nor do I understand Python

An answer like do this would be helpful

Like I said earlier there is no shortage of tutorials and other info about Python on the internet.

 

You have now told us a few times that you don't understand Python but you seem to have made no effort to learn it and you have not told us any single specific thing that you need help with.

 

To respond to "nor do I understand Python" it would be necessary to write a book. Those books have already been written and I have no plans to write another just for you.

 

...R

 

PS... An Arduino would probably be a very good solution for driving servos for model railways

Edited by Robin2
Link to post
Share on other sites

latest update

the code is getting there

 

HTML done

css      done

Java    just need to output the json

the python is part done I will get to that next

 

You would not want to be seen out with this code (it's about as pretty as Frankensteins monster) but it will LIVE

pretty can come l8r

Link to post
Share on other sites

I was thinking you guys must be wondering

If this is so good how come you have not herd about it

The hardware that makes this possible at a good price (it cost a lot more before) has only been on the market for about 7 weeks

Link to post
Share on other sites

Actually cheap servo drivers using arduinos or PICs have been available for years now. At MERG we offer kits (to members) using PICs and have sold hundreds over the last 5 years.

Either of these are easier than using a RPi. (And the Pi ZeroW has been around well over 7 weeks, I have had one in my parts box for several months.

Regards

Link to post
Share on other sites

slow progress with the software but progress

since people keep viewing this I thought I would just recap what it;s all about

 

First bit of the hardware
    Raspberry Pi zero W     approx £9  https://www.raspberrypi.org/products/ they dont sell them but they have links to distributers
    A power supply        approx £6.50 for the official one you could get a deal if you buy from the same place at the same time
    A micro SD card        mine was £6 for a 16Gb branded card, an 8Gb cardwould be fine

There is more hardware to make things run but this is the basic system (if all else fails you can yse this to turn a tv inti a smart tv,
run a media centre like kodi there are hundreds of uses for this

For our porposes (i,e, model railways) we need an operating system "Raspbain Stretch Lite" https://www.raspberrypi.org/downloads/raspbian/
Here is a link on how to install it     https://cdn-learn.adafruit.com/downloads/pdf/raspberry-pi-zero-creation.pdf
You are going to need i2c but you can swich audio to off in the raspi-config file

next we need apache to run the web server     https://www.raspberrypi.org/documentation/remote-access/web-server/apache.md

we might need some java files?     I will up date l8r if nessesary
we may need setuptools for Python    this was for me a pain in the neck, but I can tell you guys where the trouble is, it's easy to sort out

Hopefuly we can use the adafruit python libuary from github with the chineese clone servo controllers    
https://learn.adafruit.com/pages/4913/elements/1793587/download

next hardware
    A servo controller or two £1.53 each (or 62) one controller can handle 16 outputs (16 dimable leds) or (16 servos)
or (8 servos and 8 frog switches "will require extra hardware" (relay boards for 4 or 8 relays cost les than 50p per relay "set of points"))
    Servo's of course approx £1 for each set of points
    A suitable power supply "servos can give a heavy drain" 5v 10A will be enough power for about 16 servos
(if you know better please put me right) leds etc use a lot less power

After this we just need some software to make the whole thing work (that is what I am busy with)
"just because I can not write french  does not mean books can not be writen in french"

This will work (Might be me, Might be someone else) realy does not matter, It;s just another way
If all else fails shove the points with a finger, easiest and cheapest

Link to post
Share on other sites

    A suitable power supply "servos can give a heavy drain" 5v 10A will be enough power for about 16 servos

(if you know better please put me right) leds etc use a lot less power

 

Only small servos are needed for points or signals and it is rare for more than 2 or 3 to need to move at the same time so I reckon 2 amps would be plenty for 16, and maybe 1 amp would be sufficient. They probably only draw 10 or 20 mA when stationary.

 

...R

Link to post
Share on other sites

Other items that could be useful

Servo extensions    20pcs £4.50     you may need more than 20 it depends on the size of your layout and how many points you have
    https://www.ebay.co.uk/itm/20-PCS-JR-Futaba-3-Pin-M-F-RC-Servo-Extension-Lead-Wire-50cm-19-7-Q4Y1-X2L3/282698025839?epid=735036561&hash=item41d21d8b6f:g:2SYAAOSwfVhZ5gUk

More extensions    30pcs £2.70
    https://www.ebay.co.uk/itm/3X-10Pcs-10cm-Servo-Extension-Lead-Wire-Cable-MALE-TO-MALE-J9J9-BL/282757280360?hash=item41d5a5b268:g:RTQAAOSwZW5aIoiJ

Dupont housings    (6P are the ones you need)    100pcs £1.62    (you wont need 100 If you do I would like to see your layout)
    https://www.ebay.co.uk/itm/100Pcs-6p-Dupont-Jumper-Wire-Cable-Housing-Female-Pin-Connector-2-54mm-Pitch/272758157882?epid=1793977290&hash=item3f81a7323a:g:U6AAAOSwf~9ZZOBr

Header Edge Pins Strip 0.1" 2.54mm for Breadboard PCB for Dupont    A couple of 40 pin strips    
    Sorry I can not find these at a good price right now    5 strips for £3.25 is about as good as I could find

Vero PCB Prototyping Stripboard 2.54mm Pitch 983551 25 X 64mm     2boards £1.45
    https://www.ebay.co.uk/p/Vero-PCB-Prototyping-Stripboard-2-54mm-Pitch-983551-25-X-64mm-2/13004959988?iid=282564823399&_trkparms=aid%3D222007%26algo%3DSIM.MBE%26ao%3D2%26asc%3D50546%26meid%3Dbc4e72890c5b46c0b1cf4125dddbd3d1%26pid%3D100005%26rk%3D4%26rkt%3D12%26sd%3D121085311613%26itm%3D282564823399&_trksid=p2047675.c100005.m1851

The suppliers mentioned above are for a guide only you may be able to get things cheaper     Don't keep it to your self

Below is the script from an example file called simplest.py
most of it is configuring the servo board on the RPi
the last few lines tell it to move the servo
    It is written in python
I will make another copy but include my own comments

# Simple demo of of the PCA9685 PWM servo/LED controller library.
# This will move channel 0 from min to max position repeatedly.
# Author: Tony DiCola
# License: Public Domain
from __future__ import division
import time

# Import the PCA9685 module.
import Adafruit_PCA9685


# Uncomment to enable debug output.
#import logging
#logging.basicConfig(level=logging.DEBUG)

# Initialise the PCA9685 using the default address (0x40).
pwm = Adafruit_PCA9685.PCA9685()

# Alternatively specify a different address and/or bus:
#pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2)

# Configure min and max servo pulse lengths
servo_min = 150  # Min pulse length out of 4096
servo_max = 600  # Max pulse length out of 4096

# Helper function to make setting a servo pulse width simpler.
def set_servo_pulse(channel, pulse):
    pulse_length = 1000000    # 1,000,000 us per second
    pulse_length //= 60       # 60 Hz
    print('{0}us per period'.format(pulse_length))
    pulse_length //= 4096     # 12 bits of resolution
    print('{0}us per bit'.format(pulse_length))
    pulse *= 1000
    pulse //= pulse_length
    pwm.set_pwm(channel, 0, pulse)

# Set frequency to 60hz, good for servos.
pwm.set_pwm_freq(60)

print('Moving servo on channel 0, press Ctrl-C to quit...')
while True:
    # Move servo on channel O between extremes.
    pwm.set_pwm(0, 0, servo_min)
    time.sleep(1)
    pwm.set_pwm(0, 0, servo_max)
    time.sleep(1)
____________________________________________________
____________________________________________________

        we need another file to store some data
        more about this l8r
        for now i will just refer to it as data file (it stores numbers)
I origanaly thought a static file which could be edited by a user but it would be better to make it dynamic (a setup program writes it for you)

Second copy

# Simple demo of of the PCA9685 PWM servo/LED controller library.
# This will move channel 0 from min to max position repeatedly.
# Author: Tony DiCola
# License: Public Domain
from __future__ import division
import time

# Import the PCA9685 module.
import Adafruit_PCA9685


# Uncomment to enable debug output.
#import logging
#logging.basicConfig(level=logging.DEBUG)

# Initialise the PCA9685 using the default address (0x40).        there can be up to 62 pwm/servo boards
pwm = Adafruit_PCA9685.PCA9685()                            attached to each RPi each needs its own number
                                                                You can have as many RPi's on the system as you need
# Alternatively specify a different address and/or bus:                the first one is the master and all the others are slaves
#pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2)    the slaves are easier to set up

# Configure min and max servo pulse lengths                Import these settings from
servo_min = 150  # Min pulse length out of 4096            the data file (numbers)
servo_max = 600  # Max pulse length out of 4096        for all 16 channels and the servo speed

# Helper function to make setting a servo pulse width simpler.
def set_servo_pulse(channel, pulse):
    pulse_length = 1000000    # 1,000,000 us per second
    pulse_length //= 60       # 60 Hz
    print('{0}us per period'.format(pulse_length))
    pulse_length //= 4096     # 12 bits of resolution
    print('{0}us per bit'.format(pulse_length))
    pulse *= 1000
    pulse //= pulse_length
    pwm.set_pwm(channel, 0, pulse)

# Set frequency to 60hz, good for servos.
pwm.set_pwm_freq(60)

print('Moving servo on channel 0, press Ctrl-C to quit...')        This is where the control comes in
while True:                                                1/ get a number from the data file
    # Move servo on channel O between extremes.                If it is the same as the the number you already have go back to 1/
    pwm.set_pwm(0, 0, servo_min)                            2/ if the number is different
    time.sleep(1)                                                make the number you have the same as the one from the data file
    pwm.set_pwm(0, 0, servo_max)                                work out from the number which servos need to be moved
    time.sleep(1)                                                    move each servo a bit at a time until they get half way
                                                            then for frog switching change the pulse on the servo channel number plus 8
                                                            (this is the channel to connect the relay for frog switching too)
                                                            continue moving servos until they reach there max or min travel
                                                            then stop and go back to 1/

If you can make this work show me how

There will be a setup page to control the servo movement and speed

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>

<div>            Left Travel Max=225  Right Travel Max=225</div>
<div>Point 1 <input id="point1.min" class="addtableInputut225" name="point1.min" value="0" min="0" max="225" type="number" />
 <input id="point1.max" class="addtableInputut225" name="point1.max" value="0" min="0" max="225" type="number" /></div>
<div>Point 2 <input id="point2.min" class="addtableInputut225" name="point2.min" value="0" min="0" max="225" type="number" />
<input id="point2.max" class="addtableInputut225" name="point2.max" value="0" min="0" max="225" type="number" /></div>
<div>Point 3 <input id="point3.min" class="addtableInputut225" name="point3.min" value="0" min="0" max="225" type="number" />
 <input id="point3.max" class="addtableInputut225" name="point3.max" value="0" min="0" max="225" type="number" /></div>
<div>Point 4 <input id="point4.min" class="addtableInputut225" name="point4.min" value="0" min="0" max="225" type="number" />
<input id="point4.max" class="addtableInputut225" name="point4.max" value="0" min="0" max="225" type="number" /></div>
<div>Point 5 <input id="point5.min" class="addtableInputut225" name="point5.min" value="0" min="0" max="225" type="number" />
<input id="point5.max" class="addtableInputut225" name="point5.max" value="0" min="0" max="225" type="number" /></div>
<div>Point 6 <input id="point6.min" class="addtableInputut225" name="point6.min" value="0" min="0" max="225" type="number" />
<input id="point6.max" class="addtableInputut225" name="point6.max" value="0" min="0" max="225" type="number" /></div>
<div>Point 7 <input id="point7.min" class="addtableInputut225" name="point7.min" value="0" min="0" max="225" type="number" />
<input id="point7.max" class="addtableInputut225" name="point7.max" value="0" min="0" max="225" type="number" /></div>
<div>Point 8 <input id="point8.min" class="addtableInputut225" name="point8.min" value="0" min="0" max="225" type="number" />
<input id="point8.max" class="addtableInputut225" name="point8.max" value="0" min="0" max="225" type="number" /></div>

</body>
</html>    

If you cut and paste the above into a text editor as setup.html you can open it in your browser

it's not complete (as in it needs more fields (inputs)as in one for speed)
then it needs to write its out put to the data file and restart the python interpreter for the changes to take effect

I have more than this but most of you are bored by now

Link to post
Share on other sites

If you can make this work show me how

 

 

This is not the right place to ask for programming advice. You should be asking on a RaspberryPi forum or a Python programming forum.

 

...R

Link to post
Share on other sites

why is some one trying to stop this thread?

am I onto something they dont want you to know

 

I don't understand why a system that would work for you would not work for someone else. The usual way to develop something is to get a working prototype that people can try out (or build for themselves) and then maybe extend the concept based on feedback.
I have no idea what it is (specifically) that you need help with.
I have done a fair bit of Arduino programming and I have a few projects (such as a CNC controller) which use a PC screen as the interface but I have so far not been able to convince myself of the utility of an RPI. Maybe that's just because I have a few spare laptops lying around.

...R

seams this guy  has already got stuff working but is not prepared to share

 

why is he asking what is already explained?

and why does he want me to use a different controller?

 

How much did the different parts cost?
I have built a few boards using Atmega 328 microprocessors that can each control up to 12 servos. The total cost of the board is about £6. I can control several of them from an Arduino Mega used to collect the data from the switches on the control panel. A Mega clone costs about £15.
The role of the Mega could be replaced by a laptop or RPi with a suitable GUI program acting as the control panel.

...R

I know atmegas have been used in the past, so have steam trains

 

I have looked at tutorials

The boards are generic PCA9586 boards (about as mainstream as you can get)

If you guys can speak English you should have no problem with Chinese

 

There are hundreds or thousands of online tutorials about Python. If you know one language it should easy to use another.
And what are the servo boards that need to be programmed in Python?
If you are referring to a Raspberry Pi then you can program them in most languages - what languages are you familiar with?

...R

 

 

 

For my GUI projects I use Python and the Bottle web framework.

...R

sorry I have been doing computers since the early 80's and it looks like bottle is something that got past me

 

Why is this guy going on about the arduino again (does he have shares?)

With Bottle (see Reply #58) there is no need for Apache and the Bottle code is in a single .py file that is easy to distrubute if you want to give your program to others.
This Python - Arduino demo should help you with the interface between Python and your Arduino. See also Serial Input Basics - simple reliable ways to receive data on an Arduino. It was written more recently.
 
...R

 

 

looks like this guy writes book on python, but he can;t be bothered to spend 20 mins to write 30 or 40 lines of code to help out  other people

 

Like I said earlier there is no shortage of tutorials and other info about Python on the internet.
You have now told us a few times that you don't understand Python but you seem to have made no effort to learn it and you have not told us any single specific thing that you need help with.
To respond to "nor do I understand Python" it would be necessary to write a book. Those books have already been written and I have no plans to write another just for you.
 
...R

 

PS... An Arduino would probably be a very good solution for driving servos for model railways

back to the arduino again but I don't see the how to

 

 

This is not the right place to ask for programming advice. You should be asking on a RaspberryPi forum or a Python programming forum.

...R

those guys might be able to write the program but very few of them have any interest in model railways

 

personally I will accept help from anywhere, If it gets the thing running

I don't know everything

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