Oztrainz

Hi all,

I model a whole transportation system that is operated probably as prototypically as possible based on extensive research and given the technical impossibility of operating this transport system exactly prototyplcally. But for my transportation system there was no TT/TO, track warrant systems, no fixed signals or complicated train management system. Why?

Because the line was operated as "one locomotive in steam" - this meant that there was "nothing to hit" while the only operating locomotive was out there doing its stuff. Trains ran as often as the locomotive and its train could get from one end of the line to the other, and its train was swapped for another train going the other way. 

Is it likely that this layout of a transportation system will make much of an appearance here? So far, based on some of the comments I've received in various previous postings about the method of its build and logic behind how it was built as a sectional layout,  this is probably most unlikely.

After all, this layout is:

  • is based on a  "single industry" pike that hauled coal, a not very glamourous product, 
  • only ran just over a mile on the prototype,
  • only ever had 2 operational steam locomotives at any time in the 50 years of its operational life,
  • was narrow gauge, 
  • was not in the US/Canada,
  • is still small as a model layout in terms of overall footprint when compared to a larger "basement filler" layout
  • has a model train length limited to loco plus 11 small, identical-looking wagons
  • was built using a modified TOMA approach (staged construction of its modules) 
  • was planned for future exhibition use (and I've been told repeatedly here in response to some of  my previous postings that any techniques/approaches used have little or no relevance for a "home build" TOMA-based layout.)
  • probably not of much operational interest because it doesn't use US-based railroading operational practices (because it wasn't in the US? - strange that?)
  • and, was built for a different purpose than a home layout, This layout was built to do more than just "entertain the operators" as perhaps are most home layouts, when the purpose of a home layout is distilled to its essence.

The layout consists of 12 modules and covers a floor area of 23' by 17' (Hmm - starting to get towards a half-way decent sized "basement filler"  layout size). It will not grow any larger, because the logistics of moving and storing a layout of this size that doesn't have a permanent home define the layout size limits.  

Could it grow bigger? Undoubtedly yes. But should it grow bigger? No - this layout is at the limits of what can be easily stored, transported to a venue, speedily set up (in about 1 hour) and speedily dismantled for transport back to storage by a 2 person team.

Any given module can be separated from its neighbours in well under 5 minutes, and, in most cases under 2 minutes if work/running repairs are needed when the layout is together.. When not set up, any module or combination of adjoining modules can be easily pulled from its storage frame to have additional detailing work/running repairs done on it at the workbench. 

So just what did this sectionally-based, phased-build of model coal transportation system end up looking like?

_800x600.JPG 

Yes there is still more to do before this layout is fully exhibition ready, but it is almost there. How much more you see of this layout on here, and the saga of its build, is largely up to yourselves, given what I've listed above this photo,  

Regards,

John Garaty

Unanderra in oz

Read my Blog

Reply 12
Oztrainz

Holy Smoke Batman!!!

 Holy Smoke Batman!!

Hi all, 

That which was fried..

has now been replaced. 

"Engine Room?? This is the Bridge, Tell the stokers that they are now on time and a half. Give me everything you've got."

Time for Round 2 - Pass me another Scotch, I've got some ice-cubes to make...

Regards,

John Garaty

Unanderra in oz

Read my Blog

Reply 0
Rene Gourley renegourley

Admiring your perseverence

Admiring your perseverance

Keep at it, John!

Rene

Rene Gourley
Modelling Pembroke, Ontario in Proto:87

Read my MRH blog
Read my Wordpress blog

Reply 0
Prof_Klyzlr

Adult Supervision

Adult Supervision

Dear OzTrainz, Local "Adult Supervision" is available if required... You know the numbers...
Happy modelling,
Aim to Improve,
Prof Klyzlr

Reply 1
Oztrainz

It looks like that last wing might be in trouble...

 It looks like that last wing might be in trouble...

Hi all

The flash-damaged Arduino board can be successfully powered by either the USB lead and the 5V input transferred from the now re-powered breadboard, The green Power light is lit, BUT...

With Dr Geoff's "Blink Single" sketch loaded the yellow blinking light on the zapped Arduino board no longer flashes as it should. The sketch  verifies successfully but attempts to re-upload the sketch are generating  "avrdude: ser_open(): can't open device "\\.\COM1": The system cannot find the file specified" errors. I don't know if this is the Arduino board or something else??

It looks like the motors on that last remaining wing may have quit and prayers weren't sufficient to keep'em running.  It might be time to hit the silk before this damaged Arduino-powered "airframe" turns itself into geography on impact. I think this one is losing height rapidly.. 

Any thoughts from those more experienced in Arduino-ese than myself?? 

I do have a new Arduino waiting in the hangar, but I'm seriously worried about how much effort it is going to take to cut the programming for a tailored sketch without blowing up another Arduino after this less than successful test-flight.  

Regards,

John Garaty

Unanderra in oz

Read my Blog

Reply 0
pierre52

PM time

PM Time

Hi John

Dr Geoff is always happy to help out but he may not be reading your blog.  I would suggest that you PM him.

Peter

The Redwood Sub

Reply 0
Oztrainz

A whole flock of new errors

 A whole flock of new errors

Hi all, 

After finding and nominating the correct COM port 

I'm taking Peter's suggestion and sending some distress rockets via PM. Most of the US is asleep at present (or should be) so some MRH'ers might have some "morning mail". 

Just tried to upload the B&W TV sketch and got some different errors 

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x46
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x46
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x46
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x46
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x46
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x46
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x46
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x46
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x46
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x46
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#uploadfor suggestions.

Looks like this board may be terminal. 

I might have to get the new board out of its "hangar" in the morning - It's getting a bit late here to try stuff, even something as basic as plugging a new Arduino board into the USB slot. 

Regards,

John Garaty

Unanderra in oz

Read my Blog

Reply 1
Oztrainz

Arduino Programming 1 - Identifying the "Whats"

 Arduino Programming 1 - Identifying the "Whats"

Hi all,

While I sort out the hardware (hopefully without send up more smoke signals of distress), work has started on sorting out the Actual programme that has to run the Tipple. 

As a first cut only, here's a text grab from the Arduino programming screen. At this stage I am only identifying what I expect to do stuff inside the programme.

Quote:

//  Corrimal Tipple Chain Contol Circuit ver 1 Draft;
//  J. Garaty December 03 2017;
// Equipment definitions and pin assignments;
//
#define  switch_pin   2        // D2 ChainHome has a reedswitch to ground;
#define  switch_pin   4        // D4 SkipArrive has a reedswitch to ground;
#define  switch_pin   7        // D7 Cage has a reedswitch to ground;
#define  switch_pin   8        // D8 KicbackApproach has a reedswitch to ground;
#define  switch_pin   12        // D12 KickbackDivert has a reedswitch to ground;
#define  switch_pin   3        // D3 output CageServo is output to ground for TipServo at ANE SmartSwitch;
#define  switch_pin   5        // D5 output KickbackServo is output to ground for KickbackServo at ANE SmartSwitch;
#define  switch_pin   6        // D6 output MotorRelay is output to ground for a relay
// defined servo pins only provide input to ANE SmartSwitch and do not drive servos
// defined MotorRelay pin interrupts supply to tipple chain motor only. Speed control is elsewhere. 
// Determine chain magnet location as part of setup; 
void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

Now to get this defined stuff to jump through its hoops, 

Regards,

John Garaty

Unanderra in oz

Read my Blog

Reply 0
Geoff Bunza geoffb

@John re: A number of issues

@John re: a number of issues

Hi John,

Quote:
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x46
Loosely translated means the bootloader from your PC is not getting the appropriate response from the Arduino. This coupled with you not getting the Blink program to upload means the communications between the Arduino and the C is dead, and likely not recoverable.
 
Before you replace the Arduino, can you confirm what type of Arduino you are using? Perhaps an Uno?
 
Next, you actually didn't describe the method of connection of your reed relays to the Arduino. From your description it sounds like you have:
reedsw.jpg 
Is this correct? If yes, this needs to be changed. When disconnected the digital input to the Arduino is considered to be "floating" and is of indeterminate value -- meaning you don't really know whether it is ON or OFF. The typical swiych configuration is to connect the switch (reed) to ground (GND or zero volts) to the digital pin, and declare the pin as "PinMode (< pin_number> , INPUT_PULLUP);
This will internally to the arduino attach a "resistor" to +5V to the digital input pin, forcing the input ON/HIGH when the reed switch is disconnected; when the reed switch is turned on via a magnet the switch closes and forces the input OFF/LOW. It is just as easy i the Arduino to detect the pin going LOW as it is going HIGH.
 
Next, the 12V Wall wort you are using -- did you actually measure its output voltage? All wall worts are not created equal. It would be nice if yours put out 12V regulated, all the time -- meaning if it is rated at 2.5Amps, does it put out 16V when only supplying 50ma to the Arduino? The little voltage regulators on the Arduinos can't take high input voltages well -- the let you know with smoke signals!
 
Can you create an interconnect diagram taht can be read including all switches and sensors, with unique labels? It will be easier to relate thenm to your code/sketch.
 
You should be able to drive servos directly from an arduino pin, but with an external and separate 5V power supply due to current requirements of the servo.
 
How are you turning your DC motors on and off? With relays? Can you provide specs/source for your relays?
Do you know what the current draws of the relay coils are?
 
What you are trying to do is do-able -- really! And you have exactly the right idea to specify step by step what you want to have happen. Strangely enough that is usually the most difficult thing to get right! I will monitor this post regularly until you are "out of the woods."
 
On a completely different note... you stated:
Quote:
The magnetic flux pattern changes as the skip rolls past a reed switch. Effectively there is zero magnetic flux and the reed switch will open if the magnet is centred diectly over the reed switch. So once a field is sensed, we want the control circuitry to "stay switched" unless instructed otherwise. 
This can happen when each end of the magnetic field separately interacts with the reed switch, and in my experience is determined by the relative sizes of the reed and the magnet. I have found that instead of using one magnet you might try using 2,3,or 4 smaller magnets, nd you may have to alternate the poles of the magnets (north-south-north-south) by experimentation to eliminate any dead zone interaction with the reed switch.
 
Last, have you put together a control sketch as yet?
 
Have fun! 
Best regards,
Geoff Bunza
 

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 1
Geoff Bunza geoffb

Updated comments

Updated comments

Hi John,

Your code answered my question about the Reed switch connections. Consider trying this:

//  Corrimal Tipple Chain Contol Circuit ver 1 Draft;
    //  J. Garaty December 03 2017;
    // Equipment definitions and pin assignments;
    //
    #define  ChainHome_pin       2        // D2 ChainHome has a reedswitch to ground;
    #define  SkipArrive_pin      4        // D4 SkipArrive has a reedswitch to ground;
    #define  Cage_pin            7        // D7 Cage has a reedswitch to ground;
    #define  KicbackApproach_pin 8        // D8 KicbackApproach has a reedswitch to ground;
    #define  KickbackDiver_pin   12       // D12 KickbackDivert has a reedswitch to ground;
    #define  CageServo_pin       3        // D3 output CageServo is output to ground for TipServo at ANE SmartSwitch;
    #define  KickbackServo_pin   5        // D5 output KickbackServo is output to ground for KickbackServo at ANE SmartSwitch;
    #define  MotorRelay_pin      6        // D6 output MotorRelay is output to ground for a relay
    // defined servo pins only provide input to ANE SmartSwitch and do not drive servos
    // defined MotorRelay pin interrupts supply to tipple chain motor only. Speed control is elsewhere.
    // Determine chain magnet location as part of setup;
    
    void setup() {
      pinMode (ChainHome_pin, INPUT_PULLUP);
      pinMode (SkipArrive_pin, INPUT_PULLUP);
      pinMode (Cage_pin, INPUT_PULLUP);
      pinMode (KicbackApproach_pin, INPUT_PULLUP);
      pinMode (KickbackDiver_pin, INPUT_PULLUP);
      pinMode (CageServo_pin, OUTPUT);
      pinMode (KickbackServo_pin, OUTPUT);
      pinMode (KickbackServo_pin, OUTPUT);
      digitalWrite ( CageServo_pin, HIGH);       // Intialize to a known state
      digitalWrite ( KickbackServo_pin, HIGH);   // Intialize to a known state
      digitalWrite ( KickbackServo_pin, HIGH);   // Intialize to a known state

    }

    void loop() {
      // put your main code here, to run repeatedly:
      
}

By using the named identifiers it will be easier to follow what you want to do.
 
(Looks like our posts crossed in the ether!)
Have fun! 
Best regards,
Geoff

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Oztrainz

Re: A number of issues

 Re: A number of issues - from Dr Geoff above

Hi Dr Geoff and all,

First I'd like to thank Dr Geoff for his input and thoughts. It goes a long way toward helping me get my head straight about a new way forward for controlling the tipple operations. 

The Arduino Sketch

The changes in the Arduino sketch suggested by Dr Geoff in the previous post have been made. The ability to custom name pins and components goes a long way to helping me get my head around "what" has to happen "when" and be done by "which something". I didn't know this was possible. 

My initial thought on set-up is that the chain should cycle until it reaches the ChainHome reed switch. The set-up routine in the Arduino gives me the capability to run the chain only without triggering anything else. So the Set-up now looks like

Quote:

void setup() {
  // Set up conditions for power up:
pinMode (ChainHome_pin, INPUT_PULLUP);
pinMode (SkipArrive_pin, INPUT_PULLUP);
pinMode (Cage_pin, INPUT_PULLUP);
pinMode (KicbackApproach_pin, INPUT_PULLUP);
pinMode (KickbackDiver_pin, INPUT_PULLUP);
pinMode (CageServo_pin, OUTPUT);
pinMode (KickbackServo_pin, OUTPUT);
pinMode (KickbackServo_pin, OUTPUT);
digitalWrite ( CageServo_pin, HIGH);       // Intialize to a known state, cage alligned with track
digitalWrite ( KickbackServo_pin, HIGH);   // Intialize to a known state, track set to Divert
digitalWrite ( MotorRelay, LOW);   // Intialize to a known state, motor start
//chain will run until magnet reaches ChainHome reed switch
if (digitalRead(ChainHome_pin) == LOW);
digitalWrite(MotorRelay_pin, HIGH);   // end of setup-turn off motor
//setup complete - ready for skips from incline

}

This should ensure that the magnet on the chain is stopped at the ChainHome reed switch. This is the known start state from which things happen in the Loop part of the programme

For those of you who have never seen a dead Arduino UNO, look no further:

1270385a.jpg 

Some key features -  the bullet-holed MOSFET?? at the lower left that released the magic smoke and the unlit LED that was supposed to be flashing, went to on continuously and has now quit in sympathy with the MOSFET. I'm not too sure what I did, but I'll try very hard NOT to do it again.  

Hardware Design

The plan is to mount the pull-up resistors on a separate piece of vero board and then use the existing wiring to connect to the relay, servo-controller and reed switches. The board will take a +5V and Ground tap from the Arduino for distribution to the reed switches etc. This will allow the Arduino Uno to be swapped out easily if problems are encountered or the on-board programming needs tweaking. Once the programming is finalized the plan is to have another  pre-programmed Arduino in the spares kit that goes with the layout when it goes out on exhibition.

Driving the Chain 

An Arduino-compatible relay will be in the line between the motor driving the chain and its speed control. The contact specifications for the relay are rated at 10A for 30VDC. The gearhead motor driving the chain pulls 1.7A at maximum on 12V. There is a considerable margin of safety at the contacts when when using this relay.

The chain, skips and magnets

The following photo is of some chain segments with magnets attached. The magnets are 10mm diameter and are polarized so that the circular faces are the poles. 

1130193a.jpg 

Unfortunately the idea of using multiple magnets under the skips is a non-starter because of the lack of space under the skips and the requirement to hold on a 25% grade. So we needed the biggest magnet we could fit in there. The following photo shows underside of the latest of the 9 design iterations for the coal skips. This photo is much larger than full size. The wheels are 8 mm (0.31") diameter on 1.5mm (.06")diameter axles and the magnet is 6 mm (0.24") diameter.

1270293a.jpg    

 The saga of skip design was just getting started when the control system problems forced the rapid jump to Arduino territory. With the intensity of magnetic flux around these 2 magnets we have no trouble getting the reed switches to react.

Control Diagrams

I have had a go at preparing some control schematics that are probably not worthy of the term "diagram"  in PowerPoint.

The first one shows the location of the reedswitch sensors and the direction of movement of the chain

trolEqt1.jpg 

and the second shows the Arduino and inputs and outputs with pin numbers as defined in the Arduino sketch

0control.jpg 

My suspicion is that the ANE SmartSwitch trigger inputs will have to share/be grounded back to the Arduino. This shouldn't be a problem. On the old 555 control system the control circuit and the ANE Smartswitch were powered by the same powerpack. I intend to set it up this way for the Arduino as well. 

That ought to do for this post. Thanks again and,

 

Regards,

John Garaty

Unanderra in oz

Read my Blog

Reply 1
Geoff Bunza geoffb

@John re: MOSFETs and Voltage Regulators

@John re: MOSFETs and Voltage Regulators

Hi John,

That MOSFET with the hole in it is not a MOSFET (Metal Oxide Semiconductor Field Effect Transistor) it is instead a +5 Volt voltage regulator likely similar to an NCP1117ST50T3G  in an SOT223 package.

As such you likely destroyed it via 2 mechanisms: either you shorted something that it was providing the power to (it is limited to somewhere over 1Amp but is supposed to have a thermal overload shutdown), or it received an overvoltage jolt on the input (supposedly speced to 20V in max) or an overvoltage applied directly to its output -- unfortunately the most likely scenario.

If the regulator was a different  part, or if the regulator was a "counterfeit" also ran, then who knows what the specs are. You could try replacing the regulator (for such an small surface mounted part I would cut it away without destroying the PC trace as much as possible, then de-solder it one pad attachment at a time -- it is an acquired skill !), then tack solder one pad of the new part in the correct position, and then finish soldering the rest once correctly placed.

Have fun! 
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Oztrainz

Maybe this will help with the wiring??

 Maybe this will help with the wiring??

Hi all,

I'm not sure how much this will help, but it is supposed to be some type of a prototyping shield

from above

1270386a.jpg 

and as viewed from below, where the pins are that match the Arduino's below

1270387a.jpg 

Now with the breadboard unit powering this board (separated from the Arduino) like this,

1270390a.jpg 

 

And with some judicious prodding with the multimeter, I should be able to work out where the +5V goes and where I can maybe squeeze in the relevant pull-up resistors?  

Regards,

John Garaty

Unanderra in oz

Read my Blog

Reply 1
Oztrainz

Judicious prodding now done...

 Judicious prodding now done...

HI all,

I have had a good look at the board in the previous post both unpowered and checking for continuity (between +5V, Ground, and their respective pins with pads) and then powered looking for potential difference for paths between +5V and Ground. I now think I have a fair understanding of what goes where for this board

So far so good - No more magic smoke emissions   

Arduino #2 successfully loaded and is blinking away quite successfully - I had bought a Sensor Shield  (just on the off chance I might need it  ) About to try a switched servo - Wish me luck...  

Regards,

John Garaty

Unanderra in oz

Read my Blog

Reply 0
Oztrainz

It does help...

 It does help...

Hi all 

After about 2 hours with a gradually rising frustration level and no motion from the servo...

After reloading the sketch, manually adding the servo.h library (just in case it wasn't there already) rechecking all wiring etc.... (This stuff is the easy stuff - isn't it?? Only one lead to the servo and a switch in the wire between 2 pins - Really, how hard can it be???)

We now have motion and a now greatly reduced level of frustration - YAAY!!!!  After I went and got another servo 

Yeah these servo things aren't supposed to fail are they? They are supposed to be bulletproof? Yeah Right....

I don't know what the problem was with that servo, but it's now in the bottom of the bin. 

I'm almost beginning to think I might have half an idea of what I'm doing with these Arduino things.  

Thank you Dr Geoff for writing a bulletproof sketch and taking the time to look over my shoulder. But the sketch doesn't work if you have a flaky servo...

Well that's one iceberg converted to ice-cubes. I think I need another Scotch...

The next iceberg is an "IF" This "if" affects how I write the Arduino sketch to drive all this stuff "hands-free". 

If I play with the settings on the servo sketch, can I drive this "large economy-sized" beast of servo that lurks beneath the tipple cage directly from the Arduino board directly without letting any magic smoke out? 

1010993a.jpg 

This photo was taken before the tipple cage was installed. We weren't to sure if a small servo could handle the load so we went "LARGE".

The following photo shows the tipple cage and gearing installed. When we tip a skip, we intended it to stay tipped...

1110669a.jpg  

As things stand with the ANE SmartSwitch in the circuit, this servo is powering for about 3 seconds each way every minute or so.  The ANE SmartSwitch controller has done the job admirably so far, but its another piece in an already complicated jigsaw puzzle. With the Arduino driving things directly, we could probably cut the duty cycle to 2 seconds each way. This should help reduce any overheat/overcurrent problems that might arise??

Any thoughts from any Arduino-drivers out there?? I can keep the SmartSwitch servo controller and drive it with pin outputs from the Arduino. But the Arduino just might be able to handle the 2 servos and one motor powering chain I need to start and stop at various times all by itself??

  If I get really clever, at a later date, I can add in some tailored sounds that are linked to events in the Arduino simply by adding stuff to the sketch???  

Regards,

John Garaty

Unanderra in oz

Read my Blog

Reply 1
Oztrainz

"If" answered by Dr Geoff's Arduino article

 "If" answered by Dr Geoff's Arduino article

Hi all,

Well that didn't take long - The ANE SmartSwitch servo board stays.

In Dr Geoff's Arduino article in MRH December 2016 (See Final Note) there is the caution that servos should be powered by a separate power supply because they can pull more juice that the power section of the Arduino can deliver. This "If" is now a "NO!!"

So more design thinking for the final Arduino sketch...

The tipple chain is really the "rate limiting step" for the whole incline. The "rate limiting step" is that part of the process that determines the absolute fastest that stuff can happen in an industrial process. All other parts of the process can and will work faster BUT eventually there will be a "wait time" until the next whatever is produced and processed by the rate limiting step and is then transported downstream in the manufacturing process. 

For the faster downstream units, lost "wait time" can be made up because these processes can run faster than stuff can be made for them. However for the "rate limiting step", any lost time cannot be got back because this step in the process determines how fast everything else can go because everything hangs off the product from this part of the process. 

Why is the tipple chain the rate limiting step?  

  • The tipple cage is designed to handle one skip at a time. 2 skips in the cage will cause a jam-up of the servo.
  • If skips come off the incline quicker than the time taken for the chain to start, haul away and tip the skip at the tipple cage then move the empty skip to the kickback points AND then for the magnet on the chain to get back to the ChainHome reed switch, then eventually you will shove 2 skips forward at once and cause a jam up in the tipple cage. This is the "Showstopper" because with that big a servo driving the cage, YOU WILL BEND STUFF. This is a most undesirable outcome and is to be avoided at all costs 
  • Getting at the servo, and other adjustments to "unbend stuff" is not an option in an exhibition situation. 
  • There is only room at the end of the kickback siding for 1 skip.
  • Collisions of empty skips at the start of the uphill Empties Incline are also to be avoided because the skips are light and a collision will most likely cause a derailment, which means both inclines on the hill have to stop until it is fixed.
  • If a train from the mine "runs late" then there are no loaded skips to send downhill, so this doesn't affect how quickly the bottom-end can process loaded coal skips, because there are no loaded skips to tip. The "rate limiting step" now has to wait.    

So the aim of the game is to adjust the number of magnets on the and the speed of chain under the Fulls Incline so that a loaded skip arrives at the foot of at just longer than it takes the tipple chain to cycle. By running more magnets on the Empties Incline chain, skips can be hauled away quicker than they arrive from the kickback siding.

It takes about 45 seconds from start to finish at the fastest chain speed. More realistically the chain will be probably be cycling at about 1 minute intervals. So with only 1 skip on the tipple chain at a time, there is a clearly defined series of sequential events sensed by the various reed switches that need to be managed by the Arduino. 

I'll be back with a development version of the Arduino sketch next post.   

Regards,

John Garaty

Unanderra in oz

Read my Blog

Reply 0
Oztrainz

A compiled development version

 A compiled development version

Hi all, 

The formatting is probably ugly but after numerous times though the "verify" hoops and much to-ing and fro-ing between Arduino syntax on-line dictionaries we have a version that compiled cleanly. 

Now whether this Sketch when it goes into the Arduino will actually do what the current multiple control-boards do is perhaps another question? But its my best shot. So here it is - 

//  Corrimal Tipple Chain Contol Circuit ver 2 Draft;
//  J. Garaty December 03 2017;
// Equipment definitions and pin assignments;
//
#define  ChainHome_pin   2        // D2 ChainHome has a reedswitch to ground
#define  SkipArrive_pin   4        // D4 SkipArrive has a reedswitch to ground
#define  Cage_pin   7        // D7 Cage has a reedswitch to ground
#define  KickbackApproach_pin   8        // D8 KicbackApproach has a reedswitch to ground
#define  KickbackDivert_pin   12        // D12 KickbackDivert has a reedswitch to ground
#define  CageServo_pin   3        // D3 output CageServo is output to ground for TipServo at ANE SmartSwitch
#define  KickbackServo_pin   5        // D5 output KickbackServo is output to ground for KickbackServo at ANE SmartSwitch
#define  MotorRelay_pin   6        // D6 output MotorRelay is output to ground for a relay
// defined servo pins only provide input to ANE SmartSwitch and do not drive servos
// defined MotorRelay pin interrupts supply to tipple chain motor only. Speed control is elsewhere. 
// Determine chain magnet location as part of setup;
 
void setup() {
  // Set up conditions for power up:
pinMode ( ChainHome_pin, INPUT_PULLUP);
pinMode ( SkipArrive_pin, INPUT_PULLUP);
pinMode ( Cage_pin, INPUT_PULLUP);
pinMode ( KickbackApproach_pin, INPUT_PULLUP);
pinMode ( KickbackDivert_pin, INPUT_PULLUP);
pinMode ( CageServo_pin, OUTPUT);
pinMode ( KickbackServo_pin, OUTPUT);
pinMode ( MotorRelay_pin, OUTPUT);
digitalWrite ( CageServo_pin, HIGH);       // Intialize to a known state, cage alligned with track
digitalWrite ( KickbackServo_pin, HIGH);   // Intialize to a known state, track set to Divert
digitalWrite ( KickbackApproach_pin, HIGH);   // Intialize to a known state, magnet not at KickbackApproach reedswitch
digitalWrite ( KickbackDivert_pin, HIGH);   // Intialize to a known state, magnet not at KickbackDivert reedswitch
digitalWrite ( MotorRelay_pin, LOW);   // Intialize to a known state, motor start
//chain will run until magnet reaches ChainHome reed switch
if  (digitalRead (ChainHome_pin == LOW));
digitalWrite( MotorRelay_pin, HIGH);   // end of setup-turn off motor
//setup complete - ready for skips from incline
}

void loop() {
  //specify state of Inputs/Outputs at start of Loop
digitalWrite ( CageServo_pin, HIGH);       // Intialize to a known state, cage alligned with track
digitalWrite ( KickbackServo_pin, HIGH);   // Intialize to a known state, track set to Divert
digitalWrite ( ChainHome_pin, LOW);       // Intialize to a known state, magnet at ChainHome
digitalWrite ( SkipArrive_pin, HIGH);   // Intialize to a known state, awaiting skip arrivalt
digitalWrite ( MotorRelay_pin, HIGH);   // Intialize to a known state, motor off
digitalWrite ( Cage_pin, HIGH);   // Intialize to a known state, magnet not at CAGE reedswitch  
digitalWrite ( KickbackApproach_pin, HIGH);   // Intialize to a known state, magnet not at KickbackApproach reedswitch
digitalWrite ( KickbackDivert_pin, HIGH);   // Intialize to a known state, magnet not at KickbackDivert reedswitch
  
  
  //Case 1 - Motor start and moves skip to CAGE when skip triggers SkipArrive reedswitch;
  // Skip arrives at SkipArrive, start chain by MotorRelay;
  if (digitalRead ((ChainHome_pin) == LOW) && digitalRead (( SkipArrive_pin) == LOW)) ;
digitalWrite (MotorRelay_pin, LOW);   // start motor
  //condition when magnet moves away from ChainHome
if (digitalRead (ChainHome_pin) == HIGH && digitalRead ( SkipArrive_pin) == LOW) ;
(digitalWrite (MotorRelay_pin, LOW));   // run motor
  //condition after magnet picks up skip
if (digitalRead ((ChainHome_pin) == HIGH) && digitalRead (( SkipArrive_pin) == HIGH)) ;
digitalWrite (MotorRelay_pin, LOW);   // run motor

  
  //Case 2 - Tip skip at CAGE
  // Start tip - Stop chain and set CageServo_pin LOW to start tipping cycle
if (digitalRead ( Cage_pin == LOW ));     //magnet on chain arrives at CAGE reedswitch 
digitalWrite( MotorRelay_pin, HIGH);   // stop motor, prepare to tip skip 
digitalWrite ( CageServo_pin, LOW);    // Move cage to tipped position, will take 3.5 seconds to get there  
  //hold cage at Tip position for an additional 0.5 second
delay(4000);                  // waits for 4 seconds while cage is in motion plus a smidge 
  //return cage to Home position aligned with track  
digitalWrite( CageServo_pin, HIGH);    // Move Cage back to Home position aligned with track, will take 3.5 seconds to get there
 //wait to ensure skip and cage are aligned with track for an additional 0.5 second 
delay(4000);                  // waits for 4 seconds while cage is in motion plus a smidge
  //disable tip circuit - Set CAGE HIGH
digitalWrite(Cage_pin, HIGH);   // over-ride CAGE readswitch to prevent re-triggering    
  //start chain
digitalWrite(MotorRelay_pin, LOW);   // start motor, haul skip to kickback

 
  //Case 3 - Kickback points operation
  //empty skip approaches kickback point blades
  //set to straight path with KickbackApproach
if (digitalRead (KickbackApproach_pin == LOW)); //magnet on chain arrived at KickbackApproach reedswitch 
digitalWrite ( KickbackServo_pin, LOW);   //  Set track to Straight

  //remain set and allow skip to pass Kickback point blades
  //set to divert path with KickbackDivert
if (digitalRead (KickbackDivert_pin == LOW));  //magnet on chain arrived at KickbackDivert reedswitch
digitalWrite ( KickbackServo_pin, HIGH);   // Set track to Divert
//wait with motor running until magnet reaches ChainHome reedswitch
 
 
  //Case 4 - Chain magnet runs back to ChainHome after releasing skip
  //stop chain when magnet gets to ChainHome
if (digitalRead(ChainHome_pin) == LOW);
digitalWrite(MotorRelay_pin, HIGH);   // turn off motor 
  //Wait until Case 1, when next skip arrives from the incline.


}

I have used commented "cases" as  way of keeping tabs on what is happening when as the skip travels along the chain path. I hope that this all makes some sense.

and just to prove the compile worked..

Sketch uses 1,452 bytes (4%) of program storage space. Maximum is 32,256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2,039 bytes for local variables. Maximum is 2,048 bytes. 

I think that is a YAAY!!!

Hopefully this iceberg is just about ice cubes. 

Regards,

John Garaty

Unanderra in oz

Read my Blog

Reply 0
Geoff Bunza geoffb

@John re:Code review 1

@John re: Code review 1
 
Hi John,

When a pin is defined as INPUT_PULLUP, an internal pullup resistor to +5 Volts is attached to the pin, so a normally open SPST switch attached to GND and the pin, will be HIGH until the switch is closed and the pin reads LOW.

In setup() these 2 lines are not needed:
digitalWrite ( KickbackApproach_pin, HIGH);   // Intialize to a known state, magnet not at KickbackApproach reedswitch
digitalWrite ( KickbackDivert_pin, HIGH);   // Intialize to a known state, magnet not at KickbackDivert reedswitch

The question regarding the following lines is " Are you really trying to leave the Motor ON (MotorRelay_pin = LOW) UNTIL ChainHome_pin goes LOW?"
If yes, then the following statement does not do what you want
if  (digitalRead (ChainHome_pin == LOW));
      digitalWrite( MotorRelay_pin, HIGH);   // end of setup-turn off motor

If I gues correctly, then what you want is:
while ((digitalRead (ChainHome_pin) == HIGH)   // NOTE RE-ARRANGEMENT OF PARENTHESIS
      digitalWrite( MotorRelay_pin, LOW);   // Keep looping with Motor On Until Chain is HOME
      digitalWrite( MotorRelay_pin, HIGH);   // Now we're Home and out of loop, so turn off motor

Also note the statement:   if  (digitalRead (ChainHome_pin) == LOW);
Actually does nothing since you terminated it with the ";" before the next statement which is normally executed when the "if" test is TRUE.

In loop() one does not initialize inputs -- they are set by the external reed switches, and setup() does any one time init. If you need to wait for them to be at a known state, then you need to do other things so they sense the conditions you want. Further, by putting these in loop() they are not only redundant, they are executed over and over, rapidly, at the beginning of each loop iteration-- I suspect not what you want.

  //specify state of Inputs/Outputs at start of Loop
digitalWrite ( CageServo_pin, HIGH);       // Intialize to a known state, cage alligned with track
digitalWrite ( KickbackServo_pin, HIGH);   // Intialize to a known state, track set to Divert
digitalWrite ( ChainHome_pin, LOW);       // Intialize to a known state, magnet at ChainHome
digitalWrite ( SkipArrive_pin, HIGH);   // Intialize to a known state, awaiting skip arrivalt
digitalWrite ( MotorRelay_pin, HIGH);   // Intialize to a known state, motor off
digitalWrite ( Cage_pin, HIGH);   // Intialize to a known state, magnet not at CAGE reedswitch  
digitalWrite ( KickbackApproach_pin, HIGH);   // Intialize to a known state, magnet not at KickbackApproach reedswitch
digitalWrite ( KickbackDivert_pin, HIGH);   // Intialize to a known state, magnet not at KickbackDivert reedswitch

I think you need to get rid of all the extra ";" again:  CHANGE THE FOLLOWING AND NOTE ";" PLACEMENT AND CHANGE OF PARENTHESIS WHICH WILL CORRECT SOME LOGIC ERRORS:


  if (digitalRead ((ChainHome_pin) == LOW) && digitalRead (( SkipArrive_pin) == LOW)) ;
digitalWrite (MotorRelay_pin, LOW);   // start motor
  //condition when magnet moves away from ChainHome
if (digitalRead (ChainHome_pin) == HIGH && digitalRead ( SkipArrive_pin) == LOW) ;
(digitalWrite (MotorRelay_pin, LOW));   // run motor
  //condition after magnet picks up skip
if (digitalRead ((ChainHome_pin) == HIGH) && digitalRead (( SkipArrive_pin) == HIGH)) ;
digitalWrite (MotorRelay_pin, LOW);   // run motor

 
  //Case 2 - Tip skip at CAGE
  // Start tip - Stop chain and set CageServo_pin LOW to start tipping cycle
if (digitalRead ( Cage_pin == LOW ));     //magnet on chain arrives at CAGE reedswitch
digitalWrite( MotorRelay_pin, HIGH);   // stop motor, prepare to tip skip
digitalWrite ( CageServo_pin, LOW);    // Move cage to tipped position, will take 3.5 seconds to get there  
  //hold cage at Tip position for an additional 0.5 second
delay(4000);                  // waits for 4 seconds while cage is in motion plus a smidge
  //return cage to Home position aligned with track  
digitalWrite( CageServo_pin, HIGH);    // Move Cage back to Home position aligned with track, will take 3.5 seconds to get there
 //wait to ensure skip and cage are aligned with track for an additional 0.5 second
delay(4000);                  // waits for 4 seconds while cage is in motion plus a smidge
  //disable tip circuit - Set CAGE HIGH
digitalWrite(Cage_pin, HIGH);   // over-ride CAGE readswitch to prevent re-triggering    
  //start chain
digitalWrite(MotorRelay_pin, LOW);   // start motor, haul skip to kickback

 
  //Case 3 - Kickback points operation
  //empty skip approaches kickback point blades
  //set to straight path with KickbackApproach
if (digitalRead (KickbackApproach_pin == LOW)); //magnet on chain arrived at KickbackApproach reedswitch
digitalWrite ( KickbackServo_pin, LOW);   //  Set track to Straight

  //remain set and allow skip to pass Kickback point blades
  //set to divert path with KickbackDivert
if (digitalRead (KickbackDivert_pin == LOW));  //magnet on chain arrived at KickbackDivert reedswitch
digitalWrite ( KickbackServo_pin, HIGH);   // Set track to Divert
//wait with motor running until magnet reaches ChainHome reedswitch
 
 
  //Case 4 - Chain magnet runs back to ChainHome after releasing skip
  //stop chain when magnet gets to ChainHome
if (digitalRead(ChainHome_pin) == LOW);
digitalWrite(MotorRelay_pin, HIGH);   // turn off motor
  //Wait until Case 1, when next skip arrives from the incline.
 
 CHANGE TO:

  //Case 1 - Motor start and moves skip to CAGE when skip triggers SkipArrive reedswitch;
  // Skip arrives at SkipArrive, start chain by MotorRelay;
 if ((digitalRead (ChainHome_pin) == LOW) && (digitalRead ( SkipArrive_pin) == LOW))
digitalWrite (MotorRelay_pin, LOW);   // start motor
  //condition when magnet moves away from ChainHome
if ((digitalRead (ChainHome_pin) == HIGH) && (digitalRead ( SkipArrive_pin) == LOW))
digitalWrite (MotorRelay_pin, LOW);   // run motor
  //condition after magnet picks up skip
if ((digitalRead (ChainHome_pin) == HIGH) && (digitalRead ( SkipArrive_pin) == HIGH))
digitalWrite (MotorRelay_pin, LOW);   // run motor

 
  //Case 2 - Tip skip at CAGE
  // Start tip - Stop chain and set CageServo_pin LOW to start tipping cycle
if (digitalRead ( Cage_pin) == LOW )     //magnet on chain arrives at CAGE reedswitch
digitalWrite( MotorRelay_pin, HIGH);   // stop motor, prepare to tip skip
digitalWrite ( CageServo_pin, LOW);    // Move cage to tipped position, will take 3.5 seconds to get there  
  //hold cage at Tip position for an additional 0.5 second
delay(4000);                  // waits for 4 seconds while cage is in motion plus a smidge
  //return cage to Home position aligned with track  
digitalWrite( CageServo_pin, HIGH);    // Move Cage back to Home position aligned with track, will take 3.5 seconds to get there
 //wait to ensure skip and cage are aligned with track for an additional 0.5 second
delay(4000);                  // waits for 4 seconds while cage is in motion plus a smidge
  //disable tip circuit - Set CAGE HIGH
digitalWrite(Cage_pin, HIGH);   // over-ride CAGE readswitch to prevent re-triggering    
  //start chain
digitalWrite(MotorRelay_pin, LOW);   // start motor, haul skip to kickback

  //Case 3 - Kickback points operation
  //empty skip approaches kickback point blades
  //set to straight path with KickbackApproach
if (digitalRead (KickbackApproach_pin) == LOW) //magnet on chain arrived at KickbackApproach reedswitch
digitalWrite ( KickbackServo_pin, LOW);   //  Set track to Straight

  //remain set and allow skip to pass Kickback point blades
  //set to divert path with KickbackDivert
if (digitalRead (KickbackDivert_pin) == LOW)  //magnet on chain arrived at KickbackDivert reedswitch
digitalWrite ( KickbackServo_pin, HIGH);   // Set track to Divert
//wait with motor running until magnet reaches ChainHome reedswitch
 
  //Case 4 - Chain magnet runs back to ChainHome after releasing skip
  //stop chain when magnet gets to ChainHome
if (digitalRead(ChainHome_pin) == LOW)
digitalWrite(MotorRelay_pin, HIGH);   // turn off motor
  //Wait until Case 1, when next skip arrives from the incline.

Again John, look at the way the while statement is structured in setup() as I suggested and examine whether you need to use this in any places above in the loop( ). I suspect this will be necessary. Remember that if statements are tested ONCE and then they fall through to the next statement.

What you want to happen is that your code starts an operation and waits for it to conclude or waits until the next sensor indicates you are ready for the next action. The little Arduino is looking at those switches more than a million times faster than you are reading a line of code! ...and moving on to the next statement quickly. So you need to tell it to wait for an event, or slow it down like you did with the delay(4000); statements so your mechanism can catch up to your code! I hope this makes a bit of sense. Ask more questions as needed.

I think you have made much progress. Have fun! 
Best regards,
Geoff

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Oztrainz

Re: Code Review 1

 Re: Code Review 1

Thank you Dr Geoff,

The "while" statement is one that I had not heard of previously. It simplifies things considerably in LOOP. The chain runs only one way and there is a known sequence that the reed switches will be triggered as the chain does its stuff by hauling the skip to the top of the kickback siding. A lot of the "if's" will turn into "while's" for when the magnet on the chain is between the various reed switches. 

This is the first time I have actually written computer code in a long while. The last time was in the days of FORTRAN and punched cards in the 1970's. I don't think FORTRAN had a "while" statement or, if it did, I can't remember using it. Many times since I have had job roles where I have had to specify and test the events and sequences of others' programming in the workplace, but this is the first time I've had to design and my own coding. It is an acquired skill that I'm not across yet.  

Your comment on the placement of the "(  )"  is noted and I'll work my way back through each line to fully understand what I'm asking the Arduino to do.  

The Titanic hasn't sunk again and that big iceberg is no longer, but my head still hurts a bit. I don't think I'm quite at ice cubes yet, but I have some ice floes that I have to go beat upon with a coding sledgehammer to reduce them to a size that will fit in my whisky glass.   

Again, thank you for taking the time to look over my shoulder. It is greatly appreciated and has made my path a whole lot easier than it could have been.  

Regards,

John Garaty

Unanderra in oz

Read my Blog

Reply 0
Oztrainz

Next version..

 Next version..

Hi Dr Geoff and all,

I think we are close. I used "if" statements to get me out of the "while" loops. There are some unspecified big chunks of time in here where the "while" has completed, but the conditions for next item to kick off has yet to happen? It shouldn't matter. Everything other than the cage motion is event-driven rather than time-driven.

The revised V3

 

//  Corrimal Tipple Chain Contol Circuit ver 3 Draft;
//  J. Garaty & G Bunza December 12 2017;
// Equipment definitions and pin assignments;
//
#define  ChainHome_pin   2        // D2 ChainHome has a reedswitch to ground
#define  SkipArrive_pin   4        // D4 SkipArrive has a reedswitch to ground
#define  Cage_pin   7        // D7 Cage has a reedswitch to ground
#define  KickbackApproach_pin   8        // D8 KicbackApproach has a reedswitch to ground
#define  KickbackDivert_pin   12        // D12 KickbackDivert has a reedswitch to ground
#define  CageServo_pin   3        // D3 output CageServo is output to ground for TipServo at ANE SmartSwitch
#define  KickbackServo_pin   5        // D5 output KickbackServo is output to ground for KickbackServo at ANE SmartSwitch
#define  MotorRelay_pin   6        // D6 output MotorRelay is output to ground for a relay
// defined servo pins only provide input to ANE SmartSwitch and do not drive servos
// defined MotorRelay pin interrupts supply to tipple chain motor only. Speed control is elsewhere. 
// Determine chain magnet location as part of setup;
 
void setup() {
  // Set up conditions for power up:
pinMode ( ChainHome_pin, INPUT_PULLUP);
pinMode ( SkipArrive_pin, INPUT_PULLUP);
pinMode ( Cage_pin, INPUT_PULLUP);
pinMode ( KickbackApproach_pin, INPUT_PULLUP);
pinMode ( KickbackDivert_pin, INPUT_PULLUP);
pinMode ( CageServo_pin, OUTPUT);
pinMode ( KickbackServo_pin, OUTPUT);
pinMode ( MotorRelay_pin, OUTPUT);
digitalWrite ( CageServo_pin, HIGH);       // Intialize to a known state, cage alligned with track
digitalWrite ( KickbackServo_pin, HIGH);   // Intialize to a known state, track set to Divert
digitalWrite ( MotorRelay_pin, LOW);   // Intialize to a known state, motor start
//chain will run until magnet reaches ChainHome reed switch
while ((digitalRead (ChainHome_pin) == HIGH))   // Magnet on chain is not at ChainHome
      digitalWrite( MotorRelay_pin, LOW);   // Keep looping with Motor On until magnet on chain is at ChainHome reedswitch
      digitalWrite( MotorRelay_pin, HIGH);   // Magnet at ChainHome, breaks  while loop, so turn off motor
//setup complete - ready for skips from incline
}

void loop() {
  
//Case 1 - Motor start and moves skip to CAGE when skip triggers SkipArrive reedswitch;
  // Skip arrives at SkipArrive, start chain by MotorRelay
 if ((digitalRead (ChainHome_pin) == LOW) && (digitalRead ( SkipArrive_pin) == LOW))
 digitalWrite (MotorRelay_pin, LOW);   // start motor
  //condition when magnet moves away from ChainHome
while (digitalRead (ChainHome_pin) == HIGH);
while (digitalRead (SkipArrive_pin) == LOW); //magnet on way to pick up skip,
digitalWrite (MotorRelay_pin, LOW);   // run motor
if ((digitalRead ( SkipArrive_pin) == HIGH)); //skip towed away towards CAGE, causes exit of "while"
  //condition after magnet picks up skip - both ChainHome and SkipArrive reedswitches go High
while (digitalRead (ChainHome_pin) == HIGH);  
while (digitalRead ( SkipArrive_pin) == HIGH);
digitalWrite (MotorRelay_pin, LOW);   // run motor
if (digitalRead ( Cage_pin) == LOW )     //magnet on chain arrives at CAGE reedswitch, causes exit of "while"
 
  //Case 2 - Tip skip at CAGE
  // Start tip - Stop chain and set CageServo_pin LOW to start tipping cycle
digitalWrite( MotorRelay_pin, HIGH);   // stop motor, prepare to tip skip
digitalWrite ( CageServo_pin, LOW);    // Move cage to tipped position, will take 3.5 seconds to get there  
  //hold cage at Tip position for an additional 0.5 second
delay(4000);                  // waits for 4 seconds while cage is in motion to and stable at Tip position
  //return cage to Home position aligned with track  
digitalWrite( CageServo_pin, HIGH);    // Move Cage back to Home position aligned with track, will take 3.5 seconds to get there
 //wait to ensure skip and cage are aligned with track for an additional 0.5 second
delay(4000);                  // waits for 4 seconds cage is in motion to and stable at Home position aligned with rails
  //disable tip circuit - Set CAGE HIGH
digitalWrite(Cage_pin, HIGH);   // over-ride CAGE reedswitch to prevent re-triggering    
  //start chain
digitalWrite(MotorRelay_pin, LOW);   // start motor, haul skip to kickback

  //Case 3 - Kickback points operation
  //empty skip approaches kickback point blades
  //set to straight path with KickbackApproach
if (digitalRead (KickbackApproach_pin) == LOW) //magnet on chain arrived at KickbackApproach reedswitch
digitalWrite ( KickbackServo_pin, LOW);   //  Set track to Straight
  //MotorRelay pin still LOW. motor continues to run
  //remain set and allow skip to pass Kickback point blades
 //MotorRelay pin still LOW. motor continues to run
  //set to divert path with KickbackDivert
if (digitalRead (KickbackDivert_pin) == LOW)  //magnet on chain arrived at KickbackDivert reedswitch
digitalWrite ( KickbackServo_pin, HIGH);   // Set track to Divert
//MotorRelay pin still LOW. motor continues to run
//wait with motor running until magnet reaches ChainHome reedswitch
 
  //Case 4 - Chain magnet runs back towards ChainHome after releasing skip
  //stop chain when magnet gets to ChainHome 
while ((digitalRead (ChainHome_pin) == HIGH))   // Magnet on chain is not at ChainHome
      digitalWrite( MotorRelay_pin, LOW);   // Keep looping with Motor On until magnet on chain is at ChainHome reedswitch
      digitalWrite( MotorRelay_pin, HIGH);   // Magnet at ChainHome, breaks  while loop, so turn off motor
  //Wait until Case 1, when next skip arrives from the incline.
}

I think we may be getting close to a version worthy of loading into the Arduino,

Regards,

John Garaty

Unanderra in oz

Read my Blog

Reply 0
Geoff Bunza geoffb

A Brief Tutorial IF and WHILE

A Brief Tutorial IF and While

Hi John and all the ships at sea!

Please understand that an IF statement of the form:  if ( ...some expression... )  statement_Cond ;
should be read like IF what is inside the parenthesis following, here: ...some expression...  evaluates to TRUE then the statement following the parenthesis here labeled: statement_Cond  is then and only then executed and the semicolon ends the IF statement.
 
Please understand that a WHILE statement of the form:  while (...some expression... )  new_statement_Cond ;
should be read like WHILE what is inside the parenthesis following, here listed as ...some expression... evaluates to TRUE then the statement following the parenthesis here: new_statement_Cond  is then executed and CONTINUES to be executed over and over again, until ...some expression... evaluates to FALSE. The semicolon ends the WHILE statement.
 
So if I write:       while ( digitalRead (pin7) == HIGH)  variable = 1 ;      this statement continuously loops setting variable to 1 while pin7 is HIGH,  when pin7 goes LOW, if ever, the while statement ends, and the next statement following starts.
 
So.... if I write    while ( digitalRead (pin7) == HIGH)  ;  with no statement following the parenthesis and before the ";"   this statement continuously loops until pin7 goes LOW.  In other words it waits for pin7 to go LOW, and it does it VERY fast, so fast that if you are using certain libraries (like DCC libraries) you could mess up their timing. That is not the case here, however.
 
Last scenario:
The statements listed above like statement_Cond and new_statement_Cond can be more than one statement if you surround them all with these squiggly brackets: " { " and "}" and don't confuse them with parens: ( ) or square brackets: [ ] which mean very different things. So we can write.....
while ( digitalRead (pin7) == HIGH)   {
      variable = 7;
      digitalWrite ( pin7,  0 );
      // ... and even more statements...
 }    // ending the set of statements associated with the original while statement
 
All the statements in the  {  } are executed once if digitalRead (pin7) is HIGH
and THEN digitalRead (pin7) is tested HIGH again, and if still HIGH the statement set is executed again
only stopping (sometimes called leaving the loop) when digitalRead (pin7) is LOW.
 
'Hope this helps. You might have a re-look at your code. Have fun! 
Best regards,
Geoff

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
pierre52

Icebergs, Sharks, Submarines and Pirates

Icebergs, Sharks, Submarines and Pirates

if one doesn't get you the next one will????

I can't help having a quiet chuckle as I follow your progress John as it brings back vivid memories of the process that I went through. The good news is that with Dr Geoff on your shoulder you will get there and the satisfaction will more than compensate for the pain on the journey.

Keep it up dude, I for one am enjoying watching your journey.

Peter

The Redwood Sub

Reply 0
Oztrainz

Sometimes...

 Sometimes...

Hi all,

Sometimes... you have to take a back step otherwise you hit a wall...

1270406a.jpg 

This Arduino stuff is driving me nuts...

1270426a.jpg 

Still to add some junk and weeds along the base of the wall.

So here's today's effort - a long view under the screens

1270429a.jpg 

I'm all washered out  The Arduino stuff will be back... I don't give up that easy.

 

Regards,

John Garaty

Unanderra in oz

Read my Blog

Reply 1
Geoff Bunza geoffb

@John re: Comments for Rev4

@John re: Comments for Rev4

Hi John,

Please have a look at this rev and let me know if it makes sense. Look especially at the commented sections marked with "**************************"  Realize that the servo motion takes time to complete the move and keeping the skif moving may not be a good idea. I'm not sure about this so have a look.

I named the Servo and Motor Switches ON and OFF so that it might be less confusing, likewise for the REED switches ON and OFF -- see if this helps. Also note that this will continuously cycle. Do you want to add a delay at the end to slow things down?

It would be a good idea now to go through all the steps, one by one, in loop() and see if they make sense. If they do, try loading your Arduino and have a go!

Have fun! 
Best regards,
Geoff
 

//  Corrimal Tipple Chain Contol Circuit ver 4 Draft;
//  J. Garaty & G Bunza December 13 2017;
// Equipment definitions and pin assignments;
//
#define  ChainHome_pin   2        // D2 ChainHome has a reedswitch to ground
#define  SkipArrive_pin   4        // D4 SkipArrive has a reedswitch to ground
#define  Cage_pin   7        // D7 Cage has a reedswitch to ground
#define  KickbackApproach_pin   8        // D8 KicbackApproach has a reedswitch to ground
#define  KickbackDivert_pin   12        // D12 KickbackDivert has a reedswitch to ground
#define  CageServo_pin   3        // D3 output CageServo is output to ground for TipServo at ANE SmartSwitch
#define  KickbackServo_pin   5        // D5 output KickbackServo is output to ground for KickbackServo at ANE SmartSwitch
#define  MotorRelay_pin   6        // D6 output MotorRelay is output to ground for a relay
// defined servo pins only provide input to ANE SmartSwitch and do not drive servos
// defined MotorRelay pin interrupts supply to tipple chain motor only. Speed control is elsewhere.
// Determine chain magnet location as part of setup;
#define Reed_ON   LOW   // When a reed switch turns ON it connects to Ground GND setting pin LOW
#define Reed_OFF  HIGH  // When a reed switch is OFF the input floats open with internal pullup setting pin HIGH
#define Switch_ON  LOW   // Setting output pin LOW turns relay ON
#define Switch_OFF HIGH  // Setting output pin HIGH turns relay OFF

void setup() {
  // Set up conditions for power up:
pinMode ( ChainHome_pin, INPUT_PULLUP);
pinMode ( SkipArrive_pin, INPUT_PULLUP);
pinMode ( Cage_pin, INPUT_PULLUP);
pinMode ( KickbackApproach_pin, INPUT_PULLUP);
pinMode ( KickbackDivert_pin, INPUT_PULLUP);
pinMode ( CageServo_pin, OUTPUT);
pinMode ( KickbackServo_pin, OUTPUT);
pinMode ( MotorRelay_pin, OUTPUT);
digitalWrite ( CageServo_pin, Switch_OFF);       // Intialize to a known state, cage alligned with track
digitalWrite ( KickbackServo_pin, Switch_OFF);   // Intialize to a known state, track set to Divert
digitalWrite ( MotorRelay_pin, Switch_OFF);   // Intialize to a known state, motor start
//chain will run until magnet reaches ChainHome reed switch
while ((digitalRead (ChainHome_pin) == Reed_OFF)) // Magnet on chain is not at ChainHome
      digitalWrite( MotorRelay_pin, Switch_ON);    // Keep looping with Motor On until magnet on chain is at ChainHome reedswitch
      
      digitalWrite( MotorRelay_pin, Switch_OFF);   // Magnet at ChainHome, breaks  while loop, so turn off motor
//setup complete - ready for skips from incline
}

void loop() {
 
//Case 1 - Motor start and moves skip to CAGE when skip triggers SkipArrive reedswitch;
  // Skip arrives at SkipArrive, start chain by MotorRelay
 if ((digitalRead (ChainHome_pin) == Reed_ON) && (digitalRead (SkipArrive_pin) == Reed_ON))
 digitalWrite (MotorRelay_pin, Switch_ON);   // start motor
  //condition when magnet moves away from ChainHome
while (digitalRead (ChainHome_pin) == Reed_OFF); // Wait until skip leaves home
while (digitalRead (SkipArrive_pin) == Reed_ON) //magnet on way to pick up skip,
    digitalWrite (MotorRelay_pin, Switch_ON);   // Continue running motor
//  We get here when digitalRead ( SkipArrive_pin) == LOW));    //skip towed away towards CAGE, caused exit of "while"
    digitalWrite (MotorRelay_pin, Switch_OFF);   //  Turn off motor
  //condition after magnet picks up skip - both ChainHome and SkipArrive reedswitches go High
while (digitalRead (ChainHome_pin) == Reed_OFF);  
while (digitalRead ( SkipArrive_pin) == Reed_OFF);
digitalWrite (MotorRelay_pin, Switch_ON);   // run motor
if (digitalRead ( Cage_pin) == Reed_ON )     //magnet on chain arrives at CAGE reedswitch, causes exit of "while"
 
  //Case 2 - Tip skip at CAGE
  // Start tip - Stop chain and set CageServo_pin LOW to start tipping cycle
digitalWrite( MotorRelay_pin, Switch_OFF);   // stop motor, prepare to tip skip
digitalWrite ( CageServo_pin, Switch_ON);    // Move cage to tipped position, will take 3.5 seconds to get there  
  //hold cage at Tip position for an additional 0.5 second
delay(4000);                  // waits for 4 seconds while cage is in motion to and stable at Tip position
  //return cage to Home position aligned with track  
digitalWrite( CageServo_pin, Switch_OFF);    // Move Cage back to Home position aligned with track, will take 3.5 seconds to get there
 //wait to ensure skip and cage are aligned with track for an additional 0.5 second
delay(4000);                  // waits for 4 seconds cage is in motion to and stable at Home position aligned with rails
  //disable tip circuit - Set CAGE HIGH
 
//  *********************** You don't "Override an input switch - it is what it is   *********************  
//  But you can ignore the switch anytime you want
// digitalWrite(Cage_pin, Reed_OFF);   // over-ride CAGE reedswitch to prevent re-triggering    
  //start chain
digitalWrite(MotorRelay_pin, Switch_ON);   // start motor, haul skip to kickback

  //Case 3 - Kickback points operation
  //empty skip approaches kickback point blades
  //set to straight path with KickbackApproach
if (digitalRead (KickbackApproach_pin) == Reed_ON) //magnet on chain arrived at KickbackApproach reedswitch
     digitalWrite ( KickbackServo_pin, Switch_ON);   //  Set track to Straight
// ******************************************************************************************
// With regard to the  2 lines above, Do you need to stop  MotorRelay_pin
// and wait for the servo to turn??????  Maybe something like:
//        if (digitalRead (KickbackApproach_pin) == Reed_ON) //magnet on chain arrived at KickbackApproach reedswitch
//           {
//               digitalWrite(MotorRelay_pin, Switch_OFF);
//               digitalWrite ( KickbackServo_pin, LOW);   //  Set track to Straight
//               digitalWrite(MotorRelay_pin, Switch_ON);
//          }
//*******************************************************************************************

  //MotorRelay pin still LOW. motor continues to run
  //remain set and allow skip to pass Kickback point blades
 //MotorRelay pin still LOW. motor continues to run
  //set to divert path with KickbackDivert
if (digitalRead (KickbackDivert_pin) == Reed_ON)  //magnet on chain arrived at KickbackDivert reedswitch
     digitalWrite ( KickbackServo_pin, Switch_OFF);   // Set track to Divert
// ******************************************************************************************
// With regard to the  2 lines above, Do you need to stop  MotorRelay_pin
// and wait for the servo to turn??????  Maybe something like:
//        if (digitalRead (KickbackDivert_pin) == Reed_ON)  //magnet on chain arrived at KickbackDivert reedswitch
//           {
//               digitalWrite(MotorRelay_pin, Switch_OFF);
//              digitalWrite ( KickbackServo_pin, Switch_OFF);   // Set track to Divert
//               digitalWrite(MotorRelay_pin, Switch_ON);
//          }
//*******************************************************************************************

     //MotorRelay pin still LOW. motor continues to run
//wait with motor running until magnet reaches ChainHome reedswitch
 
  //Case 4 - Chain magnet runs back towards ChainHome after releasing skip
  //stop chain when magnet gets to ChainHome
while ((digitalRead (ChainHome_pin) == Reed_OFF))   // Magnet on chain is not at ChainHome
      digitalWrite( MotorRelay_pin, Switch_ON);   // Keep looping with Motor On until magnet on chain is at ChainHome reedswitch
      digitalWrite( MotorRelay_pin, Switch_OFF);   // Magnet at ChainHome, breaks  while loop, so turn off motor
  //Wait until Case 1, when next skip arrives from the incline.
}

 

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Oztrainz

The extra definitions are BRILLIANT

 The extra definitions are BRILLIANT

Thank you Dr Geoff,

The extra definitions of the switch state are BRILLIANT.

Quote:

#define Reed_ON   LOW   // When a reed switch turns ON it connects to Ground GND setting pin LOW
#define Reed_OFF  HIGH  // When a reed switch is OFF the input floats open with internal pullup setting pin HIGH
#define Switch_ON  LOW   // Setting output pin LOW turns relay ON
#define Switch_OFF HIGH  // Setting output pin HIGH turns relay OFF

It helps to physically (rather than mentally) keep track of what is actually happening with the switches. This was a "light bulb" moment for me.  

My next post was to be about working my way through the "while" trapdoors with my code revisions for each "while" statement. 

In reality, what we have is a pretty simple automated system where: 

  • the chain motor can be started and stopped from 2 different locations
  • the relay controlling the cage servo only fires on demand from one location and runs slow as controlled by the ANE Switchmaster and the CAGE reed switch
  • the kickback points change instantly as controlled by the ANE Switchmaster and kickback reed switches.
  • the operation is sequential apart from the tip operation which is time-based, set by the ANE Switchmaster speed setting for the tipple cage.

It took us a fair while (months of part-time development, 2 build iterations and a partial rebuild) to come up with the 555-based control system that is currently running the tipple chain, and some more time actually build the circuitry. It first went live in October 2012.  

In less than 2 weeks (discounting my frying an Arduino and then persisting with trying to resuscitate it) we are getting very close to cutting wires on the old system and replacing it with an Arduino-based "heart". 

I'm still digesting the rest of the previous message. It may take several hours for this to sink in. 

Thanks again Dr Geoff. Those extra definition statements have taken me a long way down the track,  

Regards,

John Garaty

Unanderra in oz

Read my Blog

Reply 0
Geoff Bunza geoffb

@John re: Comments for Rev4

@John re: Comments for Rev4

Hi John,

'Glad this makes some sense.

When I taught basic programming  to non-engineers a couple of lifetimes ago, I asked my students to go through their code "playing computer." That is, using a pad and paper, go statement by statement, step by step, keeping track of all variables on their pad. Ignore what you want to have happen and "see" only what the Arduino will see. You may be amazed at what you assume that the Arduino doesn't know !!   -- 'Been there too many times! 

There is more fun left -- adding some randomness to the operation, and maybe even a few sounds too!

I don't see any icebergs around!  Have fun! 
Best regards,
Geoff

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Reply