1

I connected Raspberry Pi 3 to an Arduino Uno through I2C. The Arduino Uno uses the I2C as slave.

When I connectAM2320 sensor (temperature and humidity) to the Arduino Uno, I am getting the response that the sensor is offline.

I tested the sensor on Raspberry Pi 3 and it is working fine. On the Raspberry Pi the address is 0x5c. On most libraries, the address is 0xb8. I have the same result when I tried these 2 addresses.

Do I have problem because Arduino Uno is working as slave?

dda's user avatar
dda
1,5951 gold badge12 silver badges18 bronze badges
askedJun 17, 2017 at 10:36
Michel Plouffe's user avatar
1
  • Two comments and a request. C1) rPI is powered at 3.3V, while the arduino uno is powered at 5V. What pullup voltage are you using on the I2C lines? Remember that 5V is too much for the rPI, and 3.3V should be not enough for the arduino.... C2) 0x5C and 0xB8 are essentially the same address. I2C have 7bit addresses, while the last bit of the first byte is the read/write one. So the proper address is, in binary, 1011100 (saved as 101 1100, or 0x5C), but arduino saves it with the R/W bit too (1011 1000, or 0xB8, for more easiness). R1) remember to choose an answer if it answers your questionCommentedSep 25, 2017 at 15:56

3 Answers3

1

You can do it. A single device like the Arduino can be both a slave and a master.

It's explained in great detail by Nick Gammon inhttp://www.gammon.com.au/i2c in the paragraphCommunicating with other devices

answeredOct 25, 2017 at 7:16
0

Indeed, I2C slaves cannot communicate with one another.

There are some obscure capabilities for devices to switch role, but that is likely to introduce lots of complications.

You might look at using bit-banged (or "soft") I2C on other digital pins and move the peripheral's I2C lines there instead o the hardware I2C pins connected to the pi. For example, a web search quickly found something that claims to do this at:

https://github.com/felias-fogg/SoftI2CMaster

No idea if that particular one will work for you, but there are others as well.

Or you can re-design your scheme so that the pi reads the sensor, and if necessary writes the values of interest to the Arduino.

answeredJun 17, 2017 at 13:55
Chris Stratton's user avatar
0

I had may be a bad connection but I can read the sensor AM2320 on Arduino-Uno and send the value back to Raspberry Pi.

Arduino side:

#include am2320#define SLAVE_ADDRESS 0x04Wire.begin(SLAVE_ADDRESS);AM2320 th;Wire.write( (int)(th.t * 10)); // th.t is for temperature which I send integer

Raspberry side:

import smbusbus = smbus.SMBus(1)address = 0x04number = bus.read_byte(address)

Raspberry Pi and Arduino Uno seems to work good together with and I2C sensor on Arduino side. Thanks for you time to help me and I will go to the link you propose.

gre_gor's user avatar
gre_gor
1,6824 gold badges18 silver badges30 bronze badges
answeredJun 24, 2017 at 13:47
user34706's user avatar

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy 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.