The personal website of Scott W Harden
July 26th, 2019

SMT QRSS Design

This page documents development of a voltage-controlled oscillator suitable for QRSS. Source code and PCB files are on https://github.com/swharden/QRSS-hardware

For QRSS it's convenient to have 2 frequency shift adjustments: a coarse one to set frequency (~200 Hz), and a fine one for FSK (5 Hz). I began with the design below allowing manual adjustment of coarse tuning, then an external input for fine tuning. Eventually I switched to a design where a single voltage controls tuning (coarse and fine). Many QRSS TX designs use a variable capacitor to set the coarse adjustment, but I don't like that design because it means you have to open your enclosure every time you want to shift frequency. If this is going to be ovenized, I'd love to close the box and do all the tuning electronically.

This design worked pretty well. Fixed capacitors (optionally populated) set the frequency so the crystal oscillates in the QRSS band. The coarse adjustment moves the signal around the QRSS band (100Hz). The fine adjustment is pulled high through a divider. Adjust R4 to control how wide the FSK can be.

Real varicap diodes definitely work better than reverse-biased LEDs. A reverse-biasd blue LED measured 60 Hz swing (with a lot of additional fixed capacitance in place to get near center frequency). Replacing this with a BB132 (I had to remove a 5pF cap to compensate) I got a swing of 159 Hz. That's more than double, and that's just one varicap. You can stack them in parallel. Real varicaps dont mind low voltage* I found out, so don't worry about avoiding that super low region like with the LED.

Eventually I stopped trying to separate fine and coarse frequency adjustments and just went with a single voltage for tuning. I can control voltage coarsely and finely using potentiometers, so I was happy to simplify the oscillator design by moving that complexity to the keyer/control system. This is the QRSS oscillator I came up with. It's just a Colpitts oscillator with an output buffer. Note that the buffer will self-oscillate if the oscillator stops, so on-off-keying should be achieved downstream of this circuit. These decisions are made with maximal frequency stability in mind.

I'm glad I used a SMA connector, but in hindsight I should have laid it out sideways because I couldn't close the lid.

Build Notes

  • I used BB132 for the varicap
  • I used 33P for C6
  • For C9 I used 33p (should be NP0)
  • For C11 I used 100p
  • For C10 and C12 I used NP0 120p caps

Ovenization

Ovenization is achieved using two power-resistors fixed to the metal enclosure. A thermistor fastened to the chassis provides temperature feedback. This chassis heater seems to be a winning design, as it is slow but stable. Having loose coupling between the PCB and the chassis is intentional. The whole thing is enclosed in a modestly insulative plastic enclosure. I'm very happy with this design!

Ovenization

QRSS Oscillators Need Ovens

My oscillator looks stable on time scales of minutes, but on time scales of hours it is obvious that it wobbles as my central air conditioning turns on and off. I could go nuts with Styrofoam, but a crystal oven (or chassis heater) is warranted.

Why I want a chassis heater (not a oven heater)

Some DIY QRSS ovens use resistors as the heater element and package the heater and temperature sensor against the crystal. While temperature stability of the crystal is good, I prefer to thermo-stabilize all frequency-determining components (capacitors and varactors) of the oscillator circuit. For this reason, I prefer a chassis heater.

Eventually I want a SMT PCB heater

When I get an oscillator I like using SMT parts, I'll try adding the temperature sensor and heater directly on the board. This is ideal for small PCBs. It would be cool if the board could thermo-regulate itself, then the oscillator would just need insulation, and the heater would require very low power.

Chassis Heater Design

This section documents my thoughts and experiments related to development of a chassis heater. Since I'll build the chassis heater inside an insulated container, I'll refer to it as a chassis oven.

Design

After running the numbers for a bunch of different power/resistor combinations, I decided to work with 50-Ohm power resistors. I'd love to have more 50-Ohm power resistors on hand to use for making dummy loads.

I settled on this part: 50 Ohm (+/- 1%) 12.5 watt resistor ($2.64)

Running 12V through a single resistor would burn 2.88W of power as heat. If we wanted more heat we could add additional resistors in parallel, but this should be okay.

Circuit

After the above considerations, this is what I came up with. I made it on a breadboard and it works well.

  • You can add multiple R4s in parallel for faster heating
  • I ended-up replacing the TIP122 (Darlington transistor) with an IRF510 (N-channel MOSEFET) for better linear operation (since the TIP122 has such high gain)
    • This works great and the IRF510 rests partially on once stabalized
    • The IRF510 gets hot! Maybe you can mount that to the chassis too?
  • You can supply it with dirty power and it doesn't seem to affect oscillator performance
  • I use a multi-turn potentiometer for RV1
  • R6 sets hysteresis
    • Large values promote squishy temperature control.
    • Small values will faster responses but may oscillate
    • Remove R6 for bang-bang operation
  • I suspect this design could be used as a crystal oven
    • Replace Q1 with a 2N2222
    • Replace R4 with a 680 Ohm 1/4-watt resistor (~17 mA, ~200 mW)

Photos

More Notes

I experimented more on 2019-08-31:

  • Switched to an LM335 (not a thermistor) super-glued to the chassis
  • I target 3.10 mV (310 Kelvin = 37C or 100F)
  • Can use LM7805 for op-amp and divider since we are using low voltages
  • A tip122 is cheaper than the IRF510 and works fine

Calculating power dissipation of a transistor heating a resistor

Consider a NPN with a collector tied to VCC (Vcc) and emitter dumping into a resistor (R) to ground. Let's say I'm driving a 50 Ohm resistor as a heater. How hot will the transistor get? Is my transistor beefy enough? To answer this I need to determine the peak power dissipation through a transistor into a resistive load.

We should assume the current flowing through the resistor (I) will be the same as the current flowing through the transistor.

// Ve is a function of R and I
Ve = R * I

// transistor voltage drop
Vce = Vcc - Ve

// power through the transistor
Pnpn = I * Vce

// substitute 
Pnpn = I * Vce
Pnpn = I * (Vcc - Ve)
Pnpn = I * (Vcc - (R * I))
Pnpn = (I * Vcc) - (I^2 * R)

// at peak power the first derivative of current is zero
Pnpn = (I * Vcc) - (I^2 * R)
d(Pnpn) = Vcc - (2 * I * R) = 0

// find the current through the resistor (= transistor) at peak power
Vcc - (2 * I * R) = 0
2 * I * R = VCC
Ipeak = VCC / (2 * R)

// substitute back into original equation
Pnpn = (Ipeak * Vcc) - (Ipeak^2 * R)
Pnpn = ((Vcc / (2 * R)) * Vcc) - ((Vcc / (2 * R))^2 * R)
Pnpn = (Vcc^2) / (2 * R) - (Vcc^2 * R) / (4 * R^2)
4 * R * Pnpn = 2 * Vcc^2 - Vcc^2
Pnpn = Vcc ^ 2 / (4 * R)
Pnpn = Vcc * Vcc / (4 * R)
Pnpn = Vcc * (I * R) / (4 * R)
Pnpn = Vcc * I / 4

// since the power through the resistor is
Pr = Vcc * I

// peak power through the NPN is 1/4 that through the resistor
Pnpn = Vcc * I / 4
  • If I drop 12V through a 330 Ohm resistor it passes 36.4 mA of current and dissipates 436.4 mW of power. This means the transistor will dissipate 109 mW of power at its max.
Markdown source code last modified on January 18th, 2021
---
title: SMT QRSS Design
date: 2019-07-26 21:00:00
tags: qrss, circuit
---

# SMT QRSS Design

This page documents development of a voltage-controlled oscillator suitable for QRSS. Source code and PCB files are on https://github.com/swharden/QRSS-hardware

**For QRSS it's convenient to have 2 frequency shift adjustments: a coarse one to set frequency (~200 Hz), and a fine one for FSK (5 Hz).** I began with the design below allowing manual adjustment of coarse tuning, then an external input for fine tuning. Eventually I switched to a design where a single voltage controls tuning (coarse and fine). Many QRSS TX designs use a variable capacitor to set the coarse adjustment, but I don't like that design because it means you have to open your enclosure every time you want to shift frequency. If this is going to be ovenized, I'd love to close the box and do all the tuning electronically.

<div class="text-center">

[![](varactor-tuning-aj4vd-v1_thumb.jpg)](varactor-tuning-aj4vd-v1.png)

</div>

**This design worked pretty well.** Fixed capacitors (optionally populated) set the frequency so the crystal oscillates in the QRSS band. The coarse adjustment moves the signal around the QRSS band (100Hz). The fine adjustment is pulled high through a divider. Adjust R4 to control how wide the FSK can be.

**Real varicap diodes definitely work better than reverse-biased LEDs.** A reverse-biasd blue LED measured 60 Hz swing (with a lot of additional fixed capacitance in place to get near center frequency). Replacing this with a BB132 (I had to remove a 5pF cap to compensate) I got a swing of 159 Hz. That's more than double, and that's just one varicap. You can stack them in parallel. Real varicaps dont mind low voltage* I found out, so don't worry about avoiding that super low region like with the LED.

**Eventually I stopped trying to separate fine and coarse frequency adjustments** and just went with a single voltage for tuning. I can control voltage coarsely and finely using potentiometers, so I was happy to simplify the oscillator design by moving that complexity to the keyer/control system. This is the QRSS oscillator I came up with. It's just a [Colpitts oscillator](https://en.wikipedia.org/wiki/Colpitts_oscillator) with an output buffer. Note that the buffer will self-oscillate if the oscillator stops, so on-off-keying should be achieved downstream of this circuit. These decisions are made with maximal frequency stability in mind.

<div class="text-center">

[![](qrss-oscillator_thumb.jpg)](qrss-oscillator.png)

</div>

<div class="text-center img-border">

[![](pcb-design_thumb.jpg)](pcb-design.png)

</div>

<div class="text-center">

[![](pcb-3d_thumb.jpg)](pcb-3d.png)

</div>

I'm glad I used a SMA connector, but in hindsight I should have laid it out sideways because I couldn't close the lid.

## Build Notes
* I used BB132 for the varicap
* I used 33P for C6
* For C9 I used 33p (should be NP0)
* For C11 I used 100p
* For C10 and C12 I used NP0 120p caps

<div class="text-center img-border">

[![](2019-07-26-a_thumb.jpg)](2019-07-26-a.jpg)
[![](2019-07-26-b_thumb.jpg)](2019-07-26-b.jpg)
[![](2019-07-26-c_thumb.jpg)](2019-07-26-c.jpg)

</div>

## Ovenization

**Ovenization is achieved using two power-resistors fixed to the metal enclosure.** A thermistor fastened to the chassis provides temperature feedback. This _chassis heater_ seems to be a winning design, as it is slow but stable. Having loose coupling between the PCB and the chassis is intentional. The whole thing is enclosed in a modestly insulative plastic enclosure. I'm very happy with this design!

## Ovenization

### QRSS Oscillators Need Ovens
My oscillator looks stable on time scales of minutes, but on time scales of hours it is obvious that it wobbles as my central air conditioning turns on and off. I could go nuts with Styrofoam, but a crystal oven (or chassis heater) is warranted.

### Why I want a chassis heater (not a oven heater)
Some DIY QRSS ovens use resistors as the heater element and package the heater and temperature sensor against the crystal. While temperature stability of the crystal is good, I prefer to thermo-stabilize all frequency-determining components (capacitors and varactors) of the oscillator circuit. For this reason, I prefer a chassis heater.

### Eventually I want a SMT PCB heater
When I get an oscillator I like using SMT parts, I'll try adding the temperature sensor and heater directly on the board. This is ideal for small PCBs. It would be cool if the board could thermo-regulate itself, then the oscillator would just need insulation, and the heater would require very low power.

### Chassis Heater Design

This section documents my thoughts and experiments related to development of a chassis heater. Since I'll build the chassis heater inside an insulated container, I'll refer to it as a chassis oven.

### Design

After running the numbers for a bunch of different power/resistor combinations, I decided to work with 50-Ohm power resistors. I'd love to have more 50-Ohm power resistors on hand to use for making dummy loads.

I settled on this part: [50 Ohm (+/- 1%) 12.5 watt resistor](https://www.mouser.com/ProductDetail/Vishay-Dale/RH01050R00FE02?qs=sGAEpiMZZMtbXrIkmrvidDNaDpN5VXc5nhpgDg1t8QQ%3D) ($2.64)

Running 12V through a single resistor would burn 2.88W of power as heat. If we wanted more heat we could add additional resistors in parallel, but this should be okay.

### Circuit
After the above considerations, this is what I came up with. I made it on a breadboard and it works well.

<div class="text-center">

[![](oven-aj4vd-resistor-heater_thumb.jpg)](oven-aj4vd-resistor-heater.png)

</div>

* You can add multiple R4s in parallel for faster heating
* I ended-up replacing the TIP122 (Darlington transistor) with an IRF510 (N-channel MOSEFET) for better linear operation (since the TIP122 has such high gain)
  * This works great and the IRF510 rests partially on once stabalized
  * The IRF510 gets hot! Maybe you can mount that to the chassis too?
* You can supply it with dirty power and it doesn't seem to affect oscillator performance
* I use a multi-turn potentiometer for RV1
* R6 sets hysteresis
  * Large values promote squishy temperature control. 
  * Small values will faster responses but may oscillate
  * Remove R6 for bang-bang operation
* I suspect this design could be used as a _crystal_ oven
  * Replace Q1 with a 2N2222
  * Replace R4 with a 680 Ohm 1/4-watt resistor (~17 mA, ~200 mW)
  
### Photos

<div class="text-center img-border">

[![](2019-07-26-d_thumb.jpg)](2019-07-26-d.jpg)
[![](2019-07-26-e_thumb.jpg)](2019-07-26-e.jpg)

</div>

### More Notes
I experimented more on 2019-08-31:

* Switched to an LM335 (not a thermistor) super-glued to the chassis
* I target 3.10 mV (310 Kelvin = 37C or 100F)
* Can use LM7805 for op-amp and divider since we are using low voltages
* A tip122 is cheaper than the IRF510 and works fine


### Calculating power dissipation of a transistor heating a resistor

Consider a NPN with a collector tied to VCC (`Vcc`) and emitter dumping into a resistor (`R`) to ground. Let's say I'm driving a 50 Ohm resistor as a heater. How hot will the transistor get? Is my transistor beefy enough? To answer this I need to ***determine the peak power dissipation through a transistor into a resistive load.***

We should assume the current flowing through the resistor (`I`) will be the same as the current flowing through the transistor.

```c
// Ve is a function of R and I
Ve = R * I

// transistor voltage drop
Vce = Vcc - Ve

// power through the transistor
Pnpn = I * Vce

// substitute 
Pnpn = I * Vce
Pnpn = I * (Vcc - Ve)
Pnpn = I * (Vcc - (R * I))
Pnpn = (I * Vcc) - (I^2 * R)

// at peak power the first derivative of current is zero
Pnpn = (I * Vcc) - (I^2 * R)
d(Pnpn) = Vcc - (2 * I * R) = 0

// find the current through the resistor (= transistor) at peak power
Vcc - (2 * I * R) = 0
2 * I * R = VCC
Ipeak = VCC / (2 * R)

// substitute back into original equation
Pnpn = (Ipeak * Vcc) - (Ipeak^2 * R)
Pnpn = ((Vcc / (2 * R)) * Vcc) - ((Vcc / (2 * R))^2 * R)
Pnpn = (Vcc^2) / (2 * R) - (Vcc^2 * R) / (4 * R^2)
4 * R * Pnpn = 2 * Vcc^2 - Vcc^2
Pnpn = Vcc ^ 2 / (4 * R)
Pnpn = Vcc * Vcc / (4 * R)
Pnpn = Vcc * (I * R) / (4 * R)
Pnpn = Vcc * I / 4

// since the power through the resistor is
Pr = Vcc * I

// peak power through the NPN is 1/4 that through the resistor
Pnpn = Vcc * I / 4
```

* If I drop 12V through a 330 Ohm resistor it passes 36.4 mA of current and dissipates 436.4 mW of power. This means the transistor will dissipate 109 mW of power at its max. 
  * A 2n7000 can handle this.
  * A [0.5W 0805 300 Ohm resistor](https://www.mouser.com/ProductDetail/Panasonic/ERJ-P06J331V?qs=sGAEpiMZZMu61qfTUdNhG4N%252BbAgO2H57MCL338q%2F2SU%3D) can handle this (Mouser # 667-ERJ-P06J331V)
July 21st, 2019

New QRSS Keyer

I'd like to use an interesting pattern that takes advantage of both FSK and OOK. I want it to be 5 Hz or less in bandwidth, and I want it to be unique and recognizable in cases where only a few seconds are spotted, but I don't want it to be so odd that it's annoying. I came up with something like:

Here's what it looks like on the air:

Microcontroller

ATTiny2313 programmed with C (source code)

GPS serial data parsing

To ensure the message transmits exactly at the 0:00 mark of every 10 minutes, the microcontroller is occasionally put into a "wait" mode where it continuously watches the GPS output (parsing the serial data that bursts out every second) and waits for the minutes digit to become zero before beginning a transmission.

Technical details: The output is 9600 baud serial data in NMEA format. A string buffer is filled as incoming characters are received. If the message starts with $GPRMC we know the 11th character is the ones digit of the minutes number in the time code. Waiting for the next ten minute rollover to occur is as easy as waiting until that character becomes zero.

$GPRMC,184130.00,...
^    ^     ^

The start of a time message looks like this. To identify $GPRMC we just need to match the $ and the C (indicated by the first two arrows above). We then know if we keep reading, we will arrive at the ones digit of the minutes number (the third arrow).

I have some notes on the Neo-6M here

FSK Circuit

I found this design very convenient. A potentiometer (RV1) sets center frequency to let me adjust where in the QRSS band I want to transmit.

The FSK input (which could be digital or analog) is 0-5V, expected to originate from a microcontroller pin. The keyer is programmed to transmits over the full 0-5V range.

The second potentiometer (RV2) sets the width of the FSK input. I adjust this to achieve a bandwidth of about 5 Hz.

The output is buffered, mixed, and sent to the oscillator module with coax.

Markdown source code last modified on January 18th, 2021
---
title: New QRSS Keyer
date: 2019-07-21 21:00:00
tags: qrss, circuit
---

# New QRSS Keyer

**I'd like to use an interesting pattern** that takes advantage of both FSK and OOK. I want it to be 5 Hz or less in bandwidth, and I want it to be unique and recognizable in cases where only a few seconds are spotted, but I don't want it to be so odd that it's annoying. I came up with something like:

<div class="text-center">

[![](pattern_thumb.jpg)](pattern.jpg)

</div>

Here's what it looks like on the air:

<div class="text-center img-border">

[![](WD4ELG-30.1907210830.d1c3ee1f06_thumb.jpg)](WD4ELG-30.1907210830.d1c3ee1f06.jpg)

</div>

### Microcontroller
ATTiny2313 programmed with C ([source code](https://github.com/swharden/QRSS-hardware/tree/master/builds/keyer/main.c))

### GPS serial data parsing
To ensure the message transmits exactly at the 0:00 mark of every 10 minutes, the microcontroller is occasionally put into a "wait" mode where it continuously watches the GPS output (parsing the serial data that bursts out every second) and waits for the minutes digit to become zero before beginning a transmission.

Technical details: The output is 9600 baud serial data in [NMEA format](https://www.gpsinformation.org/dale/nmea.htm). A string buffer is filled as incoming characters are received. If the message starts with `$GPRMC` we know the 11th character is the ones digit of the minutes number in the time code. Waiting for the next ten minute rollover to occur is as easy as waiting until that character becomes zero.

```
$GPRMC,184130.00,...
^    ^     ^
```

The start of a time message looks like this. To identify `$GPRMC` we just need to match the `$` and the `C` (indicated by the first two arrows above). We then know if we keep reading, we will arrive at the ones digit of the minutes number (the third arrow).

I have some notes on the [Neo-6M here](https://github.com/swharden/AVR-projects/tree/master/uBlox%20Neo-6M)

### FSK Circuit

I found this design very convenient. A potentiometer (RV1) sets center frequency to let me adjust where in the QRSS band I want to transmit. 

The FSK input (which could be digital or analog) is 0-5V, expected to originate from a microcontroller pin. The keyer is programmed to transmits over the full 0-5V range.

The second potentiometer (RV2) sets the width of the FSK input. I adjust this to achieve a bandwidth of about 5 Hz.

The output is buffered, mixed, and sent to the oscillator module with coax.

<div class="text-center">

[![](fsk-circuit_thumb.jpg)](fsk-circuit.jpg)

</div>

<div class="text-center img-border">

[![](2019-07-19-keyer_thumb.jpg)](2019-07-19-keyer.jpg)
[![](2019-07-19-modules_thumb.jpg)](2019-07-19-modules.jpg)
[![](2019-07-31_thumb.jpg)](2019-07-31.jpg)

</div>
December 19th, 2017

IoT Festivus Pole

The Internet of Things now includes Festivus poles! **Festivus is a holiday celebrated on December 23rd, and its customary practices include a Festivus pole, Festivus dinner, airing of grievances, feats of strength, and Festivus miracles. The internet contains a few nods to the holiday, including what happens when you Google for the word Festivus (a Festivus pole is displayed at the bottom of the page). In 2015 I had the honor of gifting the world with the first Festivus pole video game, and today I am happy to unveil the world's first internet-enabled Festivus pole. Every time somebody tweets #Festivus or #FestivusMiracle, the light at the top of the pole illuminates! All in the room then excitedly exclaim, "it's a Festivus miracle!"

The IoT Festivus Pole is powered by a Raspberry Pi (a Pi 2 Model B, although any Pi would work) running a Python script which occasionally checks for tweets using the twitter API (via twython, a pure-python twitter API wrapper) and controls the GPIO pin 12 with RPi.GPIO (extra docs). After writing the Python script (which should work identically in Python 2 or Python 3), I got it to run automatically every time the system boots by adding a line to /etc/rc.local (surrounding it with parentheses and terminating the line with & to allow it to run without blocking the startup sequence). The LED was added to the end of a long wire (with a series 220-ohm resistor) and connected across the Raspberry Pi header pins 12 (PWM) and 14 (GND). I set PWM frequency to 100 Hz, but this is easily configurable in software.

To build the Festivus pole I got a piece of wood and a steel conduit pipe from Lowe's (total <$5). Festivus purists will argue that Festivus poles should be made from aluminum (with its very high strength to weight ratio). I live in an apartment and don't have a garage, so my tool selection is limited. I cut the wood a few times with a jigsaw and glued it together to make an impressive stand similar to those of traditional Festivus poles. I have a few hole saw drill bits, but none of them perfectly matched the size of the pipe. I traced the outline of the pipe on the wood and cut-out a circular piece with a Dremel drill press in combination with a side-cutting bit. The hole was slightly larger than required for the pipe, so I used a few layers of electrical tape on the bottom of the pipe to "seal" the base of the pipe into the hole, then poured acrylic epoxy into the empty space. Clamping it against a desk allowed the epoxy to set such that the pole was rigidly upright, and the result was a fantastic-looking Festivus pole! It's a bit smaller in size than the famous one featured in Seinfeld, but I think it is appropriately sized for my apartment.

Adding the computer was easy! Internet capability was provided via a USB WiFi card. Code is at the bottom of this page. The LED was connected to Raspberry Pi header pins 12 and 14. The wiring was snaked through the conduit.

The code will work on Python 2 and Python 3. Pip can be used to install RPi.GPIO and twython: pip install python-dev python-rpi.gpio twython

import RPi.GPIO as GPIO
import time
from twython import Twython

APP_KEY = 'zSNYBNWHmXhU3CX765HnoQEbm'
APP_SECRET = 'getYourOwnApiKeyFromTwitterWebsite'
twitter = Twython(APP_KEY, APP_SECRET)
auth = twitter.get_authentication_tokens()

GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
p = GPIO.PWM(12, 100)
p.start(0)

if __name__=="__main__":
    tweetLast=0
    checkLast=0
    duty=100

    while True:
        if (checkLast+5)<time.time():
            checkLast=time.time()
            print("checking twitter...")
            tweetLatest=twitter.search(q='festivus')["statuses"][0]["created_at"]
            if tweetLatest!=tweetLast:
                print("IT'S A FESTIVUS MIRACLE!")
                tweetLast=tweetLatest
                duty=100
            else:
                print('nothing')

        if duty>=0:
            p.ChangeDutyCycle(duty)

        time.sleep(.3)
        duty-=1

This Festivus pole has been up and running for the last few days and I'm excited to see how much joy it has brought into my household! Admittedly the Raspberry Pi seems to be overkill, but at the time I was considering having it also output audio every time a tweet is made but I never decided on the clip to use so I omitted the feature. An ESP8266 WiFi module interfaced with a microntroller can do the same job with more elegance and lower cost, so I may consider improving it next year. Until then, Happy Festivus!

Markdown source code last modified on January 18th, 2021
---
title: IoT Festivus Pole
date: 2017-12-19 22:11:17
tags: circuit, microcontroller
---

# IoT Festivus Pole

The <em>Internet of Things</em> now includes Festivus poles! **Festivus is a holiday celebrated on December 23rd, and its [customary practices](https://en.wikipedia.org/wiki/Festivus) include a Festivus pole, Festivus dinner, airing of grievances, feats of strength, and Festivus miracles. The internet contains a few nods to the holiday, including [what happens when you Google for the word Festivus](https://www.google.com/search?q=festivus) (a Festivus pole is displayed at the bottom of the page). In 2015 I had the honor of gifting the world with the first [Festivus pole video game](https://www.swharden.com/wp/2015-12-23-festivus-pole-video-game/), and today I am happy to unveil the world's first internet-enabled Festivus pole. Every time somebody tweets #Festivus or #FestivusMiracle, the light at the top of the pole illuminates! All in the room then excitedly exclaim, "it's a Festivus miracle!"

<div class="text-center img-border img-small">

[![](723_thumb.jpg)](723.jpg)

</div>

__The IoT Festivus Pole is powered by a Raspberry Pi__ (a Pi 2 Model B, although any Pi would work) running a Python script which occasionally checks for tweets using the [twitter API](https://developer.twitter.com/en/docs) (via [twython](https://github.com/ryanmcgrath/twython), a pure-python twitter API wrapper) and controls the GPIO pin 12 with [RPi.GPIO](https://pypi.python.org/pypi/RPi.GPIO) ([extra docs](https://learn.sparkfun.com/tutorials/raspberry-gpio/python-rpigpio-api)). After writing the Python script (which should work identically in Python 2 or Python 3), I got it to run automatically every time the system boots by adding a line to /etc/rc.local (surrounding it with parentheses and terminating the line with & to allow it to run without blocking the startup sequence). The LED was added to the end of a long wire (with a series 220-ohm resistor) and connected across the [Raspberry Pi header](https://pinout.xyz) pins 12 (PWM) and 14 (GND). I set PWM frequency to 100 Hz, but this is easily configurable in software.

<div class="text-center img-small">

![](festivus_miracle.gif)
![](729.jpeg)

</div>

__To build the Festivus pole__ I got a piece of wood and a steel conduit pipe from Lowe's (total <$5). Festivus purists will argue that Festivus poles should be made from aluminum (with its very high strength to weight ratio). I live in an apartment and don't have a garage, so my tool selection is limited. I cut the wood a few times with a jigsaw and glued it together to make an impressive stand similar to those of [traditional Festivus poles](https://en.wikipedia.org/wiki/Festivus). I have a few hole saw drill bits, but none of them perfectly matched the size of the pipe. I traced the outline of the pipe on the wood and cut-out a circular piece with a Dremel drill press in combination with a side-cutting bit. The hole was slightly larger than required for the pipe, so I used a few layers of electrical tape on the bottom of the pipe to "seal" the base of the pipe into the hole, then poured acrylic epoxy into the empty space. Clamping it against a desk allowed the epoxy to set such that the pole was rigidly upright, and the result was a fantastic-looking Festivus pole! It's a bit smaller in size than the famous one featured in Seinfeld, but I think it is appropriately sized for my apartment.

<div class="text-center img-border">

[![](725_thumb.jpg)](725.jpg)
[![](726_thumb.jpg)](726.jpg)

</div>

__Adding the computer was easy!__ Internet capability was provided via a USB WiFi card. Code is at the bottom of this page. The LED was connected to [Raspberry Pi header](https://pinout.xyz) pins 12 and 14. The wiring was snaked through the conduit.

<div class="text-center img-border">

[![](728_thumb.jpg)](728.jpg)
[![](719_thumb.jpg)](719.jpg)
[![](726_thumb.jpg)](726.jpg)

</div>

__The code will work on Python 2 and Python 3.__
Pip can be used to install RPi.GPIO and twython: `` pip install python-dev python-rpi.gpio twython ``

```python
import RPi.GPIO as GPIO
import time
from twython import Twython

APP_KEY = 'zSNYBNWHmXhU3CX765HnoQEbm'
APP_SECRET = 'getYourOwnApiKeyFromTwitterWebsite'
twitter = Twython(APP_KEY, APP_SECRET)
auth = twitter.get_authentication_tokens()

GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
p = GPIO.PWM(12, 100)
p.start(0)

if __name__=="__main__":
    tweetLast=0
    checkLast=0
    duty=100

    while True:
        if (checkLast+5)<time.time():
            checkLast=time.time()
            print("checking twitter...")
            tweetLatest=twitter.search(q='festivus')["statuses"][0]["created_at"]
            if tweetLatest!=tweetLast:
                print("IT'S A FESTIVUS MIRACLE!")
                tweetLast=tweetLatest
                duty=100
            else:
                print('nothing')

        if duty>=0:
            p.ChangeDutyCycle(duty)

        time.sleep(.3)
        duty-=1

```

__This Festivus pole has been up and running for the last few days__ and I'm excited to see how much joy it has brought into my household! Admittedly the Raspberry Pi seems to be overkill, but at the time I was considering having it also output audio every time a tweet is made but I never decided on the clip to use so I omitted the feature. An [ESP8266 WiFi module](https://www.sparkfun.com/products/13678) interfaced with a microntroller can do the same job with more elegance and lower cost, so I may consider improving it next year. Until then, Happy Festivus!

![](https://www.youtube.com/embed/HX55AzGku5Y)
September 9th, 2017

Hurricane Hack - DIY LED Candle

Florida is about to get hit by a massive hurricane, and my home town is in the direct path! I am well prepared with lots of food, water, and communications equipment. While the storm itself is dangerous, part of getting ready for it means preparing for the potential to be out of power for weeks. A staple go-to for light when the power is out is candles. Instinctively people tend to reach for candles and kerosene lamps (in Florida they're called hurricane lanterns). However, these sources of light can be extremely dangerous!

With the storm one day away, my roommates and I began pooling our emergency supplies in the living room and I grew uneasy about how many matches and candles were accumulating. With severe weather, wind, falling trees, tornadoes, and projectiles blowing around there is an appreciable risk of knocking-over a flame and starting a fire. This risk multiplies when you consider that people often fall asleep with flames running, perhaps even in another room!

I thought how great it would be to have a bunch of LED candles, but there is absolutely no way I can buy one now. Although I could just leave a flashlight on shining at the ceiling, it would produce too much light and the batteries would die before long. With the storm one day away, every store in this town is out of water, most groceries are out of canned foods, and most of the gas stations are out of gas and have locked up. Flashlights, radios, and LED candles are surely gone from all the stores as well. I decided to hack-together several LED candles to use around the house over the next several days, and the result came out great!

I taped together 2 AA batteries and soldered a resistor and a white LED in series with jumper to serve as an on/off switch. It's not yellow and doesn't flicker like fancy LED candles, but who cares? This is perfectly functional, and for lighting a room I would say it's a superior alternative to fire-based candles when the power is out for long periods of time. The batteries will last much longer than they would if we just turned on a flashlight and aimed it at the ceiling too. My white LEDs (generic low current clear 5mm LEDs) have about a 20º light emission angle. To improve its function as a room light I taped a sheet of paper around a glass cup and set it over the top to act as a light diffuser. This couldn't be simpler!

If the light diffuser is removed this thing works pretty well as a flashlight. I practiced walking around a dark closet and pointing it around and was impressed at how much it is able to illuminate a relatively narrow area. This is a good time to add a basic warning reminding people that soldering directly to batteries is potentially dangerous for the person (and may be destructive to the battery) and it should be avoided. Battery holders are superior, and batteries with solder tabs already on them are a superior alternative to generic batteries.

3xAAA Version

I found a box of battery holders and decided to make a second version of this device. I felt better about this one since I didn't need to solder directly to any batteries. A dot of super glue is all it took to secure the LED to the enclosure, and it even stands upright!

How long will it last?

I'll use some scratch match to predict how long this device will stay lit. I'll run the math first for the 2xAA version. Placing an ammeter in the circuit while the LED was on revealed it consumes 1.8 mA of current. PowerStream has a great website showing battery discharge curves for various consumer grade batteries. Eyeballing the graph it looks like most batteries doesn't start to drop voltage significantly until near the end of their life. To make calculations simple, let's just use the mAH (milliamp hour) rating that the manufacturer provides... except I can't find where Amazon specs their "Amazon basics" battery. A consumer review indicates 997 mAh at 100 mA discharge rate. I'm sure our duration would be far beyond this since we are drawing less than 1/50 of that much current, but let's just say 1000 mAh to be conservative. We can double that since we are using two AA batteries in this circuit, so 2000 mAh / 1.8 mA = 46 days. Interestingly, the 3xAAA battery presents a larger voltage to the led/resistor so it draws more current (6.3 mA) and 3000 mAh / 6.3 mA it is expected to last only about 19 days. I could increase the value of the resistor to compensate, but it's already built and it's fine enough for my needs.

When the storm has passed and things return to normal, I'll consider making a few different designs and testing how long they actually last. Many battery tests use relatively high current challenges so their discharge finishes in days rather than weeks or months... but with a sensitive voltmeter circuit attached to a logging raspberry pi or something, I'd be interested to see the battery discharge curve of a DIY LED candle on a weeks/months timescale! For now I feel prepared for the upcoming storm, and with several DIY LED candles to light my home instead of actual candles, I'll feel safer as well.

UPDATE

Two months later (Nov 11, 2017) this thing is still going strong! I've left it on continuously since it was built, and I'm truly surprised by how long this has lasted... I'm going it continue leaving it running to see how much longer it goes. For future builds I will add more LEDs and not be so concerned about longevity. It may be work noting that a build like this would have been great for residents of Puerto Rico, because much of that island is still without power. This is a photograph in a dimly-lit room after more than 2 months continuous use:

Markdown source code last modified on January 18th, 2021
---
title: Hurricane Hack - DIY LED Candle
date: 2017-09-09 11:27:43
tags: circuit
---

# Hurricane Hack - DIY LED Candle

**Florida is about to get hit by a massive hurricane, and my home town is in the direct path!** I am well prepared with lots of food, water, and communications equipment. While the storm itself is dangerous, part of getting ready for it means preparing for the potential to be out of power for weeks. A staple go-to for light when the power is out is candles. Instinctively people tend to reach for candles and kerosene lamps (in Florida they're called hurricane lanterns). However, these sources of light can be extremely dangerous!

<div class="text-center img-border img-small">

[![](livehere_thumb.jpg)](livehere.jpg)

</div>

**With the storm one day away, my roommates and I began pooling our emergency supplies in the living room and I grew uneasy about how many matches and candles were accumulating.** With severe weather, wind, falling trees, tornadoes, and projectiles blowing around there is an appreciable risk of knocking-over a flame and starting a fire. This risk multiplies when you consider that people often fall asleep with flames running, perhaps even in another room! 

**I thought how great it would be to have a bunch of [LED candles](https://en.wikipedia.org/wiki/Flameless_candles), but there is absolutely no way I can buy one now.** Although I could just leave a flashlight on shining at the ceiling, it would produce too much light and the batteries would die before long. With the storm one day away, every store in this town is out of water, most groceries are out of canned foods, and most of the gas stations are out of gas and have locked up. Flashlights, radios, and LED candles are surely gone from all the stores as well. I decided to hack-together several LED candles to use around the house over the next several days, and the result came out great!

<div class="text-center">

[![](hurricaine-diy-led-candle_thumb.jpg)](hurricaine-diy-led-candle.jpg)

</div>

**I taped together 2 AA batteries and soldered a resistor and a white LED in series with jumper to serve as an on/off switch.** It's not yellow and doesn't flicker like fancy LED candles, but who cares? This is perfectly functional, and for lighting a room I would say it's a superior alternative to fire-based candles when the power is out for long periods of time. The batteries will last _much_ longer than they would if we just turned on a flashlight and aimed it at the ceiling too. My white LEDs (generic low current clear 5mm LEDs) have about a 20º light emission angle. To improve its function as a room light I taped a sheet of paper around a glass cup and set it over the top to act as a light diffuser. This couldn't be simpler!

<div class="text-center img-border img-medium">

[![](063_thumb.jpg)](063.jpg)

</div>

**If the light diffuser is removed this thing works pretty well as a flashlight.** I practiced walking around a dark closet and pointing it around and was impressed at how much it is able to illuminate a relatively narrow area. _This is a good time to add a basic warning reminding people that soldering directly to batteries is potentially dangerous for the person (and may be destructive to the battery) and it should be avoided. Battery holders are superior, and batteries with solder tabs already on them are a superior alternative to generic batteries._

# 3xAAA Version

**I found a box of battery holders and decided to make a second version of this device.** I felt better about this one since I didn't need to solder directly to any batteries. A dot of super glue is all it took to secure the LED to the enclosure, and it even stands upright!

<div class="text-center img-border img-small">

[![](081_thumb.jpg)](081.jpg)
[![](078_thumb.jpg)](078.jpg)

</div>

# How long will it last?

I'll use some scratch match to predict how long this device will stay lit. I'll run the math first for the 2xAA version. Placing an ammeter in the circuit while the LED was on revealed it consumes **1.8 mA** of current.  [PowerStream has a great website showing battery discharge curves](https://www.powerstream.com/AA-tests.htm) for various consumer grade batteries. Eyeballing the graph it looks like most batteries doesn't start to drop voltage significantly until near the end of their life. To make calculations simple, let's just use the mAH (milliamp hour) rating that the manufacturer provides... except I can't find where Amazon specs their "Amazon basics" battery. A consumer review indicates 997 mAh at 100 mA discharge rate. I'm sure our duration would be far beyond this since we are drawing less than 1/50 of that much current, but let's just say 1000 mAh to be conservative. We can double that since we are using two AA batteries in this circuit, so 2000 mAh / 1.8 mA = **46 days**. Interestingly, the 3xAAA battery presents a larger voltage to the led/resistor so it draws more current (6.3 mA) and 3000 mAh / 6.3 mA it is expected to last only about 19 days. I could increase the value of the resistor to compensate, but it's already built and it's fine enough for my needs.

<div class="text-center img-border img-small">

[![](088_thumb.jpg)](088.jpg)
[![](091_thumb.jpg)](091.jpg)

</div>

**When the storm has passed and things return to normal, I'll consider making a few different designs** and testing how long they actually last. Many battery tests use relatively high current challenges so their discharge finishes in days rather than weeks or months... but with a sensitive voltmeter circuit attached to a logging raspberry pi or something, I'd be interested to see the battery discharge curve of a DIY LED candle on a weeks/months timescale! For now I feel prepared for the upcoming storm, and with several DIY LED candles to light my home instead of actual candles, I'll feel safer as well.

## UPDATE

**Two months later (Nov 11, 2017) this thing is still going strong!** I've left it on continuously since it was built, and I'm truly surprised by how long this has lasted... I'm going it continue leaving it running to see how much longer it goes. For future builds I will add more LEDs and not be so concerned about longevity. It may be work noting that a build like this would have been great for residents of Puerto Rico, because much of that island is _still_ without power. This is a photograph in a dimly-lit room after more than 2 months continuous use:

<div class="text-center img-border">

[![](IMG_0303_thumb.jpg)](IMG_0303.jpg)

</div>
September 2nd, 2017

PS4 Controller Hack - Adding Auto-Run

After a long day it can be really nice to have a relaxing hobby to clear your head, and few activities shut down your brain as effectively as video games. However, a newly released video game is physically hurting me as my impulse to move quickly causes me to perpetually click the run button. After a few days of game-play and a really sore left thumb, I decided to do something about it: hack-in a microchip to automatically click the button for me.

Modifying game controllers to do things like automatically rapid fire is nothing new. I once modified a USB computer mouse to add an extra "rapid fire" button (link). Hackaday ran a story about a guy who hacked a PS4 controller to add mouse and keyboard functionality. Today's hack isn't quite as elaborate, but it's very effective. Here I show how I modified a PlayStation 4 controller to automatically click the L3 button so I am always running. This auto-run functionality mimics the auto-run feature built into many games (like Titanfall 2 which spoiled me to expect this), but I built the circuit so it can be toggled on and off by clicking the L3 button. After playing Titanfall 2 for the last few months, the recent release of the Call of Duty WWII beta is driving me crazy as it requires me to click the run button over and over (every two seconds) which, after an afternoon of playing, is actually painful.

Assessing the PS4 Controller

I started out by looking online to see what the PS4 controller looked like inside. Imgur has a great PS4 dualshock controller teardown photo collection which was an excellent starting place. From these photos I realized this hack would be pretty easy since the L3 "click" action is achieved by a through-hole SPDT tactile switch placed under the joystick.

I was surprised to find my PS4 controller (below) was a little different (green for starters), but the overall layout was the same. I quickly identified the 4 pins of the L3 tactile switch and got to work...

After probing around with a multimeter and an oscilloscope, I was able to determine which pins do what. Just from looking at the trace it's pretty obvious that two of the pins are the positive voltage rail. In this controller the positive voltage (VCC) is about 3 volts, so keep that in mind and don't hook-up a 5V power supply if you decide to debug this thing.

To test my idea I attached 3 wires to VCC, GND, and SENSE and ran into the other room where my PS4 was. As I held the left joystick up in a game, shorting the SENSE and GND wires (by tapping them together) resulted in running! At this point I knew this hack would work, and proceeded to have a microcontroller control voltage of the L3 sense line.

Simulating L3 Presses with a Microcontroller

I glued a microcontroller (ATTiny85) to the circuit board, then ran some wires to the points of interest. Visual inspection (and a double check with a multimeter when the battery was in) provided easy points for positive and ground which could power my microcontroller. The "L3 sense" pin (which toggles between two voltages when you press the L3 button) was run to pin 3 (PB4) of the microcontroller. In a production environment current limiting resistors and debounce capacitors would make sense, but in the spirit of the hack I keep things minimalistic.

The device could be easily reassembled, and there was plenty of room for the battery pack and its plastic holder to snap in place over the wires. Excellent!

While I was in the controller, I removed the light-pipe that carries light to the diffuser on the back. The PS4 has an embarrassingly poor design (IMO) where the far side of the controller emits light depending on the state of the controller (blue for in use, black for off, orange for charging, etc). This is a terrible design in my opinion because if you have a glossy and reflective TV screen like I do, you see a blue light reflect back in the screen and bobble up and down as you hold the controller. Dumb! Removing the light pipe dramatically reduced the intensity, but still retains the original functionality.

Programming the microcontroller was achieved with an in circuit serial programmer (USBtinyISP) with test clips. This is my new favorite way to program microcontrollers for one-off projects. If the pins of the microcontroller aren't directly accessable, breaking them out on 0.1" headers is simple enough and they make great points of attachment for test clips. The simplest code to continuously auto-run is achieved by just swinging the sense line between 5V and 0V. This is the code to do that:

for(;;){ // do this forever
    // simulate a button press
    PORTB|=(1<<PB4); // pull high
    _delay_ms(50); // hold it there
    // simulate a button release
    PORTB&=~(1<<PB4); // pull low
    _delay_ms(50); // hold it there
}

Sensing Actual Button Presses to Toggle Auto-Run On/Off

Simulating L3 presses was as simple as toggling the sense line between VCC and GND, but sensing manual L3 presses wasn't quite as easy. After probing the output on the scope (see video) I realized that manual button presses toggle between voltages of about 2V and 3V, and the line never really goes down to zero (or below VCC/2) so it's never read as "off" by the digital input pin. Therefore, I changed my strategy a bit. Instead of clamping between 5V and 0V, I toggled between low impedance and high impedance states. This seemed like it would be gentler on the controller circuit, as well as allow me to use the ADC (analog-to-digital controller) of the microcontroller to read voltage on the line. If voltage is above a certain amount, the microcontroller detects a manual button press is happening and toggles the auto-run functionality on/off. The new code is this:

for(;;){ // do this forever

    // simulate a button press
    PORTB|=(1<<PB4); // pull high
    DDRB|=(1<<PB4); // make output
    _delay_ms(50); // hold it there

    // simulate a button release
    DDRB&=~(1<<PB4); // make input
    PORTB&=~(1<<PB4); // pull low
    _delay_ms(50); // hold it there

    // check if the button is actually pressed to togggle auto press
    if (ADC>200) { // if the button is manually pressed
        _delay_ms(100); // wait a bit
        while (ADC>200) {} // wait until it depresses
        while (ADC<200) {} // then wait for it to be pressed again
    }
}

It works! After giving it a spin on the Call of Duty WWII Beta, I'm happy to report that this circuit is holding up well and I'm running forever effortlessly. I still suck at aiming, shooting, and not dying though.

Follow-Up Notes

Follow-up #1: After playing the fast-paced and highly dynamic Titanfall 2 for so long, I rapidly became disenchanted with the Call of Duty WWII game-play which now feels slow and monotonous in comparison. Although this auto-sprint controller hack works, I don't really use it because I barely play the game I made it for! I'm going back to exclusively playing Titanfall 2 for now, and if you get the chance I highly recommend giving it a spin!

Follow-up #1: Call of DUty WWII added auto-sprint a few months after this post was made

Markdown source code last modified on January 18th, 2021
---
title: PS4 Controller Hack - Adding Auto-Run
date: 2017-09-02 15:48:22
tags: circuit
---

# PS4 Controller Hack - Adding Auto-Run

**After a long day** it can be really nice to have a relaxing hobby to clear your head, and few activities shut down your brain as effectively as video games. However, a newly released video game is physically hurting me as my impulse to move quickly causes me to perpetually click the run button. After a few days of game-play and a really sore left thumb, I decided to do something about it: hack-in a microchip to automatically click the button for me.

**Modifying game controllers to do things like automatically rapid fire is nothing new.** I once modified a USB computer mouse to add an extra "rapid fire" button ([link](https://www.swharden.com/wp/2010-12-28-full-auto-rapidfire-mouse-modification/)). Hackaday ran a story about a guy who[ hacked a PS4 controller to add mouse and keyboard functionality](https://hackaday.com/2013/12/12/modifying-a-ps4-dualshock4-controller-to-use-a-mouse-and-keyboard/). Today's hack isn't quite as elaborate, but it's very effective. Here I show how I modified a PlayStation 4 controller to automatically click the L3 button so I am always running. This auto-run functionality mimics the auto-run feature built into many games (like [Titanfall 2](https://www.youtube.com/watch?v=EXwdWuSuiYA) which spoiled me to expect this), but I built the circuit so it can be toggled on and off by clicking the L3 button. After playing Titanfall 2 for the last few months, the recent release of the [Call of Duty WWII](https://www.youtube.com/watch?v=D4Q_XYVescc) beta is driving me crazy as it requires me to click the run button over and over (every two seconds) which, after an afternoon of playing, is actually painful.

![](https://www.youtube.com/embed/v-164sv21Tw)

## Assessing the PS4 Controller

**I started out by looking online to see what the PS4 controller looked like inside.** Imgur has a [great PS4 dualshock controller teardown photo collection](http://imgur.com/a/ytRW5) which was an excellent starting place. From these photos I realized this hack would be pretty easy since the L3 "click" action is achieved by a [through-hole SPDT tactile switch](https://learn.sparkfun.com/tutorials/switch-basics) placed under the joystick.

<div class="text-center">

[![](teardown_thumb.jpg)](teardown.jpg)

</div>

**I was surprised to find** my PS4 controller (below) was a little different (green for starters), but the overall layout was the same. I quickly identified the 4 pins of the L3 tactile switch and got to work...

<div class="text-center img-border">

[![](069_thumb.jpg)](069.jpg)

</div>

**After probing around** **with a multimeter and an oscilloscope,** **I was able to determine which pins do what.** Just from looking at the trace it's pretty obvious that two of the pins are the positive voltage rail. In this controller the positive voltage (VCC) is about 3 volts, so keep that in mind and don't hook-up a 5V power supply if you decide to debug this thing.

<div class="text-center img-border">

[![](095_thumb.jpg)](095.jpg)

</div>

**To test my idea I attached 3 wires to VCC, GND, and SENSE and ran into the other room where my PS4 was.** As I held the left joystick up in a game, shorting the SENSE and GND wires (by tapping them together) resulted in running! At this point I knew this hack would work, and proceeded to have a microcontroller control voltage of the L3 sense line.

## Simulating L3 Presses with a Microcontroller

<div class="text-center img-border">

[![](145_thumb.jpg)](145.jpg)

</div>

**I glued a microcontroller ([ATTiny85](http://www.atmel.com/images/atmel-2586-avr-8-bit-microcontroller-attiny25-attiny45-attiny85_datasheet.pdf)) to the circuit board, then ran some wires to the points of interest.** Visual inspection (and a double check with a multimeter when the battery was in) provided easy points for positive and ground which could power my microcontroller. The "L3 sense" pin (which toggles between two voltages when you press the L3 button) was run to pin 3 (PB4) of the microcontroller. In a production environment current limiting resistors and debounce capacitors would make sense, but in the spirit of the hack I keep things minimalistic.

<div class="text-center img-border">

[![](158_thumb.jpg)](158.jpg)

</div>

**The device could be easily reassembled,** and there was plenty of room for the battery pack and its plastic holder to snap in place over the wires. Excellent!

<div class="text-center img-border">

[![](161_thumb.jpg)](161.jpg)

</div>

**While I was in the controller,** I removed the light-pipe that carries light to the diffuser on the back. The PS4 has an embarrassingly poor design (IMO) where the far side of the controller emits light depending on the state of the controller (blue for in use, black for off, orange for charging, etc). This is a terrible design in my opinion because if you have a glossy and reflective TV screen like I do, you see a blue light reflect back in the screen and bobble up and down as you hold the controller. Dumb! Removing the light pipe dramatically reduced the intensity, but still retains the original functionality.

<div class="text-center img-border">

[![](166_thumb.jpg)](166.jpg)

</div>

**Programming the microcontroller** was achieved with an in circuit serial programmer ([USBtinyISP](https://www.ebay.com/sch/i.html?&_nkw=USBtinyISP)) with test clips. This is my new favorite way to program microcontrollers for one-off projects. If the pins of the microcontroller aren't directly accessable, breaking them out on 0.1" headers is simple enough and they make great points of attachment for test clips. The simplest code to continuously auto-run is achieved by just swinging the sense line between 5V and 0V. This is the code to do that:

```c
for(;;){ // do this forever
    // simulate a button press
    PORTB|=(1<<PB4); // pull high
    _delay_ms(50); // hold it there
    // simulate a button release
    PORTB&=~(1<<PB4); // pull low
    _delay_ms(50); // hold it there
}

```

## Sensing Actual Button Presses to Toggle Auto-Run On/Off

**Simulating L3 presses was as simple as toggling the sense line between VCC and GND, but _sensing_ manual L3 presses wasn't quite as easy.** After probing the output on the scope (see video) I realized that manual button presses toggle between voltages of about 2V and 3V, and the line never really goes down to zero (or below VCC/2) so it's never read as "off" by the digital input pin. Therefore, I changed my strategy a bit. Instead of clamping between 5V and 0V, I toggled between low impedance and high impedance states. This seemed like it would be gentler on the controller circuit, as well as allow me to use the ADC (analog-to-digital controller) of the microcontroller to read voltage on the line. If voltage is above a certain amount, the microcontroller detects a manual button press is happening and toggles the auto-run functionality on/off. The new code is this:

```c
for(;;){ // do this forever

    // simulate a button press
    PORTB|=(1<<PB4); // pull high
    DDRB|=(1<<PB4); // make output
    _delay_ms(50); // hold it there

    // simulate a button release
    DDRB&=~(1<<PB4); // make input
    PORTB&=~(1<<PB4); // pull low
    _delay_ms(50); // hold it there

    // check if the button is actually pressed to togggle auto press
    if (ADC>200) { // if the button is manually pressed
        _delay_ms(100); // wait a bit
        while (ADC>200) {} // wait until it depresses
        while (ADC<200) {} // then wait for it to be pressed again
    }
}
```

**It works!** After giving it a spin on the Call of Duty WWII Beta, I'm happy to report that this circuit is holding up well and I'm running forever effortlessly. I still suck at aiming, shooting, and not dying though.

## Follow-Up Notes

Follow-up #1: After playing the fast-paced and highly dynamic Titanfall 2 for so long, I rapidly became disenchanted with the Call of Duty WWII game-play which now feels slow and monotonous in comparison. Although this auto-sprint controller hack works, I don't really use it because I barely play the game I made it for! I'm going back to exclusively playing Titanfall 2 for now, and if you get the chance I highly recommend giving it a spin!

![](https://www.youtube.com/embed/ktw2k3m7Qko)

Follow-up #1: Call of DUty WWII added auto-sprint a few months after this post was made
Pages