I am building an airplane. As a controller I am using a Raspberry pi 4. There are 3 sensors (MPU6050, QMC5883L, BME280) and arduino pro mini connected to the raspberry via i2c. When sending requests to the arduino it pulls the bus to 0 and shuts down(?).
First screenshot. On the first search for all devices on the bus, the arduino responds and shuts down, but does not pull the bus to 0. On the second search It responds and pulls the bus to 0.
Second screenshot. Rebooting the arduino, the SDA line goes up. Repeated runs of the search leads to what is shown in the first screenshot.
Third screenshot. The arduino generates a PWM signal that is interrupted after a request to i2c.
As a test request I use the i2cdetect command on the Raspberry. Raspberry is connected to the sensor bus through a level converter, because the level of signals from Raspberry is 3.3V, and sensors accept 5 volt logic.
There is no bus pull-up to the upper level, it is on the schematic of all sensors used (will it be enough?).
The arduino has a simple slave i2c device code, writing to registers the value arrived and output it to other elements (servo drives, motor controller, stepper motor drivers). The Arduino acts as a port expander because the Raspberry has only 2 buses and too few outputs for all the necessary devices
Why is the bus falling and how can I fix it?
arduino code
#include <Wire.h>
#include <Servo.h>
#include <Stepper.h>
uint16_t servoAngle1 = 90;
uint16_t servoAngle2 = 90;
uint16_t servoAngle3 = 90;
uint16_t servoAngle4 = 90;
bool zoomIn = false;
bool zoomOut = false;
bool focusIn = false;
bool focusOut = false;
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo ESC;
Stepper zoomMotor(100, 2, 4, 7, 8);
Stepper focusMotor(100, 10, 11, 12, 13);
void setup() {
Wire.begin(0x23);
Wire.onReceive(receiveEvent);
servo1.attach(3);
servo2.attach(5);
servo3.attach(6);
servo4.attach(9);
ESC.attach(11, 1000, 2000);
}
void loop() {
servo1.write(servoAngle1);
servo2.write(servoAngle2);
servo3.write(servoAngle3);
servo4.write(servoAngle4);
ESC.write(0);
if (zoomIn) {
zoomMotor.step(100);
zoomIn = false;
}
if (zoomOut) {
zoomMotor.step(-100);
zoomOut = false;
}
if (focusIn) {
focusMotor.step(100);
focusIn = false;
}
if (focusOut) {
focusMotor.step(-100);
focusOut = false;
}
}
void receiveEvent(int howMany) {
if (howMany == 2) {
uint8_t action = Wire.read();
uint8_t value = Wire.read();
if (action == 1) { servoAngle1 = value; }
if (action == 2) { servoAngle2 = value; }
if (action == 3) { servoAngle3 = value; }
if (action == 4) { servoAngle4 = value; }
if (action == 10) {
if (value == 1) { zoomIn = true; }
if (value == 2) { zoomOut = true; }
}
if (action == 11) {
if (value == 1) { focusIn = true; }
if (value == 2) { focusOut = true; }
}
} else {
while (true) {
Wire.read();
}
}
}