Hi everyone,
Let me preface this by saying that I am not an expert on programming, processors, or anything. I'm just a college student learning as I go. I am working on a project that requires reading data from a set of digital calipers as seen here: http://robocombo.blogspot.com/2010/12/u ... rface.html
The good news is that I have successfully figured out how to interpret the binary data from the calipers into an integer. Right now, the code displays an integer on the terminal exactly as it appears on the calipers. It reads the signals from the caliper through two GPIO pins and decodes the data. Great.
This project also involves controlling a binary stepper motor from the same Raspberry Pi. This involves driving output signals across five other GPIO pins. Because of this, my original plan was to create a subclass of the Threading module called Caliper that would run the code to read the signal from the calipers in the background while the motor controller ran in the foreground. This Caliper subclass would provide some kind of method called read() or something that would spit out the integer value whenever I need it. This would be used in a feedback loop to move the motor with precision.
However, I've run into an unfortunate problem. While testing my Caliper subclass, it seemed to be going too slow. The caliper sends out little "packets" of data in 24-bit bursts, and while the Pi was able to handle this just fine as the main thread, it was only picking up maybe a third of the bits while running in the background. I did a little research and what I believe to be the problem is that the Pi has only one core and is thus incapable of hardware multi-threading, and software multi-threading eats up too much time with context switching (I believe there is something called a Global Interpreter Lock [GIL] or something?)
It looks like my only choice is to use some kind of external MCU to read the calipers, and then set up some kind of serial connection (I was thinking I2C) to the Raspberry Pi. That way the Pi can just poll the I2C connection for the caliper data while still running the motor. However, this is highly unappealing since we have a big deadline coming up, and frankly I don't think I have the time or skill to learn how to code in embedded C in that amount of time (tutorials and documentation are severely lacking).
So before I go down that road, I wanted to ask here if there is any workaround for this problem that would allow me to continue to run all of the code on a single Raspberry Pi. Again, I don't know much about advanced programming concepts or processors/multithreading, etc. so it's difficult for me to ask for specifics. But any help at all would be greatly appreciated.
Thanks!
I can post my code upon request, if that would be helpful.