Notifications
Clear all

Relearning Everything

9 Posts
5 Users
1 Likes
797 Views
(@gregw66)
Member
Joined: 3 years ago
Posts: 17
Topic starter  

Hi! GregW from Atlantic Canada here. I am mid 50s, originally trained as an electronic technician in the early 90s. Suffice to say the course focused on FM Radio, Television, and CB Radio. I can do a tuner alignment on a TV, change a CRT tube and fix your VCR. Not much call for that in 2020. I switched to computers and had my own shop selling PCs and doing repairs. Then laptops took over. 

Around that time I had a change of mind and heart and went into ministry. That's all I will say on the topic, I have a broad and open mind but this is not the place for any religious or philosophical discussion. As I've settled in to my new career, I have had time to focus on my life long hobby.

Since a child, and being influenced by my father, I have loved trains. Prototype and model. I am currently modelling the Canadian Pacific in Woodstock, NB. I am a modular railroader and join up with friends in Saint John, NB. Model railroading and electronics go hand in hand for me.

I discovered and built a DIY Digital Command Control system based on an arduino. To complete the system I am running Java based software tailored to Model Railroading that runs on a Pi. I also belong to the Model Railway Electronics Group (MERG) based in the UK who offer electronic kits for train control. I've built a few of those, including one for servo control of the points. 

My current project that I'm compiling parts for is a locomotive turntable drive using a stepper motor controlled by an arduino. I know enough arduino code to make small changes to the DCC++ system mentioned above but not enough to do much. My background is more analog electronics. But I am determined to learn and that's where I discovered DroneBot Workshop and love the videos on Youtube. I'm sure I'll lean on this forum as I try to sort out my latest project. Glad to be here!

GregW66


   
Quote
(@hayttom)
Member
Joined: 4 years ago
Posts: 61
 

Hello Greg!

 

Congratulations on your career adaptability!

 

I am also working on a Arcuino - DCC - stepper motor railway turntable.  What scale is your railroad?

 

Tom

 

#H&WTR

#ModelRailroad

Tom


   
ReplyQuote
(@gregw66)
Member
Joined: 3 years ago
Posts: 17
Topic starter  

@hayttom

Hi Tom, I am an HO modeller. The turntable is relatively small, about 9" actual length. The prototype was in Woodstock, NB Canada. Being a newbie, I chose a motor that seemed to have decent holding torque. It's an NEMA17 – 73oz.in 17HS8401. I'd like to program in the stops rather than have sensors. Thinking simplicity over hardware. 

GregW66


   
ReplyQuote
(@hayttom)
Member
Joined: 4 years ago
Posts: 61
 

Hi Greg,

 

I've found your website - that will give me some fun reading tonight.

 

I'm also programming my turntable stops but I think I'll need one sensor for initial homing - though it has occurred to me that if I always shut my system down with the turntable at a known position, homing might not routinely be necessary.

 

(I'm also Canadian, but I'm living in Kyiv.)

 

Tom

 

 

 

Tom


   
ReplyQuote
Photo Bud
(@photo-bud)
Member
Joined: 5 years ago
Posts: 89
 

Glad to see you here and maybe we can both share some stuff learned here back at Model Railroad Hobbyist!

Photo Bud (aka John)
The Old Curmudgeon!


   
ReplyQuote
(@gregw66)
Member
Joined: 3 years ago
Posts: 17
Topic starter  

@photo-bud

Nice to see a familiar face!

GregW66


   
ReplyQuote
(@zenneke)
Member
Joined: 3 years ago
Posts: 2
 

Hi to you all, i am Peter from the Netherlands. My model railroad scale is OO, I started a long time ago with N-scale, switched to HO while everything became too tiny for my eyes. And during a holiday in Llangollen, Wales, I decided that I had enough of all the continental stuff. At every exhibition you see the same stuff running around. A small prairie was bought in Chester and some wagons at the Dapol factory. A big thing on the wish list was also a small turntable to rotate this locomotive and the ones to come.

While these fully functional turntables are expensive I decided to go for the a Peco manual type in combination with a stepper motor. That's when I discovered the arduino's. Knowing nothing about programming these things. Just hooking up the wiring was clear to me.

I found a program that suits for me on Rudy's ModelRailroad site working with push buttons and a NEMA17.

The only thing I would like to add to this program is the smooth acceleration and deceleration when the turn table starts and reaches it's point where I want it to stop. 

I think the accelstepper library is what I need to introduce into my sketch but I do not have a clue how to use it. Or is this far too complicated for my low level of experience with arduino's and programming?

By the way at the moment the turntable is running perfectly in a prototype set up. A MDF board with an MDF bridge, a 6 wire slipring on the stepper driving the bridge. The zero point finder is made with a Hall sensor and a neodyne magnet on the bridge. The turntable has 4 stopping points ( 3 to go to the loco shed and maintenance area and 1 for turning around the locos to get their chmneys at the front side). The stepper motor runs with microstepping at 1600 steps per rotation via an A3967 easydriver board. I am using the Arduino Uno.

Below is the code I am using.

 

#define NUM_POSITIONS 4
#define ENABLE_PIN A0 // LOW = driver enabled
#define M1_PIN A1 // M1 microstepping mode
#define M2_PIN A2 // M2 microstepping mode
#define DIR_PIN A3 // to DIR pin of driver
#define STEP_PIN A4 // to DIR pin of driver
#define POTM_PIN A5 // Used to change speed
#define POS_1_PIN 9 // LOW = go to pos 1
#define POS_2_PIN 8 // LOW = go to pos 2
#define POS_3_PIN 12 // LOW = go to pos 3
#define POS_4_PIN 11 // LOW = go to pos 4
#define ZERO_PIN 6 // LOW = start find zero routine
#define ZERO_FOUND_PIN 7 // LOW = zero switch found
#define ONOFF_LED_PIN 13 // Motor running LED
#define DIR_LED_PIN 4 // Motor direction LED
#define PULSES_PER_REV 200 // Pulses per revolution

// Define number of positions, and steps from zero to each position
unsigned long tt_position[NUM_POSITIONS + 1] = {0,400,800,1200,1600};

byte dir, current_pos, new_pos, rpm, rpm_old;
unsigned long timeoflaststep;

#include <EEPROM.h>

void motor_enable() {
digitalWrite(ENABLE_PIN, LOW); // LOW = driver enabled
digitalWrite(ONOFF_LED_PIN, HIGH);
digitalWrite(DIR_PIN, dir);
}

void motor_idle() {
digitalWrite(ENABLE_PIN, HIGH); // HIGH = driver disabled
digitalWrite(ONOFF_LED_PIN, LOW);
}

void find_zero() {
Serial.println("Finding zero sensor");
dir = 0;
motor_enable();
while(digitalRead(ZERO_FOUND_PIN) == HIGH) {
if ((micros() - timeoflaststep) > stepinterval()) {
timeoflaststep = micros();
digitalWrite(STEP_PIN, HIGH);
// delayMicroseconds(10); // only needed if step pulse is too short to be detected
digitalWrite(STEP_PIN, LOW);
}
}
motor_idle();
Serial.println("Zero sensor found");
Serial.println();
current_pos = 0;
new_pos = 1;
}

unsigned long stepinterval() { // calculates step timing based on potmeter input
rpm = map(analogRead(POTM_PIN), 0, 1024, 1, 21) * 10; // max 200 rpm, else pulses get lost
if(rpm != rpm_old) {
Serial.print("RPM: ");
Serial.println(rpm);
rpm_old = rpm;
}
return 60000000UL / PULSES_PER_REV / rpm;
}

void rotate(unsigned int numsteps) {
Serial.print("moving to pos ");
Serial.print(new_pos);
Serial.print(" pulses ");
Serial.print(numsteps);
Serial.print(" dir ");
Serial.println(dir);
motor_enable();
while(numsteps > 0) {
if ((micros() - timeoflaststep) > stepinterval()) {
timeoflaststep = micros();
digitalWrite(STEP_PIN, HIGH);
// delayMicroseconds(10); // only needed if step pulse is too short to be detected
digitalWrite(STEP_PIN, LOW);
numsteps--;
}
}
motor_idle();
Serial.print("pos ");
Serial.print(new_pos);
Serial.println(" reached");
}

void setup() {
pinMode(ZERO_PIN, INPUT_PULLUP);
pinMode(ZERO_FOUND_PIN,INPUT);
pinMode(POS_1_PIN, INPUT_PULLUP);
pinMode(POS_2_PIN, INPUT_PULLUP);
pinMode(POS_3_PIN, INPUT_PULLUP);
pinMode(POS_4_PIN, INPUT_PULLUP);
pinMode(M1_PIN, OUTPUT);
pinMode(M2_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
pinMode(STEP_PIN, OUTPUT);
pinMode(ENABLE_PIN, OUTPUT);
pinMode(ONOFF_LED_PIN, OUTPUT);
pinMode(DIR_LED_PIN, OUTPUT);
digitalWrite(M1_PIN, HIGH); // set M1,M2 to 1,1 for microstepping
digitalWrite(M2_PIN, HIGH);
motor_idle();
current_pos = EEPROM.read(0);
if(current_pos > NUM_POSITIONS) {
current_pos = 1;
EEPROM.write(0,1);
}
new_pos = current_pos;
Serial.begin(9600);
Serial.println();
Serial.print("Current memory position = ");
Serial.println(current_pos);
Serial.println();
Serial.println("If memory position is NOT according");
Serial.println("to reality, then find zero first!");
Serial.println();
}

void loop() {

stepinterval(); // read speed and show RPM on serial monitor

if(digitalRead(ZERO_PIN) == 0) find_zero();
if(digitalRead(POS_1_PIN) == 0) new_pos = 1;
if(digitalRead(POS_2_PIN) == 0) new_pos = 2;
if(digitalRead(POS_3_PIN) == 0) new_pos = 3;
if(digitalRead(POS_4_PIN) == 0) new_pos = 4;

if(new_pos != current_pos) {
if(new_pos > current_pos) {
dir = 1;
rotate(tt_position[new_pos] - tt_position[current_pos]);
}
else {
dir = 0;
rotate(tt_position[current_pos] - tt_position[new_pos]);
}
current_pos = new_pos;
EEPROM.write(0, current_pos);
}
}

 

 


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

   
ReplyQuote
(@zenneke)
Member
Joined: 3 years ago
Posts: 2
 

Thanks robotBuilder,

I will notice that for a next code upload.

 

 


   
ReplyQuote