Go Down

Topic: I2C bus "problems" (Read 3540 times) previous topic - next topic

Grumpy_Mike

I can't see any referance to an I2C address in that code.

You have no need for the while loop the whole loop function repeaters.

Why not ditch the libary and write some real code.

lost_and_confused

Well, if I am not mistaken it is the centipede library of which we are speaking.

The simplicity of just sending bits to the library which does all the hard work seems a bit easier to me than "bit bashing" things out on the I2C bus.

It also allows easy set up of inputs and outputs.

So at this point in time, it seems the easier way to do it.

As to writing "real code" well, for now I shall leave that to the experts and not take that sort of stuff on.
Writing the code/s I need is difficult enough.

I have two projects on the go now and there are more in the system to be born.

So:  With the new information that if I disconnect the I2C bus I lose one of the devices, but I can't seem to get the pins going high.

Next idea?

Grumpy_Mike

Sure it is simple, it simply does not work. Because the address is hidden if you don't wire it up exactly like the libary is expecting then it won't work.
So you need to find out what the libary is expecting the external address lines to be and wire it up like that.

lost_and_confused

It (the library) is expecting the MCP to be at 20 hex.

So the device found at 27Hex is the MCP - and is the address I lost when I unplugged the MCP.

Thinking a bit, each MCP device is 0 - 15, 16 - 31, and so on.

So device 7 would be.......

(7 * 16) = .......
112?
So if I change the code to write to 112 and on, I may see outputs.

Ofcourse the question is why I was told to tie the address lines HIGH to make it address 0.
(Rhetorical in ways)
But no love lost.

All part of the learning curve.

And it is slightly flattening out for me now.



majenko

Who told you to tie the address lines high for address 0? In my post I said low for address 0 and tie reset high. Why did you tie address lines high???

lost_and_confused

Marjenko,

Sorry mate.  I misunderstood.

No harm.

The MCP seems to work.

I moved all the address lines to LOW and ran the I2C program and found the device had moved to 20 (Hex).

So that is good.

Alas, the bad news is that it still doesn't respond.

I can get the pins to go high now and then, but more out of "luck" than forcing them high.

I guess the next step is to check the supply smoothness and the I2C bus itself.

majenko

Have you tried using the Adafruit library?

https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library

It has an output example (toggle) - try it.

lost_and_confused

And sorry for the mis-spelling of your name.

Thanks.

Downloaded.

Shall look into it.

The centipede library is pretty well the same deal though.

But shall report back with developments.

AWOL

@Krodal:
Quote
Don't use ribbon cable for I2C and use two 100nF for the 7805. Every test will be useless until you have this right. I'm serious!
By using a ribbon cable you create some kind of twisted pair for the I2C-bus. The SCL and SDA lines can't handle that. Use two seperate wires.


Can you explain what you mean, please?
I use I2C quite happily over 50cm of ribbon cable carrying signals and power for four sonar modules.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

lost_and_confused

Majenko,

Ran sketch as given.

Got an error.

toggle:51: error: redefinition of 'Adafruit_MCP23017 mcp'
toggle:14: error: 'Adafruit_MCP23017 mcp' previously declared here
toggle.cpp: In function 'void setup()':
toggle:53: error: redefinition of 'void setup()'
toggle:16: error: 'void setup()' previously defined here
toggle.cpp: In function 'void loop()':
toggle:62: error: redefinition of 'void loop()'
toggle:27: error: 'void loop()' previously defined here


With my limited knowledge, I can't understand the error.

AWOL

Quote
In function 'void setup()':
toggle:53: error: redefinition of 'void setup()'

Big clue.

Can we see the code please?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

majenko

sounds like the sketch is doubled up to me.  It should only be about 34 lines long.

lost_and_confused

Code to follow.


Code: [Select]

#include <Wire.h>
#include "Adafruit_MCP23017.h"

// Basic pin reading and pullup test for the MCP23017 I/O expander
// public domain!

// Connect pin #12 of the expander to Analog 5 (i2c clock)
// Connect pin #13 of the expander to Analog 4 (i2c data)
// Connect pins #15, 16 and 17 of the expander to ground (address selection)
// Connect pin #9 of the expander to 5V (power)
// Connect pin #10 of the expander to ground (common ground)

// Output #0 is on pin 21 so connect an LED or whatever from that to ground

Adafruit_MCP23017 mcp;
 
void setup()
{  

 mcp.begin();      // use default address 0

 mcp.pinMode(0, OUTPUT);
}


// flip the pin #0 up and down

void loop()
{
 delay(100);

 mcp.digitalWrite(0, HIGH);

 delay(100);

 mcp.digitalWrite(0, LOW);
}



I put the .ccp and .h file in the same directory as the file.
Another question:
Why is there not a wire.begin() line to stat the I2C?

Grumpy_Mike

Quote
Alas, the bad news is that it still doesn't respond.
I can get the pins to go high now and then, but more out of "luck" than forcing them high.

Luck has absolutely nothing to do with it. It is down to your code.
You should say that you see and what you expect to see so we can check for a miss match.

Quote
Why is there not a wire.begin() line to stat the I2C?

Because that is in the Adafruit library.

Quote
I put the .ccp and .h file in the same directory as the file.

It sounds like you already have this library installed remove the extra copy from your sketch folder.

lost_and_confused

Done, but still get an error:

toggle:50: error: redefinition of 'Adafruit_MCP23017 mcp'
toggle:14: error: 'Adafruit_MCP23017 mcp' previously declared here
toggle.cpp: In function 'void setup()':
toggle:52: error: redefinition of 'void setup()'
toggle:16: error: 'void setup()' previously defined here
toggle.cpp: In function 'void loop()':
toggle:61: error: redefinition of 'void loop()'
toggle:26: error: 'void loop()' previously defined here

Same sketch.


Go Up