How to determine if .begin() worked

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
emg184
 
Posts: 21
Joined: Tue Oct 09, 2018 2:17 pm

How to determine if .begin() worked

Post by emg184 »

I was wondering if there is a way to determine if calling .begin() on an i2c chip worked. I looked through the libraries for the ina219 and i dont see a return value for the function. I want to make sure that when i execute a piece of my program that if .begin() fails i can handle that error but it doesnt appear that there is anything returned from that function to check for.

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: How to determine if .begin() worked

Post by adafruit_support_mike »

There's no general method, and sometimes all the .begin() methods do is store pin values in a data structure for use later.

The simplest way to check a connection is to emit a read command for the device's address and see if the device answers. For the INA219, the configuration register would be a decent choice.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”