0

I'm trying to connect an Arduino Nano with a Raspberry Pi 3 via I²C.

This is the small test-program I found and used for I²C.

#include <Arduino.h>
#include <Wire.h>

void setup() {
  Wire.begin(4);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
}

void loop() {
  delay(100);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
  while (1 < Wire.available()) { // loop through all but the last
    char c = Wire.read(); // receive byte as a character
    Serial.print(c);         // print the character
  }
  int x = Wire.read();    // receive byte as an integer
  Serial.println(x);         // print the integer
}

After compiling and uploading, I ssh-ed into my Pi and executed sudo i2cdetect -y 1 which prints an empty I²C table.

Here are images of how I connected the two devices, as far as I know the connection itself is okay. I also tested the cables with a multimeter.

enter image description here enter image description here enter image description here

Now the strange thing is, when I short-circuit my Arduino for a brief moment between GND and VIN I²C works, but Serial via USB with my PC stops working. Also the chip gets very hot and stays hot even though it isn't short-circuited anymore.

Any ideas what I'm doing wrong? I don't think the Arduinos are broken, since I tested it with 2 different ones. (while testing I accidentally short-circuited one and it worked)

EDIT: I tested I²C between the two Arduinos and it works flawlessly, but still doesn't want to work with my Pi. :(

3

Any ideas what I'm doing wrong?

Apart from deliberately shorting +5V to ground? Sheesh!


Get, or make, a level-shifter. You can't pump 5V from the Nano to the Pi and expect things to work. Example schematic:

Level converter

In this example the low voltage (3.3V) side is marked LV, and the high voltage (5V) side is marked HV.


You can use a level shifter with I²C but you don't need one. The Pi has pullup to 3.3V. Provided there are no other pullup it works. I routinely do this.

The important phrase there is "Provided there are no other pullup".

Wire.begin() enables the pull-ups. So make sure that on the Nano side you disable them again:

  Wire.begin (4);
  // disable internal pullups for twi.
  digitalWrite(SDA, LOW);
  digitalWrite(SCL, LOW);
0

There is not enough information in your question to know for sure, but remember that the rpi is three volt and the arduino is five volt. Given the heat you are seeing you have something miswired.

  • The heat only starts when I intentionally for a short moment connect GND to VIN. Before I do that once I²C doesn't work, afterwards it does, but serial stops working. Also: What kind of information do you need? I can try to get it. – Florian Wendelborn Apr 7 '16 at 0:17
  • @Dodekeract - As hildred says, the Nano is 5V. You would be better off using an Arduino Micro Pro 3V, en lieu of a Nano. – Greenonline Apr 7 '16 at 2:03
  • Yes, but a Nano is what he has to hand. A couple of transistors will be cheaper than a new Arduino. However you can never have too many Arduinos. :) – Nick Gammon Apr 7 '16 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.