Jump to content
 

The Bunny Mine (cakebox)


riscosuser
 Share

Recommended Posts

Time to move onto Phase 2

 

I've had a little time to think about the control for this cakebox.

 

Basic criteria,

1.Manual/automatic control

2.Control for the point servos

3.Speed control of loco(s)

4.possible additional animation?

 

Was intending using an Arduino, both on price and capabilities, I still feel this will meet the bill.

Worth mentioning I have never used one, so this is going to be a learning curve.

 

Requirements;

 

1x Analogue input for speed control (pot) (seems reasonable to use this for both auto and Manual modes.)

1x Analogue input for setting loop delay (would work with a fixed delay, but a good way of determining what looks best)

3x PWM outputs for the servos

2x PWM outputs to drive an L298N H-bridge Circuit

1x digital input to control siding point servo (only enabled in manual mode)

1x digital input for auto/manual switch

2x inputs for loco detection

 

Going to leave D0 & D1 free so I could possibly add a serial device later.

 

Doesn't leave many free Digital i/o's probably going to use analogue for loco detection.

 

I might as well use an L298 module considering the price despite having a couple of chips already.

 

All I need to do now is build it!

Link to post
Share on other sites

I did something similar to control a Hornby Santa trainset a few years ago.

 

Nothing as fancy as servo controlled points, but it did have a couple of triggered sound effects to annoy anyone in the vicinity for more than 5 minutes!

Link to post
Share on other sites

Well, I'm rather pleased to say I've done the basic programming in just a few hours, not bad for a first go!!

 

I hunted around last night for something to make the job easier. found it in Tinkercad, which is free to use.

 

The emulator has let me test the code and the wiring out without damaging any hardware.

(I did make a mistake on the enable pin on the L293 although using a module means this would have been taken care of for me)

 

I've designed it with switches for "testing" I'll post my code below if anybody wants to play.

 

I could have made some of the code more concise but I hope I've made it easy to read.

 

post-23137-0-97059100-1540220134_thumb.png

 

code follows;

 

#include <Servo.h>
#include <SoftwareSerial.h>
 
// Variables will change
// set servo min/maxs if required
int posmin1 = 0;
int posmax1 = 255;
int posmin2 = 0;
int posmax2 = 255;
int posmin3 = 0;
int posmax3 = 255;
  
int button = 0;
int speed = 0;
int direction = 0;
 
//set pin names
// 0 RX
// 1 TX
// 2 is free
Servo servo_3;
//4 is free
Servo servo_5;
Servo servo_6;
const int motorDirPin =7; //temp diag
const int trackloop =8; // temp dual servo diriction
const int motorPin1 = 9;
const int motorPin2 = 10; 
const int motorEnable = 11;
const int siding = 12; // on final version
//13 internal led
 
  
void setup()
{
  
  //setup pins
  pinMode(A0, INPUT);
  
  servo_3.attach(3);
  servo_5.attach(5);
  servo_6.attach(6);
  pinMode(motorDirPin, INPUT);
  pinMode(trackloop, INPUT);
  
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  
  pinMode(siding, INPUT);
  pinMode(13, OUTPUT);
  
  //Serial.begin(9600);
 
}
 
void loop()
{
    
  //H-Bridge control
  
  speed = analogRead(A0) / 4;
  direction = digitalRead(motorDirPin);
  
  analogWrite(motorEnable, speed);
  
  if (direction == HIGH) {
    
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
}
  else
  {  
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
    
  }
  // read the state of the loop pushbutton value:
    button = digitalRead(trackloop);
  
  if (button == HIGH) {
 
    digitalWrite(13, HIGH);
    
    servo_3.write(posmax1);
    servo_5.write(posmax2);
   
    
  } else 
  {
    
    digitalWrite(13, LOW);
   
    servo_3.write(posmin1);
    servo_5.write(posmin2);
    
   }
    
  // read the state of the loop pushbutton value:
    button = digitalRead(siding);
  
  if (button == HIGH) {
    
    digitalWrite(13, HIGH);
    
    servo_6.write(posmax3);
    
  } else 
  {
   
    digitalWrite(13, LOW);
   
    servo_6.write(posmin3);
      
   }
  
   // wait 15 ms for servo to reach the position
    delay(15); // Wait for 15 millisecond(s)
 }
  

 

 

  • Like 1
Link to post
Share on other sites

There are certain moments where you want to scream. While having to do so trimming due to the raised cab roof I knocked the cakebox & loco on the floor and damaged both.

 

So a bit of extra work now needed :(

 

I'm reasonably happy with my manual mode Arduino coding, need to do more work on the automatic aspect.

 

At least I've finished wiring the board and have fitted the servos.

 

post-23137-0-50513000-1540750247_thumb.jpg

 

As can be seen, I've had to trim the servo bases leaving one microswitch (& despite the rat's nest) it works.

 

 

 

 

  • Like 2
Link to post
Share on other sites

Any chance af a quick video to see it working, Lovely model.

Your wish (eventually) my command.

 

 

You can see the start of the repairs to the left-hand side, I ended up cutting it out and replacing with card.

 

The tree to the RHS front was snapped off and the rear one bent, I'm going to remake this one with a wire frame for the base.

 

I'm updating the detail on the little loco, the rear shows up how I "stretched" it.

 

One issue I have is how much it should weigh,

My figure weighs in @ 24gms, so to balance it I need another 24gm weight.

The brass loco and mechanism weigh in @ 18gms so this would be 66gms (2.3oz in English)

Just concerned it might be too much.

Does anybody know?

  • Like 1
Link to post
Share on other sites

  • 2 weeks later...

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