Is there a way to detect (in Python) that a Blinkt! is physically plugged in?

The subject says it all, really! Just wondering if there was a way to detect if a Blinkt! was plugged in or not, meaning that my python script could choose to run, or just exit and not waste cpu cycles.


No, I’m afraid, the APA102 are not communicating back.

I guess you could potentially make a small voltage divider on the blinkt from the 5V pin to another pin on the blnkt and read the voltage on the relevant GPIO, but I haven’t tried it, I’m just brainstorming out loud.

Oh well, never mind! Thanks for answering! :)

Actually, I’m not sure why I was focussed on the 5v pin, you could use the 3v3 pin on the header, easily accessible on the bottom.

Here is a simple hack that @gadgetoid suggested that will work a treat asserting whether a blinkt is hooked up or not:

it is using a 10k ohms resistor to couple BCM4 to 3.3V on physical pin 1 (for protection, so you don’t accidentally short the setup by setting BCM4 as an output driven low).

Here’s some example code to poll BCM4:

import RPi.GPIO as GPIO

Note the use of internal pull-down to avoid the pin being in a floating state when the blinkt is not fitted. Thanks to @allo for pointing that solution out.

I think you can set internal pullup/pulldown on the raspberry pi.

That’s right, you could activate the pulldown on that pin, and use a lower value for the resistor, theoretically.

How low you would need to go, and whether (another process on boot) setting the pin as an output driven low could result in damage I’m not sure. Polling in the manner I suggested is a bit clunky to be sure, but is a safe option. YMMV.

actually, good call, the internal pulldown is not strong enough to resist with a 10k value, at least on a Pi3 (but I don’t believe the internal pullup/down vary from model to model). I have amended the code supplied previously to reflect this.