blemasle / arduino-mcp23017

Complete support of MCP23017
MIT License
71 stars 40 forks source link

Possible to use TwoWire as software I2C #7

Closed ScholliYT closed 4 years ago

ScholliYT commented 5 years ago

Can you give an example on how to use your lib with software i2c? In my project I got the i2c blocked for other parts and want to use your lib to controll a mcp23017. I'm using an ESP32 Dev Board.

https://github.com/blemasle/arduino-mcp23017/blob/346e14d2a55895da7a3a7337cceda7fe336ccc1c/src/MCP23017.cpp#L3

blemasle commented 5 years ago

Hi @ScholliYT I never used SotwareI2C myself, but the tutorial at http://wiki.seeedstudio.com/Arduino_Software_I2C_user_guide/ should get you started.

Then simply pass your instance in the constructor. So my guess would be :

#include "SoftwareI2C.h"

SoftwareI2C softwarei2c;
MCP23017 mcp = MCP23017(0x24, softwarei2c);

void setup()
{
    softwarei2c.begin(3, 2);       // sda, scl
}
ScholliYT commented 5 years ago

Thank you 👍 I've got my problem fixed without software serial but I will try it out anyway.

blemasle commented 5 years ago

Hi @ScholliYT . Have you had the opportunity to test the library with SoftwareI2C yet ?

ScholliYT commented 5 years ago

Nope, sorry. Didn't have any time to test it. But it's still on my ToDo-List. Maybe you can give it a try yourself.

blemasle commented 5 years ago

I moved home recently and I haven't had the opportunity to do some devs/electronics since then. No rush though :)

Thanks

SukkoPera commented 4 years ago

Unfortunately this nice feature of this library cannot be used at the moment, due to a shortcoming of the original Wire.h library.

I have opened this issue on a Software I2C library to detail the exact issue, so please see there.

There is already an open issue on the Arduino Core. Everybody who is interested in this please add a thumbs up there.

blemasle commented 4 years ago

Arf, that's a shame ! This as s kinda strange cause I didn't came with this idea out of the blue of course. I actually took it from another library, but I can't remember which one.

I'm not sure, but wouldn't a templated version of the library solve this issue ?

SukkoPera commented 4 years ago

I've also realized it could be made to work using a template, but I see it more as a workaround rather than the proper solution.

So I would first try to get this solved in Wire.h by voting and commenting the issue I've linked above. Then, if we get nowhere with that, we can switch to a template. For my own needs, I have temporarily modified this library so that it uses that software implementation, and I can live with that for a while.

Beerlesklopfer commented 4 years ago

Wooldn‘t it be nice being more general. The chip also has a SPI interface in the mcp23S17 version. When we think about software serial there could be also the hardware and software SPI option too; either in different constructors or a special class.

SukkoPera commented 4 years ago

That could be interesting, but I think it should be filed as a different Feature Request. At the moment this is a library for the i2c version of the chip, you are asking to turn it into one for both the i2c and SPI versions. It's also quite a bit of work, actually :).

Beerlesklopfer commented 4 years ago

Sure, but if we talk about concepts, we should have that in focus...

blemasle commented 4 years ago

Until ArduinoCore API #31 is solved, nothing can be done here. A templated class isn't a solution either cause Arduino C++ does not support type constraints based on concepts.

Feel free to reopen the day something new has occured about this :)