The Let's Play Archive

SHENZHEN I/O

by Quackles

Part 44: Assignment #20: Pocket I Ching Oracle

Pocket I Ching Oracle





Ooh, the I Ching! I only really know about it because it had a cameo role in The Golden Compass (which I read as a kid), but it's an interesting suggestion.

One thing that strikes me about David's latest idea is that, uh, well, it's a good idea! I just think it might be most profitable to sell it in North America. This feels like a device that'd take off overseas (and it feels really weird to call NA overseas):

• It's foreign, so there's a mystique about it.
• It's convenient.
• It could conceivably be cheap, though that's up to how well I can build it (along with what David decides to price it at).





It's pretty obvious that there'll be two output expanders sitting between the display and whatever MCs I put in, so it's just a matter of getting the reading from the oracle chip on the left, and constructing the values for both expanders one dst at a time, kinda like what I did for the remote kill switch job.

That's pretty straightforward. The oracle chip itself is where this whole story gets interesting. I looked up the yarrow-stalk algorithm on Wikipedia - apparently, it's done by taking the remainder of several piles of stalks. Which, you'd think, requires moving them around - and Jie said the chip somehow does the yarrow-stalk thing as a "MEMS" - a Microelectronic Mechanical System.

The datasheet doesn't exactly do much to clarify how it works, but it's pretty interesting reading on its own!



"Spiritation". Forget haunted dolls, this is real fun stuff!
While we're on the subject, I looked up a few of the names on the related products list. Turns out "onomancy" refers to divination based on the user's given name (kind of like the Name Rater in Pokémon?)... but what I really want to know is how the palmistry chip/device is supposed to work. Would the input be visual, tactile, through conductivity like a tablet screen...?

In terms of actual design, the only thing that's unusual is that this chip doesn't use XBus at all. I've almost kind of gotten used to XBus being everywhere... anyway, this chip outputs six values over six time units instead, so I'll have to wait for the values to come in.

[ ~ ]



   

It turns out waiting for the values to come in is harder than expected. The button is only on for one time unit, so I have to keep track of the time left in the hexagram myself. That's one acc. Then, the current reading half is stored in another acc. I also have to store it somewhere, which means...

...which means it took several hours to get this to work.
Yeah, anyway, here's my first solution. It's three chips + expanders, ¥15 (!), 614 power on average, and I really, really think there's a better solution.

The big MC on the left keeps track of the time since the button was pressed, and also sends it on to the big MC on the right. When the first MC sends the time, it does so modulo 3 - so instead of sending 0, 1, 2, 3, 4, 5, it sends 0, 1, 2, 0, 1, 2. The MC on the right stores that in its dat and reads from the oracle; it uses the values to generate a half-reading in its acc, by setting the digit of acc picked out by the '0, 1, 2' counter to whatever the oracle says it is. This takes 3 time units.

Once the MC6000 on the right has assembled a complete half-reading, it sends it to the MC4000 on the bottom. That MC stores the half-reading and sends back a "no go" signal to the big MC— the first time. The second time, receiving the other half-reading lets the MC4000 know to display its half, and send "go" to the MC above it. The "go" signal tells the big MC it should also display the half-reading it has.

And then we do it all over again the next time the user presses the button.

Looking at this design, the space on the second MC6000 calls out to me. It feels like I might be able to remove the small MC— which only really stores the first half-reading— and put the half-reading in the second MC6000's dat instead. Of course, to do so, I'd need to stop using that dat to store the value from the 0, 1, 2 counter.
I'll see if there's a fairly simple way to do this.

[ ~ ~ ]



 


It works! Well... it's a little better, at least. Only two chips (¥12), and 589 average power usage.
The first MC is (almost) the same, but as I planned above, the second MC now stores the first half of the reading in its dat, instead of passing it off to another chip. (It knows dat is empty if it has the value set at the top of its script, -1, in it.)

This change does mean that the first MC has to send its counter value twice (the mov acc x3s), so that the second MC doesn't have to store it - but in exchange, we can remove the MC4000 entirely.

As a bonus, I found a variant of the design which trades a little cost for power. It uses an output expander to turn "0/100" into "0/1", which the second MC can use to build the half-reading without doing a test.
It looks like this:





The only major differences are the expander, and the second MC, which has slightly shorter code (instead of teq p0 100 / + dst x0 1 / – dst x0 0, we can just do dst x0 x1). This version costs ¥13, but only uses 553 power on average.

I'm going to make one more serious attempt at this. I'll give myself, oh... three hours, and fiddle with it (which is coincidentally until the end of my workday today). If nothing comes out of it, I'll accept this version and send it off.

[ ~ ~ ~ ]





It took almost all of those three hours, but it's done. And it's beautiful. It only uses one MC, bringing the cost down to ¥8, and average power usage to 215 per run (score!)

It turns out that, instead of having to count the number of time units since the button was pushed and make a loop out of that, it's easier to just have a set of instructions that does the three dsts to build the half-reading (sleeping in between) in a hard-coded fashion. That runs twice (by checking whether or not dat already has a half-reading, and storing the current half in there if not) and then pushes everything out to the display. Then the MC waits to do it again.

The key to this design was identifying which lines of code and design features were really crucial to the final product, and leaving only that in. The counter wasn't truly necessary. Setting acc was necessary. Storing the first half of the reading in dat was (ultimately) necessary. So was setting dat to -1 to empty it out. Everything comes all together in this.

I'm sure if David heard this philosophy, he'd have something pithy to say, but I can't imagine what. Let's see how he likes the design.



Holy shit, David's getting married already? I've gotta find a wedding gift!

(Also, Jie is right on the money, as usual.)



PS: An aside: I tried, just for fun, doing an I Ching divination the manual way. As I have no yarrow stalks, however, I did it with some 50 loose pencils that were lying about the office.

The results: ䷸ > ䷜ (if you do it the yarrow stalk way you can get a type of line where the hexagram changes to a second one). If you look at the commentaries*, that's...

quote:

Proceeding Humbly: 57 ䷸ (巽 xùn)

The double Xun** shows how, in accordance with it, governmental orders are reiterated.

We see that the strong fifth line has penetrated into the central and correct place, and the will of its subject is being carried into effect; we also see the weak first and fourth lines both obedient to the strong line above them.

It is hence said, there will be some little attainment and progress. There will be advantage in movement onward in whatever direction.

It will be advantageous also to see the great man.

...which becomes...

quote:

Darkness: 29 ䷜ (坎 kǎn)

K'an repeated shows us one defile*** succeeding another.

This is the nature of water; it flows on, without accumulating its volume so as to overflow; it pursues its way through a dangerous defile, without losing its true nature.

That the mind is penetrating is indicated by the strong line in the center. That action in accordance with this will be of high value tells us that advance will be followed by achievement.

The dangerous height of heaven cannot be ascended; the difficult places of the earth are mountains, rivers, hills, and mounds.

Kings and princes arrange, by means of such strengths, to maintain their territories. Great indeed is the use of what is here taught about seasons of peril.
* I'm using the King Wen commentaries, translated by Alfred Huang, via Wikibooks.
** Each half of a hexagram has its own name. Two solid lines above a broken one is Xun (wind), which apparently is pronounced 'Sun', and the first hexagram has a double Xun. The other hexagram I got has two K'an (water).
*** "defile" in the geological sense: a pass or gorge between mountains.

They say you're supposed to hold a question in your mind while casting the hexagram, which I kind of neglected to do - so I'll leave the interpretation up to you.