Jump to content
 

DCC Controlled (PECO) Turntable Project using a Arduino Uno


Recommended Posts

What does the original BlueTooth (BT) code look like?  Does your BT need specific baud such as 115200 and not 9600?

 

Couple of unrelated questions:

1.  Does this code return "8": (sizeof(gAddresses)/sizeof(gAddresses[0])),  seems like it should equate to ( 8 * IntBytes / IntBytes )

 

2.  What does this code do (beside resetting addr to 0 after 8 cycles):

if( ++addr >= (int)(sizeof(gAddresses)/sizeof(gAddresses[0])) )
{
addr = 0;
}

  Can't find any other reference to addr.

Link to post
Share on other sites

Hi NinOz

 

Please see below for the original sketch for the Bluetooth. All I have done is added it to the loop of Tender's Sketch that is on entry 48.

I tested it also on other know working DCC sketch with the same outcome. If I check the serial monitor there is some messages but none sent from the sketch.

It looks like they are coming from one of the libraries. Even if I sent a ON or OFF from the serial Monitor it still not working. Is the interrupt that the DCC is using causing the serial monitor

not to work?

 

Working Bluetooth sketch below:-

/*
  This sketch is part of a tutorial for connecting to and communicating with an HC-06 or an RN-42 bluetooth module using a custom Android App. 
  The bluetooth modules are connected to an Arduino and the Arduino is connected to an LED. The Android app is used to wirelessly turn on and
  off the LED using  bluetooth. 

   This code is in the public domain.
 */

 // Pin 13 has a LED connected to it
int led = 13;

 // the setup routine runs once when you press reset:
void setup() {
  
  Serial.begin(9600);
  // initialize the digital pin as an output and set it low initially
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW);
}

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

Regarding your question about the DCC sketch you would be better asking Tender as this is his sketch

 

Any help would be most grateful

 

Alan

Link to post
Share on other sites

 

 Is the interrupt that the DCC is using causing the serial monitor not to work?

Most likely.  Both will be trying to use interrupts to monitor inputs so quite possible that your serial info is being lost.  I doubt that the DCC library was written with consideration of any other concurrent coms usage.

Serial inputs seem to be quite problematic for arduinos, lots of correspondence on the net but little resolutions.

 

One solution to a similar problem I remember is a chap used two arduinos connected by I2C, one to handle the serial input, buffer and pass to the other.

 

If you only wanted to send a TON and TOFF to the DCC decoder then could use a second arduino (cheap pro mini type) for serial input  and use 3 input/output pins on each arduino.  Should only take a few lines of code on each sketch.

Link to post
Share on other sites

  • 2 weeks later...

alangdance

 

I looked over the code and made a small one line addition that makes it work.  I added it to your code    t.trim();   (see code below!). With this addition the code works as advertised!!!

 

Happy New Year

 

David Garrison

 

Hi NinOz

 

Please see below for the original sketch for the Bluetooth. All I have done is added it to the loop of Tender's Sketch that is on entry 48.

I tested it also on other know working DCC sketch with the same outcome. If I check the serial monitor there is some messages but none sent from the sketch.

It looks like they are coming from one of the libraries. Even if I sent a ON or OFF from the serial Monitor it still not working. Is the interrupt that the DCC is using causing the serial monitor

not to work?

 

Working Bluetooth sketch below:-

/*
  This sketch is part of a tutorial for connecting to and communicating with an HC-06 or an RN-42 bluetooth module using a custom Android App. 
  The bluetooth modules are connected to an Arduino and the Arduino is connected to an LED. The Android app is used to wirelessly turn on and
  off the LED using  bluetooth. 

   This code is in the public domain.
 */

 // Pin 13 has a LED connected to it
int led = 13;

 // the setup routine runs once when you press reset:
void setup() {
  
  Serial.begin(9600);
  // initialize the digital pin as an output and set it low initially
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW);
}

 // the loop routine runs over and over again forever:
void loop() {
  delay(30);
  String t; //create an empty string to store messages from Android
  while(Serial.available()) { //keep reading bytes while they are still more in the buffer
    t += (char)Serial.read(); //read byte, convert to char, and append it to string
  }
  
  if(t.length()) { //if string is not empty do the following


//Added this line of code

     t.trim();   // this trims off all the received unprintable characters! 




    if(t == "ON") { //if the string is equal to "on" then turn LED on
      digitalWrite(led, HIGH); //Set digital pin to high to turn LED on
      Serial.write("Moving to Main Track CW"); //Tell the Android app that the LED was turned on
    }
    else if (t == "OFF") { 
      digitalWrite(led, LOW);  
      Serial.write("Moving to Main Track CCW");
    } // turn the LED off by making the voltage LOW
  }
}

Regarding your question about the DCC sketch you would be better asking Tender as this is his sketch

 

Any help would be most grateful

 

Alan

Edited by sierrasmith
Link to post
Share on other sites

  • 2 months later...

All I can say is WOW!
I have been looking for such a longtime for Ardunio controlled Turntable information and here it all is.

 

There are so many of you to thank so without missing anyone "THANK YOU ALL"

As I progress I will also post my build and any scripting that I may write change, etc.

 

Looking forward to this with much glee :sungum:

  • Like 2
Link to post
Share on other sites

I read a thread somewhere about Hall effect devices and the magnet proximity was fairly critical even for a neo magnet.

 

The problem was the sensor could not be so low as to contact the rails at crossings but the magnet should not be so high as to be obtrusive above the sleepers. 4mm was about the max for reliable approach/depart detection.

 

A lot depended upon the rail profile ratio 100, 85, etc.

Edited by RAFHAAA96
Link to post
Share on other sites

All Parts on order, will arrive home before I get back from Germany.

Looking through the code from page one, I guessed that was the best place to start with Ray's original coding.

Done a little programming in the past so hope to get to grips with it soon.

Plus I like the drawings for all the brackets etc. I have a friend whos got a small cnc milling machine and I think I can see some worth in making them from Aluminium.

 

Will post more as I porgress.

 

Ian

  • Like 1
Link to post
Share on other sites

Hi all

After quite sometime of building the rest of the layout, I'm back to the turntable and ready to set up the programming.

luciansima80 mentions use of a servo motor brake to stop the stepper motor from making a whining noise when not in use, he refers to some code in luce001 ( page 7 post #155 code line 34 ) programme.

I've so far not been able to find the full code for this on the Arduino web site.

Any help would be greatly appreciated

Thanks

Link to post
Share on other sites

I have a massive request is it possible to have a schematic of the wiring from the post #99 I have tried to decide where and what is soldered to each other and struggling on a few areas.

Would any one know if this is available?

I don't want to destroy anything when making up the board.

 

many thanks in advance.

Ian

Link to post
Share on other sites

Hi all

After quite sometime of building the rest of the layout, I'm back to the turntable and ready to set up the programming.

luciansima80 mentions use of a servo motor brake to stop the stepper motor from making a whining noise when not in use, he refers to some code in luce001 ( page 7 post #155 code line 34 ) programme.

I've so far not been able to find the full code for this on the Arduino web site.

Any help would be greatly appreciated

Thanks

 

I think if you read this then you will see that the Servo.h is already there.

https://community.particle.io/t/servo-h-library-included-with-arduino-solved/1209

 

Regards,

Ian

Link to post
Share on other sites

Hi Ian

Thanks for your reply. If that's the case then I guess something else must be causing it to whine.

Might have to pick your brains again if I get stuck if that's ok

Link to post
Share on other sites

I have a massive request is it possible to have a schematic of the wiring from the post #99 I have tried to decide where and what is soldered to each other and struggling on a few areas.

Would any one know if this is available?

I don't want to destroy anything when making up the board.

 

many thanks in advance.

Ian

 

Hi Ian.

There's a schematic of the turntable circuit in post 8.

 

Ray.

  • Like 1
Link to post
Share on other sites

Hi Ian.

There's a schematic of the turntable circuit in post 8.

 

Ray.

Hi Ray,

 

I have that and fully understand it, I was looking at the updated or increased one for Analogue and digital that is shown in Post #155.

When I get home from Germany this week all the parts har arrived so I can start with the LK55 build and the Circuit from yours.

Then see if I understand it any further.

Thanks for the reply.

 

ATB,

Ian

Link to post
Share on other sites

  • 3 weeks later...

Good evening all.

 

I'm new to the forum having stumbled across it whilst searching how to build a dcc turntable.

 

I studied electrical enginnering at college many years ago although now only used a hobby, i'm learning arduinos but keep getting distracted by projects.

 

i'm also new to model rail, and am building a layout along with my dad, brother and uncle, at this stage i'm mocking up the turntable on a board for testing, i have followed through the first few pages (thank you so much for the easy to follow guide) and i'm now up to rev 17. i have the screen but have yet to connect it.

 

the turntable is based on a Dapol kit as its a style similar to the local area (west somerset railway) although the deck is now made from copper clad board with brass I beam to add support and height in the middle, attached to which is a mecano bush wheel drilled out to clamp directly to my stepper motor which has bearings much the same as i was planning to use.

 

under the bush wheel is a simple two track contact disk made from copper clad (35mm hole saw to seperate tracks (only through copper) and 52mm to cut out the disk. contacts is made via wipers with rolled ends made from normal pickup type strip.

 

now i've tried using a reversing loop module (merg type) but it keeps tripping, it i connect directly sound loco works fine for 360degrees plus without tripping the controller. 

 

I also plan to use a servo brake and build a control box with a rotating switch and resister ladder rather then a pot. I post up photos of the underside of the bridge when i next take it off. also have a nice idea for wooden decking that should look very realistic :)

 

what i would like to do is be able to toggle a output to switch a relay to invert the track polarity depending on the direction of the table. could someone please point me in the right direction of how to add this (code wise, hardware i'm fine with)

 

Jon

 

2016-04-02%2008.05.50.jpg

Edited by Jon Gridley
  • Like 2
Link to post
Share on other sites

Jon

 

I'm guessing you are running your locos on DCC? This will cause a short when the wipers cross the dead zone if you use a commutator, which I guess you are not doing, so I'm guessing (again!) that your reverse loop module trips when the loco drives off the table?

 

I can't think of a good reason why that should happen. Maybe something will occur to me, if so I'll shout up.

 

An alternative (and probably cheaper) approach: You can get a pair of relays which a pin on the arduino will drive - each relay is spco and can be used to power the deck rails, change over when "half way round" - something like this, for example

 

http://www.ebay.com/itm/1x-2-Channel-250V-10A-Relay-Module-Board-and-Shield-AC-DC-Arduino-Raspberry-PI-/131394111558

 

The code should be dead easy, I'm sure you'll have no issues with it. I glued a lamp to one end of my t/t so I knew which end was which. This helps!

 

Works for me! HTH

 

 

Simon

Link to post
Share on other sites

yes DCC, no break in the contacts, i've popped the bridge off and taken a couple shots, it does it ramdomly, think the reverse module is too sensitive, it'll even to it whilst rotating with a loco on. i plan to use a simple double pole double throw relay, i allready have the relay and the hardware side is easy, i just need to know how to modify the code to switch the relay when the bridge is 180 degrees out.

 

Jon

 

 

2016-04-05%2021.22.53.jpg

 

2016-04-05%2021.23.24.jpg

Edited by Jon Gridley
Link to post
Share on other sites

Sorry to butt in and take everyone back to Page 1 but I have recently bought all the parts and have got to the stage of the "turntable test" . This uploads OK and the TT spins through 180 degrees and reverses just as described. What is does not do is find the sensor first. So powering off and on again just makes it start and stop at random points albeit at 180 degrees apart. My assumption is that the sensor is not working. I have to admit to not wiring it as per the diagram as I am trying to avoid DCC (even though I use it) and I have wired the green wire to I/0 3 , the red to the adafruit +5v and the black to the adafruit ground (i.e, no DCC board in between). The code suggests that this should be OK but it does not seem to be working. I have the sensor with the writing pointing at the magnet (it is on a spinning disk, the same diameter as the deck running underneath) and the latter is only 2mm or so away as it passes by. Does anyone have any ideas what may be wrong?

My second question concerns the unpleasant high pitch noise from the motor. Is that normal? It does seem to have quietened down during the testing or I have got used to it.

Finally, I assume just being a test it is not meant to come to an end. The only way I can stop it is to disconnect the usb cable and/or the power.

 

Thanks in anticipation. This thread has been an inspiration to me for some time  and I am very grateful to all those who have paved the way.

 

Bryan

 

In response to Jon's question I am using one of those clever auto-reversers. Tam Valley do one as a variant of their frog juicers but I am using the DCC Concepts one which is excellent. Basically two wires from the turntable (one on the ring which goes all the way round and one from the centre pivot)are wired to one side of the reverser, The other two wires go to the track bus. As the loco leaves the deck after being turned the electronics sense the short and reverse the polarity. It happens so quickly it is not noticeable. Even sound equipped locos just carry on without interruption. 

Link to post
Share on other sites

have you tried the sensor the other way up, when i was playing with mine i found it only works around one way, i removed the outer plastic and heat shrunk it to make it smaller.

 

in regards to the reversing module although simple in installation I'm building to  a budget and can't justify buying a £90 reversing module when a DPDT relay costs less then £5, i'm sure its a easy mod in the software but not 100% sure how, it means then it will seemlessly flip the track polarity as the bridge rotates

Link to post
Share on other sites

Thanks Jon - I will try that. It's just occurred to me that I could use a meter to see if the voltage(?) increases as I move nearer to the magnet. Will try that when I next have time.

I had forgotten where I got my auto-reverser from and thought it was DCC Concepts - it was in fact DCC Specialties and the same one can be bought for £21:50p. That still makes it dearer than your £5 relay and part of the fun is finding new ways to do things and if that saves you money then fair enough.

 

I have a further question (sorry). The link to the DCC libraries does not work. Can anyone help with a link that does work?

 

Bryan

Link to post
Share on other sites

I have the libraries stored on my dropbox, i did find i have to alter the the name of the stepper driver library. here is the link.

 

https://www.dropbox.com/sh/o15rm6xz8iqp1uv/AADNfGefgdrStUCukmjWqVgJa?dl=0

 

 

 

I have also had a good play about, at the moment i have hacked the merg reverse loop module to allow me to controll the relay remotely, just to check all works, then i'll mount my relay and a control transistor on to a bit of strip board. i have added the following code to the bottom of the 'steppertimer' routine. line 420 this is using Rev 17 of the code by Luce001 in post #155 don't forget to add 'pinMode(8, OUTPUT) in the setup routine.

//New section to read direction bed is facing and invert the polarity if needed.
               //pinMode(8, OUTPUT) also added to void setup()             
                if (tableTargetHead)
                  {    //use head location variable
                    {
                        digitalWrite(8, HIGH);
                        Serial.println("   DCC Polarity Relay activated ");
        }
    }
                else
                  {    //use tail location variable
                   {
                       digitalWrite(8, LOW);
                       Serial.println("   DCC Polarity Relay deactivated ");
        }
    }
Link to post
Share on other sites

Hi all. Like a number of others before me, I have came across this and Tender's earlier post a few weeks ago, and have been reading through the whole topics to catch up with the discussion.

 

For some time I have been looking for a reliable way to operate a turntable, starting off with a simple DC motor and gearbox using an index ring. However the motor was so noisy that I abandoned this.

 

This thread seems to provide the answer, so after a few weeks playing with an Arduino starter kit I have taken the plunge and purchased lol the parts. Fortunately programming is not new to me although I am somewhat rusty.

 

My ne t problem is sorting a suitable turntable. I have a couple of Airfix kits, however as the years have past I have a desire for a mor accurate GWR 65’ turntable. As the Metalsmiths kit is now £105 I was wondering if it was feasible to scratch jailed one from plastic are. Has anyone ever tried this and succeeded?

 

I have decided to post here as I feel that I cannot proceed with this without acknowledging all the effort and assistance all the prior posters have given, particularly Ray (Tender) for string this all off.

 

As I am not a DCC modeller, I am planning to use something based on Cambrian Coaster's version using push buttons, but this of course is based on Ray's initial work. As I will only have two roads on the T/T I would need to simplify this a little.

 

As it is now spring, I guess progress will not be quick, but if appropriate I will let you all know how I get on, and hopefully if I get any problems one of you experienced folk will be able to help me out.

 

Once again, many thanks to you all.

 

Colin.

Link to post
Share on other sites

Hi all. Like a number of others before me, I have came across this and Tender's earlier post a few weeks ago, and have been reading through the whole topics to catch up with the discussion.

 

For some time I have been looking for a reliable way to operate a turntable, starting off with a simple DC motor and gearbox using an index ring. However the motor was so noisy that I abandoned this.

 

This thread seems to provide the answer, so after a few weeks playing with an Arduino starter kit I have taken the plunge and purchased lol the parts. Fortunately programming is not new to me although I am somewhat rusty.

 

My ne t problem is sorting a suitable turntable. I have a couple of Airfix kits, however as the years have past I have a desire for a mor accurate GWR 65’ turntable. As the Metalsmiths kit is now £105 I was wondering if it was feasible to scratch jailed one from plastic are. Has anyone ever tried this and succeeded?

 

I have decided to post here as I feel that I cannot proceed with this without acknowledging all the effort and assistance all the prior posters have given, particularly Ray (Tender) for string this all off.

 

As I am not a DCC modeller, I am planning to use something based on Cambrian Coaster's version using push buttons, but this of course is based on Ray's initial work. As I will only have two roads on the T/T I would need to simplify this a little.

 

As it is now spring, I guess progress will not be quick, but if appropriate I will let you all know how I get on, and hopefully if I get any problems one of you experienced folk will be able to help me out.

 

Once again, many thanks to you all.

 

Colin.

Link to post
Share on other sites

Sorry about the typo's in the last post. I think you can get the jist of what I was trying to say. This will teach me not to post from my iPad, but use the laptop. The iPad spellchecker can be a law unto itself.

 

Regards,

 

Colin.

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