I am giving joystick inputs to an an arduino mega and i am then giving those inputs to an arduino uno r3 through i2c. From the arduino uno i am controlling a PCA9685 motor driver with four servos. I am giving the arduinos 5V and the PCA 5V but the power going to the PCA is outputting 2V instead of 5V. When i input joytick commands the voltage going to the PCA immediately drops to 2V.
#include <Wire.h>
int joy1XPin = A0; // Joystick 1 X-axis pin
int joy1YPin = A1; // Joystick 1 Y-axis pin
int joy2XPin = A2; // Joystick 2 X-axis pin
int joy2YPin = A3; // Joystick 2 Y-axis pin
int joy1XVal, joy1YVal, joy2XVal, joy2YVal;
void setup() {
Serial.begin(9600);
Wire.begin(); // Join I2C bus as master
}
void loop() {
// Read joystick values for Joystick 1 and Joystick 2
joy1XVal = analogRead(joy1XPin); // Read X-axis of Joystick 1
joy1YVal = analogRead(joy1YPin); // Read Y-axis of Joystick 1
joy2XVal = analogRead(joy2XPin); // Read X-axis of Joystick 2
joy2YVal = analogRead(joy2YPin); // Read Y-axis of Joystick 2
// Print joystick values to the serial monitor (for debugging)
Serial.print("Joy1 X: ");
Serial.print(joy1XVal);
Serial.print(" Joy1 Y: ");
Serial.print(joy1YVal);
Serial.print(" Joy2 X: ");
Serial.print(joy2XVal);
Serial.print(" Joy2 Y: ");
Serial.println(joy2YVal);
// Send joystick values to slave (Arduino Uno) over I2C
Wire.beginTransmission(8); // Begin transmission to slave with address 8
Wire.write((joy1XVal >> 8) & 0xFF); // Send high byte of Joystick 1 X value
Wire.write(joy1XVal & 0xFF); // Send low byte of Joystick 1 X value
Wire.write((joy1YVal >> 8) & 0xFF); // Send high byte of Joystick 1 Y value
Wire.write(joy1YVal & 0xFF); // Send low byte of Joystick 1 Y value
Wire.write((joy2XVal >> 8) & 0xFF); // Send high byte of Joystick 2 X value
Wire.write(joy2XVal & 0xFF); // Send low byte of Joystick 2 X value
Wire.write((joy2YVal >> 8) & 0xFF); // Send high byte of Joystick 2 Y value
Wire.write(joy2YVal & 0xFF); // Send low byte of Joystick 2 Y value
Wire.endTransmission(); // End transmission
delay(50); // Delay for joystick readings and smoother transmission
}
Slave (Arduino Uno R3)
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); // Create PCA9685 object
int joy1XVal, joy1YVal, joy2XVal, joy2YVal;
// Define the deadzone size (e.g., ±100 units from center)
const int deadzone = 100;
const int centerValue = 512;
void setup() {
Serial.begin(9600);
Wire.begin(8); // Join I2C bus as slave with address 8
Wire.onRequest(requestEvent); // Called when master requests data
Wire.onReceive(receiveEvent); // Called when data is received
pwm.begin(); // Initialize the PCA9685 module
pwm.setPWMFreq(60); // Set PWM frequency to 60Hz for servos
}
void loop() {
// Map joystick values to servo positions for Joystick 1 (X and Y axes)
int servo1Pos = map(joy1XVal, 0, 1023, 500, 2500); // Map joystick 1 X-axis to servo 1 (PWM range: 500 to 2500)
int servo2Pos = map(joy1YVal, 0, 1023, 500, 2500); // Map joystick 1 Y-axis to servo 2 (PWM range: 500 to 2500)
// Map joystick values to servo positions for Joystick 2 (X and Y axes)
int servo3Pos = map(joy2XVal, 0, 1023, 500, 2500); // Map joystick 2 X-axis to servo 3
int servo4Pos = map(joy2YVal, 0, 1023, 500, 2500); // Map joystick 2 Y-axis to servo 4
// Apply deadzone logic for joystick 1 X and Y values
if (abs(joy1XVal - centerValue) < deadzone) {
servo1Pos = 1500; // Set servo 1 to center position if within deadzone
}
if (abs(joy1YVal - centerValue) < deadzone) {
servo2Pos = 1500; // Set servo 2 to center position if within deadzone
}
// Apply deadzone logic for joystick 2 X and Y values
if (abs(joy2XVal - centerValue) < deadzone) {
servo3Pos = 1500; // Set servo 3 to center position if within deadzone
}
if (abs(joy2YVal - centerValue) < deadzone) {
servo4Pos = 1500; // Set servo 4 to center position if within deadzone
}
// Control servos on channels 0 to 3 using the Adafruit_PWMServoDriver
pwm.writeMicroseconds(0, servo1Pos); // Control servo 1 (Joystick 1 X-axis)
pwm.writeMicroseconds(1, servo2Pos); // Control servo 2 (Joystick 1 Y-axis)
pwm.writeMicroseconds(2, servo3Pos); // Control servo 3 (Joystick 2 X-axis)
pwm.writeMicroseconds(3, servo4Pos); // Control servo 4 (Joystick 2 Y-axis)
delay(50); // Delay for servo adjustment
}
// This function is called when the slave receives data from the master
void receiveEvent(int howMany) {
joy1XVal = (Wire.read() << 8) | Wire.read(); // Receive X value for Joystick 1
joy1YVal = (Wire.read() << 8) | Wire.read(); // Receive Y value for Joystick 1
joy2XVal = (Wire.read() << 8) | Wire.read(); // Receive X value for Joystick 2
joy2YVal = (Wire.read() << 8) | Wire.read(); // Receive Y value for Joystick 2
}
// This function is called when the master requests data from the slave
void requestEvent() {
// You can send data back to the master here if needed
// For now, we won't send anything
}
If you want accurate results fast post an annotated schematic. It appears you have several problems. Here are some hints that may help. Gil's Crispy Critter Rules for Processor Hardware:
Rule #1: An Arduino is NOT a Power Supply!
Rule #2: Never connect anything inductive (motors, speakers) directly to an Arduino!
Rule #3: Avoid connecting or disconnecting wires while the power is on.
Rule #4: Do not apply power to any pin unless you are certain of what you're doing.
Rule #5: Do not exceed the maximum voltage ratings.
Rule #6: Many Arduinos cannot power transmitters directly.
Rule #7: Before powering your project, take a break and double-check the wiring.
Coro #2: Invest in a Digital Multi-Meter (DMM) to measure voltages, currents, and resistance.
Note: Violating these rules can turn your Arduinos into crispy critters. For optimal performance, keep your wires under 25 cm (10 inches).
Additional Tips:
The L293 motor driver, though common, is inefficient as it can lose around 3V as heat when driving both legs of a motor. Consider using a motor driver with MOSFET outputs to reduce heat loss and conserve battery power.
You can spend weeks spinning your wheels, or you might get lucky and solve your problem quickly. To avoid unnecessary delays, itâs crucial to provide an annotated schematic of your circuit as you have it wired, showing all connections, including power, ground, and supplies.
Why Detailed Information Matters:
Annotated Schematics: These are essential because they show exactly how your circuit is set up. Without them, it's difficult for anyone to understand what youâve done, which makes troubleshooting nearly impossible. Fritzing diagrams or unclear pictures are not enough.
Technical Information: Many modules look similar and may even have the same name, but they can function differently. This is why we always ask for links to detailed technical informationânot just sales pages like those on Amazon, which often lack the specifics we need.
Show All Connections: Itâs important to include every connection, especially power and ground, in your schematic. Missing these details makes it hard to determine if a setup issue might be causing your problem.
My Process:
When I see a question, I spend a moment assessing it. If itâs missing critical information, I might ask for it. However, if it's repeatedly lacking important details, I may assume the questioner is not serious and move on to another query.
What You Need to Consider:
We donât know your skill level or what resources you have available. If youâre missing key technical details or seem unprepared, it may indicate that you need to spend more time learning the basics before starting your project.
Providing the right information upfront will help you get the best possible assistance and avoid the frustration of running into dead ends. Let us help you by sharing what you have clearly and completely!
Very likely the servo power supply is completely inadequate. 4.8 to 6V at 1 Ampere per servo for SG-90 servos, and 2.5 Amperes per servo for large ones like the MG996R.
About 95% of all servo problems reported on this forum are due to exactly that.
My money would be a current restriction somewhere. Like perhaps those Dupont cables I see going to the PCA's power terminal. As @jremington pointed out, those four big servos could take up to 10A when first moving. I'd not be the least surprised if those little wires became good resistors when overloaded.
And I also suspect that PCA board is either a very old Adafruit model or a clone. I say this because it appears to have the tiny SOT23 MOSFET that could only handle 4A on it. Adafruit switched to a larger device that could handle 20+A quite some time ago because the little ones tended to burn up when handling more than a few servos. The clone makers, alas, have not caught up.
I wouldn't be surprised if the only thing keeping that SOT23 MOSFET from burning up is the limited current that either your "volt regulators" (whatever they are) or your wiring can supply.
It might be a good idea to file this link away for future reference once you get your current issue sorted out. I imagine you're going to be needing to buy one of these.
I couldn't even begin to speculate. You've told us absolutely nothing about them. If you want informed answers, you're going to have to start providing details.
ăParameteră DROK Power Supply Module input volt range is DC 5.3-32V; Output volt range is DC 1.2-32V which is variable. Output current can reach to 8A and Output Power can reach to 120W for long-time use. If enhance heat dissipation, this converter can reach 12A and 160W output.
ăCharacteristicsă This Buck Converter is equipped with LCD Display, Acrylic Case and Heat Sink. LCD Screen can display input/output voltage, output current and output power. Voltage precision is 0.05V, current precision is 0.005A. Acrylic case can keep the converter board away from dust, which is protective. Heat Sink can keep module 120W for long-time using in a low temperature. If you want to reach maximum power 160W, please improve heat dissipation.
ăEasy Operationă A user manual will be included in package, which can help you easier to operate. The button can control ouput voltage ON/OFF status, and you can set the default output state is ON/OFF for the next time. The potentiometer can help you to adjust volt amp in a simple and fast way.
ăProtectionă It has reverse-connect protection, short circuit protection and over current protection. When you connect the input wire reversely or short circuit, the module will not burn. And roate the CC potentiometer to set over current protection value you want.
ăApplicationă The volt conversion board can be used for 5v 6v 9v 12v 24V 30V 32V 3a 5a 10a devices, like solar panel, lab, experiment, RV, All-Terrain Vehicle, car, battery charger, LED stripes, etc.