raspberrypi / pico-examples

BSD 3-Clause "New" or "Revised" License
2.61k stars 778 forks source link

LCD1602_I2C Example does not work #456

Closed hasenradball closed 5 months ago

hasenradball commented 6 months ago

Hello,

The example LCD1602_i2c does not work with the i2c1 instance. I changed the I2C instance to:

//PICO_DEFAULT_I2C_INSTANCE
#ifdef PICO_DEFAULT_I2C
#undef PICO_DEFAULT_I2C
#define PICO_DEFAULT_I2C 1
#endif

#ifdef PICO_DEFAULT_I2C_SDA_PIN
#undef PICO_DEFAULT_I2C_SDA_PIN
#define PICO_DEFAULT_I2C_SDA_PIN 2
#endif

#ifdef PICO_DEFAULT_I2C_SCL_PIN
#undef PICO_DEFAULT_I2C_SCL_PIN
#define PICO_DEFAULT_I2C_SCL_PIN 3
#endif

Does anybody know how to get the I2C Example to work with the ì2c1?

lurch commented 6 months ago

Looks like you need to make sure you change the PICO_DEFAULT_I2C define before you include i2c.h ? (see https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_i2c/include/hardware/i2c.h#L76 )

Also, I believe if you #defined your new values before including any of the pico header-files, then you wouldn't need to #undef them.

hasenradball commented 6 months ago

@lurch Hi,

thanks for the fast reply. Ok this could be the point. I will check this.

by the way a happy new year 😊

hasenradball commented 6 months ago

@lurch I tried your proposal but does not help here. It seems to be tricky to use the i2c1. Is there an official example how to use i2c1?

lurch commented 6 months ago

If you want to explicitly use i2c1, it might be easier to modify the code to explicitly refer to I2C1 and the new pins you're using, rather than trying to hackily override the "defaults" mechanisms?

hasenradball commented 6 months ago

@lurch Thanks for your reply.

This I also tried, but without any success. It seems to me actually, I is only possible to use i2c0 with pins 4 / 5.

So I also wondering about that all examples you find in the net use i2c0 with pins 4 / 5.

lurch commented 6 months ago

See https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html#pinout-and-design-files and be careful that you don't mix up "pin numbers" and "GPIO numbers". Software will always use the GPIO numbers.

hasenradball commented 6 months ago

@lurch I used always GPIO numbers.

hasenradball commented 6 months ago

I just want to switch between these two ports:

image

lurch commented 6 months ago

This is beginning to feel more like a support question, rather than a bug report. Support questions belong in https://forums.raspberrypi.com/

hasenradball commented 6 months ago

@lurch I thik I had to double check this with a new Pico.

peterharperuk commented 5 months ago

@hasenradball any chance you could tell me what components you're using to test this? Thanks.

hasenradball commented 5 months ago

Hi Peter,

I had doupt that my pico works fine, I am waiting for my new layoutet pico dev board. then I will test again. Then I will give some feedback.

Frank

hasenradball commented 5 months ago

@peterharperuk Hi Peter what about the issue of the dht Sensor? I was wonderin why you don‘ t merged my proposal into develop due to the fact it works, against the actual example don‘ t.

Frank

peterharperuk commented 5 months ago

Yes. It'll get merged soon. It just needs me to test it again

hasenradball commented 5 months ago

@peterharperuk are these boards not lovely?

image

peterharperuk commented 5 months ago

I finally found a display to test this and it works fine on i2c1. I have pushed a fix that might make it a bit easier to change. The code is pretty bad - it would be nice to fix that sometime and get it to work with more modern devices.

P.S. The boards look very nice. What do they do?

lurch commented 5 months ago

The code is pretty bad

IIRC it was written by an intern, and everyone was so busy that no-one had the time to polish it.

hasenradball commented 5 months ago

@peterharperuk the board can take a pico or picoW. You can directly plug it onto the 40 pin on the pi, use the CSDK and directly program and flasch the pico. Additionally you have 3 buttons to use, 3 LEDs, and both I2c interfaces and so on…

hasenradball commented 5 months ago

@peterharperuk i could not see any change in the examples.

peterharperuk commented 5 months ago

I was referring to this commit https://github.com/peterharperuk/pico-examples/commit/3faa5f4a83de616c53d87767d41fff478ffaeeee

lurch commented 5 months ago

I was referring to this commit peterharperuk@3faa5f4

That commit bypasses the "default pins" mechanism, which I guess means that it "breaks" that example for anybody using a board that redefines I2C onto a different set of pins? e.g. https://github.com/raspberrypi/pico-sdk/blob/master/src/boards/include/boards/sparkfun_thingplus.h#L46

peterharperuk commented 5 months ago

It was just for testing so I could close this issue

hasenradball commented 5 months ago

@peterharperuk @lurch Hi guys I could test now the LCD_1602 example with a new Pico. I wrote a object oriented example to easiliy swith between i2c0 and i2c1. It works now fine so the issue was located in damaged Pico. Here connected to GPIO 2 and GPIO3

grafik

So issue could be closed. Sorry for miss leading.

PS: why don't you use more object oriented examples, this would be much easier to adapt like in this to switch from i2c0 to i2c1.

Best regards frank

hasenradball commented 5 months ago

I finally found a display to test this and it works fine on i2c1. I have pushed a fix that might make it a bit easier to change. The code is pretty bad - it would be nice to fix that sometime and get it to work with more modern devices.

P.S. The boards look very nice. What do they do?

Why don't you pushed the fix on the develop branch? It seems to me it takes very long time if the examples (develop/master) branch are updated, isn't it?

Best regards

Frank

peterharperuk commented 5 months ago

It's just not the top priority at the moment. We generally push as many changes as we can before making an sdk release. So it'll happen then or when it gets to the top of my todo list.

hasenradball commented 5 months ago

@peterharperuk understood, thanks for the update. nice evening and weekend.