Support Forum

Share your projects and post your questions

Register   or   Sign In
The Forum

"Failed to write to i2c port for write" with cpp demos

The Expander Pi is an Analogue, Digital and RTC development Interface for the Raspberry Pi

30/10/2022

Posted by:
jimbobauer

jimbobauer Avatar

Hello, I was able to get the demo-adcspeed python program to run without any difficulties but, when I attempt to get the C++ demos to run, I consistently get an "Failed to write to i2c port for write". I did 'sudo apt install libi2c-dev' and, when I run 'i2cdetect -y 1' I see the adc on address 20... I am stumped... any pointers? Thank you.

30/10/2022

Posted by:
jimbobauer

jimbobauer Avatar

UPDATE: after posting my question, I noticed that 'sudo i2cdetect -y 1' showed UU in address x68; aparently this indicates that address is unavailable for user application. Since I had done the rtc set up, I figured this was then due to the hwclock being in operation so, I backed out of this by undoing the edits. With hwclock not operational I have the 68 showing for that address on i2cdetect and, now the cpp demos run. To me this looks like I cannot use the rtc (as hwclock) _and_ use the cpp implementation of the adc.... does this seem correct?

31/10/2022

Posted by:
andrew

andrew Avatar

Hello

The Expander Pi library tries to write to the RTC when it initialises the object. As the RTC was locked by the hwclock module this was blocking access to the I2C address and causing the code to fail.

I have updated the Expander Pi library with a new "usertc" parameter in the ExpanderPi function so setting the parameter to false it bypasses the RTC initialisation and allows the code to work correctly. You can download the updated library from our GitHub repository at Expander Pi GitHub Repository

When you create an ExpanderPi object you will need to pass in values for the initialise and usertc parameters. For example,


ExpanderPi expi(true, false);


Hopefully, this will fix the problem you are having and allow you to use the ADC when the hwclock is operational.

31/10/2022

Posted by:
jimbobauer

jimbobauer Avatar

Wow! Thank you for the quick response and resolution! That is great support!!

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.

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