Custom Smart Battery for Pixhawk 4

My overall goal is to use more types of smart batteries with PX4 than what is listed in the batt_smbus documentation. I realize the driver was written specifically for the BQ40Z50, but am I wrong in assuming that any device which properly communicates over SMbus could be used?

I am using an Arduino Uno to emulate a smart battery over I2C. I have confirmed the emulation is correct by using another Arduino acting as an SMbus host. During testing I had a bi-directional level shifter in the middle to bring SCL and SDA down to 3.3v to act like host Arduino is the Pixhawk.

When I connect the Arduino to the Pixhawk 4 on the I2C A port and run batt_smbus start from nsh, there is no battery found. Further, there is no activity at all (verified by oscilloscope) on the I2C A port when I execute batt_smbus start. I know the A port works because I have captured some I2C message being sent upon boot, but never after.

How can I force the smart battery driver to use the I2C A port, or will it never work with what I am trying to accomplish?

1 Like

I haven’t used pixhawk 4, but it could be that batt_smbus uses another i2c bus by default. You could try other buses:

batt_smbus start -b 2
batt_smbus start -b 3
batt_smbus start -b 4

@zselgrath If you type batt_smbus info in the shell, you should see a printout with the description of how to interact with and use the driver.

Currently it supports starting the driver on either the external or internal bus (PX4_I2C_BUS_EXPANSION and PX4_I2C_BUS_ONBOARD)

I’d actually like to see the smbus portion of this driver be made into it’s own base class to enable easier development of other device specific drivers that may also implement the protocol. This is on my radar to do very soon.

Actually the driver is missing a few options for the other I2C ports on the Pixhawk 4.

I am not sure which ports these correspond to, but I bet one of them is I2C A :wink:

I don’t have a Pixhawk 4 FC so I can’t test this :confused: