Multiple Processes Reading the ACD Feedback from read_voltage
The ADC Pi is an Analogue to Digital converter for the Raspberry Pi
28/12/2016
Posted by:
SDSU_Rocket_Project
I'm trying to run 2 processes in Python 2.7 that are calling the ADC simultaneously. The program comes to a halt however, where the last call before the Keyboard Interrupt is:File "/home/pi/ABElectronics_Python_Libraries/ADCPi/ABE_ADCPi.py", line 143, in read_raw __adcreading = self._bus.read_i2c_block_data(address, config, 4)KeyboardInterrupt The python code that's creating the processes is: x_proc = multiprocessing.Process(target=run_routine, args=(x_setpoints,kp,ki,kd,"X"))y_proc = multiprocessing.Process(target=run_routine, args=(y_setpoints,kp,ki,kd,"Y")x_proc.start()y_proc.start()x_proc.join()y_proc.join()And the function that I'm trying to have run in parrallel is doing: def run_routine(setpoints,P,I,D,motor): .... if motor == 'X': adc_num = 1 feedback = adc.read_voltage(adc_num) print feedback elif motor == 'Y': adc_num = 2 feedback = adc.read_voltage(adc_num)Here, everything hangs... I'd really appreciate some help!
29/12/2016
Posted by:
andrew
Unfortunately, you can only access the ADC from one program at a time as the I2C bus is locked when reading from the ADC so any other attempts to read from the locked bus will fail.
One possible workaround would be to write a third python program that manages access to the ADC and then call that from your two other processes. That way only one program is accessing the I2C port and the other two processes and request data without blocking the I2C port.
One possible workaround would be to write a third python program that manages access to the ADC and then call that from your two other processes. That way only one program is accessing the I2C port and the other two processes and request data without blocking the I2C port.
29/12/2016
Posted by:
SDSU_Rocket_Project
Thanks for the swift response, Andrew! I'll rework the logic so the I2C bus is only accessed by one process at a time.
Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view.
Download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.