0

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

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

#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 I2C 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 I2C 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 I2C between the two Arduinos and it works flawlessly, but still doesn't want to work with my Pi. :(

asked Apr 7, 2016 at 0:07

2 Answers 2

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 I2C 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);
answered Apr 7, 2016 at 5:59
9
  • To be fair, I didn't do it intentionally the first time, that was an accident. Then I had to verify my findings. :) Also does it have to be a 2N7000? Commented Apr 7, 2016 at 6:11
  • No it doesn't. Many logic-level N-channel enhancement MOSFETs should do. Read Bi-directional level shifter for I²C-bus and other systems - PDF. And you can buy them on boards, eg. 4-channel I2C-safe Bi-directional Logic Level Converter - BSS138 Commented Apr 7, 2016 at 6:31
  • @Dodekeract 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. Commented Apr 8, 2016 at 1:51
  • @Milliways what am I doing wrong then? I attached the cables on my Pi and on my Arduino. Didn't add any resistors. Commented Apr 8, 2016 at 2:14
  • Edited answer to incorporate this suggestion. Commented Apr 8, 2016 at 2:18
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.

answered Apr 7, 2016 at 0:13
3
  • 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. Commented Apr 7, 2016 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. Commented Apr 7, 2016 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. :) Commented Apr 7, 2016 at 7:02

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.