Sign in to follow this  
Phoxtane

Control board for block signals

Recommended Posts

Now that my semester is mostly over, I've been thinking about some of the projects I had to put on hold to focus on my senior design project this year - specifically, the PCB I developed a couple years ago to run two three-color track signals off a centralized microcontroller: 

The original design called for a three-color signal: red, yellow, and green. My plan was to divide my layout into blocks, with a signal placed on each block. I wanted my signals to respond in the following manner:

- If a train is detected in a block, that block's signal must be red (block is occupied).

- The signals in the blocks adjacent to occupied blocks must be yellow (block ahead is occupied).

- Otherwise, the block signal will be green (block is unoccupied).

This would result in the signals 'following' the train around the layout, such that any trains travelling on the same track would be aware of each other, hopefully avoiding collisions. In practice, I won't be running trains on the same track, but it's still a fun effect to have!

My resulting truth table then looks like the following. Inputs A and S are the signals from the adjacent blocks and block sensor, respectively, while outputs R, Y, and G are the red, yellow, and green signals, respectively.

truthtable.PNG

It doesn't matter which 'side' I get a signal from an adjacent block, as either way I want the signal to turn yellow. In addition, if the block sensor sees a train, I don't care what the adjacent blocks are doing - the signal must turn red.

After working through this table, it occurred to me that there were two ways I could build this signal controller...

 

Form 1: NAND Logic

This truth table is simple enough that I should be able to build it with basic logic gate ICs - and if I can do that, then I can do it purely with NAND logic gates, saving cost as I only need one type of chip to make this work. However, I still need to work on converting the truth table to a set of Boolean expressions, and from there into pure NAND logic. After doing a bit of research, it looks like I'll need multiple NAND chips, as most chips I find have only four gates inside them. However, I am space and cost limited, as I can only use four NAND chips (16 NAND gates) if I want to be comparable to the cost of the ATTiny85 at 36 cents per chip.

 

Form 2: ATTiny85

Since I only have five inputs/outputs, the ATTiny85 microcontroller is perfect for this application - there are exactly five pins left over after accounting for power, ground, and reset. However, I would need to program each microcontroller, and doing so with a surface-mount device becomes problematic. The cost is also an issue, as each one costs about $1.16-1.25.

 

Buying in relatively small quantities, I think I can get the cost of components for each board to about $5 per board - including connectors and such. The main issue with using NAND gate chips is the amount I'll need, and thus the space they'll take up on a size-limited board. I also will need some transistors to drive the LEDs as the logic chips can't drive that much current directly. The issue with using an ATTiny85 chip for each board is how to program the much smaller surface-mount versions, as well as the relatively large fixed cost of each chip - I can't work on optimizing out some of the cost in the same way I could with the NAND version.

I want to use JST connectors for running cables between the boards and sensors and such, as they're directional and I don't have to worry about plugging things in backwards this way.

There is another question I have for you all: what's the most useful form factor? My original project had a board that was designed to fit in a 4x4 stud area, but for this I'm leaning more towards a 2x6 or 2x8 board, as I think I can fit that into more spaces.

Share this post


Link to post
Share on other sites

The tech is interesting but I'm curious what these signal will look like?

Share this post


Link to post
Share on other sites
10 hours ago, sed6 said:

The tech is interesting but I'm curious what these signal will look like?

I'm using three colors - red, yellow, and green. I want to use 3mm LEDs as opposed to the 5mm I tried last time; my hope was that the 5mm LEDs would fit in the holes in a Technic brick or beam. However, they're oversized for that hole size, and to make them fit I either had to sand them down or force them in such that they would never come out.

The 3mm LEDs fit into the holes in pieces such as the headlight brick or the 1x1 round plate with hole - basically, any hole that a lightsaber blade piece can fit into - so that gives me many more options for methods to build proper signals. I am also considering 3D printing an insert for Technic beams or bricks that fits into the 5mm hole, but has a place for the 3mm LED to pass through. 3D printing would also let me model the shrouds on these signals. I'm imagining something that looks like this: 

signal01.jpg

...although it would have to be somewhat taller to fit in.

Share this post


Link to post
Share on other sites
6 hours ago, ronenson said:

I did something similar recently using an Arduino Nano:

Lego Train Lights

I'd love to see more, would you consider starting your own thread (or pointing us toward an existing one)?

Share this post


Link to post
Share on other sites

After taking a break on the boards, I've begun work on the physical design of the signals themselves. There are multiple problems with designing such a model, however - the standard 5mm LEDs that many people are familiar with are too large to fit into a Technic hole (4.8mm diameter) without considerable force, and then we have light leaking out the back due to the exposed underside of the LED. The 3mm LEDs which I am working with currently are small enough around that they don't lock into holes that a standard Lego bar piece would (e.g., the front of a headlight brick), but the ring at the bottom prevents them from passing through entirely. For either case, once the LED is located, I still need a way to get the wires out of the model and under the 'floor' to their power source. For many models I've come across online, the trick here is to drill or cut Lego pieces to provide passthroughs, but the last guy I saw try that still isn't out of the hospital.

The model below provides a decent method to mount 3mm LEDs, but has the issue of being quite bulky due to how the LEDs are fixed in place. The LED leads are passed through the center of a Technic pin mounted on the Technic beam, with the base of the LED butted against the top of the pin. A 1x1 cylinder piece slips over the Technic pin and allows the LED to poke through the hole at the top. An appropriately colored transparent piece is used as a lense.

800x450.jpg

I'm not a huge fan of this design as it's quite large, ugly, and has no good way to hide the wires that will come off the back to form a cable. I was able to slim it down somewhat by using a Technic half-pin and one of the new 1x1 round plates with a hole to lock the LED in place, but the body of the device is still quite large.

I think the best way to hide the wires is to use a ground-mounted signal, avoiding showing any large lengths of wire to begin with, but I still have the problem of fixing the LEDs in place without the model looking huge. I think this is where the various 3rd party lighting companies have it figured out - use tiny surface-mount LEDs with a very small gauge of wire attached that can slip between assembled bricks. In order to test this theory, I've ordered a 10-pack of pre-wired 0805 SMD LEDs from AliExpress. In theory, the package should arrive within 12-20 days, and I paid with Paypal because I didn't feel comfortable with giving them my card info (despite reading many assurances to the contrary on Reddit and such). They added a $0.80 charge for using Paypal, but overall my out-of-pocket expense was $7.06.

Tonight I also settled on a design for the PCBs, so those have been sent off to a board house I've never tried before. Given how cheap it was, I'm very curious to see how they'll turn out. They should be here in about a week or so.

Share this post


Link to post
Share on other sites

The printed circuit boards have arrived, and they're looking quite decent:

800x580.jpg

The board house appears to have added a designator of their own in the upper-right of the top side of the board. I assume this is because they're taking multiple orders and putting them on to one large panel, and this allows them to track whose order is whose. I've satisfied myself that the electrical connections are correct, so I've ordered the resistors, capacitors, and diodes I'll need to put this together. Those should arrive later this week. I already have the other components on hand.

I did end up going ahead with the microcontroller version of this board, as with the space I had available both component placement and routing would have been very difficult using NAND logic chips. I'm already using up about half of the available area on the connectors alone. While on my prototypes the microcontrollers will be socketed, on the final product they'll be soldered in permanently, though I've left myself an ISP connection if it becomes necessary to update the software.

My plan is to assemble as many boards as I have sockets, which should be five. This will allow me to demonstrate that the system works as intended, and if everything works out I can move on from a prototype to a final version.

Share this post


Link to post
Share on other sites

I assembled the first board today, and I'm quite pleased with the results. The socket is a perfect modification for a prototype, as I had to make multiple changes to the software (firmware?) in order to get the desired behavior. I also put together a quick test board with three warm white LEDs to get visual confirmation of things working correctly. 

800x450.jpg

800x450.jpg

800x450.jpg

I have had one large setback; as it turns out, crimping connectors onto cables gets really irritating and difficult, really fast. I'm attributing this to my cheap crimping tool and supplies - however, a proper crimping tool from the 'real' supplier costs in the range of hundreds of dollars. I also noticed that of the time I spent working on this project today, crimping took up the vast majority of it. As such, I'm going to instead start using pre-crimped wires rather that roll my own. Not only will this save me time, but it should boost the quality and repeatability of my results - once I move beyond two wires in a given cable, they never seem to line up perfectly to form an even-length bunch.

This now means I get to choose the exact lengths of wire that I'll be getting. Therefore, I'd like to ask the community what the most useful lengths of wire would be. I'm thinking of two shorter cables for going to the LEDs and the block sensor, and a much longer cable for going between boards. I don't know if I had made it clear earlier, but these boards are designed to be daisy-chained - they pass power and the appropriate signals to their neighbors - so this cable must be much longer if it will be of any use. How long is long enough? I'm thinking of 24 inches (~61cm) as a good compromise for an appropriate distance between each signal and being long to actually be useful.

Share this post


Link to post
Share on other sites
On 17.5.2018 at 7:19 AM, Phoxtane said:

I'm not a huge fan of this design as it's quite large, ugly, and has no good way to hide the wires that will come off the back to form a cable. I was able to slim it down somewhat by using a Technic half-pin and one of the new 1x1 round plates with a hole to lock the LED in place, but the body of the device is still quite large.

  1. Get 5 mm LEDs just like the one that were used in 7860, sand the lip off and cut the legs as short as possible. Leave no more than 1 mm.
  2. Drill out the "+" sections of a 1x3 thin technic liftarm. Make the holes big enough so that 5 mm LEDs barely fit in there.
  3. Insert your 3 LEDs into the 1x3 liftarm. Use as little glue as possible. If any.
  4. Wire up the LEDs using thin enamel coated wire.
  5. Remove the marked sections (see picture) of a 1x3 tile and drill a hole that's barely big enough for the enamel coated wires to pass through.
  6. Glue the 1x3 liftarm with your LEDs to the 1x3 tile. After routing the wires through the hole, of course. Use as little glue as possible.
  7. Glue the 1x3 tile with the attached liftarm onto the top of an antenna that has the newer style flat top.
  8. Carefully glue the wires to the back of the antenna, if you want it to look nice.
  9. Hollow out a 2x2 or 2x3 or brick. Drill a hole in one side that's barely big enough to pass the enamel coated wires through. Put a tiny PCB inside the brick that connects the enamel coated wires to some sort of micro JST connector. Depending on how many wires are needed. Or just solder the wires to the connector. Cut a hole for the JST connector in the opposing side of the brick. Use needle files.

41657637744_ec39d59838_b.jpg

40573038540_0c109367c1_b.jpg

41657414714_0d2a19863c_b.jpg

Edit:

If you want it to have that shroud, then take a piece of cardboard or thin plastic, cut it to size, paint it black and glue it onto the liftarm. No 3D printer needed.

Actually, you can use a "Hose, Rigid 3mm D." instead of the antenna. That way the wires can be completely hidden, if you are willing to drill two holes through the green 4x4 plate. In that case you only need something like a 2x2 45° slope to house the JST connector.

42382469361_f072decd65_b.jpg

Edited by 3797

Share this post


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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.