mcp9808 I2C proper syntax addressing

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
sxrg
 
Posts: 249
Joined: Mon Dec 10, 2012 10:02 pm

mcp9808 I2C proper syntax addressing

Post by sxrg »

I tried the example code for the mcp9808 and it works fine.
I would like to have two mcp9808.
My question is how do i properly syntax in code to address each mcp9808 and read the temperature from both?

**below is just an lcd example, i'm not asking about LCDs**
Just for an example when I use two LCDs with the backpack with I2C, I use the following:
LiquidCrystal lcd1(0);
LiquidCrystal lcd2(1);

then i can print to each lcd such as:
lcd1.print("some text");
lcd2.print("some other text");

User avatar
sxrg
 
Posts: 249
Joined: Mon Dec 10, 2012 10:02 pm

Re: mcp9808 I2C proper syntax addressing

Post by sxrg »

Let me add that I know that the default addressing is 0x18 and how to apply the addressing by connecting A0 and or A1 and A@ high with would change the addressing to 0x19 and so on.

User avatar
Franklin97355
 
Posts: 23940
Joined: Mon Apr 21, 2008 2:33 pm

Re: mcp9808 I2C proper syntax addressing

Post by Franklin97355 »

This is the code for the begin function:

Code: Select all

boolean Adafruit_MCP9808::begin(uint8_t addr)
so you would add an address to the begin call in your code.

Code: Select all

mcp2.begin(0x19);

User avatar
sxrg
 
Posts: 249
Joined: Mon Dec 10, 2012 10:02 pm

Re: mcp9808 I2C proper syntax addressing

Post by sxrg »

Thanks for the reply.

Using the example code for the mcp9808 I added your code:

Code: Select all

 
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
Adafruit_MCP9808 mcp2 = Adafruit_MCP9808();   //your added code for the second mcp9808

void setup() {
  tempsensor.begin();
  mcp2.begin(0x19);
This seems to work, i can see the two different temperatures.
But i kept getting errors when I tried to add:

Code: Select all

boolean Adafruit_MCP9808::begin(uint8_t add)
Where is this placed?

User avatar
Franklin97355
 
Posts: 23940
Joined: Mon Apr 21, 2008 2:33 pm

Re: mcp9808 I2C proper syntax addressing

Post by Franklin97355 »

Where is this placed?
That is the prototype in the .h file. You don't add that it was just to show you where the address went.

User avatar
sxrg
 
Posts: 249
Joined: Mon Dec 10, 2012 10:02 pm

Re: mcp9808 I2C proper syntax addressing

Post by sxrg »

Sorry for my ignorance..lol
But, Thank you very much. I appreciate it.

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

Return to “Arduino”