Jump to content

Lighting your Star trek federation models - HOW TO (programming)


Recommended Posts

So its quite a popular thing to install lighting into star trek models, most notably star fleet ships such as the enterprise, defiant and many others that are available.

In this How to I'm going to offer step by step instructions on how to program an AVR micro controller chip and cover the changes you can make to the code so that the subtle differences between lighting on the model ships can be achieved.

Coverage:

1) Cover what you need to move forward with the concept

2) Go over the code and how to make the changes to the lighting timings

3) go over preparation

4) Inform you on how to prepare your programming platform (in this case, it will be using an arduino Uno)

5) Moving onto programming the micro controller

6) the final step for this how to will be testing the chip.

I will add various programs to this post for download:

Enterprise

Motorcycle

Car, truck, bus, trike

Vader TIE Fighter with push button gun firing

Edited by SecretReeve
  • Like 2
Link to comment
Share on other sites

First thing's first, the parts list

1) An Arduino Uno

You can buy these from maplins as a stand alone board. If you go down this route you will need your own usb printer cable to use with the board.

Or

You can buy them including a starter kit for just under £40 from ebay. These kits are fantastic as they include almost everything you will need for the entire how to as well as many extras. which is nice incase you decide to experiment further.

2) ZIP socket x2

Zero insertion force socket. a 20 pin one will do nicely! These handy little fellas allow you to install micro controller chips without risking damage to your chips pins like dips or dils would through friction.

3) Attiny2313 micro controllers x2

These are 20 pin micro controllers. They have 18 input/output pins of which 17 are usable. We avoid using the "reset" pin as this can mess with the clock fuses. Buy 2 just in case something goes wrong with one.

4) 20 led's.

Color wise, its best to get the following quantities

white - windows 3 (we're assuming your doing this for the enterprise A as its the most complex) (1 for saucer section windows, 1 for the "neck" windows and 1 for engineering hull windows)

blue - deflector dish and nacells 5 leds

orange - deflector dish and impulse engines 5

red - impulse engines and bussard collectors 5

Now thats 15 led's in total.

5) resistors - 9

The arduino uses 5v outputs so we need resistor values for 5v for each led. here they are

white 68 ohm

red 150 ohm

blue 68 ohm

orange 150 ohm

You want one resistor per led. some people wire 2 or 3 leds per resistor but MINUTE variations in the forward voltage or forward current can cause problems in leds wired like that in the long run, best not to risk it in a model which will be sealed up tighter than a....well you get the idea

6) jumper wires

These wires will link your arduino to the breadboard (included in the arduino starter kit on ebay)

7) Breadboard

Here is where we will test everything before making the real thing. (included in the arduino starter kit on ebay)

a 20cm x 15cm will do nicely.

8) Strip board

We will use this to make an interface board for the arduino and the attiny40 chip. It will allow you to easily and quickly swap chips out if your programming multiple chips in the same sitting.

9) solid core wire (any color)

Used on the strip board

10) straight pcb mount jumper headers

These will connect the strip board to the arduino

I think that is everything, if I have missed something i will come back and add it in. (first how to)

Edited by SecretReeve
Link to comment
Share on other sites

Alright, so we have everything. Or do we?

You bought an arduino uno board, but have you downloaded the software for it?

You did? fantastic!

Then here is the code you will need to load up into the arduino IDE (integrated developer enviroment)

// The Enterprise

#include <LedFader.h>
#include <LedFlasher.h>

// pin assignments
const byte StrobesPin = 13;
const byte NavigationPin = 12;
const byte DeflectorbluePin = 11;   // PWM
const byte DeflectororangePin = 10;    // PWM
const byte NacellsbluePin = 9;      // PWM
const byte ShuttlebayPin = 8;
const byte NacellsvioletPin = 6;   // PWM
const byte ImpulseorangePin = 5;  // PWM
const byte TorpedoPin = 4;
const byte ImpulseredPin = 3;   // PWM
const byte RCSPin = 2; 
const byte CabinPin = 1;

// Faders                           pin           min  max  millis    on?    stop?
LedFader impulseredFader      (ImpulseredPin,      0,   40,  3000,   false,  true);
LedFader impulseorangeFader   (ImpulseorangePin,   0,   40,  3000,   false,  true);
LedFader deflectororangeFader (DeflectororangePin, 0,   40,  3000,   false,  true);
LedFader deflectorblueFader   (DeflectorbluePin,   0,   40,  3000,   false,  true);
LedFader nacellsvioletFader   (NacellsvioletPin,   0,   40,  3000,   false,  true);
LedFader nacellsblueFader     (NacellsbluePin,     0,   40,  3000,   false,  true);

// Flashers                pin          off-time  on-time       on?
LedFlasher strobes    (StrobesPin,        900,       100,     false);
LedFlasher navigation (NavigationPin,     2900,      100,     false);

// states for the state machine
typedef enum
  {
  initialState,
  wantCabin,                 // ALWAYS ON
  wantRCS,                   // ALWAYS ON
  wantNavigation,            // ALWAYS ON
  wantStrobes,               // ALWAYS ON
  wantTorpedostartup,        // ALWAYS ON  
  wantDeflectororangestartup,// Startup mode
  wantShuttleBaystartup,     // Startup mode
  wantImpulseorangestartup,  // Startup mode
  wantNacellvioletstartup,   // Startup mode
  wantDeflectororangeon,     // Impulse mode
  wantDeflectorblueoff,      // Impulse mode
  wantNacellsvioleton,       // Impulse mode
  wantNacellsblueoff,        // Impulse mode
  wantImpulseredon,          // Impulse mode
  wantImpulseorangeoff,      // Impulse mode
  wantShuttleBayon,          // Impulse mode
  wantTorpedoon,             // Impulse mode
  wantDeflectorblueoffreturn,// Impulse mode return
  wantNacellsblueoffreturn,  // Impulse mode return
  wantDeflectorblueon,       // Warp mode
  wantDeflectororangeoff,    // Warp mode
  wantNacellsblueon,         // Warp mode
  wantNacellsvioletoff,      // Warp mode
  wantImpulseorangeon,       // Warp mode
  wantImpulseredoff,         // Warp mode
  wantShuttleBayoff,         // Warp mode
  wantTorpedooff,            // Warp mode
    
  } states;

states state = initialState;
unsigned long lastStateChange = 0;
unsigned long timeInThisState = 1000;

void setup ()
  {
  pinMode (CabinPin, OUTPUT);
  pinMode (RCSPin, OUTPUT);
  pinMode (ShuttlebayPin, OUTPUT);
  pinMode (NavigationPin, OUTPUT);
  pinMode (StrobesPin, OUTPUT);
  pinMode (TorpedoPin, OUTPUT);
  

  impulseorangeFader.begin ();
  impulseredFader.begin ();
  deflectororangeFader.begin ();
  deflectorblueFader.begin ();
  nacellsvioletFader.begin ();
  nacellsblueFader.begin ();
  strobes.begin ();
  navigation.begin ();
        
void doStateChange ()
  {
  lastStateChange = millis (); 
  timeInThisState = 1000; 

  switch (state)
   {
    case initialState:
         state = wantCabin;
         break;
         
    case wantCabin:
         digitalWrite (CabinPin, HIGH);
         state = wantRCS;
         break;
         
    case wantRCS:
         digitalWrite (RCSPin, HIGH);
         state = wantDeflectororangestartup;
         break;
         
    case wantDeflectororangestartup:
         deflectororangeFader.on();
         state = wantImpulseorangestartup;
         break;
         
    case wantImpulseorangestartup:
         impulseorangeFader.on();
         state = wantNacellvioletstartup;
         break;
         
    case wantNacellvioletstartup:
         nacellsvioletFader.on();
         state = wantShuttleBaystartup;
         break;
        
    case wantShuttleBaystartup:
         digitalWrite (ShuttlebayPin, HIGH);
         state = wantStrobes;
         break;
         
    case wantStrobes:
         strobes.on();
         state = wantNavigation;
         break;
         
    case wantNavigation:
         navigation.on();
         state = wantTorpedostartup;
         break;
         
    case wantTorpedostartup:
         digitalWrite (TorpedoPin, HIGH);
         state = wantImpulseorangeoff;              
         timeInThisState = 600000;
         break;
         
//impulse mode
    case wantImpulseorangeoff:
         impulseorangeFader.off();
         state = wantImpulseredon;
         break;
         
    case wantImpulseredon:
         impulseredFader.on();
         state = wantDeflectorblueoffreturn;
         break;
         
    case wantDeflectorblueoffreturn:
         deflectorblueFader.off();
         state = wantDeflectororangeon;
         break;
         
    case wantDeflectororangeon:
         deflectororangeFader.on();
         state = wantNacellsblueoffreturn;
         break;
         
    case wantNacellsblueoffreturn:
         nacellsblueFader.off();
         state = wantNacellsvioleton;
         break;
         
    case wantNacellsvioleton:
         nacellsvioletFader.on();
         state = wantShuttleBayon;
         break;
         
    case wantShuttleBayon:
         digitalWrite (ShuttlebayPin, HIGH);
         state = wantTorpedoon;
         break;
         
    case wantTorpedoon:
         digitalWrite (TorpedoPin, HIGH);
         state = wantImpulseredoff;
         
         timeInThisState = 600000;  
         break;
         
//warp mode         
   case wantImpulseredoff:
        impulseredFader.off();
        state = wantImpulseorangeon;
        break;
        
   case wantImpulseorangeon:
        impulseorangeFader.on();
        state = wantDeflectororangeoff;
        break;
        
   case wantDeflectororangeoff:
        deflectororangeFader.off();
        state = wantDeflectorblueon;
        break;
        
   case wantDeflectorblueon:
        deflectorblueFader.on();
        state = wantNacellsvioletoff;
        break;
   
   case wantNacellsvioletoff:
        nacellsvioletFader.off();
        state = wantNacellsblueon;
        break;
        
   case wantNacellsblueon:
        nacellsblueFader.on();
        state = wantShuttleBayoff;
        break;
        
   case wantShuttleBayoff:
        digitalWrite(ShuttlebayPin, LOW);
        state = wantTorpedooff;
        break;
        
   case wantTorpedooff:
        digitalWrite(TorpedoPin, LOW);
        state = wantImpulseorangeoff;
   timeInThisState = 600000;     
         break;
    } 
  }


void loop ()
  {
   if (millis () - lastStateChange >= timeInThisState)
     doStateChange ();
   // update faders, flashers
   impulseorangeFader.update ();
   impulseredFader.update ();
   deflectororangeFader.update ();
   deflectorblueFader.update ();
   nacellsvioletFader.update ();
   nacellsblueFader.update ();
   navigation.update ();
   strobes.update ();
  }  // end of loop

Looks terrifying doesn't it? Don't worry all the hard work has been done.

There are only a few lines of this code we actually want to pay and real attention to when making changes. those are the very first line "//The enterprise" and the lines with the flasher timings.

That would be this little block

// Flashers                pin          off-time  on-time       on?
LedFlasher strobes    (StrobesPin,        900,       100,     false);
LedFlasher navigation (NavigationPin,     2900,      100,     false);

its fairly self explanatory, we have the type of flashing like (strobes and navigation, the white stroby lights and red/green nav lights) the off time and of course the on time.

If you want the lights to be ON for longer, increase the number on the on time, likewise for the off time. These numbers are milliseconds. good to remember that!

In this code, the strobes flash once per second and the navigation lights flash once every 3 seconds. so we have a 3 to 1 ratio on them.

Each federation star fleet ship seems to have its own flashing time for these 2 sets of lights. I can't find a consise table of them all so use your best judgement here.

When we have everything hooked up for testing the code, you can make on the fly changes so dont be afraid to experiment.

// pin assignments
const byte StrobesPin = 13;
const byte NavigationPin = 12;
const byte DeflectorbluePin = 11; // PWM
const byte DeflectororangePin = 10; // PWM
const byte NacellsbluePin = 9; // PWM
const byte ShuttlebayPin = 8;
const byte NacellsvioletPin = 6; // PWM
const byte ImpulseorangePin = 5; // PWM
const byte TorpedoPin = 4;
const byte ImpulseredPin = 3; // PWM
const byte RCSPin = 2; 
const byte CabinPin = 1;

Let me go over this block a little.

// pin assignments
const byte StrobesPin = 13; This means the strobe lights are on pin 13 of the arduino uno
const byte NavigationPin = 12; This means the navigation lights are on pin 12
const byte DeflectorbluePin = 11; // PWM This means that the deflector dish' blue led's are on pin 11
const byte DeflectororangePin = 10; // PWM This means that the deflector dish' orange led's are on pin 10
const byte NacellsbluePin = 9; // PWM Nacell blue leds are on pin 9
const byte ShuttlebayPin = 8; If you include room lights in your shuttle bay or another circuit in there, this can be used to

trigger those lights or circuit.
const byte NacellsvioletPin = 6; // PWM If you use violet lights for "impulse mode" this is the pin those led go on
const byte ImpulseorangePin = 5; // PWM impulse engines orange led on pin 5
const byte TorpedoPin = 4; torpedo lights pin on 4
const byte ImpulseredPin = 3; // PWM red impulse engine leds on pin 3
const byte RCSPin = 2; reaction control thrusters (orange) on pin 2
const byte CabinPin = 1; cabin lighting.

Edited by SecretReeve
Link to comment
Share on other sites

Preperation:

Alright, so we have the code, open up the arduino ide software, and copy and paste the first big block of code from my post above into the software. Then save it in your sketchbook (this should be documents > arduino) and save it as something like "star ship" or "enterprise"

Because now, we're going to move onto preparing the arduino board and bread board with led's and jumper wires and those easily forgettable resistors.

First thing you'll want to do is find a nice flat solid surface to work on that is clean and tidy so you dont loose anything.

Then take your arduino and breadboard, and sit next to each other.

Take your jumper wires and place 1 jumper wire in each of the arduino uno's 13 ouput pins. Then place the other ends of the jumper wires into the breadboard staggering them. If your breadboard is numbered and lettered, put the jumper wires in the even numbered rows.

link the odd numbered rows together with jumper wires and connect these to the ground on the arduino (its above pin 13)

insert the led's with their possitive (longer leg or smaller flat peice inside the head) in the even numbered rows.

Or like this:

arduino_traffic_light_simple_FR_zps92a0b

For each of the 13 pins.

From here, open your arduino sketch (the one we saved earlier) and click on the "upload" button. The lights should be performing similar to this:

Edited by SecretReeve
Link to comment
Share on other sites

Right, so we've hooked up the test bed, uploaded a sketch to the arduino and tested it.

Next thing is making an interface board so we can easily swap out the micro controllers and not damage anything.

Heres 2 pictures of one I have already made using a 8 pin DIL socket. you'll want to use your 40 pin ZIF sockets so you'll need a larger bread board than i used@

IMAG1128_zpsbfd58c0b.jpg

IMAG1127_zpsf562d199.jpg

Here are the pin connections:

Ardiuno > micro controller

10 > 1

11 > 17

12 > 18

13 > 19

gnd > 10

5v >pin 20

If you decide to just bread board the chip instead of making the interface similar to the above, then you should end up with something like this

fibidi-arduino-attiny2313-connecting_zps

Place your ZIP socket in the middle of the strip board so 1 pin from each side (such as pin 1 and pin 20) are on the same copper tracks and solder it in place

place 4 pcb headers at the right hand side of the strip board so each pcb header is in its own track and solder in place. (these need to be on the under side, the side with the copper tracks)

line up those pcb headers with pins 13 to 10 on the arduino and place 1 pcb header where the ground is and solder on the under side of the strip board and another on the 5v just the same as the ground and solder.

Now use jumpe wires to make the connections and solder them in place.

Now solder a 10uf capacitor between ground and 5v on the strip board, the side of the capacitor with the white line should be on the track of the strip board to the arduino ground.

Now we need to cut the copper tracks.

Cut all the copper tracks between the micro controllers zip socket pins and all the tracks between the jumper wires and the zif socket.

There shouldn't be any shorts.

If you want to include the led's you can but they are optional.

Edited by SecretReeve
Link to comment
Share on other sites

Okay, so you have a couple of things to download now.

It's a zip file which you will need to unzip and place into your arduino folder, the files contained within the folder have been configured already as many guides want you to download seperate files and rename or move things around. this has already been done, if you put it into the relevant location

windows will be my documents> Arduino unsure on other platforms.

and if you get any messages about "overwrite/merge" just merge the files or overwrite what you already have.

Heres the link:http://sdrv.ms/10XPJWh

The next file is an AVR ISP program. This little bit of software uploads to your arduino and allows you to use it as an in system programmer. its a little better than the arduino isp software.

Link:http://sdrv.ms/10XQjmO

this link goes into My documents > Arduino > ArduinoISP2 (create this folder)

Now we are going to open the sketch you just downloaded and upload it to the arduino. So disconnect any jumper wires and led's. remove the 10uf capacitor and leave just the arduino board plugged into usb.

Open the sketch you just downloaded.

Now you want to go to "tools" > "programmer" and select "AVRISP mkII"

2313-2_zpsdc580443.png

Then select "upload"

Edited by SecretReeve
Link to comment
Share on other sites

Now you can close the IDE.

Re-open the Arduino software, then choose these options:

2313-1_zps943b33f3.png

2313-5_zps4a3ba2d9.png

Now close the software.

Open the sketch you want to upload to the microchip and make sure the selections you just made haven't changed.

Reconnect your interface board or breadboard back to the arduino for the setup below

fibidi-arduino-attiny2313-connecting_zps

Now we need to make some changes to the code, its nothing major just pin allocations.

you started with this:

// pin assignments
const byte StrobesPin = 13;
const byte NavigationPin = 12;
const byte DeflectorbluePin = 11;   // PWM
const byte DeflectororangePin = 10;    // PWM
const byte NacellsbluePin = 9;      // PWM
const byte ShuttlebayPin = 8;
const byte DoorsPin = 7;
const byte NacellsvioletPin = 6;   // PWM
const byte ImpulseorangePin = 5;  // PWM
const byte TorpedoPin = 4;
const byte ImpulseredPin = 3;   // PWM
const byte RCSPin = 2; 
const byte CabinPin = 1;

But we need to change those numbers around to this

const byte StrobesPin = 13;
const byte NavigationPin = 12;
const byte DeflectorbluePin = 14;   // PWM
const byte DeflectororangePin = 15;    // PWM
const byte NacellsbluePin = 16;      // PWM
const byte ShuttlebayPin = 5;
const byte NacellsvioletPin = 7;   // PWM
const byte ImpulseorangePin = 4;  // PWM
const byte TorpedoPin = 3;
const byte ImpulseredPin = 2;   // PWM
const byte RCSPin = 1; 
const byte CabinPin = 0;

Here is a pinout image of the chip

attiny2313-pinout_zps75b17ce0.jpg

Now you want to select:

2313-4_zps3ac5d747.png

Once it has uploaded you should be able to make up your circuit using the chip, the 5v power feed from arduino board as well as the ground, some led's and resistors to test the chip. If all went well. you will have a fully programmed ATTiny2313 microprocessor with the star fleet star ship coding.

Enjoy.

as a side note, i should mention, once you understand what is going on with the code and how it works, it can be easily changed for other things such as land vehicles, my motorcycle lighting was created out of this very code, although it does look somewhat different.

Edited by SecretReeve
Link to comment
Share on other sites

No problem. If anyone tries this and has any problems, i'd suggest posting up on here.

Also, any questions and i will start up a FAQs in the last post i made as well.

FAQ's

I uploaded the program using 20mhz external clock and receive a sync error

you will need to burn the 1mhz or 8mhz internal clock bootloader using lady ada's modified arduinoISP to reset the fuses.

Remember 1mhz translates to about 1,000,000 operations per second. pleanty.

Edited by SecretReeve
Link to comment
Share on other sites

I've added some other "vehicle" programs to first post that people might be interested in.

I will also be updating the section about the code because i forgot to include information on changing the pin numbers to that of the chip.

It is worth noting, the motorcycle, car ect and tie vader both can be used on a 8 pin micro controller such as the attiny85

Link to comment
Share on other sites

Great stuff SecretReeve, my starter kit arrived this morning but unfortunately we are away for the weekend do the DV TIE programme will have to wait till Wednesday.

Cheers,

Warren

Link to comment
Share on other sites

  • 2 weeks later...

Hi I have been following this topic and want to know more!!!.

Being of simple mind, I must admit to being a little confused.....does the arduino unit have to be fully attached to your lighting circuit, or is it just used to programme the micro processor ?.

Also on looking up the unit on ebay I found a whole page of different "starter sets"...which one should I go for?

Help me obiwan secretreeve your my only hope!

Link to comment
Share on other sites

aeryn43, I've just started down this road thanks to SecretReeve, from what I know so far the Arduino unit can be used to operate the lighting circuits but if they are simple circuits then it is best to use the Arduino unit to programme a separate microprocessor as these are only a couple of quid each to buy.

I bought this set which seems to have everything needed to get started.

http://www.ebay.co.uk/itm/SainSmart-UNO-R3-2-CHs-Relay-LCD1602-Prototype-Starter-Kit-Arduino-UK-/300911919121?pt=UK_Computing_Other_Computing_Networking&hash=item460fbf8011

Cheers,

Warren

Link to comment
Share on other sites

Hi SecretReeve,

Uploaded the ZIP file and run tried to upload the sketch to the UNO and got this message.

Errormessage_zps10b06027.jpg

What did I do wrong?

Edit: Think I know what I did wrong, need to upload a sketch first before trying to upload to the UNO!

Cheers,

Warren

Edited by Madmonk
Link to comment
Share on other sites

my appologies for not responding sooner,

the arduino can be used to control lighting and lots of other things, i've seen CNC machines and 3D printers controlled by these boards, but hey can alo be used as micro controller programmers, this guide covers mostly the programming aspect of the board.

the starter kit warren linked to is fantastic for starting out, the arduino plaground has lots of sketches to try out and the forums offer alot of help.

warren as for your sketch, did you upload the ISP sketch before loading the sketch to the micro controller?

Link to comment
Share on other sites

Yep think that is the problem Chris, will hopefully get. A bit of. Time this afternoon to play around with it some more.

Cheers,

Warren

Link to comment
Share on other sites

Hi Chris, when I follow your instructions above to upload to a ATtiny85-20 chip I get the following message.

avrdude: stk500_getsync(): not in sync: resp=0x00

I have the board set to ATtiny85 (external 20MHz clock) is that right.

Cheers,

WArren

Link to comment
Share on other sites

you want it on internal 1mhz or 8mhz not external. the external requires an external crystal so now we need to reset the micro controllers fuses.

Can you take a picture of our breadboard so i can see how you have things setup please?

also we'll need to make sure you are using the lady ada modified arduinoISP to burn the bootloader back to 1 or 8 mhz.

fore the majority of scale model coding, 1,000,000 operations per second (1mhz) will be more than enough and anything over may cause difficulties down the line.

Link to comment
Share on other sites

HI Chris,

Two issues I think.

Firstly I didn't down load the ISP sketch and when I run it now I get these error messages.

ErrorMessage2_zpsca7db405.jpg

As for the board set up here is UNO running programme

IMG_0514_zps3caa6f19.jpg

And the set up so you can see it. (Note I have changed the Cannon pin to 6)

IMG_0516_zps7eff6bb2.jpg

And finally the hook up for programming the ATtiny85.

IMG_0517_zps2fb7552b.jpg

Cheers,

Warren

Edited by Madmonk
Link to comment
Share on other sites

Can you pm me your code again so I can check it over and run some tests?

Usually not declared in this scope means that particular is not in the definitions so we need to check everything is properly defined and set accordingly.

Have you got the 1mhz or 8mhz bootloader burnt to the at yet?

The other thing is, that chip may not have the required outputs.

Try loading the arduino blink sketch to the chip after loading the lady ada modified arduinoisp and change the pin in the seketch to pin 4

Link to comment
Share on other sites

Hi Chris,

After a couple of hours away from it then starting all over again I have cracked it and now have the sketch running off the ATtiny85.

I think the main problem was that I didn't load the bootloader before loading the sketch.

IMG_0541_zps8a881c93.jpg

IMG_0542_zpsf2dad532.jpg

Thanks for all the help so far and I'm sure there will be plenty more as I move onwards and upwards.

Cheers,

Warren

Link to comment
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
×
×
  • Create New...