SUMMER SALE • UP TO 20% OFF • Ends 31st AUGUST 2025 *excludes trade customers
Support Forum

Share your projects and post your questions

The Forum

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

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

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.

Forum Notice – Closure to New Posts

As part of our compliance with the UK’s Online Safety Act, the AB Electronics UK support forum is now closed to new posts and replies.

We understand the importance of continued support for our products, so if you have a technical query or require assistance, please use the Contact Form or consult our Knowledge Base for helpful articles and documentation.

We appreciate your understanding and continued support.


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.

Home

Shop

Learn

Forum

FAQ

Contact

0 item

Your cart is empty

Please browse our shop to order from the wide range of Raspberry Pi boards and accessories.

Subtotal:£0.00
View Basket Continue to Checkout