Experiment 28: The Ching Thing - Make: More Electronics (2014)

Make: More Electronics (2014)

Chapter 28. Experiment 28: The Ching Thing

In this experiment, you can build a device to display a pair of hexagrams in an electronic version of the I Ching. I’m calling it the “Ching Thing.”

If these terms mean nothing to you, there is no cause for concern, as I will be explaining them almost immediately.

A much shorter version of this project appeared in Make magazine. Really it was too complicated to be compressed into just a few pages, so I’m presenting a new version of it here, with more illustrations and detailed explanations.

Also, I simplified the circuit with help from my friend Fredrik Jansson, who once built his own computer entirely from 4000-series logic chips. In fact, my first contact with Fredrik was when he sent an email to me at the magazine, pointing out that I could eliminate one of the OR gates that I had included in the schematic. I mention this to make it clear that I really do read all the messages that come my way. And I take them seriously!

Hexagrams

Getting back to the Ching Thing:

The I Ching (pronounced “ee-ching”) is an ancient Chinese book containing enigmatic advice about your present situation and future prospects. You can think of it as telling your fortune.

This strange and remarkable compendium of advice is more than 2,000 years old, and the basis for it may be more than 3,000 years old. Some people believe it really does have predictive power. I’m not sure they’re right, but on the other hand, I can’t prove they’re wrong.

Many English translations of the I Ching are available, and some of them are free online. Every version contains sixty-four basic descriptions of your status, and each description is identified by a graphic image called a hexagram.

To give you an example, two hexagrams are shown in Figure 28-1, with abbreviated explanations of their meaning. Anyone who takes the I Ching seriously will complain that these interpretations are much too simplistic—which is true. The thing is, I don’t claim to be an I Ching expert. I’m just here to show you how to simulate it electronically.

Two sample hexagrams, and some very approximate interpretations.

Figure 28-1. Two sample hexagrams, and some very approximate interpretations.

Each of the six lines in a hexagram can be solid or broken. In other words, each line can have two states. There are six lines, which is why the number of different possible hexagrams is sixty-four:

2 * 2 * 2 * 2 * 2 * 2 = 64

The important part is that the hexagram on the left relates to your situation at the present time, while the hexagram on the right tells you your future. You always need a pair of hexagrams to figure out where you are and where you’re going.

The Display

When I started planning this project, I decided to display the hexagrams electronically with light bars—little rectangular components with LEDs inside. A closeup of a light bar is shown in Figure 28-2, and a rendering showing how the Ching Thing could look is inFigure 28-3.

An LTL-2450Y light bar (or similar) can be used to make a neat display.

Figure 28-2. An LTL-2450Y light bar (or similar) can be used to make a neat display.

A 3D rendering of the Ching Thing, displaying a couple of hexagrams.

Figure 28-3. A 3D rendering of the Ching Thing, displaying a couple of hexagrams.

To use the Ching Thing, I’m imagining that you will hold down a button while two hexagrams are generated for you. Then you can look up their interpretation in the I Ching translation of your choice to acquire some insight about your fate.

The challenge is to generate the hexagrams in a way that is an accurate simulation of the traditional method. This required me to do a bit of research.

The Straight and Yarrow Path

In ancient times, you determined the solid and broken lines in a pair of hexagrams by “casting yarrow stalks.” Yarrow is a weed, and a yarrow stalk is what you end up with when the weed dries up and dies. Casting the stalks involved a complicated procedure of dividing them into piles and counting them, but the underlying principle was clear: your fortune depended on the way in which the stalks fell by chance.

Casting yarrow stalks was a complicated business, and when the I Ching experienced a surge of popularity in the 1960s, most people lacked the patience to follow the correct procedure. In any case, hardly anyone knew what a yarrow stalk was, and there was nowhere to buy them, because the Web had not been invented. This may seem hard to believe, but back in the 1960s, you couldn’t order stuff from Amazon or eBay.

Consequently, people started using an easier system to generate hexagrams, based on tossing coins. Unfortunately, this system created a set of probabilities for hexagrams which was different from the set associated with yarrow stalks.

When I started planning an electronic simulation, I decided that it should be as authentic as possible. I wanted to follow the original, stalk-based probability set—but how could I figure that out? No problem! I looked it up in Wikipedia, which has a pretty good entry on the I Ching.

Now, remember, you must have two hexagrams, the one on the left describing your present state and the one on the right relating to your future.

The I Ching goes into a lot of detail about situations where a broken line in the lefthand hexagram becomes a solid line in the righthand hexagram, or vice versa. These are referred to as “changes,” which is why the I Ching text is often called “the book of changes.” In fact, I think it was the source of that old 1960s saying, “My life is going through so many changes,” which Buddy Miles recorded as a song with Jimi Hendrix—but, I digress.

So, to do this job right, we need to know the odds of a broken line changing into a solid line, or a solid line changing into a broken line, or a solid line staying the same, or a broken line staying the same. That’s how the hexagrams are constructed: one pair of lines at a time, six times in succession. For convenience, I’m going to refer to a single pair of lines as a horizontal “slice” that spans the two hexagrams.

The Numbers

Figure 28-4 shows the four ways that solid and broken lines can be paired in a slice. Each of these combinations is not equally probable because of the complicated way in which the yarrow stalks were counted. The probabilities are shown on the right.

Probabilities of each combination of hexagram lines in a “slice” composed of one line from the left hexagram and one line from the right hexagram.

Figure 28-4. Probabilities of each combination of hexagram lines in a “slice” composed of one line from the left hexagram and one line from the right hexagram.

How to make this work electronically? Well, the number 16 is very convenient, because (as I’m sure you remember) a decoder has sixteen outputs. Suppose a timer is running very fast, controlling a binary counter, and the counter output is going to the decoder. Now suppose the timer stops arbitrarily so that one of the decoder outputs is selected at random. The decoder outputs can be grouped to create probabilities of 1 out of 16, 8 out of 16, or whatever we want.

Figure 28-5 shows the general idea. The decoder has sixteen outputs, numbered 0 through 15. We could decide that if any of the bottom eight outputs has a high state, the left line in a slice will be solid. That is, the light bars will all be illuminated.

How the outputs from a decoder can be grouped so that a random selection has the correct odds for creating a pair of hexagram lines.

Figure 28-5. How the outputs from a decoder can be grouped so that a random selection has the correct odds for creating a pair of hexagram lines.

Looking back at Figure 28-4, you can see that in the 8 times out of 16 when we have a solid line on the left, 3 of those 8 times there will be a broken line on the right, and 5 of those 8 times there will be a solid line on the right. You can see that I have taken care of this in Figure 28-5.

Now, if any of the other eight outputs from the decoder has a high state, the left line will be broken—that is, we’ll have two light bars illuminated at either end, but the one in the middle will be off. One time out of those eight, we will have a solid line on the right. This, again, matches the specification in Figure 28-4.

The natural state of the light bars is off, so we only have to worry about switching them on. The rules for doing this can be summarized using the decoder output numbers, like this:

§ Rule 1: if output 8 OR 9 OR 10 OR 11 OR 12 OR 13 OR 14 OR 15 has a high state, the left line in a slice is switched on.

§ Rule 2: if output 1 OR 11 OR 12 OR 13 OR 14 OR 15 has a high state, the right line in a slice is switched on.

Sounds like we will need a couple of big OR gates. Although—wait a minute. In rule 1 (as Fredrik Jansson pointed out to me), the left line is solid for all numbers in the range 8 through 15 (1000 through 1111 binary), and off the rest of the time (0000 through 0111 binary). What do binary numbers 1000 through 1111 all have in common? They all have a 1 in the leftmost place. So I can rewrite the rule like this:

§ Rule 1 (revised): if the 8-value output from the binary counter has a high state, the left line in a slice is switched on.

We will no longer need an OR gate for rule 1.

As for rule 2, it will require an OR gate with six inputs. Does such a thing exist? No, but there is an eight-input gate that has an OR output (it also has a NOR output, which I can ignore). I’ll tie two of its inputs to negative ground and use the remaining six.

This is sufficient to create one slice in a pair of hexagrams. There are six slices, so I’ll have to go through the procedure six times.

Random Sampling

My method for choosing a random number will be to sample or stop the rapid counter at an arbitrary moment. Okay, but—how?

I want the process to seem automatic. I don’t want the user to have to press a button six times. So how about this: I can add a timer running slowly (about one pulse per second) in asynchronous mode. If its speed varies unpredictably, I can use it to sample the fast-running counter six times.

How can I make it unpredictable? I have an idea. If you moisten your finger, the skin resistance between two points that are fairly close together will range from maybe 500K to 2M. I can use this as the resistance that controls the pulse speed of the slow timer.

Now all I need is an automatic system to generate the bottom slice of the two hexagrams, shift it up one space, generate another slice, shift it up, and repeat this process until I have six slices. The phrase “shift it up” strongly suggests to me that I need a shift register.

In fact, I need two shift registers, one to store and display the lines in the left hexagram, and the other to store and display the lines in the right hexagram. I’ll call them Register 1 and Register 2. You can see them in Figure 28-6--which also shows a third shift register, but I’ll deal with that in a moment.

Digital-logic components to generate two hexagrams.

Figure 28-6. Digital-logic components to generate two hexagrams.

The counter runs continuously, the decoder runs continuously, and they are hard-wired into the data inputs of the shift registers. (Fortunately, chips don’t wear out when we run them fast like this, on a continuous basis.) But as you may recall from Experiment 27, the shift registers don’t do anything until they receive a clock signal. This tells them to shift the contents of their memory locations, “clock in” the new data, and display the result.

The slow-running timer will provide the clock pulses. It doesn’t matter that the pulses are relatively long, because the shift register only responds to the rising edge of each pulse.

The Look and Feel

So here’s the scenario. You switch on the Ching Thing. You moisten your finger and press it against the terminals. Depending how moist the skin is, and how hard you push, the slow timer runs at a variable speed. It samples the fast timer at random intervals, and two hexagrams scroll slowly up the light-bar display.

I especially like this plan because the slow timer won’t run at all until you press your finger against the terminals. The resistance between the terminals will be almost infinite, preventing the timing capacitor in the slow timer from charging. So we don’t need a “start” button. You plug in the Ching Thing and it waits for your finger press.

Ideally, it should stop itself, too. Perhaps when the topmost slice of the hexagrams is generated, I can take some voltage from there to activate the reset pin of the slow timer so that it ceases to generate pulses. I will have to convert the high state of the topmost slice into a low voltage on the reset pin, but a transistor can take care of that.

In case this isn’t entirely clear, I have summarized the “chain of command” in the circuit in a flow diagram in Figure 28-7.

The basic principle of the Ching Thing is outlined in this flow diagram.

Figure 28-7. The basic principle of the Ching Thing is outlined in this flow diagram.

One question remains. Why is there a third shift register in Figure 28-6? Notice that its outputs drive the two outermost light bars in each hexagram. Those light bars will be on all the time, regardless of the state of the center light bar. I could just connect all of the bars permanently to the positive side of the power supply—but the hexagram display will look nicer if each slice is illuminated in succession, with all the light bars coming on and scrolling upward together. So, the third shift register is used just to make the process look good. It has its data input hard-wired to the positive side of the power supply, and it jogs the positive states upward with each clock pulse, in sync with the other shift registers.

The Details

I omitted a few details in this circuit. First, you could add a reset button that would apply a pulse to the “clear” pins of all three shift registers. Since the 74HC164 shift register requires a low input to reset it, the “clear” pins should be held high with pullup resistors, and a pushbutton would connect them momentarily with negative ground.

Second, the 74HC4078 single eight-input OR chip is listed by some suppliers as being obsolete. I still see it advertised online for less than 50 cents apiece, but in the future it will be less readily available. Fortunately the old 4078B CMOS version is still in plentiful supply and can be substituted, as we won’t be taking any significant current from its output. You can use either the 74HC4078 or the 4078B in this circuit.

Both of these chips actually contain a NOR gate and an inverter, because an inverted NOR is the same as an OR. The OR output and the NOR output are available from separate pins, as shown in Figure 28-8.

Pinouts of the 74HC4078 and the 4078B, either of which may be used in the Ching Thing circuit. These chips provide a choice of an OR output or a NOR output.

Figure 28-8. Pinouts of the 74HC4078 and the 4078B, either of which may be used in the Ching Thing circuit. These chips provide a choice of an OR output or a NOR output.

As for the binary counter, it can be the same 4520B chip that was used in Experiment 21. Its pinouts are shown in Figure 21-6.

Bars or LEDs

The light bars will draw too much current to be illuminated directly by shift-register outputs. The righthand register in Figure 28-6 has to illuminate four light bars in each row and will be powering a total of 24 light bars when the hexagrams are fully lit. At 20mA per light bar, that’s a total of almost 500mA.

You could deal with this by using a TPIC6C596 “power logic” shift register, which can drive 100mA from each output when all outputs are high. But its mode of operation is slightly different from that of the 74HC164 shift register, and I don’t want to get into those variations. You can check its datasheet if you decide to try using it.

I prefer to drive the light bars with a Darlington array, such as the ULN2003. This contains transistors that can handle up to 500mA on each of seven output pins. The pinouts for the ULN2003 are shown in Figure 28-9. Note that because each internal Darlington pair of transistors has an open-collector output, the chip does not source current, but sinks current.

Pinouts of the ULN2003 Darlington array, which contains seven transistor pairs, each capable of sinking up to 500mA.

Figure 28-9. Pinouts of the ULN2003 Darlington array, which contains seven transistor pairs, each capable of sinking up to 500mA.

A negative ground connection must be made on pin 8 of the ULN2003 to sink the current. The optional ground on pin 9 is needed only where inductive loads may create “back EMF.” Diodes included in the ULN2003 are intended to divert such transients if the optional ground is included. For a circuit that is only driving light bars, the optional ground is not required.

You can reduce the power consumption of the light bars slightly, while eliminating the chore of soldering series resistors. Most light bars contain an array of LEDs, with each LED being individually accessible via external leads. Using the Lite-On LTL-2450Y light bar, I found that if I connected the LEDs in series by soldering pairs of leads together, as shown in Figure 28-2, I could run 9 volts through them, and they would take about 16mA, which is less than their rated 20mA. This does require a 9VDC supply. You can run the whole circuit from 9VDC, which will be fine for the Darlington arrays. But remember to pass the voltage through an LM7805 voltage regulator to create 5VDC for the logic chips.

Some sample schematics illustrating three different ways to wire LEDs with a Darlington array are shown in Figure 28-10.

Three different options to wire LEDs with a Darlington array.

Figure 28-10. Three different options to wire LEDs with a Darlington array.

These various options can be boiled down into two alternatives.

1. For a fully finished circuit:

o Use 74HC164 shift registers, which you have already tested earlier in this experiment.

o Add a ULN2003 Darlington array to amplify the outputs of each shift register.

o Use Lite-On LTL-2450Y or similar light bars, with the four internal LEDs connected in series.

o Power the light bars with an unregulated 9VDC supply. The rest of the circuit must have 5VDC, which can be provided by passing the 9V through an LM7805 five-volt regulator.

2. For a demonstration circuit:

o Substitute low-current individual LEDs instead of light bars. Each LED must draw no more than 8mA.

o Connect the four outside LEDs in each slice of the hexagrams in series-parallel, which is the middle configuration shown in Figure 28-10.

o Drive all the LEDs directly from 74HC164 shift registers after verifying that the load on each output from a shift register does not exceed 8mA. (The total current consumed by a whole shift register chip should not exceed 50mA.) No Darlingtons are required.

o Power the whole circuit with 5VDC regulated.

Either way, note that the circuit uses too much current to be battery powered.

Boarding the Ching Thing

The entire circuit is too large to fit on one breadboard, so I have broken it into part 1 and part 2. The schematic for part 1 is shown in Figure 28-11. This section of the circuit will be the same for both the demonstration and the fully finished versions. I had to offset the chips in the schematic to make everything fit.

Part 1 of the Ching Thing schematic is the same for either a demonstration version or a fully finished version of the circuit.

Figure 28-11. Part 1 of the Ching Thing schematic is the same for either a demonstration version or a fully finished version of the circuit.

The schematic for part 2 of the circuit is shown in Figure 28-12. This is for a demonstration version where the three shift registers drive LEDs directly. To upgrade this to a fully finished version, Darlington arrays would be added to the shift-register outputs, and light bars would be substituted for LEDs. A separate 9VDC line would be brought in to power the light bars.

Part 2 of the Ching Thing schematic (demonstration version, with LEDs instead of light bars).

Figure 28-12. Part 2 of the Ching Thing schematic (demonstration version, with LEDs instead of light bars).

I regret that space limitations compelled me to draw many conductors very close together in Figure 28-12. If you place a ruler alongside each conductor in turn, you can see how they power the LEDs. The arrangement repeats itself for each row of LEDs.

Also because of space limitations, I used yellow circles to represent LEDs, and omitted series resistors that may be required.

§ All LEDs have their positive (anode) leads at the top and the negative (cathode) leads at the bottom.

The always-on LEDs at the left and right side of each hexagram are wired in series-parallel, and if they don’t contain their own resistors, they will need a series resistor of a value that is different from the value of the resistors you use with individual LEDs. In both cases, you must try a variety of series resistors while checking the current that they are passing. Each LED that is powered singly, and each set of four LEDs wired in series-parallel, must not take more than 8mA.

Figure 28-13 shows how LEDs that require series resistors can be wired on a breadboard to occupy minimal space. The six LEDs here represent one slice of a pair of hexagrams. The LEDs are numbered to indicate which of the shift registers drives them. The thick gray lines represent the conductors inside the breadboard.

How to wire two LEDs that are driven individually by shift registers 1 and 2, and four LEDs wired in series-parallel, driven by shift register 3. If your LEDs do not contain their own resistors, adjust the series resistors so that each draws no more than 8mA.

Figure 28-13. How to wire two LEDs that are driven individually by shift registers 1 and 2, and four LEDs wired in series-parallel, driven by shift register 3. If your LEDs do not contain their own resistors, adjust the series resistors so that each draws no more than 8mA.

This layout requires only five rows of holes so that six sets of LEDs will occupy thirty rows on the breadboard. This allows sufficient room for the shift registers in the upper half of the board.

The complete demonstration circuit is shown in Figure 28-14 and Figure 28-15.

The logic-chip section of the Ching Thing circuit.

Figure 28-14. The logic-chip section of the Ching Thing circuit.

The second section of the Ching Thing circuit.

Figure 28-15. The second section of the Ching Thing circuit.

Assembly and Testing

Because this is a relatively large project, you should verify sections of it as you build them. When I was building my proof-of-concept version, I followed this sequence of steps, beginning with the LEDs and moving backward:

1. On the second breadboard, place all the jumpers and resistors associated with the LEDs. Then install the LEDs and apply voltage to each of them to make sure there are no bad connections.

2. Install the three shift registers and wire them to the LEDs. Trigger the shift registers manually using inputs C and D (in the schematic) to load them and input B to clock them. You’ll have difficulty getting a clean clock signal into input B. Try grounding it through a 10K resistor and then touching a positive wire to it very, very briefly.

3. Set aside the second breadboard. Install the fast 7555 timer at the top of the first board. Use a 33µF capacitor instead of the 1nF capacitor to slow the timer for testing purposes. Leave this capacitor in place until step 10. Add an LED to the timer’s output pin.

4. Add the binary counter. Test it with LEDs on its output pins, using high-value series resistors so that you don’t try to draw more than 2mA maximum.

5. Add the decoder and use LEDs with high-value series resistors to check its outputs.

6. Add the OR/NOR gate and use high-value series resistors to check its output. The OR output should be high for decoder output values 1011, 1100, 1101, 1110, 1111, and 0000 binary.

7. Test the slow-running 7555 timer with an LED. The LED should come on as soon as you apply power. This is okay. Moisten your finger and press it against the sensor contacts (which can be just a pair of stripped wires). The contacts should be no more than 0.1” apart. After a second or two, the LED should blink off and then on again.

8. Add the transistor and connections between the two breadboards.

9. Remove all LEDs from the counter, decoder, and OR/NOR logic chips. This is important! If these chips are driving LEDs at high speed, they will not communicate properly with each other.

10. Substitute a 0.001µF capacitor for the 33µF capacitor on the fast 7555 timer.

11. Don’t forget to link the two positive buses and two negative buses of your two breadboards so that both boards will be powered when you are ready for testing. In your eagerness to see if it works, be careful not to connect the power the wrong way around!

Ching Usage

The 100µF capacitor (shown at top-left in Figure 28-11) should suppress transient voltage spikes that occur when you first apply power. If the capacitor is doing its job, all the LEDs should remain dark. If some light up, use the reset button on the second breadboard.

Press your finger against the sensor contacts. For a faster response, moisten it first. Be patient; it may take a second or two to charge the capacitor. The output from the timer will go low, and then high again, at which point the first slice of the display should be displayed. This process should repeat in six steps, and then stop. If the display continues to scroll upward, use your meter to check the voltage on the reset pin of the slow timer. It should be above 4.5VDC while the display is being generated, and should fall below 0.5VDC when the display is complete.

If you disconnect and then reconnect power, probably there will be enough voltage left on the 100µF capacitor to regenerate the display. You will need to let the circuit sit without power for a minute or two to allow this capacitor to discharge.

Long jumpers are unavoidable to connect the two boards. Jumpers with plugs at each end may not make good connections. If your circuit behaves erratically, the jumpers will be the first thing to check.

Packaging

Figure 28-3 shows how the finished Ching Thing could look while displaying a couple of hexagrams, and Figure 28-16 shows the cutouts that you would need for the top panel of the box.

The cutouts that would be needed for the top of a box that could be used for the Ching Thing.

Figure 28-16. The cutouts that would be needed for the top of a box that could be used for the Ching Thing.

This project is not quite as ambitious as it looks because the chip connections are relatively simple. Most of the wiring relates to the hexagram displays. Of course, this becomes a little more complicated if you use Darlington arrays. There is also the issue of cost: if you use light bars, they are likely to be about $40 for the whole project.

Still, so far as I know the Ching Thing is unique as an electronic version of the world’s oldest system for predicting the future.

Can it really work comparably to the yarrow-stalk version? There’s certainly something compelling about the process of casting the stalks and drawing hexagrams by hand. But if you believe that fate is controlling the positions of the stalks, it seems to me that fate could also control the behavior of electrons inside silicon chips.

This leads me to my conclusion: may your fortunes all be electrically positive!