Support Forum

Share your projects and post your questions

Register   or   Sign In
The Forum

Multiple Processes Reading the ACD Feedback from read_voltage

2264 Views - Created 28/12/2016

28/12/2016

Posted by:
SDSU_Rocket_Project

SDSU_Rocket_Project Avatar

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

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

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.

29/12/2016

Posted by:
SDSU_Rocket_Project

SDSU_Rocket_Project Avatar

Thanks for the swift response, Andrew! I'll rework the logic so the I2C bus is only accessed by one process at a time.

Sign in to post your reply

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.