How to read binary (10101..) data from a device?

Here’s my situation: I have a device with four pins: GND, Vin, data and DTR. When DTR is pulled low, device sends digital data to the data line. I know the bit length and the data message length, but the question is, how can I read the data (zeros and ones) with a Beaglebone Black?

Just to clarify, I need to read data from this device:
However, it would be nice to know the principal of data capture/reading. For now I know only how to detect the start of the data transmission (rising edge) but everything else is unclear: what programming languages/libraries do I need?.

That looks like an inconvenient, non-standard protocol to interpret. Since there is no clock line, you can’t rely on edges to signal the start of each bit(other than the start of the datagram). However the timing of the packet is consistent, so I would approach it based on timing. The data transmission rate is very slow(833 bits per second => 833Hz) so you may be able to sample the data accurately without using the PRUs.

  • Detect the rising edge to indicate the start of the packet
    Do the following 41 times:
  • Sample the data pin
  • Pause for 1.2ms
    -Verify that the message is valid by calculating the checksum

My current language of choice is Python, so I would put this logic in a thread which runs independently of the main program thread and creates a valid, parsed data structure representing the contents of the packet. However, you can use any language you want though.

NOTE: If you find that a lot of your of your packets are invalid then you should switch to using a PRU, which allows much more accurate sampling at higher rates.

Here’s my current python code:


import Adafruit_BBIO.GPIO as GPIO
import time
import sys

import psutil, os
p = psutil.Process(os.getpid())

GPIO.setup(“P8_10”, GPIO.OUT)
GPIO.output(“P8_10”, GPIO.LOW)
GPIO.setup(“P8_12”, GPIO.IN)

while True:

data = []
GPIO.wait_for_edge(“P8_12”, GPIO.RISING)
for i in range (0,41):
if GPIO.input(“P8_12”):

if (i == 0):



However it doesnt capture the bits correctly, the 5 first bits are often 11011 but not always (I changed the time.wait for very first bit but it didnt help much). How can I improve the reception speed?
I dont know assembly at all and very little C. Is there better python solution available?