1

thanks in advance for any help, this is quite the sticking point for me unfortunately,

Basically I'm coding a program in python for my raspberry pi 3 to read values from two voltmeters, through an ADC, and display them on a TFT screen. The program works, but in order to use the program at the same time as the TFT screen, I need to move the i2c bus to GPIO pins 5 and 6.

(Side note: yes, I'm using external resistors to pull up to 3V3)

I have done this on the end of the raspberry pi by altering config.txt, and I can detect the ADC using i2cdetect. So all good there.

In my python program, it's really only one line of code for the I2C initialization:

i2c = busio.I2C(board.D6, board.D5)

This returns ValueError: No Hardware I2C on (slc,sda)=(6, 5) when I try to run the program.

I won't claim to be a great or even experienced programmer, and am honestly open to any ideas at this point. I've been all over using google and it seems like this is just a limitation of busio.py and there's no real way around it.

I guess at this point I'm wondering if there's another way to code an i2c bus into python, possibly using an alternative library other than busio? Or should I instead rethink my whole project? It might be annoying to change to a different board that either has two i2c hardware busses or analog pins, but at this point maybe it'd be worth it - or I could abandon an LCD display and do something else instead. I tried to use an HDMI display, losing touchscreen functionality but there are very few out there that size. I'd hate to rewrite my program in another language, but... maybe I could just put in a section of code in C, if C doesn't have the limitations of busio?

Thanks again for any thoughts or ideas!

2 Answers 2

1

RPi 3 has only 2 "hardware" i2c buses: i2c0 & i2c1. If you'll read through the "documentation" in /boot/overlays/README, you can confirm that for yourself. I think you'll find that the RPi 4 is the only model with more than 2 hardware i2c channels.

I can detect the ADC using i2cdetect. From that & other comments in your question, I'll assume you've configured a software i2c channel in /boot/config.txt? Software i2c can be a poor substitute for the hardware i2c. Also, the error message "ValueError: No Hardware I2C on (slc,sda)=(6, 5)" suggests that opinion is shared by your Python library :)

For RPi 3, there are two hardware i2c channels; i2c0 & i2c1. I assume from your question that your TFT screen is using i2c1. There have been some vague warnings re use of i2c0 in the past; these warnings may still be valid for some models, but I've encountered no problems using i2c0 on my RPi 3B+ model.

Here's how to use i2c0:

  1. Check your /boot/config.txt file for the following line: dtparam=i2c_vc=on. If it's not in the file, then add it now. This will enable i2c0 for your use with the ADC.

  2. If you're using a dtoverlay for your ADC, make sure it calls out i2c0 for the GPIO pin.

  3. With the RPi powered OFF, move your ADC i2c to GPIO 0 (SDA) & GPIO 1 (SCL). Connect your other hardware (pullups incl), boot up & test the connection using sudo i2cdetect -y 0 .

  4. Assuming that checks out, re-code your Python script to reflect use of i2c0 & try again.

Let us know how it works, and the specific model # of your RPi:

$ cat /proc/cpuinfo | awk '/Model/' 
# post the output from this command
2
  • Unfortunately, that would not work either. The screen uses the first 26 pins. Unless it doesn't actually need all of them...? And the output is, Raspberry Pi 3 Model B Rev 1.2 Commented Mar 21, 2022 at 20:54
  • @Chaos_Spear: ?!? 26 pins... does it actually use the pins, or just cover them up? What's the model # & source for this screen?
    – Seamus
    Commented Mar 22, 2022 at 9:33
1

First off, sorry if this looks weird, apparently according to SE my registered account is different than my guest account so I'm just going to put an answer down because I found a way to sidestep the issue.

Basically the previous screen I tried to use had the option of working just as an HDMI display, no touchscreen capability, not using any GPIO pins. I had trouble getting this to work before but decided to revisit the idea, and this time the screen worked, so that means I can use the hardware i2c like busio wants me to! Much easier this way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.