Go Down

Topic: New MCP23017 library! (Read 4 times) previous topic - next topic

ICEMAN

Hi,
First , sorry for my English, is not my native Language

Can you put some examples for initialitation with this library ¿?

Thanks

David Pye

MCP23017 buttonMux(0x00); // Assuming the three address pins are all 0
buttonMux.init();

You can use the arduino like syntax of:
buttonMux.pinMode(0,  INPUT);
int result = buttonMux.digitalRead(0);

//result now contains the state of pin number 1.

to set pins one at a time.  Alternatively, there are functions more like the options in the MCP23017 data sheet.

Have a look at the .h file - it explains each of the functions.  There are ones that function like arduino ones - pinMode, digitalRead, digitalRead if you want to work on individual pins, or there are functions to let you read words rather than pins one at a time - up to you!

David

ICEMAN


WanaGo

#8
Dec 03, 2010, 04:52 am Last Edit: Dec 03, 2010, 04:54 am by WanaGo Reason: 1
Hi

I have had this working, however now I am getting the following errors on compile and I am not sure why.
The library is the same, I am running IDE 21.

Code: [Select]
C: \arduino-0021\libraries\MCP23017\MCP23017.cpp: In member function 'void MCP23017::writeRegister(int, word)':
C:\ arduino-0021\libraries\MCP23017\MCP23017.cpp:107: error: call of overloaded 'send(word)' is ambiguous
C:\ arduino-0021\libraries\Wire/Wire.h:54: note: candidates are: void TwoWire::send(uint8_t)
C:\ arduino-0021\libraries\Wire/Wire.h:56: note:                 void TwoWire::send(int)
C:\ arduino-0021\libraries\Wire/Wire.h:57: note:                 void TwoWire::send(char*) <near match>
C:\ arduino-0021\libraries\MCP23017\MCP23017.cpp:108: error: call of overloaded 'send(unsigned int)' is ambiguous
C:\ arduino-0021\libraries\Wire/Wire.h:54: note: candidates are: void TwoWire::send(uint8_t)
C:\ arduino-0021\libraries\Wire/Wire.h:56: note:                 void TwoWire::send(int)
C:\ arduino-0021\libraries\Wire/Wire.h:57: note:                 void TwoWire::send(char*) <near match>


I dont understand the problem really. It appears it is saying the library cannot send a word, however the library clearly is converting the word into bytes before sending it - so I dont understand.
Also I am not sure what has changed either.

I started a new project with the following code, and still got the above errors.
Any ideas?

Code: [Select]
#include <Wire.h>
#include <MCP23017.h>

void setup()
{
 
}
void loop()
{

}


Most likely its just me doing something stupid, but I dont see what I could have done to cause this.

Cheers
James

PaulS

I'm not sure why you can't understand what the message is telling you, so I'll break it down.

Quote
C: \arduino-0021\libraries\MCP23017\MCP23017.cpp: In member function 'void MCP23017::writeRegister(int, word)':


The first part is the name of the file that was being compiled, in which an error occurred.

Next is some information about where the error occurred. In this case, it is in the writeRegister function that takes two arguments - an int and a word.


Quote
C:\ arduino-0021\libraries\MCP23017\MCP23017.cpp:107: error: call of overloaded 'send(word)' is ambiguous


In the writeRegister function, it calls send() with an argument of type word. In the class associated with the send() function, there are two or more overloads that might be the function to call, but none of them EXPLICITLY take a word. So, an implicit cast will need to be performed, and the compiler does not know which one it should select. At this point, we don't (you might, but we don't) know what that class is, or what the possible overloads are.

Quote
C:\ arduino-0021\libraries\Wire/Wire.h:54: note: candidates are: void TwoWire::send(uint8_t)
C:\ arduino-0021\libraries\Wire/Wire.h:56: note:                 void TwoWire::send(int)
C:\ arduino-0021\libraries\Wire/Wire.h:57: note:                 void TwoWire::send(char*) <near match>

OK. Now we know what class send() belongs to, and what the "best" overloads are.

From http://arduino.cc/en/Reference/Word, we see that
Quote
A word stores a 16-bit unsigned number, from 0 to 65535. Same as an unsigned int.

So, one would really wonder why MCP23017 needs to adopt the bastardization that Microsoft came up with. What is wrong with the explicit type unsigned int? The explicitly defines what type value we are dealing with, while word attempts to hide that knowledge. Why?

And, how does this help you?

Well, that depends on what you are trying to do. If you just want to understand the message, by now you should.

If you want to solve the problem, you need to either fix the Wire library so that it has a send method that takes an unsigned int argument, and correctly processes it.

Or, you need to revise the MCP23017 library (specifically, the writeRegister() method) so that it converts or casts the value that it has to a type for which there is an existing send() method in the Wire class.

Which would be easiest or most appropriate is not for us to say.

Go Up