I2C-Bus Slave writing on own Register

Hey I'm Tom,

my Situation is is the following:

I have Data on an Arduino NANO (Slave) which needs to be transfered over to my Raspberry PI (Master)via I2C-Bus... so far so good.

I want to use the I2C-registers for that.
Writing on other Registers from the Arduino is no Problem, reading Registers from the Raspberry PI neither.

But from what I understood I need to write on the I2C-Registers from the Arduino itsself, to read them out from the Raspberry. But after now many hours of searching I still don't know if this is even possible.
Continuing I am thinking that if I read out a Sensor like MPU6050 via I2C, I read the direct Registers, so the MPU needs to be writing on the own Registers too.

On the Arduino I'm curently using the Wire.h library.

Mabee some of you have experience with this.

Greetings

Hi, welcome to the forum.

Can you do your project in a different way ?
The I2C bus is not a good bus between processors or between boards.

Do you have a classic Arduino Nano ? That is a 5V board, and it has a 5V I2C bus (SDA and SCL change between 0V and 5V). The Raspberry Pi has a 3.3V I2C bus. Do you use a I2C level shifter ?

How long are the wires for the I2C bus ? If you use a cable, what kind of cable is it ?

A sensors has registers. An Arduino board in I2C Slave mode (also called "Target" mode) does not have such registers. You can write code to make something similar to the registers of a sensor.
However, in most cases a certain package of data is defined, which is transferred over the I2C bus, without "registers".

Can you show the code for both the Nano and the Raspberry Pi ?

If you use a USB cable and connect the Arduino Nano to a USB port on the Raspberry Pi, then you have a Serial/UART connection. There is also no conflict with voltage levels.

Thanks,

so later the to boards should go on a PCB-Board and I planed to also use it for the data transfer. Right now the cables are just jumpers.

Aside from that I use a level shifter, yes... but thank you anyways

I also thought about UART, but an I2C-Bus for sensors so I wanted to combine both.

I would also love to show you some code but I only have many small Programms in which I tried it out. So there is nothing to really see.

I will then probably put all of my data in one Array and send the whole.

Except you say its possible to code the registers, with low effort of time.

A single block of data is easier than writing code to behave like the registers of sensors.

The buffer in the Wire library for sending and receiving is 32 bytes.
That means that your array can have a maximum of 16 integers (of 2 bytes each).

Suppose that your sensors update the array and the array is read via the I2C bus.
If there is a bug in the sketch or a sensor is disconnected and the array is no longer updated, how do you know in the Raspberry Pi how old the sensor data is ? I could be from weeks ago.

ehm yes the Arduino recieves Data via CAN-Bus and this data needs to go to the Raspberry. The Sensors on the I2C can be direcly read out by the Raspberry.

And I can make a loop that waits for a new Message via CAN, which then writes the Information to the Array and sends it.

Do you have other Suggestions, except from using UART?

There are USB to Can adapters. Then you have something that works.

okay thank you, but the CAN-bus is working great...

have a nice day

Topic moved; please read the sticky topics in Uncategorized - Arduino Forum to understand why.

Raspberry Pi + CAN hat (or USB-can) + MPU6050 :arrow_right: Working :smiley:

Raspberry Pi + I2C bus + Level shifter + Arduino + CAN interface + MPU6050 :arrow_right: It is not a guaranteed fail, but it is close :face_with_spiral_eyes:

oh I love a challange, but thanks anyways

Also it would be sad because all of the other stuff ist finished.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.