I was hoping to hear if anyone else has experienced any issues getting the I2C to work on an Arduino Mega R3? And if they have, how have they overcome it?
I’ve got a Sparkfun Qwiic Connect Shield sitting on top of a brand new Arduino Mega R3 (Arduino branded) and i’m connecting a Spark fun I2C sensor via the Qwiic cable. It is essentially a plug and play system. When i go to run an I2C scanner code, i’m getting nothing return. The Baud rate is set correctly in the serial monitor to match the code also. The slave device address should be returning a vale of 0x69. The code comes from How to Scan I2C Address in Arduino - Arduino Project Hub
I’ve also checked my solder joints on the Qwiic shield and I’ve got continuity between my pins and the board.
Does anybody have any suggestions or is there something i’m missing?
Is this a MEGA shield or a UNO shield? The sparkfun site doesn’t seem to have any MEGA shields, so if you are usig a UNO shield it won’t break out the pins for I2C on a Mega board, and the I2C header will be wired to the UNO I2C pins, not the Mega pins… You should be use D20 and D21 for I2c on the Mega.
So the MEGA has 2 sets of I2C pins on it. You are correct with the pins D20 and D21. However, there is also a set up the top of the board in the same place as the UNO. These are ladled on the MEGA as SCL1 and SDA1. So the UNO shield should still work regardless when connected to the MEGA due to the double up. Hopefully this image pastes below, otherwise I’ll put a link to the board layout as well.
You can use almost any pair of pins for I2C. If you want to use the SCL1 and SDA1 then you need to adjust the code you are using so that it knows you are not referring to the default pins So it’s not plug and play - the code must be modified for the change in pin numbering between the UNO and MEGA. Is the code you are using referring to the correct set of pins?
I have examined the web site information for both boards.
The Sparkfun Qwiic Connect Shield is designed for a UNO, which has I2C on pins A4 & A5.
The Sparkfun web site shows it working connected to a UNO.
The schematic shows pins A4 & A5 connected to 5V to 3V3 level converter Mosfets and then to the Qwiic connectors. There is no connection to D20 & D21 of the Mega. The SDA & SCL pin labels on the Shield are NOT connected to A4 & A5 and should not be. If I had a board in front of me I could confirm this with a multimeter.
So to use the Sparkfun Qwiic Connect Shield with the Mega you would need to use A4 & A5 as the I2C interface in your program, not D20 & D21.
Maybe I am wrong here, I only have web pics to go off. But I’d see how it went changing the pins in the program.
You are on the money.
So naive me thought that if the pins on the shield were labled they they might be connected. Agter looking at the traces on the shield, they weren’t connection to the SCL and SDA pins. So using some jumper cables from A4 and A5 into the labled SCL and SDA terminals on the shield, everything works correctly.
Something maybe worth checking.
The SCL & SDA pins connect to D20 & D21 on the Mega, if I read the pic correctly.
Connecting A4 & A5 to SCL & SDA on the shield means A4 & A5 of the Mega are now connected to D20 & D21 of the Mega.
When the Mega starts the pins are usually in a high impedance state so the connection would not be a problem if A4 & A5 are never used in software.
Personally I would change the software to use A4 & A5. The long term effects of these pins connected is unknown. Probably it would be ok, maybe not.