fogbound.net




Sun, 13 Oct 2019

Maccabeam™ Part 2: the physical structure

— SjG @ 5:30 pm

Background:
Introduction
Part 1: Simulating candle-light with pseudo-random sequences

I’ve been developing the software for the Maccabeam, and have a lot to write on that subject. But before I do that, I have a few words on the physical structure of the Maccabeam. There are some basic requirements: it needs to hold the microcontroller, the power regulation, the GPS unit, the lasers, the LCD status display, and some assorted lighting. It needs to be able to stand on its own, and, ideally, it should look nice.

The software is at the point where I need to figure out some hardware-dependencies. Specifically, I’ll need to lay out NeoPixels for part of the display.

What are NeoPixels? NeoPixels are a fancy form of light-emitting diodes (LEDs). LEDs are circuits that emit a narrow wavelength of light when the right voltage is applied, meaning that LEDs are emit a single color. Tricolor LEDs were a fancy development where three separate LEDs (one each of red, green, and blue) were combined in a single device, each with its own separate input lead, so you could change the color output. Other color LEDs took this a step further, combining this three-LED device with a pulse-width modulation driver that allows discrete levels for each color, thus allowing a whole range of apparent colors. NeoPixels are a product from AdaFruit industries that add an embedded circuit so that a whole string of RGB LEDs can be individually controlled with a single serial signal.

NeoPixels are available in a large number of form factors. For the Maccabeam, I have a thin tape with NeoPixels. It can be cut at various points, and then wires soldered between segments. The thing is, the software to drive the NeoPixels thinks of them as a single string, with each one having an address 1, 2, 3, … whatever. Since my layout is not linear like that, I have to think through the placement, and then figure out what the addresses are for each desired lighting operation. I’ll write more on this subject too.

I designed a basic plan. The design makes sense on the screen, but there could be a lot of issues when converting from digital to physical. So the next step was building a prototype, discovering the errors, and making corrections.

To digress a bit, I say I designed a basic plan. This is an oversimplification. I went through many designs over the past year or so, sometimes thinking from a visual sense, somethings thinking from a practical sense (e.g., where am I going to put wires?). I even built a prototype a year ago, with a design that I abandoned. Here’s a gallery of abandoned sketches and designs.

Design detail

Here’s a design detail. The brown rectangles up top are the vials, the red rectangles the lasers, and the strips with stars are the NeoPixels. The design has a front and back plane, with layers sandwiched between to give it the third dimension.

(I’ve been designing using Serif Lab’s Affinity Designer as my CAD program. I like it beacause it’s easy to use, allows precise sizing — you can even enter things like “1/2 + 1/16 – 1/32 in” into the sizing input, and it will give you the correct size! It’s a good tool, but I’m sure there are better tools for doing 3D design and CAD output. For example, if I design everything assuming 1/8″ thick materials, and then change my mind and decide to use 1/4″ thick materials, there’s no built-in intelligence to help me adjust all the interlocking tabs.)

Back to the final design. I chose Baltic birch plywood for the physical structure because it’s relatively easy to work with, and reasonably available from craft and hardware stores. Before designing, there’s the question of dimensions. CrashSpace’s laser cutter has a 24-inch by 12-inch bed, so that determines one set of dimensions. Then the question of how thick? I chose the nominally 1/8th inch (which is theoretically 3.2mm), and designed as if it was actually that size. It turns out that neither English nor Metric dimensions are exact.

One of the things that plagues laser-cutting with plywood is that the plywood thickness and/or density are not perfectly uniform. The same amount of laser power may cut perfectly in one portion of the wood, but not in another.

So I cut out a partial prototype, and measured and checked. It was a good thing, too, since I discovered a lot of oversights and errors. This is the iterative design process! Also, to address the laser-not-quite-cutting-through problem, next time I think I will either slow down the laser, or, alternatively, speed it up and run through the entire design twice.

Laser and vials in sockets

Sat, 20 Jul 2019

Maccabeam™ Part 1: Simulating candle-light with pseudo-random sequences

— SjG @ 3:05 pm

Background: Introduction

There are many components to the the Maccabeam™ Menorah project. In describing the build, I’ll address each component separately. This first posting will cover the simulation of candle-light.

The warm flicker of candlelight is a familiar sight, and unsurpringly there are a lot of examples and techniques you can find on the internet for simulating it. You could buy pre-made candle light LEDs from Evil Mad Scientist or JMFX, you could read Tim’s excellent analysis and implement something based upon it, or you could look up a myriad examples and how-tos at YouTube or Hackaday or elsewhere. Being perverse, I decided to implement my own approach.

My requirement is that my light source act as a binary source: either on or off. If I were to use LEDs, for example, I could actually change the current to change the brightness. But I’ll be using laser diodes which are either illuminated or not.

Since I’m using a Teensy microcontroller, I can use pulse width modulation (PWM) to control brightness. That’s a fancy way of saying turning the light on and off very rapidly, and simulating intensity. The higher the duty cycle (i.e., the larger percentage of the time the light is “on”), the brighter our eyes see illumination. This works on the property of the human eye known as “persistence of vision.” Our eyes and visual cortex integrate the incoming signal over time. It enables us to look at screens that rapidly flash changing images and see motion (i.e., movies) or a quickly moving point of illumination painting out a pattern and seeing an image (raster images, old tube-style TVs, etc).

So now the question is how to make the pattern of on and off that will look most like a candle flicker? Like many other people presented with this challenge, my first thought is to turn to a pseudo-random sequence generator. Specifically, my first thought is a linear shift-register sequence. Why? A couple of reasons, but the primary is that in the late sixties, my father worked at JPL and assisted Solomon Golomb, who wrote the definitive book on the subject. Thus, when I was in high school, my father helped me with an electronics project where we implemented one.

So, what’s this linear shift-register sequence? It starts with a shift register. This is a circuit with a series of cells or registers, each of which holds a bit with a value of either one or zero. Every time an external signal (like a clock pulse) comes, every value gets moved over to the neighboring cell. So a linear shift-register sequence adds circuity so that after each shift, it populates the input bit using some algorithmic function of its previous state. Depending on the function, it can create a long sequence that seems nearly random.

Consider the following 8-bit shift register:

8-bit linear shift register
8-bit linear shift register

At each tick of the clock, new value is computed by XOR-ing the values of bit numbers 3 and 7 (these are called the “taps”). The contents of each bit shifts to the position to its left, and the newly computed value populates bit number 0. In this case, the function is exclusive-or (XOR) which has the following truth table:

Input 1Input 2Output
000
011
101
110

So imagine only bit number 0 is set and the others are empty. The sequence will go as follows (a space is added between bits 3 and 4 to enhance readability):

0000 0001 (0 xor 0 -> 0, so we'll inject a 0) 
0000 0010 (0 xor 0 -> 0, so we'll inject a 0)
0000 0100 (0 xor 0 -> 0, so we'll inject a 0)
0000 1000 (0 xor 1 -> 1, so we'll inject a 1)
0001 0001 (0 xor 0 -> 0, so we'll inject a 0)
0010 0010 ...
0100 0100 
1000 1000 
0001 0000 
0010 0000 
0100 0000 
1000 0000 
0000 0001 

This particular configuration is considered “non-maximal” because even though 8 bits can represent 256 combinations, this sequence will repeat after every 12 clock cycles. If you move where the tap is, you can get better sequences. However, it turns out there is no maximal single-tap sequence for an 8-bit register. With an 8-bit register, you can get up to 217 step sequences if you put the tap at bit number 2 or 4. If you add more taps, you can achieve the full 255 states (the fully zero state is omitted, since it will always stay zero).

For our simulation, we want more than 255 steps anyway, so we go up to a 16-bit shift register and use taps that will yield a 65,535 step sequence. Several pages on the web (I like Burton Rosenberg’s page, as well as the Wikipedia reference) will help you find the right taps for any reasonable register you wish to create.

16-bit linear shift register
16-bit linear shift register

This is implemented in hardware with a handful of chips, or in software with a few lines of code like:

// code is unforgivably formatted, as good C should be[?]
uint16_t srs; // 16-bits for our shift register
srs = 1;
while (1)
{
   srs = (srs << 1) | (
        (
           (
              (
                 ((srs & 0x8000) == 0x8000) ^
                 ((srs & 0x2000) == 0x2000)
              )
              ^
              ((srs & 0x1000) == 0x1000)
            )
            ^
            ((srs & 0x0400) == 0x0400)
        )
);

So for the Maccabeam™, we’ll have a maximum of nine candles going at any one time. So if we have a stream of pseudo-random bits flying by in our 16-bit register, we could just pick nine arbitrary bits and route each one to our laser diode. The problem here is that the values keep shifting left, so there will be a visible pattern. So even if candle number 1 is driven by bit 5 and candle number 2 is driven by bit 8, candle 2 will always flicker three clock cycles after candle 1. Even if the order of the candles is different than the order of the bits, our brains are very good at detecting repeating patterns. It just won’t look very good.

So to break this visible pattern, we will drive each candle by OR-ing two bits together. The spacing between the two bits will be as close to unique as we can make it — of course, given that we only have 16 bits to play with, and nine candles, there will be some overlap.

Candle OR pattern

So you can see that there are two sets of candles that will always be illuminated simultaneous: candle 2 and candle 8; and candle 5 and candle S (the shamos/shamas/shamash. Here’s Wikipedia’s explanation of menorah candles).

There’s a question of timing, too. How frequently does the shift register shift? What looks good may or may not be what’s most like actual candle light. My first stab uses a 40ms cycle time. Adjustments may be in order.

I’m not at the point where I’m ready to hook up the lasers (still practicing the proper intonation of the cry “fire ze laaaaasers!“), but below is some sample video of this approach being run into lowly LEDs.

Blinky lights!

Sun, 14 Jul 2019

Sensor Problems

— SjG @ 9:28 am

I’m working on a circuit based on a 34685-MP chip bought at Marlin P Jones. The chip is supposed to be sensitive up to 7m away, but I’m not getting very reliable detection. My first thought was that, being next to a bunch of high-frequency stuff (a Teensy 3.2 with the audio shield), maybe it was interference.

The not-yet-functioning Annoy-o-Tron

I tried taking its output to the base of a transitor and lighting a LED to see if that was better. I got similar results.

I’m not sure what’s going on yet. If I do figure it out, I’ll post here.

Update: the Interwebs deliver! Following the recommendation I found in the comments on this article, I put the 34685-MP on a cable, and moved it away from the breadboard. Voilà! It now works as I had hoped!


Tue, 7 May 2019

The Maccabeam™

— SjG @ 5:43 pm

Back in 2017, I laser-cut a menorah out of poplar. When the family showed up for Hannukah, I mentioned my “laser menorah.” My nephew’s eyes lit up with excitement, but I could see his disappointment upon presentation of the actual product.

Subsequently, I’ve been building something closer to what he probably envisioned in the first place.

I’m slow at building things, and have lots of other commitments taking up time. I spend maybe an hour or two a week on the project, and tend to forget a lot of important details between sessions. There is a whole lot of learning and re-learning. However, I thought that documenting the various processes here would be good for me (my external memory), and may be of interest to others.

The first step of any project, of course, is to give it a good name and maybe a logo. Since it’s a laser menorah, I’m calling it the Maccabeam™, and my initial version of the logo looks like this:

The Official Maccabeam™ logo

So there are a lot of things to talk about here. I’ll post a lot of circuit design ideas, physical design ideas, and details on the software that drives it. I’ll also probably post some ambivalent thoughts on the whole holiday of Hannukah1. But for now, I’ll start with the list the requirements I’ve been using for the project:

  1. Instead of candles, I’ll be using lasers!
  2. The lasers will probably be illuminating vials of olive oil rather than shining on the ceiling.
  3. There will be more lights, too. Color LEDs! NeoPixels!
  4. The whole thing will be driven by an embedded controller I can program. Since I like the Teensy and Paul & Robin seem like the kind of people I want to support, I’ll go with a Teensy LC.
  5. Since I have a microcontroller, it should take advantage of the smarts, and not just rely on an on/off switch.
  6. Hey, if it’s gonna be smart, it should use a GPS receiver to figure out the location and date, and automatically run itself on Hannukah.
  7. It will need some kind of display so you can tell what it’s doing, what time it is, how long until Hannukah, etc.
  8. It’ll be cool if it could play some music too.
  9. OK, maybe I don’t want an on/off switch, but I do need a switch to trigger a simulation mode. That way, I can show it off to people at any time of year.
  10. [update 13 May 2019] Oh, I forgot an important one. The Maccabeam™ wants to be stand-alone. It doesn’t want any dependencies on the Interet, wireless networks, or the like. It should only depend on a source of electricity and a constellation of 20-some-odd highly sophisticated satellites and their ground support network.

So with that set of requirements, I got started. I hope to write something here about each of those requirements as I complete the build.

Update 1: The Flickering Candles.
Update 2: Some Physical Structure
Update 3: When Exactly is Hannukah?

1 I mean, it’s celebrating the victory of a family of intolerant religious fanatics over both their foreign imperial enemies and their more moderate coreligionists. Their victory established the shaky Hasmonean dynasty whose infighting and collapse resulted in Herod’s rise to power in the region, etc.


Wed, 13 Mar 2019

Replacing the battery in a mid-2012 Retina MBP

— SjG @ 8:17 pm

I bought my MBP back in September of 2012, and it’s been the best machine I’ve ever owned. Named Apotheosis, it’s quiet, powerful, good battery life, and all that. It’s been through four or five iterations of MacOS, and still runs fast. It’s got old-school USB 3 ports, an SD card reader, and the mag-safe connector. In short, the only thing I could hope to improve it would be more storage.

Of late, however, it’s been exhibiting power issues. It will log itself out, or spontaneously go to sleep and not wake up without external power. I reset the System Management Controller (SMC) by the arcane ritual of holding down Shift, Control, and Option on the left side of the keyboard, then holding down the power button for 10 seconds. No luck.

Then, there’s some minor issues with the screen; small areas that look almost like fungus in the display. From what I’ve read, this has affected a lot of older Retina displays, but in my case it’s more an annoyance than a serious problem. Still, given these two issues, I thought perhaps it’s time to upgrade. After all, the machine’s over six years old.

Looking at the new MacBooks and MacBook Pros, though, I can’t find anything that would be satisfactory. Certainly nothing at a price-point that I feel like paying. I’m not a big fan of the new keyboards, and if you want to put a lot of storage (i.e., 2TB) in a machine, Apple really makes you pay. Resolved, then, try to get more years out of Apotheosis. Apple no longer services this model, and the indy/Authorized dealers wanted $500 to replace the battery. That seemed high to me.

Other World Computing has a replacement battery kit for $85. I ordered it, and it arrived overnight! In big red letters, they warn that “Professional Installation Highly Recommended” but people like me don’t pay any attention to such things.

Back cover removed

The kit comes complete with Torx screwdrivers specifically for the MBP, including the (in)famous “pentalobe” driver.

They also supply a step-by-step video for the process. This is a really outstanding instructional video. It shows everything in perfect detail. Things which sound simple in words (e.g., “unclip the connector”) are often not so clear when staring at the physical object. But watching each step makes it very simple.

That being said, they estimated two hours to do the process, and it took me more like three. Part of that was my obsessive disassembly process which I’ve perfected over the years. It involves lots of post-it notes, with little drawings and sticky tape that I use to make sure I can reassemble things correctly. In this case, the video would have been sufficient, but old habits die hard. And, frankly, this is a good habit.

Even thought OWC makes this a straightforward process, Apple certainly didn’t intend it to be. You have to remove the speakers to really get at the battery. To get the speakers out, you basically have to remove all the guts:

Ready for battery removal
All The Innards… haruspices take note

The kit includes a gnarly solvent that helps dissove the adhesive holding the battery in place. This is the worst part of the process, although they provide gloves and eye protection to make it a safer process.

Once the machine was back together, I went through a full charge/discharge cycle, and it’s seemed quite stable. There are some weird minor discrepancies. For example, while writing this post and doing some other odd chores, I’ve been unplugged. The menu bar battery gauge tells me I’m at 81%, while CoconutBattery tells me I’m at 77.6%.

With any luck, this repair will help me keep Apotheosis up and running for a few more years!