Close
0%
0%

Not Just Another Coffee Table

Custom coffee table with a DCC train track, automation, LEDs and a web interface

Similar projects worth following
Model trains are fun and cool but they can take up a lot of space. This project is about compressing that fun into a fully functional piece of furniture that keeps the partner happy but lets the kids play and gives us a chance to express our hacking desires.

The key design criteria for the coffee table are;

Functional living room table - no mess and nice to look at
Additional practicality features - USB charging ports for devices, storage for living room "stuff"
Fun layout and interesting design
Interactive train and lighting control - easy to use, kid friendly
Automation for added flair

With these criteria in mind, we're documenting on Hackaday as a way to show off what we've achieved, what's failed and all the lessons learned along the way.

The project details will expand as we progress, however, for now these diagrams outlay the main project design as it currently stands;

  • 1 × Raspberry Pi "Brains" of the operation
  • 1 × Teensy 3.2/LC Teensy used to handle effects
  • 1 × Sprog DCC Controller DCC controller for handling DCC interface for controlling the trains
  • 1 × LED Lighting Various LED lighting options
  • 1 × 5V WS2812B 5050 RGB 30LEDs/M LED Strip RGB addressable lighting strip

View all 9 components

  • From "What the Flock" to "Stairway to Heaven"

    Steve Wells12/15/2018 at 05:00 0 comments

    Light at the end of the tunnel

    OK! loads of progress to update on, it's been a while since I have had a chance to do this entry on the terrain.

    The tunnel grouting turned out OK, I have learned a lot about terrain building from Mel the Terrain Tutor, he has a great resource on YouTube and I encourage anyone wanting to find out more to visit his channel https://www.youtube.com/channel/UCx_aro8CTHw7ZD5H661hC6Q

    He has some brilliant ideas and hacks about making your own materials and well explained tutorials on landscaping that I have borrowed from heavily as you will see from the next few log entries.

    But first to catch up, the tunnel was just begging for some lights and at that point I wired it for led's, the intention was to have white light but I didn't notice until I had them in position and was able to test them that I realised they were blue.

    I printed a full size track layout using AnyRail v6.16 DRail Modelspoor Software (Trial Version), a resource that has proven really useful when planning a model railway.

    The full size track layout was a useful guide for checking the tunnel for clearances.

    What the Flock!

    It was time to get on the internet and get some materials for the next stage, this is where I quickly realised how expensive the materials for model making were, I bought some small items (literally!) to get the feel for the scale and experiment with. 

    This is when Mel The Terrain Tutor came in, and I began creating my own flock and foliage using sawdust, fish tank sand, and a sponge.

    I looked at making a static grass applicator but did't have the time or budget to make one never mind buy one, so I went for the super budget version and a balloon rubbed on my jumper, I experimented with PVA glue on a plastic tray, I put blobs of PVA on the tray and chucked some static grass at it, then waved my static charged balloon over it, looks OK and will do for now, cheap and cheerful.

    I gathered up the sawdust from the table saw and used acrylic paint to colour it, left it to dry for a couple of days then sieved it into 3 different sizes.

    I took some fine light sand out of my aquarium and after mixing it with acrylic paint I aggressively dried it on top of the wood-burner.

    I then shredded a sponge with my drill and wire brush and once again coloured with acrylic paint, then air drying for a few days.

    Garden earth and leaves collected from the garden baked and sieve graded into 3 sizes completed the terrain material creation.

    Blue it!

    The grout rock tunnel structure was painted brown then the LED's soldered and sunk into the tunnel roof, later after rigging up a 3v tester from two AA batteries I realised that the LED's were blue, can live with it as it was the only long nose LED's I had, plus they were soldered and embedded in place at this point. These were linked together by the -ve terminal and each with a tail back to the control box area in the tunnel hill centre.

    Having being gifted a kitchen table I test fitted the terrain and measured the overall height. I had to cut the corners of the board base to accommodate the leg brackets of the table.

    Stairway to Heaven!

    My attention turned to the buildings that we want for the layout, a Station is a must, once again I printed, cut out and assembled the building using scalescene kits. These are pretty detailed and take a lot of time and patience to build, but really satisfying to complete, the stairs and roof trusses on the station look awesome, there is a good chance a casual admirer would not notice, but a nice touch if you take the time to try to see through the windows. More buildings to follow.

    The station was mounted on a bit of plasterboard that happened to be the right thickness for the platform, having finally bought the extra track needed.

    The next stage is to run all the wires for LED's, Servo's and track bus back to the control box area ready for fitting the hardware.

  • Programming - Changes before Wiring

    Jack Flynn12/10/2018 at 14:41 0 comments

    Now that the electronics hardware has been confirmed, I've been able to update the code bases to better reflect the hardware we'll use. You can see my code on github

    The main changes on the Arduino/Teensy side have been to support the i2c PWM boards, as well as the Neopixel RGB strip. Instead of stripping out and re-writing from scratch I took the classes I had made for the placeholder hardware and added support for the new additional hardware. This means that my local test piece still works but I can easily change the code over to the new hardware once I get it up and running.

    On the Django/Webserver side of things I was adding support for the Servos which will be used to control the track point switching. The buttons have been added and I've included an image of the track layout to make it clearer what areas the servos affect. I'd like to add a further layer to the interface that indicates what position the track switch points are in and how the servos effect this. It's a work in progress.

    Further backend work was also done so now the Django database is updated when commands are sent to the Arduino Effects Manager. This means when we refresh the page it should show the current positon of all of the connected hardware. A future development will be to add feedback from the Arduino Effects Manager so that the database is fully reflective of the hardware. Currently we're working on the assumption that the database and physical hardware currently match up which might not be the case at first start.

  • Hardware - Electronics - Shopping Montage

    Jack Flynn12/03/2018 at 10:45 0 comments

    The project has been quiet on Hackaday but we've been working away on finalising the electronic elements. We've been working to build the layout, settle on the scenery and, most importantly for electronics, settling on the number of LEDs required. We're estimating around 60 single LEDs across the whole table for lighting effects. This includes Street Lighting, Cars and individual LEDs inside the housing. Once that was settled, I went shopping;

    The strip lighting LEDs will be used around the rim of the top of the table. This will give us ambient lighting that can be controlled via the web interface. At a later date we'll be able to add cool effects and automation such as day and night cycles, moon and sun cycles, and maybe some SciFi effects for fun. The rest of the LEDs will be inside the buildings for nighttime effects. The servos will give us control of the track allowing the trains to move onto different parts of the layout. LDRs will be used for lighting automation and the transistors are needed for controlling some of the higher voltage LED strings. Finally we have the Teensy LC for low level control and a nice I2C PWM board with 16 channels that can be used for providing the Servo and Single LEDs with power and PWM control. These boards seem really nice because we can reduce our pin requirements from over 60 devices to just a single 2 pin I2C bus. Each board can support 16 devices (LEDs and Sevos) and we can daisy chain up to 62 boards together. Thankfully we only require about 5...

    17th of December is our wiring date. It's the day I'll be onsite with the build and we'll be putting all of the electronics together. The planning stages have been fun but I can't wait to get hands on.

  • I am Grout!

    Steve Wells11/05/2018 at 00:32 0 comments

    Having recently tiled the bathroom I had some grout left over, it occurred to me while tiling that this could be used to make scenery for the train table. I sourced some cut offs of wall insulation foam by chance at my local tile DIY shop - shout out to Solway Tile, cost me £1.00 for insulation and £3.89 for the grout, 70% used on the bathroom the rest used for project.

    We wanted a tunnel with lighting options and with the sides being visible via the perspex sides, using the foam and a knife I measured up the curve of the track from the full scale plan and cut the foam roughly to the right shape, I then carved the foam with the knife, cutting out chunks to look like rock face. 

    I constructed the tunnel by joining the pieces of insulation together with cocktail sticks and wood glue, I used chop sticks to keep the foam in line with the base. I then mixed up the grout and added some brown paint (£1.99 The Range)  just to take the whiteness off. I painted the grout on to the foam with an old brush and assembled the tunnel structure. The chop sticks allow me to leave the upper section free to remove for further construction.

    As the grout was drying I realised that the centre section of the hill that forms the tunnel would be a great place to hide some electronics and if I can make it accessible from the top somehow, it would be ideal for top down maintenance or expansion.

    Kind of winging it at this stage with the terrain, adapting as we push forward with the build, the rough terrain idea is for a rolling Hill with tunnels in half the layout and which levels out to a small village with a station and engine shed.  We really need an idea of electronics requirements at this point (position and number of LED's, points servos, signalling  and sensors) , both for the electronics design and the modelling .

  • Paper, glue and tweezers too!

    Steve Wells10/22/2018 at 00:07 0 comments

    Using Smart Models printable building kits, I have created a few test buildings for the project, one early attempt was used for testing with the LED lighting, these paper-craft buildings in N Scale are really small to work with and a few things learned on early builds were that cutting out with a craft knife has to be precise, straight cuts on the line are vital (had to get a pair of reading glasses from the pound shop) Also glue gets everywhere (maybe just me) accurate gluing with minimum glue is required. Tweezers, magnifier and toothpicks are handy tools to have around.

    Oh yeah bought some sheep from China too.

    Needless to say I have got better at paper-craft and planning on doing a small village scene, but first the track layout is next on the list. First of all the dimensions are somewhat dictated by the glass top which is 1100 mm by 600 mm. We used a trial version of layout planning software AnyRail to come up with a layout that is simple but has enough interest with two trains running simultaneously. This turns out to be more of a challenge than meets the eye if we want to automate the running with manual override capabilities.

    We have some track in the workshop but not enough for what we have planned, we will need to hit amazon or eBay at some point but for now we have printed out a full scale plan of the track layout allowing us to consider the table construction and the scenery construction. 

  • Raspberry Pi - Sprog - DCC Train Control

    Jack Flynn10/17/2018 at 08:16 0 comments

    The model train world has moved far forward from the old-school days of analogue current motor control. It's now possible to have multiple trains on a track with sound effects, lights, and motors, and control these trains with ease. DCC (Digital Command Control) is the cool new way to do this. It's a command protocol on the rail lines that allows for addressing  and commanding of individual trains on a shared "network" of rail line. DCC  can be thought of as quite similar to an i2c or rs482 communications bus but also supplying power at the same time as data. We're planning to use, likely 3, N-scale locomotives for our train layout that all have DCC decoders built into them. To interface to the DCC decoders on the trains we're using the Sprog 3 Command Station.

    Sprog 3

    The Sprog 3 is a simple USB based DCC controller that allows for both programming and running of devices on a DCC rail network. It's a really small packaged device and it works on a simple serial command interface. Traditionally it's connected to a PC or Raspberry Pi running JMRI which is a super powerful program that handles reprogramming of devices, track layouts and automation and a tonne of other stuff; it's actually over powered for what we're looking to do and I'm excited for the opportunity to create my own interface for working with the Sprog. To be fair, another reason we're using this controller is it was repurposed from a previous project so essentially for this project it was free.


    DCC Command Protocol 

    So when it came to working with the Sprog I had a little bit of a harder time than expected. The documentation for the Sprog is reasonable. It has a command list for "rolling roads" and other testing features but these setups tend to be for reprogramming purposes. When it comes to actually running a full working track layout you need the sprog in it's command mode instead. 

    I needed a way to get a better look at what the command structure should be for the Sprog. I struggled to find anything under "Dcc command list" on google due to an open source "Dcc controller" project that actually led me astray. In frustration I tried a different tactic; I setup JMRI and after a lot of jigger-pokery I managed to get it up and running with my lovely little DCC decoder tester.

    The decoder tester is basically a deconstructed train on a pcb. It has lights, a motor and speaker and with a decoder plugged in it reacts exactly like a train. Using JMRI (which reaffirmed my opinion that it's overly complex) I was able to monitor the packets that JMRI was sending to the Sprog based on my inputs to the JMRI "throttle" control. This made it clear that the Sprog works on a packet format similar to;

    < O -Train Address- -Data 1- -Data2- -CheckSum- >

    Now I could have simply gone through the process of testing every button press and speed value, creating a look up table of commands and using that to jerry-rig the control I wanted, but obviously it was much better to understand the packet and decode it to allow me to create commands on the fly. I did a couple of easy checks to start out; Speed, Forward, Backward, Stop slow and hard emergency stop. Interestingly these commands were all encoded in one packet. I thought that possibly there would be a separate command for direction and then speed but this didn't turn out to be the case.  

    Clearly I needed some documentation to move forward. I contacted the owner of the Sprog site and he replied pointing out that the sprog accepts "standard NMRA DCC commands". That led me down the rabbit hole of eventually finding the NMRA spec sheet for DCC commands. Reading through the document we can see that the DCC commands are based on a packet layout as discovered and use the individual bits in a byte to differentiate the different commands and control. Another point made to me in the email was that JMRI repeatedly sends the same commands over and over again. This makes sense...

    Read more »

  • Hardware - LEDs & LDRs - Automation Part 1

    Jack Flynn10/12/2018 at 12:19 0 comments

    Part of the fun of this build is to put small subtle details into it that add a layer of complexity to create a more "life-like" feel to the miniature layout. With this in mind we've taken our LED lighting for the housing, street lighting, etc and paired them with an LDR - light dependent resistor, or photoresistor. An LDR can be used to measure the level of light around the sensor. For our application this means we can use an LDR to measure the ambient light level in the layout and use that data to turn on LEDs as if the world is reacting to the light around the table.  This paired with our dimming LEDs creates a nice result (code block at the end of the post);

    By pairing multiple LDRs with block groups of LEDs then I'm hoping we can create localised areas that will react to objects placed on the top of the table that reduce the light in a certain area and the local LEDs turn on in response.  Combining this with my house and street light setup we can see a nice little result;

    /*
     Turns on LEDs based on LDR feedback
     Uses analogue write to handle dimming of LEDs
     */
     
    int Redled = 6;
    int Yelled = 5;
    int Grnled = 3;
    
    boolean RedState, YelState, GrnState = false;
    
    int RedRate = 1;
    int YelRate = 10;
    int GrnRate = 60;
    
    // the setup routine runs once when you press reset:
    void setup() {                
      // initialize the digital pin as an output.
      pinMode(Redled, OUTPUT);     
      pinMode(Yelled, OUTPUT);     
      pinMode(Grnled, OUTPUT);     
      pinMode(A5,INPUT);
      Serial.begin(115200);
    }
    
    // the loop routine runs over and over again forever:
    void loop() {
      Serial.print("LDR Value;"); Serial.println(analogRead(A5));
    
      static boolean LightState = true;
      boolean newLightState = LightState;
      
      if(analogRead(A5) < 600)
       newLightState = true;
      else
       newLightState = false;
       
    if(LightState != newLightState)
    { 
      LightState = newLightState; 
      
      if(newLightState == true)
      {
      //Brigthen all leds
      for (int i = 0; i < 255; i++)
      {
        analogWrite(Redled, i);
        analogWrite(Yelled, i);
        analogWrite(Grnled, i);
        delay(10);//reset timer
       
      }
      }else
      {
       
      //Dim all leds
        for (int i = 0; i < 256; i++)
      {
        analogWrite(Redled, 255-i);
        analogWrite(Yelled, 255-i);
        analogWrite(Grnled, 255-i);
        delay(10);//reset timer
      } 
      }
    }
    }

  • Hack a glass table top

    Steve Wells10/12/2018 at 00:37 0 comments

    I bought a £29.99 glass table just for the glass although it had 4 of these metal adaptors glued in place. It was the correct size for the table project and it was tempered and bevelled glass (thought it'd be worth the risk). After a bit of research on the internet, I realised I had to apply enough heat to the adaptor to melt the glue used to attach the adaptor without risking too much heat to the glass.  

    I used a soldering iron and ground down a steel bolt so it would replace the tip and could be also screwed into the metal adaptors and rest there while heating up. While it was heating I clamped some mole grips to the metal and applied a constant downward pressure to it until the glue got to its its melting / softening point (500 degrees?)and it comes away. So no heating of the glass and just enough heat to get it off.

    Worked great and we now have a clean piece of bevelled tempered  glass for the project. 

     While it was heating I clamped some mole grips to the metal and applied a constant downward pressure to it.

    It took about 40 mins before any signs of softening.

    The bubbles began appearing on the edge and spread across the adaptor.

    Just drops off when soft enough without any damage to the glass, just another three to go!

  • Hardware - LEDs - A digital boy in an imperfect world.

    Jack Flynn10/11/2018 at 15:39 0 comments

    I've had a lot of fun playing with the LEDs. As of this moment each LED is connected to a pin on the Teensy. In the future, as the number of LEDs grows, I'll need to use a buffer chip of sorts to prevent running out of pins or over current draw from the Teensy. For the code I've created wrapper modules to make controlling the LEDs easy with the Teensy and they should be upgradable when I change control method. 

    Before writing this log entry I had the LEDs switching on and off as shown in my previous entry. This shows that the logic control for the LEDs is working and we have that instantaneous control. How this is achieved from mouse click to LED "on" is detailed below;

    The Imperfect World

    LEDs are a perfect example of a digital device. They are generally on or off without any variation of power in the middle; as soon as you apply a voltage above a threshold you get full brightness depending on the allowed current usage. This is great for fast paced, reactive interfaces; nothing catches your attention like a blinking LED. However in the real world of lighting, particularly older homes and street lights, this on-off flip to full brightness isn't achieved  instantaneously. It takes time for normal bulbs to warm up and produce their full brightness, perhaps this isn't ideal in the real world but aesthetically it's comforting and more natural than instant "LIGHT!". With this in mind can our LEDs replicate this imperfect "warm up"?

    Trick of the eyes

    Again, unlike the analogue world of bulbs where we can use a variable resistor (dimmer) to vary  our brightness, the digital world of LEDs requires a more complex solution to allow for "dimming". As stated an LED is either on or off, this is fact, but our eyes are easily deceived. Blink an LED above 60 blinks a second and what should be on-off-on-off appears to our eyes as constantly on; this neat little trick can be seen here:

    (red flashing 1/s, yellow 10/s and green 60/s - not as easy to see as the yellow is brighter)

    The code to achieve this effect is really simple. We're just turning the LED on and off and on again 60 times a second.

    /*
    Based on "Blink" example.
    
    Runs 3 LEDs blinking at different rates dependent on timers. 
    
    The "on" and "off" period are the same amount of time.
     */
     
    int Redled = 6;
    int Yelled = 5;
    int Grnled = 3;
    
    boolean RedState, YelState, GrnState = false;
    
    int RedRate = 1;
    int YelRate = 10;
    int GrnRate = 60;
    
    // the setup routine runs once when you press reset:
    void setup() {                
      // initialize the digital pin as an output.
      pinMode(Redled, OUTPUT);     
      pinMode(Yelled, OUTPUT);     
      pinMode(Grnled, OUTPUT);     
      Serial.begin(115200);
    }
    
    // the loop routine runs over and over again forever:
    void loop() {
    
      static unsigned long RedTimer = millis();
      static unsigned long GrnTimer = millis();
      static unsigned long YelTimer = millis();
    
      //Timer for red led
      if(millis() - RedTimer > 1000/(RedRate*2))
      {
        RedState = !RedState; //Flip value of RedState
        digitalWrite(Redled, RedState); //Write to pin
        RedTimer = millis(); //reset timer
      }
      
      //Timer for Yellow led
      if(millis() - YelTimer > 1000/(YelRate*2))
      {
        YelState = !YelState; //Flip value of YelState
        digitalWrite(Yelled, YelState); //Write to pin
        YelTimer = millis(); //reset timer
      }
      
      //Timer for Green led
      if(millis() - GrnTimer > 1000/(GrnRate*2)) //need to double the rate as this covers "on" and "off" cycle
      {
        GrnState = !GrnState; //Flip value of RedState
        digitalWrite(Grnled, GrnState); //Write to pin
        GrnTimer = millis(); //reset timer
      }
    }

    Dimming by PWM

    So blinking really fast allows us to trick the eyes into seeing a constantly "on" LED but we still don't have control over the brightness. The answer lies in "PWM" - Pulse Width Modulation. We're basically taking the "blinking-really-fast" trick and adding another layer on top. Previously when we were blinking the LED we had the same amount of "on" and "off" time. This is known as a 50% duty cycle where the pin spends the same number...

    Read more »

  • Hardware - LED Testing - Little blinkies are fun!

    Jack Flynn10/09/2018 at 14:33 0 comments

    Putting LEDs inside something instantly increases its cool factor by 50%. What started as a miniature house that would forever sit lifeless on the layout is now more alive simply by adding some LEDs to liven up the place. The cool thing about these miniature N-Scale (which is tiny by the way!) buildings is that they've been built with acetate clear windows and internal floors. That means when I put 2 LEDs into the house then I can individually light up the top floor and the bottom separately. It's a nice touch and you can see the effect in the video below.




View all 18 project logs

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates