About Us Knowledge Base Community Forum Electronics Toolbox FAQ Shipping & Delivery

Community Forum

Share your projects and post your questions

Register or Sign In

Multiple Processes Reading the ACD Feedback from read_voltage

1004 Views - Created 28/12/2016


Posted by:

Users 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)


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")



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! 




Posted by:

Users Avatar

United Kingdom

Users Twitter  Users Website  

Unfortunatly 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.

AB Electronics UK Tech Support


Posted by:

Users 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. 

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.