The Smell of Molten Projects in the Morning

Ed Nisley's Blog: Shop notes, electronics, firmware, machinery, 3D printing, laser cuttery, and curiosities. Contents: 100% human thinking, 0% AI slop.

Category: Software

General-purpose computers doing something specific

  • Hydrant Wrench

    Just because I can:

    Fire Hydrant Wrench
    Fire Hydrant Wrench

    The Slic3r preview shows a bit more detail:

    Hydrant Wrench - Slic3r preview
    Hydrant Wrench – Slic3r preview

    Even an inch-thick handle wouldn’t have enough mojo for the task.

    Wikipedia has the equations you need to go from the easily measured “height” (vertex to opposite side) dimension to the pentagon’s “outside radius”, which equals the radius of the circumscribed circle needed by OpenSCAD.

    The OpenSCAD source code as a GitHub Gist:

    // Hydrant Wrench
    // Ed Nisley KE4ZNU – September 2017
    /* [Extrusion] */
    ThreadThick = 0.25; // [0.20, 0.25]
    ThreadWidth = 0.40; // [0.40]
    function IntegerMultiple(Size,Unit) = Unit * ceil(Size / Unit);
    Protrusion = 0.01; // [0.01, 0.1]
    HoleWindage = 0.2;
    //- Sizes
    /* [Dimensions] */
    NumFlats = 5; // this is not a variable for this geometry!
    Height = 39.0; // pentagon flat-to-vertex measurement
    Side = Height / 1.539;
    echo(str("Side:",Side));
    Radius = Side / 1.176;
    echo(str("Radius: ",Radius));
    WrenchDia = 2*Radius; // pentagon circumcircle diameter
    echo(str("Wrench dia:",WrenchDia));
    JawWidth = 10.0;
    JawOD = 2*JawWidth + WrenchDia;
    echo(str("Jaw OD: ",JawOD));
    WrenchThick = 5.0;
    HandleLength = 2*JawOD;
    HandleWidth = 25.0;
    //- Build things
    difference() {
    linear_extrude(height=WrenchThick,convexity=4) {
    hull() { // taper wrench body to handle
    circle(d=JawOD);
    translate([0.75*JawOD,0,0])
    circle(d=HandleWidth);
    }
    hull() { // handle
    translate([0.75*JawOD,0,0])
    circle(d=HandleWidth);
    translate([HandleLength,0,0])
    circle(d=HandleWidth);
    }
    }
    translate([0,0,-Protrusion])
    rotate(180/NumFlats)
    cylinder(d=WrenchDia,h=(WrenchThick + 2*Protrusion),$fn=NumFlats);
    translate([WrenchDia,0,WrenchThick – 3*ThreadThick])
    linear_extrude(3*ThreadThick + Protrusion,convexity=10)
    text(text=str("Fire Hydrant!"),size=8,spacing=1.20,font="Arial",halign="left",valign="center");
    }

    Sorry ’bout that … had to do it.

  • Streaming Media Player: OLED Weirdness

    Of late, the OLED displays on two RPi 3 streaming players (the others are RPi 2) have occasionally gone blank, while the players continue to work fine. I checked the logs, swapped MicroSD cards, rebuilt the images, and generally screwed around, all to no avail. The SH1106 controller has a command containing a single bit to blank the display and, perhaps, an SPI data transfer error could shut it off.

    This is much harder to explain:

    Mirror-image OLED display
    Mirror-image OLED display

    There’s a hardware command to flip the display top-to-bottom, not left-to-right. The Luma OLED driver can rotate the display in 90° increments, but AFAICT not reflect it.

    Yes, they’re networked, but, no, they’re not directly exposed to the Intertubes.

    Changing streams had no effect. Shutting down and rebooting restored normal operation.

    There’s been exactly one such failure so far, so I lack evidence.

    I have no clue what’s going on.

  • LF DDS Sine Generator With 0.1 Hz Steps

    Gutting the crystal tester program and grafting a simple joystick interface onto the corpse produces an LF sine wave generator with 0.10 Hz steps:

    FG085 vs AD9850 DDS frequencies
    FG085 vs AD9850 DDS frequencies

    The FG085 function generator shows 60000 Hz and the AD9850 shows 60001.58 Hz, but they’re running at exactly the same frequency:

    DDS 1.58 FG085 0.0
    DDS 1.58 FG085 0.0

    I trust the AD9850 readout, because I just finished zero-beating it against the GPS-locked 10 MHz frequency reference: it’s dead on. The scope’s frequency measurement is clearly out of its depth at this resolution.

    The “user interface” doesn’t amount to much. The DDS starts at 60.000 kHz, as defined by a program constant. Push the joystick left-right to step by 0.1 Hz (actually, multiples of 0.0291 Hz, so either 0.087 or 0.116 Hz, whichever makes the answer come out closer to the next multiple of 0.1 Hz). Push it up-down to step by 1.0 Hz (insert similar handwaving here). Push the button inward to reset to 60.000 kHz.

    The OLED displays the frequency (in big digits), the output of the log amplifier (which isn’t hooked up here) in dB (over 4 μV), the DDS clock oscillator temperature, and a few lines of static prompting. The camera shutter blanked the last line, which should read “Button = reset”.

    There’s no amplitude adjustment, other than the DDS current-control twiddlepot and the buffer amp’s gain-setting jumpers, but I (think I can) gimmick up an adequate inductive kicker for the fake preamp antenna circuit.

    Not much to look at, but now I can (manually) probe the frequency response of the 60 kHz preamp with sufficient resolution to figure out if / how the tuning fork resonator filter behaves.

    The Arduino source code as a GitHub Gist:

    // Sine wave generator
    // Ed Nisley – KE4ZNU
    // 2017-09-20
    #include <avr/pgmspace.h>
    #include <U8g2lib.h>
    #include <U8x8lib.h>
    #include <Adafruit_MCP4725.h>
    //———————
    // Pin locations
    #define PIN_SYNC 5
    #define PIN_CX_SHORT 6
    #define PIN_DDS_RESET 7
    #define PIN_DDS_LATCH 8
    #define PIN_HEARTBEAT 9
    #define PIN_LOG_AMP A0
    #define PIN_JOYBUTTTON A1
    #define PIN_JOY_Y A2
    #define PIN_JOY_X A3
    // SPI & I2C use hardware support: these pins are predetermined
    #define PIN_SS 10
    #define PIN_MOSI 11
    #define PIN_MISO 12
    #define PIN_SCK 13
    #define PIN_IIC_SDA A4
    #define PIN_IIC_SCL A5
    // IIC Hardware addresses
    // OLED library uses its default address
    #define LM75_ADDR 0x48
    #define SH1106_ADDR 0x70
    #define MCP4725_ADDR 0x60
    // Useful constants
    #define GIGA 1000000000LL
    #define MEGA 1000000LL
    #define KILO 1000LL
    #define ONE_FX (1LL << 32)
    #define CALFREQ (10LL * MEGA * ONE_FX)
    // Structures for 64-bit fixed point numbers
    // Low word = fractional part
    // High word = integer part
    struct ll_fx {
    uint32_t low; // fractional part
    uint32_t high; // integer part
    };
    union ll_u {
    uint64_t fx_64;
    struct ll_fx fx_32;
    };
    // Define semi-constant values
    union ll_u CenterFreq = {(60000 – 0) * ONE_FX}; // center of scan
    //union ll_u CenterFreq = {(32768 – 2) * ONE_FX}; // center of scan
    #define NOMINAL_OSC ((125 * MEGA) * ONE_FX)
    union ll_u Oscillator = {NOMINAL_OSC}; // oscillator frequency
    int16_t OscOffset = 287; // offset from NOMINAL_OSC at room-ish temperature
    // Coefficients for oscillator offset as function of temperature
    #define TC_SQUARE ((1340 * ONE_FX) / 1000)
    #define TC_LINEAR ((-1474 * ONE_FX) / 10)
    #define TC_INTERCEPT ((3415 * ONE_FX) )
    // Frequency range & step size
    uint16_t TestWidth = 5*2; // width must be an even integer
    union ll_u StepSize = {ONE_FX / 10}; // 0.1 Hz is smallest practical decimal step
    union ll_u NomFreq, ActualFreq; // displayed vs actual DDS frequency
    union ll_u TestFreq;
    // Global variables of interest to everyone
    union ll_u CtPerHz; // will be 2^32 / oscillator
    union ll_u HzPerCt; // will be oscillator / 2^32
    char Buffer[10+1+10+1]; // string buffer for fixed point number conversions
    union ll_u Temperature; // read from LM75A
    // Hardware library variables
    U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(U8X8_PIN_NONE);
    //U8X8_SH1106_128X64_NONAME_4W_HW_SPI u8x8(PIN_DISP_SEL, PIN_DISP_DC , PIN_DISP_RST);
    //U8X8_SH1106_128X64_NONAME_4W_SW_SPI u8x8(PIN_SCK, PIN_MOSI, PIN_DISP_SEL, PIN_DISP_DC , PIN_DISP_RST);
    #define DAC_WR false
    #define DAC_WR_EEP true
    #define DAC_BITS 12
    #define DAC_MAX 0x0fff
    Adafruit_MCP4725 XAxisDAC; // I²C DAC for X axis output
    uint32_t XAxisValue; // DAC parameter uses 32 bits
    union ll_u LogAmpdB; // computed dB value
    // Timekeeping
    #define HEARTBEAT_MS 3000
    unsigned long MillisNow,MillisThen;
    //———–
    // Useful functions
    // Pin twiddling
    void TogglePin(char bitpin) {
    digitalWrite(bitpin,!digitalRead(bitpin)); // toggle the bit based on previous output
    }
    void PulsePin(char bitpin) {
    TogglePin(bitpin);
    TogglePin(bitpin);
    }
    // These may need debouncing in some circuits
    void WaitButtonDown() {
    word ai;
    do {
    ai = analogRead(PIN_JOYBUTTTON);
    } while (ai > 600);
    }
    void WaitButtonUp() {
    word ai;
    do {
    ai = analogRead(PIN_JOYBUTTTON);
    } while (ai < 400);
    }
    void WaitButton() {
    Serial.print(F("Waiting for button:"));
    WaitButtonDown();
    delay(10);
    WaitButtonUp();
    delay(100);
    Serial.println(F(" done"));
    }
    // Hardware-assisted SPI I/O
    void EnableSPI(void) {
    digitalWrite(PIN_SS,HIGH); // set SPI into Master mode
    SPCR |= 1 << SPE;
    }
    void DisableSPI(void) {
    SPCR &= ~(1 << SPE);
    }
    void WaitSPIF(void) {
    while (! (SPSR & (1 << SPIF))) {
    // TogglePin(PIN_HEARTBEAT);
    // TogglePin(PIN_HEARTBEAT);
    continue;
    }
    }
    byte SendRecSPI(byte Dbyte) { // send one byte, get another in exchange
    SPDR = Dbyte;
    WaitSPIF();
    return SPDR; // SPIF will be cleared
    }
    //————–
    // DDS module
    void EnableDDS(void) {
    digitalWrite(PIN_DDS_LATCH,LOW); // ensure proper startup
    digitalWrite(PIN_DDS_RESET,HIGH); // minimum reset pulse 40 ns, not a problem
    digitalWrite(PIN_DDS_RESET,LOW);
    delayMicroseconds(1); // max latency 100 ns, not a problem
    DisableSPI(); // allow manual control of outputs
    digitalWrite(PIN_SCK,LOW); // ensure clean SCK pulse
    PulsePin(PIN_SCK); // … to latch hardwired config bits
    PulsePin(PIN_DDS_LATCH); // load hardwired config bits = begin serial mode
    EnableSPI(); // turn on hardware SPI controls
    SendRecSPI(0x00); // shift in serial config bits
    PulsePin(PIN_DDS_LATCH); // load serial config bits
    }
    // Write delta phase count to DDS
    // This comes from the integer part of a 64-bit scaled value
    void WriteDDS(uint32_t DeltaPhase) {
    SendRecSPI((byte)DeltaPhase); // low-order byte first
    SendRecSPI((byte)(DeltaPhase >> 8));
    SendRecSPI((byte)(DeltaPhase >> 16));
    SendRecSPI((byte)(DeltaPhase >> 24));
    SendRecSPI(0x00); // 5 MSBs = phase = 0, 3 LSBs must be zero
    PulsePin(PIN_DDS_LATCH); // write data to DDS
    }
    //————–
    // Log amp module
    #define LOG_AMP_SAMPLES 10
    #define LOG_AMP_DELAYMS 10
    uint64_t ReadLogAmp() {
    union ll_u LogAmpRaw;
    LogAmpRaw.fx_64 = 0;
    for (byte i=0; i<LOG_AMP_SAMPLES; i++) {
    LogAmpRaw.fx_32.high += analogRead(PIN_LOG_AMP);
    delay(LOG_AMP_DELAYMS);
    }
    LogAmpRaw.fx_64 /= LOG_AMP_SAMPLES; // figure average from totally ad-hoc number of samples
    LogAmpRaw.fx_64 *= 5; // convert from ADC counts to voltage at 5 V/1024 counts
    LogAmpRaw.fx_64 /= 1024;
    LogAmpRaw.fx_64 /= 24; // convert from voltage to dBV at 24 mV/dBV
    LogAmpRaw.fx_64 *= 1000;
    return LogAmpRaw.fx_64;
    }
    //———–
    // Read LM75A and convert to signed fixed point
    // Returns signed value in something otherwise used as unsigned
    // Blithely ignores most IIC error conditions
    int64_t GetTemperature() {
    union ll_u Temp;
    Wire.requestFrom(LM75_ADDR,2);
    if (Wire.available() == 2) {
    Temp.fx_32.high = Wire.read();
    Temp.fx_32.low = (uint32_t)Wire.read() << 24;
    if (Temp.fx_32.high & 0x00000080L) { // propagate – sign
    Temp.fx_32.high |= 0xffffff00L;
    }
    }
    else {
    Temp.fx_64 = 256 * ONE_FX; // in-band error flagging: 256 C
    }
    return Temp.fx_64;
    }
    //———–
    // Compute frequency offset from oscillator temperature
    // This is an ordinary signed integer
    // Because 1 Hz resolution at 125 MHz is Good Enough
    int16_t ComputeOffset() {
    union ll_u Temperature;
    union ll_u T1;
    Temperature.fx_64 = GetTemperature();
    T1.fx_64 = TC_SQUARE;
    if (TC_SQUARE) // skip multiply for linear fit
    T1.fx_64 = MultiplyFixedPt(T1,Temperature);
    T1.fx_64 += TC_LINEAR;
    T1.fx_64 = MultiplyFixedPt(T1,Temperature);
    T1.fx_64 += TC_INTERCEPT;
    PrintFixedPtRounded(Buffer,Temperature,3);
    printf("Offset: %d at %s C\n",(int16_t)T1.fx_32.high,Buffer);
    return (int16_t)(T1.fx_32.high); // extract integer part
    }
    //———–
    // Zero-beat oscillator to 10 MHz GPS-locked reference
    void ZeroBeat() {
    union ll_u TempFreq,TempCount;
    printf("Zero beat DDS oscillator against GPS\n");
    TempFreq.fx_64 = CALFREQ;
    u8x8.clearDisplay();
    byte ln = 0;
    u8x8.drawString(0,ln++,"10 MHz Zero Beat");
    u8x8.drawString(0,ln++," <- Jog -> ");
    u8x8.drawString(0,ln++," ^ recalc ");
    u8x8.drawString(0,ln++," Button = set ");
    int32_t OldOffset = -OscOffset; // ensure first update
    while (analogRead(PIN_JOYBUTTTON) > 500) {
    TogglePin(PIN_HEARTBEAT); // show we got here
    int ai = analogRead(PIN_JOY_Y) – 512; // totally ad-hoc axes
    if (ai < -100) {
    OscOffset += 1;
    }
    else if (ai > 100) {
    OscOffset -= 1;
    }
    ai = analogRead(PIN_JOY_X) – 512;
    if (ai < -100) {
    OscOffset = ComputeOffset();
    }
    if (OscOffset != OldOffset) {
    ln = 5;
    sprintf(Buffer,"Offset %9d",OscOffset);
    u8x8.drawString(0,ln,Buffer);
    CalcOscillator(OscOffset); // recalculate constants
    TempCount.fx_64 = MultiplyFixedPt(TempFreq,CtPerHz); // recalculate delta phase count
    WriteDDS(TempCount.fx_32.high); // DDS output should be exactly 10 MHz
    OldOffset = OscOffset;
    }
    Temperature.fx_64 = GetTemperature();
    PrintFixedPtRounded(Buffer,Temperature,3);
    ln = 7;
    u8x8.drawString(0,ln,"DDS Temp");
    u8x8.drawString(16-strlen(Buffer),ln,Buffer);
    delay(100);
    }
    printf("Oscillator offset: %d at %s C\n",OscOffset,Buffer);
    WaitButtonUp();
    u8x8.clearDisplay();
    }
    //———–
    // Round scaled fixed point to specific number of decimal places: 0 through 8
    // You should display the value with only Decimals characters beyond the point
    // Must calculate rounding value as separate variable to avoid mystery error
    uint64_t RoundFixedPt(union ll_u TheNumber,unsigned Decimals) {
    union ll_u Rnd;
    Rnd.fx_64 = (ONE_FX >> 1) / (pow(10LL,Decimals)); // that's 0.5 / number of places
    TheNumber.fx_64 = TheNumber.fx_64 + Rnd.fx_64;
    return TheNumber.fx_64;
    }
    //———–
    // Multiply two unsigned scaled fixed point numbers without overflowing a 64 bit value
    // Perforce, the product of the two integer parts mut be < 2^32
    uint64_t MultiplyFixedPt(union ll_u Mcand, union ll_u Mplier) {
    union ll_u Result;
    Result.fx_64 = ((uint64_t)Mcand.fx_32.high * (uint64_t)Mplier.fx_32.high) << 32; // integer parts (clear fract)
    Result.fx_64 += ((uint64_t)Mcand.fx_32.low * (uint64_t)Mplier.fx_32.low) >> 32; // fraction parts (always < 1)
    Result.fx_64 += (uint64_t)Mcand.fx_32.high * (uint64_t)Mplier.fx_32.low; // cross products
    Result.fx_64 += (uint64_t)Mcand.fx_32.low * (uint64_t)Mplier.fx_32.high;
    return Result.fx_64;
    }
    //———–
    // Long long print-to-buffer helpers
    // Assumes little-Endian layout
    void PrintHexLL(char *pBuffer,union ll_u FixedPt) {
    sprintf(pBuffer,"%08lx %08lx",FixedPt.fx_32.high,FixedPt.fx_32.low);
    }
    // converts all 9 decimal digits of fraction, which should suffice
    void PrintFractionLL(char *pBuffer,union ll_u FixedPt) {
    union ll_u Fraction;
    Fraction.fx_64 = FixedPt.fx_32.low; // copy 32 fraction bits, high order = 0
    Fraction.fx_64 *= GIGA; // times 10^9 for conversion
    Fraction.fx_64 >>= 32; // align integer part in low long
    sprintf(pBuffer,"%09lu",Fraction.fx_32.low); // convert low long to decimal
    }
    void PrintIntegerLL(char *pBuffer,union ll_u FixedPt) {
    sprintf(pBuffer,"%lu",FixedPt.fx_32.high);
    }
    void PrintFixedPt(char *pBuffer,union ll_u FixedPt) {
    PrintIntegerLL(pBuffer,FixedPt); // do the integer part
    pBuffer += strlen(pBuffer); // aim pointer beyond integer
    *pBuffer++ = '.'; // drop in the decimal point, tick pointer
    PrintFractionLL(pBuffer,FixedPt);
    }
    void PrintFixedPtRounded(char *pBuffer,union ll_u FixedPt,unsigned Decimals) {
    char *pDecPt;
    FixedPt.fx_64 = RoundFixedPt(FixedPt,Decimals);
    PrintIntegerLL(pBuffer,FixedPt); // do the integer part
    pBuffer += strlen(pBuffer); // aim pointer beyond integer
    pDecPt = pBuffer; // save the point location
    *pBuffer++ = '.'; // drop in the decimal point, tick pointer
    PrintFractionLL(pBuffer,FixedPt); // do the fraction
    if (Decimals == 0)
    *pDecPt = 0; // 0 places means discard the decimal point
    else
    *(pDecPt + Decimals + 1) = 0; // truncate string to leave . and Decimals chars
    }
    //———–
    // Calculate useful "constants" from oscillator info
    void CalcOscillator(int16_t Offset) {
    Oscillator.fx_64 = NOMINAL_OSC + (Offset * ONE_FX); // offset may be negative, It Just Works
    HzPerCt.fx_32.low = Oscillator.fx_32.high; // divide oscillator by 2^32 with simple shifting
    HzPerCt.fx_32.high = 0;
    CtPerHz.fx_64 = -1; // Compute (2^32 – 1) / oscillator
    CtPerHz.fx_64 /= (uint64_t)Oscillator.fx_32.high; // remove 2^32 scale factor from divisor
    }
    //———–
    //– Helper routine for printf()
    int s_putc(char c, FILE *t) {
    Serial.write(c);
    }
    //———–
    void setup () {
    union ll_u TempFreq,TempCount;
    pinMode(PIN_HEARTBEAT,OUTPUT);
    digitalWrite(PIN_HEARTBEAT,LOW); // show we got here
    pinMode(PIN_SYNC,OUTPUT);
    digitalWrite(PIN_SYNC,LOW);
    Serial.begin (115200);
    fdevopen(&s_putc,0); // set up serial output for printf()
    Serial.println (F("60 kHz Sine Generator"));
    Serial.println (F("Ed Nisley – KE4ZNU – September 2017\n"));
    // DDS module controls
    pinMode(PIN_DDS_LATCH,OUTPUT);
    digitalWrite(PIN_DDS_LATCH,LOW);
    pinMode(PIN_DDS_RESET,OUTPUT);
    digitalWrite(PIN_DDS_RESET,HIGH);
    // Light up the display
    Serial.println("Initialize OLED");
    u8x8.begin();
    u8x8.setFont(u8x8_font_artossans8_r);
    // u8x8.setPowerSave(0);
    u8x8.setFont(u8x8_font_pxplusibmcga_f);
    u8x8.draw2x2String(0,0,"Sine Gen");
    u8x8.drawString(0,3,"Ed Nisley");
    u8x8.drawString(0,4," KE4ZNU");
    u8x8.drawString(0,5,"2017-09-20");
    u8x8.drawString(0,6,"Press Button …");
    // configure SPI hardware
    pinMode(PIN_SS,OUTPUT); // set up manual controls
    digitalWrite(PIN_SS,HIGH);
    pinMode(PIN_SCK,OUTPUT);
    digitalWrite(PIN_SCK,LOW);
    pinMode(PIN_MOSI,OUTPUT);
    digitalWrite(PIN_MOSI,LOW);
    pinMode(PIN_MISO,INPUT_PULLUP);
    SPCR = B00110000; // Auto SPI: no int, disabled, LSB first, master, + edge, leading, f/4
    SPSR = B00000000; // not double data rate
    TogglePin(PIN_HEARTBEAT); // show we got here
    // Set up X axis DAC output
    XAxisDAC.begin(MCP4725_ADDR); // start up MCP4725 DAC at Sparkfun address
    // XAxisDAC.setVoltage(0,DAC_WR_EEP); // do this once per DAC to set power-on at 0 V
    XAxisDAC.setVoltage(0,DAC_WR); // force 0 V after a reset without a power cycle
    // LM75A temperature sensor requires no setup!
    // External capacitor in test fixture
    // Turn relay off to keep the heat down
    pinMode(PIN_CX_SHORT,OUTPUT);
    digitalWrite(PIN_CX_SHORT,LOW);
    // Frequencies
    PrintFixedPtRounded(Buffer,CenterFreq,1);
    printf("Center freq: %s Hz\n",Buffer);
    NomFreq = CenterFreq;
    // Wake up and load the DDS
    OscOffset = ComputeOffset();
    CalcOscillator(OscOffset);
    Serial.print("\nStarting DDS: ");
    TempFreq.fx_64 = CALFREQ;
    TempCount.fx_64 = MultiplyFixedPt(TempFreq,CtPerHz);
    EnableDDS();
    WriteDDS(TempCount.fx_32.high);
    Serial.println("running\n");
    WaitButton(); // pause until button release
    u8x8.setPowerSave(0);
    u8x8.clearDisplay();
    Serial.println("\nStartup done\n");
    MillisThen = millis();
    ZeroBeat(); // compensate for oscillator clock offset
    TempCount.fx_64 = MultiplyFixedPt(NomFreq,CtPerHz); // set up initial frequency
    WriteDDS(TempCount.fx_32.high);
    u8x8.drawString(0,5," <- Jog -> ");
    u8x8.drawString(0,6," ^ 1 Hz v ");
    u8x8.drawString(0,7," Button = reset ");
    }
    //———–
    void loop () {
    byte ln;
    union ll_u DDSCount;
    TestFreq = NomFreq; // assume no change
    if (analogRead(PIN_JOYBUTTTON) > 500) { // button unpushed?
    int ai = analogRead(PIN_JOY_Y) – 512; // X axis = left-right
    if (ai < -100)
    TestFreq.fx_64 = NomFreq.fx_64 + StepSize.fx_64;
    else if (ai > 100)
    TestFreq.fx_64 = NomFreq.fx_64 – StepSize.fx_64;
    else {
    ai = analogRead(PIN_JOY_X) – 512; // Y axis = up-down
    if (ai < -100)
    TestFreq.fx_64 = NomFreq.fx_64 + ONE_FX;
    else if (ai > 100)
    TestFreq.fx_64 = NomFreq.fx_64 – ONE_FX;
    }
    }
    else
    TestFreq = CenterFreq; // reset on button push
    DDSCount.fx_64 = MultiplyFixedPt(TestFreq,CtPerHz); // compute DDS delta phase
    DDSCount.fx_32.low = 0; // truncate count to integer
    ActualFreq.fx_64 = MultiplyFixedPt(DDSCount,HzPerCt);
    if (TestFreq.fx_64 != NomFreq.fx_64) { // avoid writing same value
    WriteDDS(DDSCount.fx_32.high);
    NomFreq = TestFreq; // set up new value
    }
    ln = 0;
    PrintFixedPtRounded(Buffer,ActualFreq,2); // display actual frequency
    u8x8.draw2x2String(0,ln,Buffer);
    ln = 3;
    LogAmpdB.fx_64 = ReadLogAmp(); // show current response
    PrintFixedPtRounded(Buffer,LogAmpdB,1);
    u8x8.drawString(0,ln,"Response");
    u8x8.drawString(16-strlen(Buffer),ln++,Buffer);
    Temperature.fx_64 = GetTemperature(); // and temperature
    PrintFixedPtRounded(Buffer,Temperature,3);
    u8x8.drawString(0,ln,"DDS Temp");
    u8x8.drawString(16-strlen(Buffer),ln++,Buffer);
    delay(100);
    }
  • Tour Easy Headset Wrench

    The headset on my Tour Easy ‘bent worked its way loose, which led to a disturbing discovery: the headset wrench I made from a discarded flat wrench vanished with the shop tools donated to MakerSmiths.

    Fortunately, we live in the future:

    Tour Easy Headset Wrench - Slic3r preview
    Tour Easy Headset Wrench – Slic3r preview

    A thin plastic wrench is absolutely no good for torquing down the locknut, but that’s not what it’s for. Adjust the bearing race to the proper preload with this wrench, hold it in place, then torque the locknut with the BFW.

    The OpenSCAD source code as a GitHub Gist:

    // Tour Easy Headset Wrench
    // Ed Nisley KE4ZNU – September 2017
    /* [Extrusion] */
    ThreadThick = 0.25; // [0.20, 0.25]
    ThreadWidth = 0.40; // [0.40]
    function IntegerMultiple(Size,Unit) = Unit * ceil(Size / Unit);
    Protrusion = 0.01; // [0.01, 0.1]
    HoleWindage = 0.2;
    //- Sizes
    /* [Dimensions] */
    WrenchSize = 32.0; // headset race across-the-flats size
    NumFlats = 8;
    JawWidth = 10.0;
    JawOD = 2*JawWidth + WrenchSize;
    echo(str("Jaw OD: ",JawOD));
    StemOD = 23.0;
    WrenchThick = 5.0;
    HandleLength = 2*JawOD;
    HandleWidth = 25.0;
    //- Build things
    difference() {
    linear_extrude(height=WrenchThick,convexity=4) {
    hull() { // taper wrench body to handle
    circle(d=JawOD);
    translate([0.75*JawOD,0,0])
    circle(d=HandleWidth);
    }
    hull() { // handle
    translate([0.75*JawOD,0,0])
    circle(d=HandleWidth);
    translate([HandleLength,0,0])
    circle(d=HandleWidth);
    }
    }
    translate([0,0,-Protrusion])
    rotate(1*180/NumFlats) { // cosine converts across-flats to circle dia
    cylinder(d=WrenchSize/cos(180/NumFlats),h=(WrenchThick + 2*Protrusion),$fn=NumFlats);
    }
    translate([-StemOD,0,WrenchThick/2])
    cube([2*StemOD,StemOD,(WrenchThick + 2*Protrusion)],center=true);
    translate([WrenchSize,0,WrenchThick – 3*ThreadThick])
    linear_extrude(3*ThreadThick + Protrusion,convexity=10)
    text(text=str("TE Headset"),size=8,spacing=1.20,font="Arial",halign="left",valign="center");
    }

    Now, I’d like to say that was easy, but in actual point of fact …

    First, I forgot to divide by cos(180/6) to convert the across-the-flats size to the diameter of OpenSCAD’s circumscribed hexagon-as-circle, which made the wrench uselessly small:

    Tour Easy Headset Wrench - v1
    Tour Easy Headset Wrench – v1

    If you have a 28 mm nut with low torque requirements, though, I’ve got your back.

    While I had the hood up, I slenderized the handle into a much shapelier figure:

    Tour Easy Headset Wrench
    Tour Easy Headset Wrench

    Trotting off to the garage with a warm plastic wrench in hand, I discovered the blindingly obvious fact that the headset nuts have eight sides. On the upside, the number of sides became a parameter, so, should you happen to need a five-sided wrench (perhaps on Mars), you can have one.

    So, yeah, it’s rapid prototyping in full effect:

    Tour Easy Headset Wrench Iterations
    Tour Easy Headset Wrench Iterations

    Remember, kids, never design while distracted …

  • Tour Easy Daytime Running Light: Now with Chirality!

    In the unlikely event our bikes need two running lights or, perhaps, a running light and a headlight, the solid model now builds mounts for the right side of the fairing, as before:

    Fairing Flashlight Mount - Right side - solid model
    Fairing Flashlight Mount – Right side – solid model

    And for the left side:

    Fairing Flashlight Mount - Left side - solid model
    Fairing Flashlight Mount – Left side – solid model

    Ahhh, chirality: love that word.

    Those pix come from a cleaned-up version of the OpenSCAD code that finally gets the 3-axis rotations right, after a rip-and-replace rewrite to deliver the ball model with its origin in the center of the ball where it belonged and rotate the ring about its geometric center. Then the rotations become trivially easy and a slight hack job spits out a completely assembled model:

    if (Component == "Complete") {
      translate([-BracketHoleOC,0,0])
        PlateBlank();
      mirror(TiltMirror) {
        translate([0,0,ClampOD/2]) {
          rotate([-Roll,ToeIn,Tilt])
            SlotBall();
          rotate([-Roll,ToeIn,Tilt])
            BallClamp();
        }
      }
    }
    

    However, putting the center of rotation directly over the center of the base plate means the ToeIn rotation shifts the bottom of the clamp ring along the X axis, where it can obstruct the mounting holes. Shifting the ring by a little bit:

    ClampOD*sin(ToeIn/2)

    … keeps the ring more-or-less centered on the top of the plate. That’s not quite the correct geometry, but it’s close enough for the small angles needed here.

    Aiming the beam slightly higher makes a 400 lumen flashlight about as bright as any single LED in new car running lights:

    Fairing Flashlight Mount - Mary approaching
    Fairing Flashlight Mount – Mary approaching

    You can just barely make out the snazzy new blue plate on the left side of the fairing.

    A bike’s natural back-and-forth handlebar motion sweeps the beam across the lane, so I think there’s no real benefit from blinking.

    The OpenSCAD source code as a GitHub Gist:

    // Tour Easy Fairing Flashlight Mount
    // Ed Nisley KE4ZNU – July 2017
    // August 2017 –
    /* [Build Options] */
    FlashName = "AnkerLC40"; // [AnkerLC40,AnkerLC90,J5TactV2,InnovaX5]
    Component = "Complete"; // [Ball, BallClamp, Mount, Plates, Bracket, Complete]
    Layout = "Show"; // [Build, Show]
    Support = false;
    MountSupport = false;
    /* [Extrusion] */
    ThreadThick = 0.25; // [0.20, 0.25]
    ThreadWidth = 0.40; // [0.40]
    function IntegerMultiple(Size,Unit) = Unit * ceil(Size / Unit);
    Protrusion = 0.01; // [0.01, 0.1]
    HoleWindage = 0.2;
    /* [Fairing Mount] */
    Side = "Right"; // [Right,Left]
    ToeIn = 0; // inward from ahead
    Tilt = 15; // upward from forward (M=20 E=15)
    Roll = 0; // outward from top
    //- Screws *c
    /* [Hidden] */
    ID = 0;
    OD = 1;
    LENGTH = 2;
    /* [Screws and Inserts] */
    ClampInsert = [3.0,4.2,8.0];
    ClampScrew = [3.0,5.9,35.0]; // thread dia, head OD, screw length
    ClampScrewWasher = [3.0,6.75,0.5];
    ClampScrewNut = [3.0,6.1,4.0]; // nyloc nut
    /* [Hidden] */
    F_NAME = 0;
    F_GRIPOD = 1;
    F_GRIPLEN = 2;
    LightBodies = [
    ["AnkerLC90",26.6,48.0],
    ["AnkerLC40",26.6,55.0],
    ["J5TactV2",25.0,30.0],
    ["InnovaX5",22.0,55.0]
    ];
    //- Fairing Bracket
    // Magic numbers taken from the actual fairing mount
    /* [Hidden] */
    inch = 25.4;
    BracketHoleOD = 0.25 * inch; // 1/4-20 bolt holes
    BracketHoleOC = 1.0 * inch; // fairing hole spacing
    // usually 1 inch, but 15/16 on one fairing
    Bracket = [48.0,16.3,3.6 – 0.6]; // fairing bracket end plate overall size
    BracketHoleOffset = (3/8) * inch; // end to hole center
    BracketM = 3.0; // endcap arc height
    BracketR = (pow(BracketM,2) + pow(Bracket[1],2)/4) / (2*BracketM); // … radius
    //- Base plate dimensions
    Plate = [100.0,30.0,6*ThreadThick + Bracket[2]];
    PlateRad = Plate[1]/4;
    RoundEnds = true;
    echo(str("Base plate thick: ",Plate[2]));
    //- Select flashlight data from table
    echo(str("Flashlight: ",FlashName));
    FlashIndex = search([FlashName],LightBodies,1,0)[F_NAME];
    //- Set ball dimensions
    BallWall = 5.0; // max ball wall thickness
    echo(str("Ball wall: ",BallWall));
    BallOD = IntegerMultiple(LightBodies[FlashIndex][F_GRIPOD] + 2*BallWall,1.0);
    echo(str(" OD: ",BallOD));
    BallLength = IntegerMultiple(min(sqrt(pow(BallOD,2) – pow(LightBodies[FlashIndex][F_GRIPOD],2)) – 2*4*ThreadThick,
    LightBodies[FlashIndex][F_GRIPLEN]),1.0);
    echo(str(" length: ",BallLength));
    BallSides = 8*4;
    //- Set clamp ring dimensions
    ClampOD = 50;
    echo(str("Clamp OD: ",ClampOD));
    ClampLength = min(20.0,0.75*BallLength);
    echo(str(" length: ",ClampLength));
    ClampScrewOC = IntegerMultiple((ClampOD + BallOD)/2,1);
    echo(str(" screw OC: ",ClampScrewOC));
    TiltMirror = (Side == "Right") ? [0,0,0] : [0,1,0];
    //- Adjust hole diameter to make the size come out right
    module PolyCyl(Dia,Height,ForceSides=0) { // based on nophead's polyholes
    Sides = (ForceSides != 0) ? ForceSides : (ceil(Dia) + 2);
    FixDia = Dia / cos(180/Sides);
    cylinder(r=(FixDia + HoleWindage)/2,h=Height,$fn=Sides);
    }
    //- Fairing Bracket
    // This part of the fairing mount supports the whole flashlight mount
    // Centered on screw hole
    module Bracket() {
    linear_extrude(height=Bracket[2],convexity=2)
    difference() {
    translate([(Bracket[0]/2 – BracketHoleOffset),0,0])
    offset(delta=ThreadWidth)
    intersection() {
    square([Bracket[0],Bracket[1]],center=true);
    union() {
    for (i=[-1,0,1]) // middle circle fills gap
    translate([i*(Bracket[0]/2 – BracketR),0])
    circle(r=BracketR);
    }
    }
    circle(d=BracketHoleOD/cos(180/8),$fn=8); // dead center at the origin
    }
    }
    //- General plate shape
    // Centered on the hole for the fairing bracket
    module PlateBlank() {
    difference() {
    translate([BracketHoleOC,0,0])
    intersection() {
    translate([0,0,Plate[2]/2]) // select upper half of spheres
    cube(Plate,center=true);
    hull()
    if (RoundEnds)
    for (i=[-1,1])
    translate([i*(Plate[0]/2 – PlateRad),0,0])
    resize([Plate[1]/2,Plate[1],2*Plate[2]])
    sphere(r=PlateRad); // nice round ends!
    else
    for (i=[-1,1], j=[-1,1])
    translate([i*(Plate[0]/2 – PlateRad),j*(Plate[1]/2 – PlateRad),0])
    resize([2*PlateRad,2*PlateRad,2*Plate[2]])
    sphere(r=PlateRad); // nice round corners!
    }
    translate([2*BracketHoleOC,0,-Protrusion]) // punch screw holes
    PolyCyl(BracketHoleOD,2*Plate[2],8);
    translate([0,0,-Protrusion])
    PolyCyl(BracketHoleOD,2*Plate[2],8);
    }
    }
    //- Inner plate
    module InnerPlate() {
    difference() {
    PlateBlank();
    translate([0,0,Plate[2] – Bracket[2] + Protrusion]) // punch fairing bracket
    Bracket();
    }
    }
    //- Slotted ball around flashlight
    // Print with brim to ensure adhesion!
    module SlotBall() {
    NumSlots = 8*2; // must be even, half cut from each end
    SlotWidth = 2*ThreadWidth;
    SlotBaseThick = 10*ThreadThick; // enough to hold finger ends together
    RibLength = (BallOD – LightBodies[FlashIndex][F_GRIPOD])/2;
    translate([0,0,(Layout == "Build") ? BallLength/2 : 0])
    rotate([0,(Layout == "Show") ? 90 : 0,0])
    difference() {
    intersection() {
    sphere(d=BallOD,$fn=2*BallSides); // basic ball
    cube([2*BallOD,2*BallOD,BallLength],center=true); // trim to length
    }
    translate([0,0,-LightBodies[FlashIndex][F_GRIPOD]])
    rotate(180/BallSides)
    PolyCyl(LightBodies[FlashIndex][F_GRIPOD],2*BallOD,BallSides); // remove flashlight body
    for (i=[0:NumSlots/2 – 1]) { // cut slots
    a=i*(2*360/NumSlots);
    SlotCutterLength = LightBodies[FlashIndex][F_GRIPOD];
    rotate(a)
    translate([SlotCutterLength/2,0,SlotBaseThick])
    cube([SlotCutterLength,SlotWidth,BallLength],center=true);
    rotate(a + 360/NumSlots)
    translate([SlotCutterLength/2,0,-SlotBaseThick])
    cube([SlotCutterLength,SlotWidth,BallLength],center=true);
    }
    }
    color("Yellow")
    if (Support && (Layout == "Build")) {
    for (i=[0:NumSlots-1]) {
    a = i*360/NumSlots;
    rotate(a + 180/NumSlots)
    translate([(LightBodies[FlashIndex][F_GRIPOD] + RibLength)/2 + ThreadWidth,0,BallLength/(2*4)])
    cube([RibLength,2*ThreadWidth,BallLength/4],center=true);
    }
    }
    }
    //- Clamp around flashlight ball
    module BallClamp(Section="All") {
    BossLength = ClampScrew[LENGTH] – 1*ClampScrewWasher[LENGTH];
    BossOD = ClampInsert[OD] + 2*(6*ThreadWidth);
    difference() {
    union() {
    intersection() {
    sphere(d=ClampOD,$fn=BallSides); // exterior ball clamp
    cube([ClampLength,2*ClampOD,2*ClampOD],center=true); // aiming allowance
    }
    hull()
    for (j=[-1,1])
    translate([0,j*ClampScrewOC/2,-BossLength/2])
    cylinder(d=BossOD,h=BossLength,$fn=6);
    }
    sphere(d=(BallOD + 1*ThreadThick),$fn=BallSides); // interior ball with minimal clearance
    for (j=[-1,1]) {
    translate([0,j*ClampScrewOC/2,-ClampOD]) // screw clearance
    PolyCyl(ClampScrew[ID],2*ClampOD,6);
    translate([0,j*ClampScrewOC/2, // insert clearance
    -(BossLength/2 – ClampInsert[LENGTH] – 3*ThreadThick)])
    rotate([0,180,0])
    PolyCyl(ClampInsert[OD],2*ClampOD,6);
    translate([0,j*ClampScrewOC/2, // insert transition
    -(BossLength/2 – ClampInsert[LENGTH] – 3*ThreadThick)])
    cylinder(d1=ClampInsert[OD]/cos(180/6),d2=ClampScrew[ID],h=6*ThreadThick,$fn=6);
    }
    if (Section == "Top")
    translate([0,0,-ClampOD/2])
    cube([2*ClampOD,2*ClampOD,ClampOD],center=true);
    else if (Section == "Bottom")
    translate([0,0,ClampOD/2])
    cube([2*ClampOD,2*ClampOD,ClampOD],center=true);
    }
    color("Yellow")
    if (Support) { // ad-hoc supports
    NumRibs = 6;
    RibLength = 0.5 * BallOD;
    RibWidth = 1.9*ThreadWidth;
    SupportOC = ClampLength / NumRibs;
    if (Section == "Top") // base plate for adhesion
    translate([0,0,ThreadThick])
    cube([ClampLength + 6*ThreadWidth,RibLength,2*ThreadThick],center=true);
    else if (Section == "Bottom")
    translate([0,0,-ThreadThick])
    cube([ClampLength + 6*ThreadWidth,RibLength,2*ThreadThick],center=true);
    render(convexity=2*NumRibs)
    intersection() {
    sphere(d=BallOD – 0*ThreadWidth); // cut at inner sphere OD
    cube([ClampLength + 2*ThreadWidth,RibLength,BallOD],center=true);
    if (Section == "Top") // select only desired section
    translate([0,0,ClampOD/2])
    cube([2*ClampOD,2*ClampOD,ClampOD],center=true);
    else if (Section == "Bottom")
    translate([0,0,-ClampOD/2])
    cube([2*ClampOD,2*ClampOD,ClampOD],center=true);
    union() { // ribs for E-Z build
    for (j=[-1,0,1])
    translate([0,j*SupportOC,0])
    cube([ClampLength,RibWidth,1.0*BallOD],center=true);
    for (i=[0:NumRibs]) // allow NumRibs + 1 to fill the far end
    translate([i*SupportOC – ClampLength/2,0,0])
    rotate([0,90,0])
    cylinder(d=BallOD – 2*ThreadThick,
    h=RibWidth,$fn=BallSides,center=true);
    }
    }
    }
    }
    //- Mount between fairing plate and flashlight ball
    // Build with support for bottom of clamp screws!
    module Mount() {
    TextRotate = (Side == "Right") ? 0 : 180;
    MountShift = [ClampOD*sin(ToeIn/2),
    0,
    ClampOD/2];
    difference() {
    translate([-BracketHoleOC,0,0]) // put bracket center at origin
    PlateBlank();
    mirror([0,1,0])
    translate([0,0,-Protrusion])
    linear_extrude(height=3*ThreadThick + Protrusion) {
    translate([BracketHoleOC + 15,0,0])
    text(text=">>>",size=5,spacing=1.20,font="Arial",halign="center",valign="center");
    translate([-BracketHoleOC,8,0]) rotate(TextRotate)
    text(text=str("Toe ",ToeIn),size=5,spacing=1.20,font="Arial",halign="center",valign="center");
    translate([-BracketHoleOC,-8,0]) rotate(TextRotate)
    text(text=str("Tilt ",Tilt),size=5,spacing=1.20,font="Arial",halign="center",valign="center");
    translate([BracketHoleOC,-8,0]) rotate(TextRotate)
    text(text=Side,size=5,spacing=1.20,font="Arial",halign="center",valign="center");
    translate([BracketHoleOC,8,0]) rotate(TextRotate)
    text(text=str("Roll ",Roll),size=5,spacing=1.20,font="Arial",halign="center",valign="center");
    translate([-(BracketHoleOC + 15),0,0])
    rotate(90)
    text(text="KE4ZNU",size=4,spacing=1.20,font="Arial",halign="center",valign="center");
    }
    }
    mirror(TiltMirror) {
    translate(MountShift)
    rotate([-Roll,ToeIn,Tilt])
    BallClamp("Bottom");
    color("Yellow")
    if (MountSupport) { // anchor outer corners at worst overhang
    RibWidth = 1.9*ThreadWidth;
    SupportOC = 0.1 * ClampLength;
    difference() {
    rotate([0,0,Tilt])
    translate([(ClampOD – BallOD)*sin(ToeIn/2),0,0])
    for (i=[-4.5,-2.5,0,2.0,4.5])
    translate([i*SupportOC – 0.0,0,(5 + Plate[2])/2])
    cube([RibWidth,0.7*ClampOD,(5 + Plate[2])],center=true);
    translate(MountShift)
    rotate([-Roll,ToeIn,Tilt])
    sphere(d=ClampOD – 2*ThreadWidth,$fn=BallSides);
    }
    }
    }
    }
    //- Build things
    if (Component == "Bracket")
    Bracket();
    if (Component == "Ball")
    SlotBall();
    if (Component == "BallClamp")
    if (Layout == "Show")
    BallClamp("All");
    else if (Layout == "Build")
    BallClamp("Top");
    if (Component == "Mount")
    Mount();
    if (Component == "Plates") {
    translate([0,0.7*Plate[1],0])
    InnerPlate();
    translate([0,-0.7*Plate[1],0])
    PlateBlank();
    }
    if (Component == "Complete") {
    translate([-BracketHoleOC,0,0])
    PlateBlank();
    mirror(TiltMirror) {
    translate([0,0,ClampOD/2]) {
    rotate([-Roll,ToeIn,Tilt])
    SlotBall();
    rotate([-Roll,ToeIn,Tilt])
    BallClamp();
    }
    }
    }
  • Tour Easy Daytime Running Light: Annotation

    The flashlight mount need not be symmetric after applying all the rotations, so recording how it’s aimed and which end goes forward seemed appropriate:

    Fairing Flashlight Mount - Mount Annotation
    Fairing Flashlight Mount – Mount Annotation

    Optionally, with rounded ends just for pretty:

    Fairing Flashlight Mount - Mount Annotation - rounded
    Fairing Flashlight Mount – Mount Annotation – rounded

    Because the rounding comes from resized spheres, the plate gets a ridge along the top to (maybe) lock the nylon screws / wing nuts in place:

    Fairing Flashlight Mount - Mount - rounded
    Fairing Flashlight Mount – Mount – rounded

    Or discourage them from turning, which would be OK, too. After the second tightening, they don’t seem to come loose, so this may be overthinking the problem.

    All in all, they look pretty good in cyan PETG:

    Fairing Flashlight Mount - rounded
    Fairing Flashlight Mount – rounded

    Believe it or not, that’s aimed so the top edge of the beam is roughly horizontal to keep the hot spot out of oncoming traffic. They’re plenty bright, even on the “low power” setting.

    The flashlight mounting balls produce a decorative brim that ought to be useful for something:

    Slotted ball on platform
    Slotted ball on platform

    Maybe earrings?

    The OpenSCAD source code as a GitHub Gist:

    // Tour Easy Fairing Flashlight Mount
    // Ed Nisley KE4ZNU – July 2017
    // August 2017 –
    /* [Build Options] */
    FlashName = "AnkerLC40"; // [AnkerLC40,AnkerLC90,J5TactV2,InnovaX5]
    Component = "Plates"; // [Ball, BallClamp, Mount, Plates, Bracket]
    Layout = "Build"; // [Build, Show]
    Support = false;
    MountSupport = true;
    /* [Extrusion] */
    ThreadThick = 0.25; // [0.20, 0.25]
    ThreadWidth = 0.40; // [0.40]
    function IntegerMultiple(Size,Unit) = Unit * ceil(Size / Unit);
    Protrusion = 0.01; // [0.01, 0.1]
    HoleWindage = 0.2;
    /* [Fairing Mount] */
    ToeIn = 0; // inward from ahead
    Tilt = 20; // upward from forward (M=20 E=15)
    Roll = 0; // outward from top
    Shift = 0; // Finagle Constant for support ribs
    //- Screws *c
    /* [Hidden] */
    ID = 0;
    OD = 1;
    LENGTH = 2;
    /* [Screws and Inserts] */
    ClampInsert = [3.0,4.2,8.0];
    ClampScrew = [3.0,5.9,35.0]; // thread dia, head OD, screw length
    ClampScrewWasher = [3.0,6.75,0.5];
    ClampScrewNut = [3.0,6.1,4.0]; // nyloc nut
    /* [Hidden] */
    F_NAME = 0;
    F_GRIPOD = 1;
    F_GRIPLEN = 2;
    LightBodies = [
    ["AnkerLC90",26.6,48.0],
    ["AnkerLC40",26.6,55.0],
    ["J5TactV2",25.0,30.0],
    ["InnovaX5",22.0,55.0]
    ];
    //- Fairing Bracket
    // Magic numbers taken from the actual fairing mount
    /* [Hidden] */
    inch = 25.4;
    BracketHoleOD = 0.25 * inch; // 1/4-20 bolt holes
    BracketHoleOC = 1.0 * inch; // fairing hole spacing
    // usually 1 inch, but 15/16 on one fairing
    Bracket = [48.0,16.3,3.6 – 0.6]; // fairing bracket end plate overall size
    BracketHoleOffset = (3/8) * inch; // end to hole center
    BracketM = 3.0; // endcap arc height
    BracketR = (pow(BracketM,2) + pow(Bracket[1],2)/4) / (2*BracketM); // … radius
    //- Base plate dimensions
    Plate = [100.0,30.0,6*ThreadThick + Bracket[2]];
    PlateRad = Plate[1]/4;
    RoundEnds = true;
    echo(str("Base plate thick: ",Plate[2]));
    //- Select flashlight data from table
    echo(str("Flashlight: ",FlashName));
    FlashIndex = search([FlashName],LightBodies,1,0)[F_NAME];
    //- Set ball dimensions
    BallWall = 5.0; // max ball wall thickness
    echo(str("Ball wall: ",BallWall));
    BallOD = IntegerMultiple(LightBodies[FlashIndex][F_GRIPOD] + 2*BallWall,1.0);
    echo(str(" OD: ",BallOD));
    BallLength = IntegerMultiple(min(sqrt(pow(BallOD,2) – pow(LightBodies[FlashIndex][F_GRIPOD],2)) – 2*4*ThreadThick,
    LightBodies[FlashIndex][F_GRIPLEN]),1.0);
    echo(str(" length: ",BallLength));
    BallSides = 8*4;
    //- Set clamp ring dimensions
    ClampOD = 50;
    echo(str("Clamp OD: ",ClampOD));
    ClampLength = min(20.0,0.75*BallLength);
    echo(str(" length: ",ClampLength));
    ClampScrewOC = IntegerMultiple((ClampOD + BallOD)/2,1);
    echo(str(" screw OC: ",ClampScrewOC));
    //- Adjust hole diameter to make the size come out right
    module PolyCyl(Dia,Height,ForceSides=0) { // based on nophead's polyholes
    Sides = (ForceSides != 0) ? ForceSides : (ceil(Dia) + 2);
    FixDia = Dia / cos(180/Sides);
    cylinder(r=(FixDia + HoleWindage)/2,h=Height,$fn=Sides);
    }
    //- Fairing Bracket
    // This part of the fairing mount supports the whole flashlight mount
    // Centered on screw hole
    module Bracket() {
    linear_extrude(height=Bracket[2],convexity=2)
    difference() {
    translate([(Bracket[0]/2 – BracketHoleOffset),0,0])
    offset(delta=ThreadWidth)
    intersection() {
    square([Bracket[0],Bracket[1]],center=true);
    union() {
    for (i=[-1,0,1]) // middle circle fills gap
    translate([i*(Bracket[0]/2 – BracketR),0])
    circle(r=BracketR);
    }
    }
    circle(d=BracketHoleOD/cos(180/8),$fn=8); // dead center at the origin
    }
    }
    //- General plate shape
    // Centered on the hole for the fairing bracket
    module PlateBlank() {
    difference() {
    translate([BracketHoleOC,0,0])
    intersection() {
    translate([0,0,Plate[2]/2]) // select upper half of spheres
    cube(Plate,center=true);
    hull()
    if (RoundEnds)
    for (i=[-1,1])
    translate([i*(Plate[0]/2 – PlateRad),0,0])
    resize([Plate[1]/2,Plate[1],2*Plate[2]])
    sphere(r=PlateRad); // nice round ends!
    else
    for (i=[-1,1], j=[-1,1])
    translate([i*(Plate[0]/2 – PlateRad),j*(Plate[1]/2 – PlateRad),0])
    resize([2*PlateRad,2*PlateRad,2*Plate[2]])
    sphere(r=PlateRad); // nice round corners!
    }
    translate([2*BracketHoleOC,0,-Protrusion]) // punch screw holes
    PolyCyl(BracketHoleOD,2*Plate[2],8);
    translate([0,0,-Protrusion])
    PolyCyl(BracketHoleOD,2*Plate[2],8);
    }
    }
    //- Inner plate
    module InnerPlate() {
    difference() {
    PlateBlank();
    translate([0,0,Plate[2] – Bracket[2] + Protrusion]) // punch fairing bracket
    Bracket();
    }
    }
    //- Slotted ball around flashlight
    // Print with brim to ensure adhesion!
    module SlotBall() {
    NumSlots = 8*2; // must be even, half cut from each end
    SlotWidth = 2*ThreadWidth;
    SlotBaseThick = 10*ThreadThick; // enough to hold finger ends together
    RibLength = (BallOD – LightBodies[FlashIndex][F_GRIPOD])/2;
    translate([0,0,BallLength/2])
    difference() {
    intersection() {
    sphere(d=BallOD,$fn=2*BallSides); // basic ball
    cube([2*BallOD,2*BallOD,BallLength],center=true); // trim to length
    }
    translate([0,0,-LightBodies[FlashIndex][F_GRIPOD]])
    rotate(180/BallSides)
    PolyCyl(LightBodies[FlashIndex][F_GRIPOD],2*BallOD,BallSides); // remove flashlight body
    for (i=[0:NumSlots/2 – 1]) { // cut slots
    a=i*(2*360/NumSlots);
    SlotCutterLength = LightBodies[FlashIndex][F_GRIPOD];
    rotate(a)
    translate([SlotCutterLength/2,0,SlotBaseThick])
    cube([SlotCutterLength,SlotWidth,BallLength],center=true);
    rotate(a + 360/NumSlots)
    translate([SlotCutterLength/2,0,-SlotBaseThick])
    cube([SlotCutterLength,SlotWidth,BallLength],center=true);
    }
    }
    color("Yellow")
    if (Support) {
    for (i=[0:NumSlots-1]) {
    a = i*360/NumSlots;
    rotate(a + 180/NumSlots)
    translate([(LightBodies[FlashIndex][F_GRIPOD] + RibLength)/2 + ThreadWidth,0,BallLength/(2*4)])
    cube([RibLength,2*ThreadWidth,BallLength/4],center=true);
    }
    }
    }
    //- Clamp around flashlight ball
    module BallClamp() {
    BossLength = ClampScrew[LENGTH] – 1*ClampScrewWasher[LENGTH];
    BossOD = ClampInsert[OD] + 2*(6*ThreadWidth);
    difference() {
    union() {
    intersection() {
    sphere(d=ClampOD,$fn=BallSides); // exterior ball clamp
    cube([ClampLength,2*ClampOD,2*ClampOD],center=true); // aiming allowance
    }
    hull()
    for (j=[-1,1])
    translate([0,j*ClampScrewOC/2,-BossLength/2])
    cylinder(d=BossOD,h=BossLength,$fn=6);
    }
    sphere(d=(BallOD + 1*ThreadThick),$fn=BallSides); // interior ball with minimal clearance
    for (j=[-1,1]) {
    translate([0,j*ClampScrewOC/2,-ClampOD]) // screw clearance
    PolyCyl(ClampScrew[ID],2*ClampOD,6);
    translate([0,j*ClampScrewOC/2, // insert clearance
    -(BossLength/2 – ClampInsert[LENGTH] – 3*ThreadThick)])
    rotate([0,180,0])
    PolyCyl(ClampInsert[OD],2*ClampOD,6);
    translate([0,j*ClampScrewOC/2, // insert transition
    -(BossLength/2 – ClampInsert[LENGTH] – 3*ThreadThick)])
    cylinder(d1=ClampInsert[OD]/cos(180/6),d2=ClampScrew[ID],h=6*ThreadThick,$fn=6);
    }
    }
    color("Yellow")
    if (Support) { // ad-hoc supports for top half
    NumRibs = 6;
    RibLength = 0.5 * BallOD;
    RibWidth = 1.9*ThreadWidth;
    SupportOC = ClampLength / NumRibs;
    cube([ClampLength,RibLength,4*ThreadThick],center=true); // base plate for adhesion
    render(convexity=2*NumRibs)
    intersection() {
    sphere(d=BallOD – 0*ThreadWidth); // cut at inner sphere OD
    cube([ClampLength + 2*ThreadWidth,RibLength,BallOD],center=true);
    union() { // ribs for E-Z build
    for (j=[-1,0,1])
    translate([0,j*SupportOC,0])
    cube([ClampLength,RibWidth,1.0*BallOD],center=true);
    for (i=[0:NumRibs]) // allow NumRibs + 1 to fill the far end
    translate([i*SupportOC – ClampLength/2,0,0])
    rotate([0,90,0])
    cylinder(d=BallOD – 2*ThreadThick,
    h=RibWidth,$fn=BallSides,center=true);
    }
    }
    }
    }
    //- Mount between fairing plate and flashlight ball
    // Build with support for bottom of clamp screws!
    module Mount() {
    difference() {
    translate([-BracketHoleOC,0,0]) // put bracket center at origin
    PlateBlank();
    mirror([0,1,0])
    translate([0,0,-Protrusion])
    linear_extrude(height=3*ThreadThick + Protrusion) {
    translate([BracketHoleOC + 15,0,0])
    text(text=">>>",size=5,spacing=1.20,font="Arial",halign="center",valign="center");
    translate([-BracketHoleOC,8,0])
    text(text=str("Toe ",ToeIn),size=5,spacing=1.20,font="Arial",halign="center",valign="center");
    translate([-BracketHoleOC,-8,0])
    text(text=str("Tilt ",Tilt),size=5,spacing=1.20,font="Arial",halign="center",valign="center");
    translate([BracketHoleOC,8,0])
    text(text=str("Roll ",Roll),size=5,spacing=1.20,font="Arial",halign="center",valign="center");
    translate([-(BracketHoleOC + 15),0,0])
    rotate(90)
    text(text="KE4ZNU",size=4,spacing=1.20,font="Arial",halign="center",valign="center");
    }
    }
    rotate([0,ToeIn,Tilt])
    translate([0,0,ClampOD/2])
    rotate([-Roll,0,0])
    intersection() {
    translate([0,0,-ClampOD/2])
    cube([2*ClampOD,2*ClampOD,ClampOD],center=true);
    BallClamp();
    }
    color("Yellow")
    if (MountSupport) { // anchor outer corners at worst overhang
    RibWidth = 1.9*ThreadWidth;
    SupportOC = 0.1 * ClampLength;
    difference() {
    rotate([0,0,Tilt])
    translate([Shift,0,0])
    for (i=[-4.5,-2.5,0,2.0,4.5])
    translate([i*SupportOC – 0.0,0,(5 + Plate[2])/2])
    cube([RibWidth,0.7*ClampOD,(5 + Plate[2])],center=true);
    rotate([0,ToeIn,Tilt])
    translate([Shift,0,ClampOD/2])
    rotate([-Roll,0,0])
    sphere(d=ClampOD – 2*ThreadWidth,$fn=BallSides);
    }
    }
    }
    //- Build things
    if (Component == "Ball")
    SlotBall();
    if (Component == "BallClamp")
    if (Layout == "Show")
    BallClamp();
    else if (Layout == "Build") {
    Both = false;
    difference() {
    union() {
    translate([Both ? ClampLength : 0,0,0])
    BallClamp();
    if (Both)
    translate([-ClampLength,0,0])
    rotate([180,0,0])
    BallClamp();
    }
    translate([0,0,-ClampOD/2])
    cube([2*ClampOD,2*ClampOD,ClampOD],center=true);
    }
    }
    if (Component == "Mount")
    Mount();
    if (Component == "Plates") {
    translate([0,0.7*Plate[1],0])
    InnerPlate();
    translate([0,-0.7*Plate[1],0])
    PlateBlank();
    }
    if (Component == "Bracket")
    Bracket();

     

  • Tour Easy Daytime Running Light: Improved Ball Mount

    The original ball around the flashlight consisted of two identical parts joined with 2 mm screws and brass inserts:

    Flashlight Ball Mount - flattening fins
    Flashlight Ball Mount – flattening fins

    Providing enough space for the inserts made the ball bigger than it really ought be, so I designed a one-piece ball with “expansion joints” between the fingers:

    Fairing Flashlight Mount - Finger Ball - solid model
    Fairing Flashlight Mount – Finger Ball – solid model

    Having Slic3r put a 3 mm brim around the bottom almost worked. Adding a little support flange, then building with a brim, kept each segment upright and the whole affair firmly anchored.

    Fairing Flashlight Mount - Finger Ball - solid model - support fins
    Fairing Flashlight Mount – Finger Ball – solid model – support fins

    Those had to be part of the model, because I also wanted to anchor the perimeter threads to prevent upward warping. Worked great and cleanup was surprisingly easy: apply the flush cutter, introduce the ball to Mr Belt Sander, then rotate the ball around the flashlight wrapped with fine sandpaper to wear off the nubs.

    The joints between the fingers provide enough flexibility to expand slightly around the flashlight body:

    Flashlight Mount - finger ball
    Flashlight Mount – finger ball

    I made that one the same size as the original screw + insert balls to fit the original clamp, where it worked fine. The clamp ring applies enough pressure to the ball to secure the flashlight and prevent the ball from rotating unless you (well, I) apply more-than-incidental force.

    Then I shrank the ball to the flashlight diameter + 10 mm (= 5 mm thick at the equator) and reduced the size of the clamp ring accordingly, which made the whole mount much more compact:

    Flashlight Mount - LC40 - finger ball - side
    Flashlight Mount – LC40 – finger ball – side

    Here’s what the larger mount looks like in action:

    The flashlights allegedly puts out 400 lumen in a fairly tight beam. The fairings produce a much larger and brighter glint in full sunlight than the flashlights, so I think they’re about the right brightness.

    The OpenSCAD source code for the new ball as a GitHub Gist:

    //- Slotted ball around flashlight
    // Print with brim to ensure adhesion!
    module SlotBall() {
    NumSlots = 8*2; // must be even, half cut from each end
    SlotWidth = 2*ThreadWidth;
    SlotBaseThick = 10*ThreadThick; // enough to hold finger ends together
    RibLength = (BallOD – LightBodies[FlashIndex][F_GRIPOD])/2;
    translate([0,0,BallLength/2])
    difference() {
    intersection() {
    sphere(d=BallOD,$fn=2*BallSides); // basic ball
    cube([2*BallOD,2*BallOD,BallLength],center=true); // trim to length
    }
    translate([0,0,-LightBodies[FlashIndex][F_GRIPOD]])
    rotate(180/BallSides)
    PolyCyl(LightBodies[FlashIndex][F_GRIPOD],2*BallOD,BallSides); // remove flashlight body
    for (i=[0:NumSlots/2 – 1]) { // cut slots
    a=i*(2*360/NumSlots);
    SlotCutterLength = LightBodies[FlashIndex][F_GRIPOD];
    rotate(a)
    translate([SlotCutterLength/2,0,SlotBaseThick])
    cube([SlotCutterLength,SlotWidth,BallLength],center=true);
    rotate(a + 360/NumSlots)
    translate([SlotCutterLength/2,0,-SlotBaseThick])
    cube([SlotCutterLength,SlotWidth,BallLength],center=true);
    }
    }
    color("Yellow")
    if (Support) {
    for (i=[0:NumSlots-1]) {
    a = i*360/NumSlots;
    rotate(a + 180/NumSlots)
    translate([(LightBodies[FlashIndex][F_GRIPOD] + RibLength)/2 + ThreadWidth,0,BallLength/(2*4)])
    cube([RibLength,2*ThreadWidth,BallLength/4],center=true);
    }
    }
    }