Using pyFirmata for Peeps with Arduinos #180
Replies: 4 comments 3 replies
-
i have only heard this timing precision argument literally every time someone asks about the pi, but it's an empirical question! in my experience it's mostly superstition and in my opinion optimizing for the wrong thing when weight against the complexity and maintainability of the code. But define what kind of accuracy you need and try measuring it! here's the jitter we get in a roundtrip external input -> read -> write test, so it includes both read and write. The read also happens with hardware interrupts and pigpio passes in the CPU tick from when the logic level changes, so idk i think it's pretty accurate. test details and code to replicate is in the paper. so if you need better than 50 microseconds IQR jitter then by all means! Avoiding needing to write a virtualization wrapper to a microcontroller is one of the main reasons to use the pi, but if that's the route you want to go then that would be totally doable, that's basically what bpod does. You'd basically just need to define what you would want from such an interface and then i can help coach through - eg. what kind of instructions do you want to be able to send and receive from the microcontroller? Using the pi to do things like individual GPIO flips on the arduino is sort of pointless, as you then just add whatever jitter/latency from routing through serial/etc. to the jitter/latency you were trying to avoid from the PI. But otherwise it's totally possible to write a firmware for the microcontroller that can accept instructions from the pi, would just need to know what! |
Beta Was this translation helpful? Give feedback.
-
Before I started using Autopilot, I wrote a behavioral control system entirely using Arduino. IMO the biggest problem is that debugging on Arduino is much more difficult -- no log files, no ability to ssh in or hook up a display, all you can do is write messages to the serial port ... but in a crash scenario, that probably won't work anyway. As a result I found that code of even moderate complexity became very brittle on Arduino. I do like using Arduino for fast and simple tasks -- for instance, Autopilot can raise a digital line, and this triggers the Arduino to execute a precisely timed sequence to flash LEDs. I think of the Arduino as a bit like the "spinal cord" in this scenario. But once things get complicated, I think you're way better off on the Pi. |
Beta Was this translation helpful? Give feedback.
-
As far as I'm aware, we definitely don't need better than 50us IQR jitter for things! The main reason I posted this was because it's one of the most common threads about adopting Autopilot that I've run into so far. I've tried talking about how you have indeed benchmarked these things and that the Pi, especially when used how you designed it with the cool multi-threading of things, is likely plenty fast! When looking around at ways to assuage those fears, beyond the ones in your paper, I found this stuff and thought it could be interesting. I personally would very much like to use the pi for our headfixed discrimination task (similar to 2AFC, but even simpler than that lol) but haven't had much success in getting fellow lab mates to join on the adventure yet...
This is something that Jonny pointed out to me about how we've been doing things on Arduinos and I can't stop thinking about it! The elegance of how Autopilot can make things so simple but also so robust is just something that makes me smile. Also after reading the Autopilot paper again over the weekend, I started trying to understand the notion of how Arduinos act as state machines and how limiting that can be for behavior! On the speed side of things, I'm a little confused about how sampling is actually performed with threading. I'm very new to asynchronous programming/threading except for knowing it's possible/doing very simple things with it, so I will probably make a separate discussion tab for going over my understanding of how Autopilot implements those things... been trying to get ffmpeg pipes to work for the evening lol |
Beta Was this translation helpful? Give feedback.
-
Is someone exposed github SMTP or what is this email?Delivered-To: [my github email] ARC-Authentication-Results: i=1; mx.google.com; ----==_mimepart_63ace003d79dd_247c710449144 Already wet from dirty thoughts bout you https://in.sv/_gn_FE -- Message ID: auto-pi-lot/autopilot/repo-discussions/180/comments/[email protected] |
Beta Was this translation helpful? Give feedback.
-
Hey everyone! People in the lab are quite fond of them and seem to trust the timings/clock consistency of them more than the pi. A talented programmer in our lab, Annie (not sure what her github handle is yet...), mentioned that making a plugin for Autopilot to run with Arduinos would be cool.
While looking into how to communicate with Arduinos/send sketches over the wire to them in Python, I came across a library called firmata and a Python library called pyFirmata. Maybe these libraries could be used to generate an interface with Arduinos in Autopilot? Just figured it would be cool to have this on the discussions forum as well.
Beta Was this translation helpful? Give feedback.
All reactions