I’m using binmode on a Bus Pirate 5 to log the ADC voltages on several pins of a PIC 16F in a battery charge controller to understand how it works. It’s been running for a couple of days so far and it’s working pretty well!
This is essentially all I’m doing:
with BPIOClient(args.port) as client:
with args.logfile.open("w") as f:
f.write("Timestamp,IO0,IO1,IO2,IO3,IO4,IO5,IO6,IO7\n")
while True:
try:
adc_values = client.status_request(adc=True)["adc_mv"]
except Exception:
continue
timestamp_ms = time.time_ns() // 1_000_000
f.write(f"{timestamp_ms},{','.join(str(v) for v in adc_values)}\n")
I get ~50 samples/sec on my MacBook and ~38 samples/sec on a Raspberry Pi 3. I experimented with optimizing the loop (including removing the file writes), but I suspect the Pi is just spending more time in the flatbuffers/cobs code.
This brings a few thoughts/questions to mind:
- How fast could the Bus Pirate send ADC sample packets? 40-50 samples/sec is working for my use case, but a bit faster may be useful to fill the gap between voltmeter and oscilloscope (?). The fastest signal I’ve seen on this PIC has been a 40 Hz PWM fan speed control.
- A voltage logging mode might be useful (?). Like send a command that asks the BP to send ADC sample packets as fast as it can (or maybe at a requested rate?). This would avoid needing to send a request for each sample and the overhead that comes with that. Some kind of relative timestamp would need to be included with each sample.
- I haven’t experimented with the DIO mode yet, but a similar digital input logging mode might be useful (?). Now that I’ve determined which signals are digital, logging the digital states would be more efficient. The BP could potentially only send a packet when one of the digital states changed.
Just some ideas
. It’s already been very useful as is!