ValueError: No i2c device at address 0x40

Have an Adafruit 16 PWM Servo HAT connected to a Raspberry Pi 4B.

I get an error:

ValueError: No i2c device at address 0x40

When I try run:

import time
from adafruit_servokit import ServoKit
kit = ServoKit(channels=16)

kit.servo[0].angle = 180
kit.servo[4].angle = 20
time.sleep(0.5)
kit.servo[4].angle = 0
time.sleep(0.5)
kit.servo[0].angle = 0

Just as an fyi, i2cdetect -y 20 and i2cdetect -y 21 display contents, just not i2cdetect -y 1. Is that normal?

This exact same code runs perfectly when I connect the HAT to a raspberry pi zero.

Thanks
-formlessform

Hi formlessform,

Welcome to the forum :slight_smile:

Can you let me know what Raspberry Pi OS version your Pi 4B and Pi Zero were each running? If the code is working well on one of them and not the other then it would be good to try and isolate the issue to either the hardware or the OS configuration.

Have a quick read through this guide:

My understanding is that you’ll probably want to start by using i2cdetect -l to detect which I2C busses are available on your machine. Then you can specify the bus you want to scan by changing the number after i2cdetect -y so you know you’re interrogating a bus that actually exists on your device.

Hey Trent,

Thanks for the reply. I am using Buster on the pi zero, was using Bullseye on the Pi 4, downgraded to Buster last night, still having the same issue on the pi 4. Wondering if there’s something wrong hardware wise on my pi 4?

Btw, I have noticed I only have an i2c-bcm2708.dtbo file in my overlays folder, not 2835, could this be the issue? How do I get the 2835 driver file to put into this folder to test that out?

After doing a bit of reading, im wondering if it has something to do with the i2c driver, and needing a different driver for the pi 4 than is default with i2c install. Everything is the same OS and driver-wise between my pi zero and pi 4, but still getting the no i2c device error on the pi 4.

i2cdetect -l produces:

i2c-1 bcm2835 (i2c@7e804000) I2C adapter

Im wondering if there is an issue regarding the bcm2835 driver, as there is no bcm2835 driver in the overlay folder, only bcm2708.

Another fyi. On the pi zero where the hat works, i2cdetect -l produces:

i2c-1 bcm2835 i2c adapter I2C adapter

and i2cdetect -y 1 produces results on 70 and 40.

Its just the pi 4 that seems to not be producing results.

Also, running the following code produces no error:

# Simple example of reading the MCP3008 analog input channels and printing
# them all out.
# Author: Tony DiCola
# License: Public Domain
import time

# Import SPI library (for hardware SPI) and MCP3008 library.
import Adafruit_GPIO.SPI as SPI
import Adafruit_MCP3008


# Software SPI configuration:
CLK  = 18
MISO = 23
MOSI = 24
CS   = 25
mcp = Adafruit_MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI)

# Hardware SPI configuration:
# SPI_PORT   = 0
# SPI_DEVICE = 0
# mcp = Adafruit_MCP3008.MCP3008(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))


print('Reading MCP3008 values, press Ctrl-C to quit...')
# Print nice channel column headers.
print('| {0:>4} | {1:>4} | {2:>4} | {3:>4} | {4:>4} | {5:>4} | {6:>4} | {7:>4} |'.format(*range(8)))
print('-' * 57)
# Main program loop.
while True:
    # Read all the ADC channel values in a list.
    values = [0]*8
    for i in range(8):
        # The read_adc function will get the value of the specified channel (0-7).
        values[i] = mcp.read_adc(i)
    # Print the ADC values.
    print('| {0:>4} | {1:>4} | {2:>4} | {3:>4} | {4:>4} | {5:>4} | {6:>4} | {7:>4} |'.format(*values))
    # Pause for half a second.
    time.sleep(0.5)
```````````````````````````````````````````````````````````````

Is there possibly something wrong with my Pi 4b? As I said above that code works fine, it just seems to be the adafruit servo hat code thats not working with it, the hat works perfectly on a pi zero, and have now also tested it working on a pi 3b (buster on the pi zero, bullseye on the pi3b, bullseye on the pi4)

Thanks,
-FF

Hello,

This one has me scratching my head, it sounds like a hardware issue is most likely.
If your Pi is still within its warranty period shoot us an email with a photo of the Pi and a link to this forum thread and we can proceed with an RMA and potentially get it replaced.

1 Like