Micro Controllers

Discussion in 'Welcome to the DARK side' started by paul_l, Apr 28, 2022.

  1. paul_l

    paul_l Staff Member Administrator

    Messages:
    9,848
    Likes Received:
    5,902
    Joined:
    Dec 5, 2015
    It's been a while since I've done anything on controllers, but the intention is to resurect the Toto's Traverser thread and redo the control system, to reflect the comments / preferences expressed by users when it was at the 2018 Dundee & Elgin shows.

    I had no issues with using the DCC handset to select the road required on either traverser, however both Toto and Yorkie reckoned that more local tactile controls and a display would be preferable.

    Up until now I've used Arduino based Microcontrollers - Uno for development and then deployed on a Nano based custom board

    [​IMG]

    So in three and a half years what progress has been made .... er ..... ummm Nowt, zip, nada :facepalm:

    I have had a few thoughts :eek: :headbanger: and looked at the possible ways ahead.

    Now while the Uno and Nano are good little controllers they are limited in Storage capacity, speed and Input/Output capability, so I have been looking at alternatives. From the Arduino the Mega is an obvious choice

    [​IMG]

    I have a couple of clones, they have substantialy more resources but cost 2 to 3 times the price of and Uno / Nano.

    During the Lockdown, MERG started a beginners Special Interest Group (SIG) for PIC microcontrollers. These are the family of microcontrollers that MERG uses for its electronic kits.
    A large range of microcontrollers that are aimed at industrial and projects, with many features - you tend to make a list of the features you will require and find the appropriate chip to suit.

    So I joined the SIG and started to learn how to program these microcontrollers using a free program called JAL (Just another Language) a version of C - I think.

    Now I found the Arduino IDE easier to use, but then I am more used to it.

    There is a also new kid on the block as well, the Raspberry Pi Foundation Pico microcontroller

    upload_2022-4-28_16-55-34.png

    Now this controller uses the custom Raspberry Pi RP2040 microcontroller chip, interestingly the chip is available seperately so a custom board could be designed with its own chip installed.

    And Arduino have also produced a board thatuses one of these chips :scratchchin:

    At £3.40 per module for the Pico, I decided to buy three to play with.

    The Pico's are also very versatile pinouts as foollows

    upload_2022-4-28_17-3-57.png

    Programming is either Python or C/C++, with plenty of documentation on the RPi foundation website, they arrived today so time to play.

    However at the moment the Arduino is still the favoured option for the Traverser controller, as I know the drivers are available for the stepper controllers etc, etc.so that will appear on the Toto Traversers thread once I can get the Traverser back on a workbench to restart the project.

    For the Pico as Arnie would say I'll be back .......

    Paul
     
    Rob Pulham, York Paul and Andy_Sollis like this.
  2. Andrew Laing

    Andrew Laing Full Member

    Messages:
    357
    Likes Received:
    531
    Joined:
    Jan 19, 2020
    Bought an Uno a few years back, good fun and lots of potential.
    Need to dig it out sometime.
     
    Andy_Sollis likes this.
  3. Andy_Sollis

    Andy_Sollis Staff Member Moderator

    Messages:
    3,896
    Likes Received:
    3,622
    Joined:
    Aug 4, 2018
    Think I need to look at dads turntable again. I think I’m going to use some more of the hall switches and get each line to alight that way due to slip in the stepper motors gearbox. May have to upgrade to a mega as don’t think there are enough inputs etc to cover the 6 switches.
    Probably look at it come the warmer months.
     
  4. gormo

    gormo Staff Member Administrator

    Messages:
    5,991
    Likes Received:
    4,140
    Joined:
    Dec 5, 2015
    From memory Paul,
    You got Toto`s traverser working quite well, so these improvements should be terrific...:thumbs:
    :tophat:Gormo
     
  5. paul_l

    paul_l Staff Member Administrator

    Messages:
    9,848
    Likes Received:
    5,902
    Joined:
    Dec 5, 2015
    Hi Gormo

    Yep the Mk 2 worked pretty reliably, but unlike Andy's stepper I used a Nema 17 stepper motor with direct drive via GT2 drive belts to the lead screws. This keeps the backlash to a minimum. Whereas the smaller motor / gearbox Andy used is susceptable to wear and backlash. I think when I have to build a turntable (worryingly Toto has one waiting to be built), I'll make a stepdown gear box from 3D printed GT2 gears and belts. The Nema 17 motors are 200 (most common) or 400 steps per revolution (1.8 / 0.9 degrees of movement per step) so for OO gauge a table size of 300mm will give a circumference of 942.5mm giving 4.71 mm movement per full step. I'd want this to be approx 0.1 to 0.2 mm per step. Now I know you can get micro stepping controllers, but to hold the position you would need to keep the coils energised, with a turntable the turntable spends most of its life stationary.

    But to give an idea of the benefit
    1/16th microstepping will give 3200 microsteps per rev, or in the above case of a 300mm turntable a movement of 0.3mm per step for a 200 step motor
    1/32nd microstepping will give 6400 microsteps per rev, or in the above case of a 300mm turntable a movement of 0.15mm per step for a 200 step motor

    So direct drive would work, but the motor would have to be on all the time, providing the motor controller is setup correctly then it should be able to hold position without heating up. However I have not reliably achieved this with hobbyist level controllers - but I do keep trying and I do have a couple of controllers to try.
    My way round this is to turn off the motor after the movement has completed, so to maintain accuracy I tend to use full steps, so when the coils are re-energised they are already aligned with the full step position.

    Looks like I'm looking for between 16:1 and 32:1 gear ratio for OO, and for Toto's Turntable (approx 600mm dia, giving a circumference of 1.9m i'd need a 64:1 ration :facepalm:
    At least I'll 600mm to hide them under.

    Paul
     
    York Paul likes this.
  6. Andy_Sollis

    Andy_Sollis Staff Member Moderator

    Messages:
    3,896
    Likes Received:
    3,622
    Joined:
    Aug 4, 2018
    Why does it need to stay on Paul?

    I wrote coding in mine to turn off after every move?
     
  7. paul_l

    paul_l Staff Member Administrator

    Messages:
    9,848
    Likes Received:
    5,902
    Joined:
    Dec 5, 2015
    I will do an update on the Rpi Pico using both Python and C/C++ to program them.

    Good news is (especially python) you'd only need a text editor to create the program, so any type of PC will work.

    I will have a go at using my Raspberry Pi 400, and the included Thonny Python IDE (included with the Rpi), and downloadable from thr Rpi foundation.

    I forgot to include the technical spec for the Pico in the first post

    Raspberry Pi Pico

    Technical Specification



    Raspberry Pi Pico is a low-cost, high-performance microcontroller board with flexible digital interfaces. Key features include:

    RP2040 microcontroller chip designed by Raspberry Pi in the United Kingdom

    Dual-core Arm Cortex M0+ processor, flexible clock running up to 133 MHz

    264KB of SRAM, and 2MB of on-board Flash memory

    Castellated module allows soldering direct to carrier boards

    USB 1.1 with device and host support

    Low-power sleep and dormant modes

    Drag-and-drop programming using mass storage over USB

    26 × multi-function GPIO pins

    2 × SPI, 2 × I2C, 2 × UART, 3 × 12-bit ADC, 16 × controllable PWM channels

    Accurate clock and timer on-chip

    Temperature sensor

    Accelerated floating-point libraries on-chip

    8 × Programmable I/O (PIO) state machines for custom peripheral support


    As I said more to follow

    Paul
     
  8. paul_l

    paul_l Staff Member Administrator

    Messages:
    9,848
    Likes Received:
    5,902
    Joined:
    Dec 5, 2015
    If you use microstepping then the multiple coils are enegised to hold the stator between the full step position, if you switch off the motor (de-energise the coils) there is nothing holding the stator in the correct position which can allow the stator to move when re-enegised. So your accuracy can be scuppered. I've found it less apparent on the small type motors you're using if you only travel in one direction - you keep the backlash in one direction.

    I have found with the small motor / stepper controller you can leave them powered up for long periods of time without them getting hot. The nema motors stepper controllersneed fine tuning for each motors current setting - too low and it will stall and miss steps, too high and it gets hot very quickly.

    Hope that helps - Joe le Taxi has been summoned

    Paul
     
    Andy_Sollis likes this.
  9. gormo

    gormo Staff Member Administrator

    Messages:
    5,991
    Likes Received:
    4,140
    Joined:
    Dec 5, 2015
    G`day Paul,
    Is there any way that you could employ an electronically operated latch to hold the turntable in position once it`s reached it`s location.
    Something like a small solenoid operated shaft that once latched also cuts power to the motor via a micro switch.?
    :tophat:Gormo
     
  10. Jim Freight

    Jim Freight Full Member

    Messages:
    1,101
    Likes Received:
    878
    Joined:
    Sep 9, 2019
    if you can vary the applied voltage to the stepper motors in micro-stepping mode you will need less current to hold the position than to move position which would help keep the motor windings cool.

    I try and avoid getting into this aspect of electronics on my layout, I had good fun with stepper motors a few decades ago but if I resurrect that interest then I can forget playing with my trains as I would get lost again in the tech-whizzie land of my past :hammer:

    Jim
     
  11. paul_l

    paul_l Staff Member Administrator

    Messages:
    9,848
    Likes Received:
    5,902
    Joined:
    Dec 5, 2015
    Hi Gormo - short answer is yes ....

    But if I was going down that route, I'd probably use a standard motor rather than a stepper motor.

    The beauty / attraction of the stepper motor is its accuracy, hence the use in 3D printers, cnc and laser cutters.

    Paul
     
    Andy_Sollis likes this.
  12. Colin_W

    Colin_W Full Member

    Messages:
    230
    Likes Received:
    95
    Joined:
    Nov 19, 2016
    Hi Peeps
    someone woke me up again :giggle:. I still have my traverser running but where I originally used a Mega with a Eazydriver it now runs on a Nano with an 8825, still using a Nema17 motor. The original one also had TOTI (which was why I used the Mega) but the new(-er) one doesn't yet. Like Andy I switch off the enable pin when stopped and I haven't had any problems so far with the stepping jumping out of sequence on start and stop even when using a 0.9 Deg and 32 Microstepping.
    This is the old traverser.
    I haven't really got a video of the new one except from about 04:30 mins to about 6mins in this video.
    It's all good fun you know. :hammer:
    Col
     
    paul_l and Andy_Sollis like this.
  13. paul_l

    paul_l Staff Member Administrator

    Messages:
    9,848
    Likes Received:
    5,902
    Joined:
    Dec 5, 2015
    Welcome back Colin .....

    Now a little more research into to these little beauties, is the have 8 independant PIO's (Programable Input / Outputs). At first I just skimmed over these as mmmm nice, but ....

    However, one of the local modelrailway club members has been trying to create lighting modules for his various emergency vehicles. Now using a nano to produce flashing lights is relatively straight forward, unless you want to have them flashing at different rates, then it becomes a bit more awkward.

    Now step in the RPi Pico.

    These will still have the timing issues for scheduling differing flash rates, untill you remember those PIO's, each PIO can control any of the GPIO's, independantly without using the main cpu. These are controlled by simple (only 8 instructions I think) mini programs which are triggered from the main program, so while the main program is crunching away at it's main tasks, these PIO's can monitor inputs, and control outputs without effecting the main cpu.

    More learing required I think

    Paul
     
    Andy_Sollis likes this.
  14. Colin_W

    Colin_W Full Member

    Messages:
    230
    Likes Received:
    95
    Joined:
    Nov 19, 2016
    And the learning curve goes vertical again!! At the moment I'm working on a couple of projects for my local club members BUT I do have a couple of Pico's in my box that I haven't even looked at yet. Could do some bedtime reading maybe :scratchchin:.

    Col
     
  15. Colin_W

    Colin_W Full Member

    Messages:
    230
    Likes Received:
    95
    Joined:
    Nov 19, 2016
    Been having a wee think on this and I'm going to have to delve into the Picos fairly soon. For the flashing lights though you may be better using 555 timers or ATTiny 85 processors.
    These are like an 8 pin version of an arduino nano.
    ATTiny85pinout.png
    Opps! hope you can see that :redface:
    This is a nano setup to program the chip.
    IMG_20220519_143533766.jpg
    This is a pair of ATTinys one to flash red and blue and one to fade the yellow LED when the button is pressed(PWM). Oddly in the video the Yellow LED flashes slightly but to the naked MK1 eyeball it doesn't.:faint:


    The Push button can of course be replaced by a master arduino switching the level up and down
     
    Andy_Sollis likes this.
  16. Colin_W

    Colin_W Full Member

    Messages:
    230
    Likes Received:
    95
    Joined:
    Nov 19, 2016
    You can also buy these modules
    digispark-attiny85-pinout-.png
    Saves you having to build a programmer and using a nano. Plugs straight into a USB and programmes on the Arduino IDE.
    Has IC2 on board. More expensive though for something like flashing lights :twitch:.
    Col
     
    Andy_Sollis likes this.
  17. redpiperbob

    redpiperbob Full Member

    Messages:
    367
    Likes Received:
    299
    Joined:
    Aug 19, 2016
    Hi Paul another way of using the Pico is to put Basic on it
    Here is a link great site
    If you think a tutorial on it would be of use on the site I will do one.
    https://geoffg.net/picomite.html

    Be seeing you
    Bob
     
    Last edited by a moderator: May 21, 2022
    Colin_W likes this.
  18. paul_l

    paul_l Staff Member Administrator

    Messages:
    9,848
    Likes Received:
    5,902
    Joined:
    Dec 5, 2015
    Cheers Bob

    That's my homework sorted - off to watch Youtube - not that that is anything new

    Now to further Muddy the Waters, I attended the Gauge O Guild intro into Picaxe Microcontrollers, and have ordered up a few bits to get me started. Also in programmed Basic (like being back in school again, just without the hand encoding of punched cards), I feel happier in basic, but I've not tried to program a stepper motor with ramp up / ramp down yet.

    Paul
     
    Colin_W and Andy_Sollis like this.
  19. redpiperbob

    redpiperbob Full Member

    Messages:
    367
    Likes Received:
    299
    Joined:
    Aug 19, 2016
    Hi Paul did you use Logicator for the picaxe? I use it all the time
    be seeing you
    Bob
     
  20. paul_l

    paul_l Staff Member Administrator

    Messages:
    9,848
    Likes Received:
    5,902
    Joined:
    Dec 5, 2015
    Hi Bob

    I've downloaded the free Picaxe editor 6 software, I will give that a go at first.

    At the moment the Arduino Libraries are giving the Arduino the edge, but I've not spent enough time playing, and need to get my mind back into programming mode, actually with this covid I'd be happy just getting the mind to think straight and stay on track :facepalm:

    Paul
     

Share This Page