Control servos through app trouble

I have a code here meant to control 2 servos through an app by sending serial codes I'm having issues with getting it to work in using aada fruit trinket 3v a hm-10 BT component and 2 linear servos I think I may not have defined the pinouts for the Rx tx I hope this is the issue but if there is anything else i need help figuring it out.

#include   // SoftwareServo (works on non PWM pins)
#include 

#define SERVO0PIN 0 
#define SERVO1PIN 1 

int moveAmount = 1;  // change this value to change speed of servo
int servoPos = 0;  // variable for servo position
const int x=0;
const int y=1;
int w =1001;
SoftwareSerial BTSerial(x,y); //RX|TX

Adafruit_SoftServo myServo1;
Adafruit_SoftServo myServo2;//create servo object
   
void setup() {
  BTSerial.begin(9600); // default baud rate
  // Set up the interrupt that will refresh the servo for us automagically
  OCR0A = 0xAF;            // any number is OK
  TIMSK |= _BV(OCIE0A);    // Turn on the compare interrupt (below!)
  
  myServo1.attach(SERVO0PIN);
  myServo2.attach(SERVO1PIN);   // Attach the servo to pin 0 on Trinket
  myServo1.write(90); 
  myServo2.write(5);            // Tell servo to go to position per quirk
  delay(15);                    // Wait 15ms for the servo to reach the position
}

void loop()  {
  if(BTSerial.available()== w)
    myServo2.write(10);
    delay(20);
    myServo1.write(servoPos);                  
    servoPos = servoPos + moveAmount; 
    if (servoPos == 0 || servoPos == 180){
    moveAmount = -moveAmount; 
    }
    delay(15);                              // waits 15ms for the servo to reach the position
    if(BTSerial.available()== w * 7)  
      myServo2.write(0);
      delay(20);
  if(BTSerial.available()== w * 2)
    myServo2.write(20);
    delay(20);
    myServo1.write(servoPos);                  
    servoPos = servoPos + moveAmount; 
    if (servoPos == 0 || servoPos == 180){
    moveAmount = -moveAmount; 
    }
    delay(15);                              // waits 15ms for the servo to reach the position
    if(BTSerial.available()== w * 7)  
      myServo2.write(0);
      delay(20);   
  if(BTSerial.available()== w *3)
    myServo2.write(30);
    delay(20);
    myServo1.write(servoPos);                  
    servoPos = servoPos + moveAmount; 
    if (servoPos == 0 || servoPos == 180){
    moveAmount = -moveAmount; 
    }
    delay(15);                              // waits 15ms for the servo to reach the position
    if(BTSerial.available()== w * 7)  
      myServo2.write(0);
      delay(20);
  if(BTSerial.available()== w * 4)
    myServo2.write(40);
    delay(20);
    myServo1.write(servoPos);                  
    servoPos = servoPos + moveAmount; 
    if (servoPos == 0 || servoPos == 180){
    moveAmount = -moveAmount; 
    }
    delay(15);                              // waits 15ms for the servo to reach the position
    if(BTSerial.available()== w * 7)  
      myServo2.write(0);
      delay(20);
  if(BTSerial.available()== w *5)
    myServo2.write(50);
    delay(20);
    myServo1.write(servoPos);                  
    servoPos = servoPos + moveAmount; 
    if (servoPos == 0 || servoPos == 180){
    moveAmount = -moveAmount; 
    }
    delay(15);                              // waits 15ms for the servo to reach the position
    if(BTSerial.available()== w * 7)  
      myServo2.write(0);
      delay(20);
  if(BTSerial.available()== w * 6)
    myServo2.write(6w);
    delay(20);
    myServo1.write(servoPos);                  
    servoPos = servoPos + moveAmount; 
    if (servoPos == 0 || servoPos == 180){
    moveAmount = -moveAmount; 
    }
    delay(15);                              // waits 15ms for the servo to reach the position
    if(BTSerial.available()== w  * 7)  
      myServo2.write(0);
      delay(20);
} 

volatile uint8_t counter = 0;
SIGNAL(TIMER0_COMPA_vect) {
  // this gets called every 2 milliseconds
  counter += 2;
  // every 20 milliseconds, refresh the servos!
  if (counter >= 20) {
    counter = 0;
    myServo1.refresh();
  }
}

Moderator edit: [code]

[/code] tags added.

#define SERVO0PIN 0 
#define SERVO1PIN 1

And

myServo1.attach(SERVO0PIN);
  myServo2.attach(SERVO1PIN);

So the Servos use pins 0 and 1

AND:

const int x=0;
const int y=1;
int w =1001;
SoftwareSerial BTSerial(x,y); //RX|TX

SoftwareSerial will use pins 0 and 1.

Do you see the problem now?

Have you not tried to hook this up yet? Once you realize that you're trying to connect the servos and the bluetooth to the same pins it should dawn on you.

// SoftwareServo (works on non PWM pins)

So does the normal servo library. It uses one of the PWM timers, but works on any pin.

 if(BTSerial.available()== w)

w is defined in your code as 1001. Your serial buffer is only 64 bytes. You won't ever have a thousand bytes available to read. The receive buffer would overflow way before you got to a thousand. You need to rethink this.

Actually, it looks like you may have available() and read() confused. Perhaps you should take some time to have a look at Serial Input Basics

Thank you so much fo r the input

Having issues controlling 2 servos with trinket through the app using hm-10 BT component

I have a code here meant to control 2 servos through an app by sending serial codes I'm having issues with getting it to work in using aada fruit trinket 3v a hm-10 BT component and 2 linear servos I think I may not have defined the pinouts for the Rx tx I hope this is the issue but if there is anything else i need help figuring it out.

#include   // SoftwareServo (works on non PWM pins)
#include 

#define SERVO0PIN 3 
#define SERVO1PIN 4 

int moveAmount = 1;  // change this value to change speed of servo
int servoPos = 0;  // variable for servo position
const int x=0;
const int y=1;
int w =1001;

SoftwareSerial BTSerial(x,y); //RX|TX

Adafruit_SoftServo myServo1;
Adafruit_SoftServo myServo2;//create servo object
   
void setup() {
  BTSerial.begin(9600); // default baud rate
  // Set up the interrupt that will refresh the servo for us automagically
  OCR0A = 0xAF;            // any number is OK
   TIMSK |= _BV(OCIE0A);    // Turn on the compare interrupt (below!)
  
  myServo1.attach(SERVO0PIN);
  myServo2.attach(SERVO1PIN);   // Attach the servo to pin 0 on Trinket
  myServo1.write(90); 
  myServo2.write(5);            // Tell servo to go to position per quirk
  delay(15);                    // Wait 15ms for the servo to reach the position
}

void loop()  {
  if(BTSerial.read()== w)
    myServo2.write(10);
    delay(20);
    myServo1.write(servoPos);                  
    servoPos = servoPos + moveAmount; 
    if (servoPos == 0 || servoPos == 180){
    moveAmount = -moveAmount; 
    }
    delay(15);                              // waits 15ms for the servo to reach the position
    if(BTSerial.read()== w * 7)  
      myServo2.write(0);
      delay(20);
  if(BTSerial.read()== w * 2)
    myServo2.write(20);
    delay(20);
    myServo1.write(servoPos);                  
    servoPos = servoPos + moveAmount; 
    if (servoPos == 0 || servoPos == 180){
    moveAmount = -moveAmount; 
    }
    delay(15);                              // waits 15ms for the servo to reach the position
    if(BTSerial.read()== w * 7)  
      myServo2.write(0);
      delay(20);   
  if(BTSerial.read()== w *3)
    myServo2.write(30);
    delay(20);
    myServo1.write(servoPos);                  
    servoPos = servoPos + moveAmount; 
    if (servoPos == 0 || servoPos == 180){
    moveAmount = -moveAmount; 
    }
    delay(15);                              // waits 15ms for the servo to reach the position
    if(BTSerial.read()== w * 7)  
      myServo2.write(0);
      delay(20);
  if(BTSerial.read()== w * 4)
    myServo2.write(40);
    delay(20);
    myServo1.write(servoPos);                  
    servoPos = servoPos + moveAmount; 
    if (servoPos == 0 || servoPos == 180){
    moveAmount = -moveAmount; 
    }
    delay(15);                              // waits 15ms for the servo to reach the position
    if(BTSerial.read()== w * 7)  
      myServo2.write(0);
      delay(20);
  if(BTSerial.read()== w *5)
    myServo2.write(50);
    delay(20);
    myServo1.write(servoPos);                  
    servoPos = servoPos + moveAmount; 
    if (servoPos == 0 || servoPos == 180){
    moveAmount = -moveAmount; 
    }
    delay(15);                              // waits 15ms for the servo to reach the position
    if(BTSerial.read()== w * 7)  
      myServo2.write(0);
      delay(20);
  if(BTSerial.read()== w * 6)
    myServo2.write(6w);
    delay(20);
    myServo1.write(servoPos);                  
    servoPos = servoPos + moveAmount; 
    if (servoPos == 0 || servoPos == 180){
    moveAmount = -moveAmount; 
    }
    delay(15);                              // waits 15ms for the servo to reach the position
    if(BTSerial.read()== w  * 7)  
      myServo2.write(0);
      delay(20);
} 

volatile uint8_t counter = 0;
SIGNAL(TIMER0_COMPA_vect) {
  // this gets called every 2 milliseconds
  counter += 2;
  // every 20 milliseconds, refresh the servos!
  if (counter >= 20) {
    counter = 0;
    myServo1.refresh();
  }
}

Moderator edit: [code]

[/code] tags added.

SoftwareSerial BTSerial(x,y); //RX|TX
const int x=0;
const int y=1;

think I may not have defined the pinouts for the Rx tx

The constructor for SoftwareSerial is written from the perspective of the AVR controller. It needs to be cross connected with the BT. The BT tx should go the software serial rx, and the BT rx should go to the software serial tx.

So, bt tx to pin 0 and bt rx to pin 1.

I tried but im still having issues could it be something else?

I have been trying all weekend to get my app working with my device i feel like its the BT code but im not sure Please send help?

#include   // SoftwareServo (works on non PWM pins)
#include 

#define SERVO0PIN 3 
#define SERVO1PIN 4 

#define TXPIN 0 //Connected to TX on HM-10
#define RXPIN 1 //Connected to RX on HM-10

int moveAmount = 1;  // change this value to change speed of servo
int servoPos = 0;  // variable for servo position
int w =1001;

SoftwareSerial BTSerial(0,1)); //RX|TX
  
Adafruit_SoftServo myServo1;
Adafruit_SoftServo myServo2;//create servo object
   
void setup() {
  BTSerial.begin(9600); // default baud rate
  // Set up the interrupt that will refresh the servo for us automagically
  OCR0A = 0xAF;            // any number is OK
  TIMSK |= _BV(OCIE0A);    // Turn on the compare interrupt (below!)
  
  myServo1.attach(SERVO0PIN);
  myServo2.attach(SERVO1PIN);   // Attach the servo to pin 0 on Trinket   
}

void loop(){
  if(BTSerial.read()== w)
    myServo2.write(90);
    delay(20);
    myServo1.write(servoPos);                  
    servoPos = servoPos + moveAmount; 
    if (servoPos == 0 || servoPos == 180){
    moveAmount = -moveAmount; 
    }
    delay(15);                              // Slot 1
    if(BTSerial.read()== w * 7)  
      myServo2.write(90);
      delay(20);
  if(BTSerial.read()== w * 2)
    myServo2.write(102);
    delay(20);
    myServo1.write(servoPos);                  
    servoPos = servoPos + moveAmount; 
    if (servoPos == 0 || servoPos == 180){
    moveAmount = -moveAmount; 
    }
    delay(15);                              // Slot 2
    if(BTSerial.read()== w * 7)  
      myServo2.write(90);
      delay(20);   
  if(BTSerial.read()== w *3)
    myServo2.write(114);
    delay(20);
    myServo1.write(servoPos);                  
    servoPos = servoPos + moveAmount; 
    if (servoPos == 0 || servoPos == 180){
    moveAmount = -moveAmount; 
    }
    delay(15);                              // Slot 3
    if(BTSerial.read()== w * 7)  
      myServo2.write(90);
      delay(20);
  if(BTSerial.read()== w * 4)
    myServo2.write(126);
    delay(20);
    myServo1.write(servoPos);                  
    servoPos = servoPos + moveAmount; 
    if (servoPos == 0 || servoPos == 180){
    moveAmount = -moveAmount; 
    }
    delay(15);                              // Slot 4
    if(BTSerial.read()== w * 7)  
      myServo2.write(90);
      delay(20);
  if(BTSerial.read()== w *5)
    myServo2.write(138);
    delay(20);
    myServo1.write(servoPos);                  
    servoPos = servoPos + moveAmount; 
    if (servoPos == 0 || servoPos == 180){
    moveAmount = -moveAmount; 
    }
    delay(15);                              // Slot 5
    if(BTSerial.read()== w * 7)  
      myServo2.write(90);
      delay(20);
  if(BTSerial.read()== w * 6)
    myServo2.write(150);
    delay(20);
    myServo1.write(servoPos);                  
    servoPos = servoPos + moveAmount; 
    if (servoPos == 0 || servoPos == 180){
    moveAmount = -moveAmount; 
    }
    delay(15);                              // Slot 6
    if(BTSerial.read()== w  * 7)  
      myServo2.write(90);
      delay(20);
} 

volatile uint8_t counter = 0;
SIGNAL(TIMER0_COMPA_vect) {
  // this gets called every 2 milliseconds
  counter += 2;
  // every 20 milliseconds, refresh the servos!
  if (counter >= 20) {
    counter = 0;
    myServo1.refresh();
  }
}

Moderator edit: [code]

[/code] tags added.

could it be something else?

I have a code here meant to control 2 servos through an app by sending serial codes

int w =1001;

Then there are several instances like this

if(BTSerial.read()== w)
if(BTSerial.read()== w * 2)
if(BTSerial.read()== w * 7)

What is the app sending? What "serial codes"?

BTSerial.read() reads one byte/char. I'm not sure about what you are sending and I strongly doubt that the code shown will recognize what you send.

Can you run a basic turn an led on and off sketch to validate the bluetooth/phone and trinket set up?

@WallAppAlpha, stop cross-posting. Threads merged. Twice.

im just sending a list of numbers to actvate the function i re did it and it still isnt working

include // SoftwareServo (works on non PWM pins)

include

define SERVO0PIN 3

define SERVO1PIN 4

define TXPIN 0 //Connected to TX on HM-10

define RXPIN 1 //Connected to RX on HM-10

int moveAmount = 1; // change this value to change speed of servo int servoPos = 0; // variable for servo position char w;

SoftwareSerial BTSerial(1,0); //RX|TX

Adafruit_SoftServo myServo1; Adafruit_SoftServo myServo2;//create servo object

void setup() { BTSerial.begin(9600); // default baud rate while (!BTSerial) // Set up the interrupt that will refresh the servo for us automagically OCR0A = 0xAF; // any number is OK TIMSK |= _BV(OCIE0A); // Turn on the compare interrupt (below!)

myServo1.attach(SERVO0PIN); myServo2.attach(SERVO1PIN); // Attach the servo to pin 0 on Trinket }

void loop(){ if(BTSerial.available()) w = BTSerial.read(); if(w == '1001') myServo2.write(90); delay(20); myServo1.write(servoPos); servoPos = servoPos + moveAmount; if (servoPos == 0 || servoPos == 180){ moveAmount = -moveAmount; } delay(15); // Slot 1 if(w == '7007') myServo2.write(90); delay(20); if(w == '2002') myServo2.write(102); delay(20); myServo1.write(servoPos); servoPos = servoPos + moveAmount; if (servoPos == 0 || servoPos == 180){ moveAmount = -moveAmount; } delay(15); // Slot 2 if(w == '7007') myServo2.write(90); delay(20); if(w == '3003') myServo2.write(114); delay(20); myServo1.write(servoPos); servoPos = servoPos + moveAmount; if (servoPos == 0 || servoPos == 180){ moveAmount = -moveAmount; } delay(15); // Slot 3 if(w == '7007') myServo2.write(90); delay(20); if(w == '4004') myServo2.write(126); delay(20); myServo1.write(servoPos); servoPos = servoPos + moveAmount; if (servoPos == 0 || servoPos == 180){ moveAmount = -moveAmount; } delay(15); // Slot 4 if(w == '7007') myServo2.write(90); delay(20); if(w == '5005') myServo2.write(138); delay(20); myServo1.write(servoPos); servoPos = servoPos + moveAmount; if (servoPos == 0 || servoPos == 180){ moveAmount = -moveAmount; } delay(15); // Slot 5 if(w == '7007') myServo2.write(90); delay(20); if(w == '6006') myServo2.write(150); delay(20); myServo1.write(servoPos); servoPos = servoPos + moveAmount; if (servoPos == 0 || servoPos == 180){ moveAmount = -moveAmount; } delay(15); // Slot 6 if(w == '7007') myServo2.write(90); delay(20); }

volatile uint8_t counter = 0; SIGNAL(TIMER0_COMPA_vect) { // this gets called every 2 milliseconds counter += 2; // every 20 milliseconds, refresh the servos! if (counter >= 20) { counter = 0; myServo1.refresh(); } }

  if(w == '1001')Do you know what single quotes denote?

Clearly not.

Please take a look at Robin2's excellent serial handling basics tutorial.

And.... please remember to use code tags when posting code.

would you recommend a different approach? and if so what would that approach be?

would you recommend a different approach? and if so what would that approach be?

Send single character control commands.

I just tried it seems like I still have no luck could it be the code? and if it is what could it be? I'm new to Arduino so this is a process for me but thank you for the help

I'm new to Arduino so this is a process

As mentioned earlier, take a big step backwards and write a simple program to turn an led on and off. This will simplify the issues with the phone/bluetooth , trinket and basic serial communications. Introduce the servos and the timer after the basics are solid.

what about my code is there anything I need to correct I'm afraid I might have the wrong syntax

I'm afraid I might have the wrong syntax

The compiler will find syntax errors for you.

ive tried but it still seems to not be working what would be the best way for me to set up the code