I2C Slave <-> Slave communication

Hi,
I've set up a "network" of one Mega2560 acting as I2C master, a nano and a ADS1115 DAC.
My goal is to send the values from the DAC to the Arduino nano.
Using this example code ( Arduino Code | Adafruit 4-Channel ADC Breakouts | Adafruit Learning System ), without the mega connected, everything works fine. As soon as I connect the mega, which is set up as I2C host, the nano hangs and I don't receive any values anymore.

I hope you get the problem I'm facing. Making the nano master is not an option.

Thanks
best regards
Axel

It sounds like you have all three devices connected via I2C. In your first test, Nano as master and DAC as slave, it works. When you connected the Mega as master, you must then turn the Nano into a slave as you cannot have two masters. If you want the Mega as master then the other devices must be slaves. You will have to get the Mega to query the DAC for data then send it to the Nano as slave. The Nano will need an I2C address of it's own. What values are you getting from a DAC? It's usually the other way around.

Here are some details.

Thanks for the reply.
Sorry it's an ADC, not DAC :-[

Okay I see how it's supposed to work, but I've actually no idea how to send a query with the Mega and read the response with the nano, I'm quite new to I2C :cold_sweat:

Thanks

Are you saying that the Nano collects the ADC data then the Mega gets it from the Nano?

This tutorial will help.

No. I need to receive the data from the ADC with the nano, but the mega has to be I2C master, since I need the mega for some other applications.
I' had partial success with the Mega (master) receiving values from the ADC and simply relaying it to nano.
However, this option causes a huge ping in the Ethernet Shield which is installed on the mega, very strange.
So if there is an option to send the data from the ADC to the nano without relaying it, I'd highly appreciate it.

Best regards

I have heard of a new library called Soft-I2C, or a similar spelling, which can use any two pins. There may be a way of getting the ADC data into the Nano( as soft master ) via Soft-I2C then relaying to Mega as hardware slave. Would that solve your problem?

That might actually work :slight_smile:
I'll have to re-solder some wires, but that's doable,
Thanks, I'll have a look at.

Here is the link to the SoftI2C description and library. The only question is if the Nano can be a hardware slave and a software master at the same time.

The only problem right now is that I'm using the Adafruit_ADS1015 library to communicate with the ADC, but it uses the hardware-I2C, I can't tell the library to use the software I2C. Why does is always has to be that complicated :confused:

The ADC may not know the difference if you connect it's I2C pins to the Nano's SoftI2C pins. The Nano's hard pins will go to the Mega's hard pins. Never tried anything like that but give it a shot. The Nano will have the two onRequest() and onReceive() functions for sending/receiving data to/from the Mega.

Arctic_Eddie:
The ADC may not know the difference if you connect it's I2C pins to the Nano's SoftI2C pins. The Nano's hard pins will go to the Mega's hard pins. Never tried anything like that but give it a shot. The Nano will have the two onRequest() and onReceive() functions for sending/receiving data to/from the Mega.

I guess it will work, but I don't know how to use the Soft I2C pins with the Adafruit_ADS1015.h library which "connects" the the ADC =/

Note: I've opened a new threat, since the topic changed quite a bit...

That will be a problem as the library commands are aimed at the hardware pins. You might be able to use lower level commands and aim at the ADC registers. One thing to try is including and initiating only the soft version. The ADC library might not know the difference. Read the description at the link I posted as it might give some clues.

PS
Connect the ADC to the Nano and try the soft version only.

Another idea, use hardware I2C between Nano and ADC and between Mega and your other devices. Now set up a softserial link between Mega and Nano. It's not that fast but you can select almost any pin pair.

PS
For I2C, the Nano would need both hard and soft I2C and probably not work. The softserial looks like the best option now.

"Solved" it by using a serial connection between the mega and nano. So easy that I didn't think of it :slight_smile:

That's great and good luck on the rest of your project.