Ed Nisley's Blog: Shop notes, electronics, firmware, machinery, 3D printing, laser cuttery, and curiosities. Contents: 100% human thinking, 0% AI slop.
For a pure indicator, it’d be easier to slap a spot on the screen with the Adafruit GFX library’sfillRect() function. If you’re setting up a generic button handler, then button bitmap images make more sense.
Being that type of guy, I want a visible indication that the firmware continues trudging around the Main Loop. The standard Arduino LED works fine for that (unless you’re using hardware SPI), but the Adafruit 2.8 inch Touch-screen TFT LCD shield covers the entire Arduino board, so I can’t see the glowing chip.
Given a few spare pixels and the Adafruit GFX library, slap a mood light in the corner:
Adafruit TFT – heartbeat spot
The library defines the RGB color as a 16 bit word, so this code produces a dot that changes color every half second around the loop() function:
millis() produces an obvious counting sequence of colors. If that matters, you use random(0x10000).
A square might be slightly faster than a circle. If that matters, you need an actual measurement in place of an opinion.
Not much, but it makes me happy…
There’s an obvious extension for decimal values: five adjacent spots in the resistor color code show you an unsigned number. Use dark gray for black to prevent it from getting lost; light gray and white would be fine. Prefix it with a weird color spot for the negative sign, should you need such a thing.
Hexadecimal values present a challenge. That’s insufficient justification to bring back octal notation.
In this day and age, color-coded numeric readouts should be patentable, as casual searching didn’t turn up anything similar. You saw it here first… [grin]
Now that I think about it, a set of tiny buttons that control various modes might be in order.
Aren’t those just the ugliest buttons you’ve ever seen?
The garish colors identify different functions, the crude shading does a (rather poor) job of identifying the states, and the text & glyphs should be unambiguous in context. Obviously, there’s room for improvement.
The point is that I can begin building the UI code that will slap those bitmaps on the Arduino’s touch-panel LCD while responding to touches, then come back and prettify the buttons as needed. With a bit of attention to detail, I should be able to re-skin the entire UI without building the data into the Arduino sketch, but I’ll start crude.
The mkAll.sh script that defines the button characteristics and calls the generator script:
It turns out, for some reasons that aren’t relevant here, that I’ll be using the Adafruit Arduino LCD panel for the sewing machine control panel, at least to get started. In mulling that over, the notion of putting text on the buttons suggests using getting simple pictures with Unicode characters.
Herewith, some that may prove useful:
Needle stop up: ↥ = U+21A5
Needle stop up: ⤒=U+2912
Needle stop down: ⤓ = U+2913
Needle stop any: ↕ = U+2195
Needle stop any: ⟳ = U+27F3
Needle stop any: ⇅ = U+21C5
Rapid speed: ⛷ = U+26F7 (skier)
Rapid speed: 🐇 = U+1F407 (rabbit)
Slow speed: 🐢 = U+1F422 (turtle)
Dead slow: 🐌 = U+1F40C (snail)
Maximum speed: 🏃 = U+1F3C3 (runner)
Bobbin: ⛀ = U+26C0 (white draughts man)
Bobbin: ⛂ = U+26C2 (black draughts man)
Bobbin winding: 🍥 = U+1F365 (fish cake with swirl)
Of course, displaying those characters require a font with deep Unicode support, which may explain why your browser renders them as gibberish / open blocks / whatever. The speed glyphs look great on the Unicode table, but none of the fonts around here support them; I’m using the Droid font family to no avail.
The LED mounting plate inside the sewing machine’s end cap sits 30° from the vertical axis of the needle. Even though the surface-mount LED emitters have a broad pattern, it seemed reasonable to aim them toward the needle to put the brightest spot where it’s needed.
The LEDs must have enough heatsinking to pull 2+ W out of the solder pads, so I figured I’d just epoxy them firmly to the mounting plate, rather than try to gimmick up a circuit board that would interpose a fiberglass slab in the thermal path.
Combine those two requirements and you (well, I) get a wire fixture that provides both power and alignment:
LED mount – wire fixture
The LED body is 5 mm square, sin(30°) = 0.5, and the rear wire raises contact end by 2.5 mm. This still isn’t an exact science; if the center of the beam lands in the right time zone, that’s close enough.
Testing the LED assembly at low current before entombing it shows the emitters have six chips in series (clicky for more dots):
LED mount – lighting test
The grotendous solder job follows my “The Bigger the Blob, the Better the Job” principle, modulated by the difficulty of getting a smooth finish on bare wires. Indeed, the first wires I painstakingly bent, set up, and soldered turned out to have an un-solderable surface, much like the header pins from a while ago. That hank of wire now resides in the copper cable recycling bucket; you’re looking at Version 1.1.
Two strips of Kapton tape under the ends of the wires hold them off the (scoured and wiped clean!) aluminum plate, with more tape forming a dam around the nearest edges:
LED mount – epoxy pour
Despite being steel-filled, JB Weld remains nonconductive, the epoxy-filled gap under the wires insulates them from the plate, the wires aren’t shorted together, and there’s a great thermal bond to the heatsink. Good stuff, that JB Weld!
A view from the back side shows the epoxy sagging over the wires before I added another blob:
LED mount – epoxy pour – rear
The LED assembly just sits there, without being anchored, until the epoxy cures. The epoxy remains thick enough (in the rather chilly Basement Laboratory) so that it doesn’t exactly pour, can be eased into place without too much muss & fuss, and stays pretty much where it’s put.
After the epoxy stiffened a bit, I gingerly positioned stranded wires not-quite-touching the LED wires and applied a dot of solder to each. Powering the LEDs from a bench supply at 500 mW each took the chill off the heatsink and encouraged proper curing:
LED mount – heated epoxy cure
Fast forward to the next day, return the heatsink to the Sherline, and drill a hole for the power cable. It’s centered between the wires in Y and between the fins in X, which is why I couldn’t drill before mounting the LEDs:
LED mount – drilling cable hole
It’s not like I’m building this from any specs…
Trim the wires, solder the cable in place, cover the wire ends & joints with JB KwikWeld epoxy, and it’s done:
LED mount – final epoxy
With the LEDs running their 230 mA rated current, the entire heatsink gets pleasantly warm and the mounting plate isn’t much warmer than that. I loves me a good JB Weld job…
However, I suspect they’ll shine too brightly at full throttle, which means an adjustable power supply looms on the horizon…
That’s roughly two half-cycles of the full-wave rectified AC with about 100 ms between pulses.
The upper trace comes from the differential amp, the lower trace from the Tek current probe at 1 A/div. The overall amp transconductance looks to be 1.3 A/V = 1.3 A/div, minus that small DC offset, so the ADC range is actually 6.5 A. That might be a bit too much, all things considered, but not worth changing right now.
Notice that the upper trace drops like a rock at the end of the pulse, while the Tek probe shows a gradual decrease. The missing current goes ’round and ’round through the flyback diode across the motor:
Pulse Drive – Flyback Diode – Tek 1 A-div
The Tek probe in the lower trace goes on the green wire connecting the diode to the bridge rectifier, oriented to match the diode polarity (+ current flows from motor to blue wire on collector to brown wire on rectifier to motor):
Motor flyback diode – installed
That nasty little spike in the middle of the diff amp output occurs when the collector voltage drops to zero and the ET227 shuts off, but the motor current continues to flow due to the winding inductance. In the first scope shot, the Tek probe doesn’t show any spikes in the motor current, because there aren’t any.
Compare that with the voltage and current of the motor running from an isolation transformer:
Rectified AC – 200 mA div – 875 RPM
As the pulse repetition frequency increases, the motor speed goes up and the current goes down:
Pulse Drive – Fast – Tek 1 A-div
The dropouts between successive pairs of half-cycles show where the firmware shuts off the current and goes once around the main loop.
The Arduino code making that happen:
PedalPosition = ReadAI(PIN_PEDAL);
if (PedalPosition > 190) {
BaseDAC.setVoltage(Cvt_mA_to_DAC(3000),false); // give it a solid pulse
MotorDrive.ADCvalue = SampleCurrent(PIN_CURRENT_SENSE); // measure current = half cycle delay
MotorDrive.ActualCurrent = Cvt_ADC_to_mA(MotorDrive.ADCvalue);
printf("%5u, %5u, %5u, %5u, %5u, %5u, %5u\r\n",
MotorSensor.RPM,ShaftSensor.RPM,MotorDrive.State,
MotorDrive.DACvalue,MotorDrive.ADCvalue,MotorDrive.ActualCurrent,PedalPosition);
delay(3); // finish rest of half cycle
BaseDAC.setVoltage(0,false); // ... then turn it off
delay(map(PedalPosition,190,870,100,0)); // pedal controls off time
}
The map() function flips the sense of the analog voltage coming from the pedal, so that more pedal pressure = higher voltage = lower delay. The pedal voltage produces ADC values from about 185 through 860, with a pleasant sigmoid shape that gives good speed control.
The maximum motor speed isn’t quite high enough for bobbin winding, but I like what I see so far!
Reducing the differential amp gain fits a higher current into the Arduino’s fixed 5 V ADC range:
Hall Sensor Differential Amp
Those are 1% resistors, chosen from the heap for being pretty close to what I needed. Given that it’s an LM324 op amp, we’re not talking instrumentation grade results here.
The same calibration run that produced the DAC plot gave these values:
Current Calibrate – ADC – 270k Hall 2.7k opto
The linear fit gives the actual current, as seen by the Tek probe, for a given ADC reading.
The trimpot controls the offset voltage at zero current; working backwards, ADC = 0 corresponds to 140 mV, a bit higher than the actual 90 mV. Close enough, at least for a linear fit to eyeballed data, sez I.
Working forward, the maximum ADC value of 1023 corresponds to 4 A, which should suffice.