Hi everyone,
I need help regarding the connection of another I2Cparticipant. I hope someone could help me and tell me how the PCA9685 should be connected and with what resistors it should be. And how would i have to extend my code so that the PCA9685 can communicate via I2C?
My circuit is the following (irrelavante such as other sensors removed):
My code for the master (unrelated code removed):
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
//Lenken
#define PWM_FREQUENCY_HZ 60 // Frequency of PWM signals
#define PCA_CHANNEL_SERVO 0 // Board PCA9685: servo channel
#define PWM_SERVO_CENTER 390 // Neutral position in 0..4095
#define PWM_SERVO_MAX_DELTA 120 // Max. +/- deviation from neutral position
// PWM servo driver module
#define PWM_CHANNEL_ESC 1
#define PWM_NEUTRAL 400
#define PWM_DRIVE 415
#define PWM_BACKWARDS 380
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
//Lenken
int minPulse = PWM_SERVO_CENTER - PWM_SERVO_MAX_DELTA;
int maxPulse = PWM_SERVO_CENTER + PWM_SERVO_MAX_DELTA;
char distance_Char[] = "V"
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600);
}
void loop() {
/*pwm.setPWM(PWM_CHANNEL_ESC, 0, PWM_DRIVE)
this doesn't work yet because i'm already using scl and sda to connect both arduinos*/
Serial.println(distance_Char);
Wire.beginTransmission(4); // transmit to device #4
Wire.write(distance_Char); // sends five bytes
Wire.endTransmission(); // stop transmitting
}
My code for the slave (unrelated code removed):
#include <SoftwareSerial.h>
#include <Wire.h>
SoftwareSerial BT(4, 2);
char myChar;
void setup() {
BT.begin(9600); // set the data rate for the SoftwareSerial port
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600);
pinMode(8, OUTPUT);
}
void loop() {
while (BT.available()) {
myChar = BT.read();
if (myChar == 'V') {
Serial.println("Hi")
}
}
}
void receiveEvent(int howMany) {
int charCount = 0;
while (Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
if (c == '#') {
BT.println("Hi");
}
}