Dabble-controlled ESP32 doesn't move servo

Continuing the discussion from DabbleESP32 library compilation failure: "'ledcAttachPin' was not declared in this scope":

My dabble app on my phone connects to the esp32 but dosent move the servos at all iv check wiring power supplies changed position of servo ect but it dosnt seem to help any bright idea's?

Hi @jorvikk. Please post your full sketch.

I'll provide instructions you can follow to do that:

  1. Select Tools > Auto Format from the Arduino IDE menus.
    ⓘ This is done to make the code easier for us to read.
  2. Select Edit > Copy for Forum (Markdown) from the Arduino IDE menus.
  3. Open a reply here on this forum topic by clicking the "Reply" button.
  4. Press the Ctrl+V keyboard shortcut (Command+V for macOS users).
    This will paste the sketch to the post composer.
  5. Move the cursor outside of the code block markup before you add any additional text to your reply.
  6. Repeat the above process if your sketch has multiple tabs.
  7. Click the "Reply" button to publish the post.

I have deleted your other post on the same subject @jorvikk.

Please use this forum topic for all further discussion on the problem you are encountering with controlling a servo using Dabble.

Someone is already trying to help you here, so why don't you provide the information they requested instead of wasting time creating duplicate topics???

sorry was a bit confused shall do

#define CUSTOM_SETTINGS
#define INCLUDE_GAMEPAD_MODULE
#include <DabbleESP32.h>
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

// Initialize PCA9685 (Default I2C address is 0x40)
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

// Servo pulse length constants (adjust based on your servo datasheet)
#define SERVOMIN 150   // Minimum pulse length count (out of 4096)
#define SERVOMAX 600   // Maximum pulse length count (out of 4096)
#define SERVO_FREQ 50  // Analog servos run at ~50 Hz

void setup() {
  Serial.begin(115200);

  // Initialize BLE and name your device
  Dabble.begin("ESP32_Servo_Controller");

  // Initialize PCA9685
  pwm.begin();
  pwm.setOscillatorFrequency(27000000);
  pwm.setPWMFreq(SERVO_FREQ);

  delay(10);
}

void loop() {
  Dabble.processInput();  // Refresh BLE data from phone

  // Control Servo 0 (Port 0) with Triangle Button
  if (GamePad.isTrianglePressed()) {
    pwm.setPWM(0, 0, SERVOMAX);  // Move to 180 degrees
  } else {
    pwm.setPWM(0, 0, SERVOMIN);  // Return to 0 degrees
  }

  // Control Servo 1 (Port 1) with Circle Button
  if (GamePad.isCirclePressed()) {
    pwm.setPWM(1, 0, SERVOMAX);
  } else {
    pwm.setPWM(1, 0, SERVOMIN);
  }

  // Control Servo 2 (Port 2) with Cross Button
  if (GamePad.isCrossPressed()) {
    pwm.setPWM(2, 0, SERVOMAX);
  } else {
    pwm.setPWM(2, 0, SERVOMIN);
  }

  // Control Servo 3 (Port 3) with Square Button
  if (GamePad.isSquarePressed()) {
    pwm.setPWM(3, 0, SERVOMAX);
  } else {
    pwm.setPWM(3, 0, SERVOMIN);
  }

  // Control Servo 4 (Port 4) with Select Button
  if (GamePad.isSelectPressed()) {
    pwm.setPWM(4, 0, SERVOMAX);
  } else {
    pwm.setPWM(4, 0, SERVOMIN);
  }
}

hope this is what you need

Verify the ESP32 can control the servo without the BT/wifi connection.

Use external power for the servo, like this (from esp32io.com):

#include <ESP32Servo.h>
#define servopin 26
int angle, direction = -1;

Servo servoMotor;

void setup() {
  // Serial.begin(115200);
  servoMotor.attach(servopin);
}

void loop() {
  if (angle <= 0 || angle >= 180) // if outside bounds...
    direction = -direction; // ... change direction
  angle += direction; // increment/decrement
  servoMotor.write(angle); // write angle to servo
  delay(10); // wait for servo
  // Serial.println(angle);
}

C:\Users\jorvi\AppData\Local\Temp.arduinoIDE-unsaved2026731-10436-1mt84li.4jo7\sketch_aug31a\sketch_aug31a.ino:2:10: fatal error: ESP32Servo.h: No such file or directory
2 | #include <ESP32Servo.h>
| ^~~~~~~~~~~~~~
compilation terminated.
exit status 1

Compilation error: ESP32Servo.h: No such file or directory

this is what came up when I tried it

In your IDE, click the LIBRARY icon, enter "esp32servo" in the search bar, select "Kevin Harrington" library... After it is installed, compile the test sketch. Please, verify you are supplying power to the servo (VCC and GND) with an external power supply, and the ground pins are connected from ESP to Servo to Power Supply)

(sorry for my previous post... which I deleted)

hi I have done that and yes my esp32 operates the servo. what do I do next

Very good.

Next:

  • what is sent by the sender (Dabble)? A value? A character?
  • what is the ESP32 receiver expecting? A value? A character?

Would you describe how the system works, from power-on to servo movement?

so dabble is using a game control layout. Using diamond, circle,ex,square & select buttons to move servo's. my phone has the dabble control it connects to the esp32 via bluetooth no problems but dosent make the servos move when appropriate buttons are pressed

So, the app on your phone is supposed to send the information that a "Dabble" does?

Can you send the ESP32 incoming bluetooth to the Serial Monitor?

well yes that is what the app is supposed to do.
Im not sure what your asking in the second part of your question

(sorry, I fatfingered the delete button and the Discourse will not let me undelete)

The ESP blootooth must receive the correct commands to make the servo move. The question is: is the phone sending the correct commands?

The ESP32 code will show what commands it is waiting to receive.

The phone app is not accessible.

You need to "send" all the commands from the phone and use a general bluetooth sketch in the ESP32 to receive everything the phone sends.

After you trap those commands in the ESP32, you transfer the sent commands into the ESP32+servo system to move the servo.

Look up any generice "send from phone bluetooth to ESP32 bluetooth" sketch to accomplish this.

For example:

ok Im not really sure how to do that im not feeling very smart at the moment.
Can you possible step by step it or really dumb it down for me thanks

Follow that example link and see if you can "talk" from phone to ESP and back.

Im not sure followed the link but my ide dosnt have the bluetooth example his did Im not sure if the app is dodgy or just my code im at a bit of a loss at the moment.

ok finaly ran test but to no avail not sure what do do next wondering if its my code:

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;

void setup() {
  Serial.begin(115200);
  SerialBT.begin("ESP32test");  //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");
}

void loop() {
  if (Serial.available()) {
    SerialBT.write(Serial.read());
  }
  if (SerialBT.available()) {
    Serial.write(SerialBT.read());
  }
  delay(20);
}

Can you describe how this sketch is not working?

Referring to the previous post with a link to a tutorial... let's "check some boxes."

  • are you using an Android smartphone?
  • did you downolad, install, start and use the Android app for serial communication?