Pages: 1 [2] 3 4   Go Down
Author Topic: I2C bus "problems"  (Read 2418 times)
0 Members and 1 Guest are viewing this topic.
Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31541
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Oz
Offline Offline
God Member
*****
Karma: 3
Posts: 659
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31541
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Oz
Offline Offline
God Member
*****
Karma: 3
Posts: 659
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


Logged

UK
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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???
Logged

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

Oz
Offline Offline
God Member
*****
Karma: 3
Posts: 659
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

UK
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you tried using the Adafruit library?

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

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

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

Oz
Offline Offline
God Member
*****
Karma: 3
Posts: 659
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24449
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@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.
Logged

"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.

Oz
Offline Offline
God Member
*****
Karma: 3
Posts: 659
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24449
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Can we see the code please?
Logged

"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.

UK
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

Oz
Offline Offline
God Member
*****
Karma: 3
Posts: 659
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code to follow.


Code:
#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?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31541
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Oz
Offline Offline
God Member
*****
Karma: 3
Posts: 659
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Pages: 1 [2] 3 4   Go Up
Jump to: