Spooky
C library for OOK Manchester encoding, decoding, and dynamic clock recovery
Install / Use
/learn @silentbicycle/SpookyREADME
spooky: OOK Manchester encoding, decoding, and dynamic clock recovery. For when you need action at a distance.
This is a library for microcontroller projects (Arduinos, ATtinys, PICs, etc.) that need to transmit digital data using cheap, short-range radio. Better radio parts usually do more signal management for you, but tend to be more expensive per circuit and/or surface-mount only.
If you're making a sensor network for a home automation project (for example), this will encode and decode the raw radio data with Manchester coding to help distinguish from radio noise, and help the receiver to automatically detect the signal's baud rate ("clock recovery").
To use the encoder, initialize a spooky_encoder struct with a buffer,
then enqueue outgoing messages as needed. Call spooky_encoder_step at
a regular interval (use a timer interrupt) and set the data line
connected to the transmitter accordingly.
To use the decoder, initialize a spooky_decoder struct with a working
buffer and a 'data received' callback, then check the current state of
the receiver's data line periodically (again, use a timer interrupt) and
pass the low/high state to spooky_decoder_step. Oversampling will help
to compensate for small amounts of variability in timing -- several data
points per transition in the signal is best.
For further usage details, see spooky_decoder.h and
spooky_encoder.h.
To build the tests, run make test_spooky.
Also, I wrote a blog post about the project that motivated this.
example/ contains two example projects, for Arduinos
The example projects should use amateur-band, ASK/OOK radio transmitters and receivers such as the following:
- Transmitter: https://www.sparkfun.com/products/10534
- Receiver: https://www.sparkfun.com/products/10532
- Transmitter, receiver pair: http://www.seeedstudio.com/depot/315Mhz-RF-link-kit-p-76.html?cPath=19_22
Check the data sheets for the parts you get, of course.
tx: Transmit the state of (up to) four switches.
Connect Arduino pins 8, 9, 10, and 11 to switches, with pulldown resistors on the Arduino side (so they don't float when the switch is open), and the other side to VCC.
Connect Arduino pin 12 to a momentary switch (button), with a pulldown resistor so it doesn't float, and the other side to VCC.
Connect Arduino pin 13 to the radio transmitter data pin. Power/ground the transmitter as indicated by its data sheet.
When the Arduino is powered and the button is pressed, it will transmit the current state of the switches to the receiver approximately every 3 seconds.
rx: Receive the switch state, light up four LEDs when the message arrives.
Connect Arduino pin 8 to the digital output pin on the radio receiver. Power/ground the receiver as indicated by its data sheet.
Connect Arduino pins 10, 11, 12, and 13 to four LEDs, each of which has a resistor connecting it to ground.
When the Arduino receives a radio message from the corresponding transmitter circuit, it will briefly light up the LEDs to match the closed switches.
Related Skills
node-connect
343.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
92.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
