Arduino Forum

Using Arduino => Microcontrollers => Topic started by: WallAppAlpha on Aug 05, 2018, 12:09 am

Title: Control servos through app trouble
Post by: WallAppAlpha on Aug 05, 2018, 12:09 am
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.

Code: [Select]


#include <Adafruit_SoftServo.h>  // SoftwareServo (works on non PWM pins)
#include <SoftwareSerial.h>

#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.
Title: Re: Control servos through app trouble
Post by: Delta_G on Aug 05, 2018, 01:18 am
Code: [Select]
#define SERVO0PIN 0
#define SERVO1PIN 1


And

Code: [Select]
myServo1.attach(SERVO0PIN);
  myServo2.attach(SERVO1PIN);


So the Servos use pins 0 and 1


AND:

Code: [Select]
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. 
Title: Re: Control servos through app trouble
Post by: Delta_G on Aug 05, 2018, 01:19 am
Code: [Select]
// SoftwareServo (works on non PWM pins)

So does the normal servo library.  It uses one of the PWM timers, but works on any pin. 
Title: Re: Control servos through app trouble
Post by: Delta_G on Aug 05, 2018, 01:21 am
Code: [Select]
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 (http://forum.arduino.cc/index.php?topic=396450)
Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 05, 2018, 01:43 am
Thank you so much fo
r the input
Title: Having issues controlling 2 servos with trinket through the app using hm-10 BT
Post by: WallAppAlpha on Aug 05, 2018, 03:56 am
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.

Code: [Select]

#include <Adafruit_SoftServo.h>  // SoftwareServo (works on non PWM pins)
#include <SoftwareSerial.h>

#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.
Title: Re: Having issues controlling 2 servos with trinket through the app using hm-10 BT
Post by: cattledog on Aug 05, 2018, 06:09 am
Code: [Select]
SoftwareSerial BTSerial(x,y); //RX|TX
const int x=0;
const int y=1;


Quote
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.
Title: Re: Having issues controlling 2 servos with trinket through the app using hm-10 BT
Post by: WallAppAlpha on Aug 07, 2018, 01:15 am
I tried but im still having issues could it be something else?
Title: 2 servos with BT uising trinket and hm-10
Post by: WallAppAlpha on Aug 07, 2018, 01:21 am
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?

Code: [Select]

#include <Adafruit_SoftServo.h>  // SoftwareServo (works on non PWM pins)
#include <SoftwareSerial.h>

#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.
Title: Re: Having issues controlling 2 servos with trinket through the app using hm-10 BT
Post by: cattledog on Aug 07, 2018, 01:36 am
Quote
could it be something else?
Quote
I have a code here meant to control 2 servos through an app by sending serial codes
Code: [Select]
int w =1001;

Then there are several instances like this
 
Code: [Select]
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?



Title: Re: Control servos through app trouble
Post by: Coding Badly on Aug 07, 2018, 05:08 am

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

Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 07, 2018, 09:15 pm
im just sending a list of numbers to actvate the function i re did it and it still isnt working



#include <Adafruit_SoftServo.h>  // SoftwareServo (works on non PWM pins)
#include <SoftwareSerial.h>

#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();
  }
}
Title: Re: Control servos through app trouble
Post by: AWOL on Aug 07, 2018, 09:28 pm
Code: [Select]
  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.
Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 08, 2018, 12:55 am
would you recommend a different approach? and if so what would that approach be?
Title: Re: Control servos through app trouble
Post by: cattledog on Aug 08, 2018, 01:17 am
Quote
would you recommend a different approach? and if so what would that approach be?
Send single character control commands.
Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 08, 2018, 01:57 am
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
Title: Re: Control servos through app trouble
Post by: cattledog on Aug 08, 2018, 02:25 am
Quote
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.
Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 08, 2018, 06:16 pm
what about my code is there anything I need to correct I'm afraid I might have the wrong syntax
Title: Re: Control servos through app trouble
Post by: AWOL on Aug 08, 2018, 07:04 pm
Quote
I'm afraid I might have the wrong syntax
The compiler will find syntax errors for you.
Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 08, 2018, 08:23 pm
ive tried but it still seems to not be working what would be the best way for me to set up the code
Title: Re: Control servos through app trouble
Post by: AWOL on Aug 08, 2018, 08:48 pm
I can absolutely assure you that the compiler is working.
Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 09, 2018, 12:07 am
Alright thank you it seems i have connection i just tested with a simple blink code and works fine so now i dont understand what the issue with my servo code is there inherently wrong? i believe to have the code and wiring correct but it seems as if my motors wont move.
Title: Re: Control servos through app trouble
Post by: cattledog on Aug 09, 2018, 12:25 am
Quote
Alright thank you it seems i have connection i just tested with a simple blink code and works fine so now i dont understand what the issue with my servo code is there inherently wrong?
Can you now write some simple test code for the trinket which runs the servos? Don't use any input from the BT module.

Can you run the basic example from the Adafruit _SoftServo library
https://github.com/adafruit/Adafruit_SoftServo/blob/master/examples/TrinketKnob/TrinketKnob.ino (http://)

Please post the "simple blink code" you have written.
Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 09, 2018, 07:40 am
here is the basic blink code


Code: [Select]
#include <SoftwareSerial.h>

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

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

// the setup function runs once when you press reset or power the board
void setup() {
  Serial.begin(9600);
  while (!Serial);
  // initialize digital pin LED_BUILTIN as an outpu.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  if(Serial.available()>0) 
  {
    char w = Serial.read();
    if(w == 'a')
      digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)                // wait for a second
    if(w == 'b')
      digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
                    // wait for a second
  }
}
Title: Re: Control servos through app trouble
Post by: cattledog on Aug 09, 2018, 08:34 am
Quote
here is the basic blink code
Excellent progress. This tells us that the basics of the phone/bluetooth/trinket connection are correct.

Get the trinket servo example running and it should be straightforward to combine the sketches.
Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 09, 2018, 09:30 am
i combined the 2 sketches and i still seem to be running into issues the motors will not move.
Code: [Select]
#include <Adafruit_SoftServo.h> 
#include <SoftwareSerial.h>

#define SERVO1PIN 3
#define SERVO2PIN 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 pos = 90;
int pos2 =0;

SoftwareSerial Serial(1,0); //RX|TX
 
Adafruit_SoftServo myServo1, myServo2;

   
void setup() {
  Serial.begin(9600);
  while (!Serial);
  // 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(SERVO1PIN); 
  myServo2.attach(SERVO2PIN);   // Attach the servo to pin 0 on Trinket

  myServo1.write(12);
  myServo2.write(12);
}
 
void loop()
{
  if(Serial.available()>0) 
    {
    char w = Serial.read();
    if(w == 'a')
      for(pos = 0; pos <= 102; pos += 1)
      {
      myServo2.write(pos);
      delay(20);
      }
      for(pos2 = 0; pos2 <= 180; pos2 += 1)
      {
      myServo1.write(pos2);                 
      pos2 = pos2 + moveAmount;
      if (pos2 == 0 || pos2 == 180){
      moveAmount = -moveAmount;
      } 
      }
    delay(15);                              // Slot 1
    if(w == 'z') 
        for(pos = 0; pos <= 102; pos += 1)
        {
        myServo2.write(90);
        delay(20);
 
        }
    }
}
    // We'll take advantage of the built in millis() timer that goes off
    // to keep track of time, and refresh the servo every 20 milliseconds
    // The SIGNAL(TIMER0_COMPA_vect) function is the interrupt that will be
    // Called by the microcontroller every 2 milliseconds
    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();
    }
}
Title: Re: Control servos through app trouble
Post by: cattledog on Aug 09, 2018, 06:37 pm
Quote
i combined the 2 sketches and i still seem to be running into issues the motors will not move.
Did you run the basic library sketch to confirm that the motors are powered and wired correctly?
If the library sketch as written works properly, did you confirm that it will work correctly on pins 3 and 4?

Code: [Select]
#include <Adafruit_SoftServo.h>  // SoftwareServo (works on non PWM pins)

// We demonstrate two servos!
#define SERVO1PIN 0   // Servo control line (orange) on Trinket Pin #0
#define SERVO2PIN 1   // Servo control line (orange) on Trinket Pin #1

#define POTPIN   1   // Potentiometer sweep (center) on Trinket Pin #2 (Analog 1)

Adafruit_SoftServo myServo1, myServo2;  //create TWO servo objects
   
void setup() {
  // 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(SERVO1PIN);   // Attach the servo to pin 0 on Trinket
  myServo1.write(90);           // Tell servo to go to position per quirk
  myServo2.attach(SERVO2PIN);   // Attach the servo to pin 1 on Trinket
  myServo2.write(90);           // Tell servo to go to position per quirk
  delay(15);                    // Wait 15ms for the servo to reach the position
}

void loop()  {
  int potValue;  // variable to read potentiometer
  int servoPos;  // variable to convert voltage on pot to servo position
  potValue=analogRead(POTPIN);                // Read voltage on potentiometer
  servoPos = map(potValue, 0, 1023, 0, 179);  // scale it to use it with the servo (value between 0 and 180)
  myServo1.write(servoPos);                    // tell servo to go to position
  myServo2.write(180-servoPos);                    // tell servo to go to position

  delay(15);                              // waits 15ms for the servo to reach the position
}

// We'll take advantage of the built in millis() timer that goes off
// to keep track of time, and refresh the servo every 20 milliseconds
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();
    myServo2.refresh();
  }
}


There are several things wrong with your "combined" sketch, but until you can confirm, by using the library sketch, that the hardware situation is correct, it not worth the effort to address the software problems. You need to see the servos move, before you get involved with the serial commands.
Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 09, 2018, 07:32 pm
oh my it seems as if i posted the wrong code and the servos are responsive but once i have it all together they dont work anymore

#include <Adafruit_SoftServo.h> 
#include <SoftwareSerial.h>

#define SERVO1PIN 3
#define SERVO2PIN 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


SoftwareSerial Serial(1,0); //RX|TX
 
Adafruit_SoftServo myServo1, myServo2;

   
void setup() {
  Serial.begin(9600);
  while (!Serial);
  // 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(SERVO1PIN); 
  myServo2.attach(SERVO2PIN);   // Attach the servo to pin 0 on Trinket

  myServo1.write(12);
  myServo2.write(12);
}
 
void loop()
{
  if(Serial.available()>0) 
    {
    char w = Serial.read();
    int pos = 90;
    int pos2 =0;
    if(w == 'a')
      for(pos = 0; pos <= 102; pos += 1)
      {
      myServo2.write(pos);
      delay(20);
      }
      for(pos2 = 0; pos2 <= 180; pos2 += 1)
      {
      myServo1.write(pos2);                 
      pos2 = pos2 + moveAmount;
      if (pos2 == 0 || pos2 == 180){
      moveAmount = -moveAmount;
      } 
      }
    delay(15);                              // Slot 1
    if(w == 'z') 
        for(pos = 0; pos <= 102; pos += 1)
        {
        myServo2.write(90);
        delay(20);
 
        }
    }
}
    // We'll take advantage of the built in millis() timer that goes off
    // to keep track of time, and refresh the servo every 20 milliseconds
    // The SIGNAL(TIMER0_COMPA_vect) function is the interrupt that will be
    // Called by the microcontroller every 2 milliseconds
    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();
    }
}
Title: Re: Control servos through app trouble
Post by: AWOL on Aug 09, 2018, 07:58 pm
Quote
oh my it seems as if i posted the wrong code
And now the right code badly?


Please remember to use code tags when posting code.
Title: Re: Control servos through app trouble
Post by: cattledog on Aug 09, 2018, 08:09 pm
You were doing well with the use of code tags. Don't stop now!


Here's some things I see:


1)You had this in the working code for basic bluetooth connection

Code: [Select]
#define TXPIN 0 //Connected to TX on HM-10
#define RXPIN 1 //Connected to RX on HM-10
SoftwareSerial Serial(0,1); //RX|TX


You have changed the Software Serial constructor in the latest code. Are you connected to the correct pins?

Code: [Select]

#define TXPIN 0 //Connected to TX on HM-10
#define RXPIN 1 //Connected to RX on HM-10
SoftwareSerial Serial(1,0); //RX|TX



2)You need to refresh both servos in the Timer ISR. Did you not see this in the example?
Code: [Select]
myServo1.refresh();
myServo2.refresh();


3)You need opening and closing braces to define the if conditional tests for the values of the received char. Without defining the block to be executed, you only execute the next line. In the simple BT test sketch you only had one line following the if() so it worked. It's a good habit to develop to always use braces to define the conditional block, even if its one line.

4) I'm not sure if the w == 'z' code makes any sense where you write the constant position in the for loop().

You can try this, but if it doesn't move the servos as you want, I'd take a step backwards and write more simple servo moves in response to the BT commands.

Code: [Select]
#include <Adafruit_SoftServo.h>
#include <SoftwareSerial.h>

#define SERVO1PIN 3
#define SERVO2PIN 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


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

Adafruit_SoftServo myServo1, myServo2;


void setup() {
  Serial.begin(9600);
  while (!Serial);
  // 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(SERVO1PIN);
  myServo2.attach(SERVO2PIN);   // Attach the servo to pin 0 on Trinket

  myServo1.write(12);
  myServo2.write(12);
}

void loop()
{
  if (Serial.available() > 0)
  {
    char w = Serial.read();
    int pos = 90;
    int pos2 = 0;
    if (w == 'a')
    { //add brace
      for (pos = 0; pos <= 102; pos += 1)
      {
        myServo2.write(pos);
        delay(20);
      }
      for (pos2 = 0; pos2 <= 180; pos2 += 1)
      {
        myServo1.write(pos2);
        pos2 = pos2 + moveAmount;
        if (pos2 == 0 || pos2 == 180) {
          moveAmount = -moveAmount;
        }
      }
      delay(15);
    }//add brace
    if (w == 'z')
    { //add brace
      for (pos = 0; pos <= 102; pos += 1)
      {
        myServo2.write(90);
        delay(20);

      }
    }//add brace
  }
}
// We'll take advantage of the built in millis() timer that goes off
// to keep track of time, and refresh the servo every 20 milliseconds
// The SIGNAL(TIMER0_COMPA_vect) function is the interrupt that will be
// Called by the microcontroller every 2 milliseconds
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();
    myServo2.refresh();//add this line for second servo
  }
}


Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 09, 2018, 08:43 pm
actually, the code is very responsive the only issue I have now is it seems through the serial port there are a bunch of random data slowing my connection down I just started doing this with the working servo code and not with the blink code also thank you so much for all of your help
Title: Re: Control servos through app trouble
Post by: AWOL on Aug 09, 2018, 08:45 pm
Quote
there are a bunch of random data slowing my connection down
?
Title: Re: Control servos through app trouble
Post by: cattledog on Aug 09, 2018, 08:53 pm
Quote
it seems through the serial port there are a bunch of random data slowing my connection down
Make sure that the phone app is sending the commands to the BT with out line endings.

You should be able to echo the Serial.read() values back to the phone with Serial.write() commands and see what the "random data" is. Perhaps if you shared the findings with us, we could help.
Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 09, 2018, 10:45 pm
it just seems as if data is being sent in the serial monitor and its making actual inputs delay could it be the loop in the code? and if it is what can I do about that? also, I think it may be the loop What is a way I can have the code hold and wait for input for every action
Title: Re: Control servos through app trouble
Post by: AWOL on Aug 10, 2018, 12:34 am
Quote
could it be the loop in the code?
What code?
I don't see any code.
Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 10, 2018, 01:04 am
oh sorry here it is everything works independently but when trying to send commands it seems as if I'm bombarded with random data idk if it's my app of iff my code is producing weird values or taking wired values

Code: [Select]
#include <Adafruit_SoftServo.h>
#include <SoftwareSerial.h>

#define SERVO1PIN 3
#define SERVO2PIN 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


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

Adafruit_SoftServo myServo1, myServo2;


void setup() {
  Serial.begin(9600);
  while (!Serial);
  // 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(SERVO1PIN);
  myServo2.attach(SERVO2PIN);   // Attach the servo to pin 0 on Trinket

  myServo1.write(12);
  myServo2.write(12);
}

void loop()
{
  if (Serial.available() > 0)
  {
    char w = Serial.read();
    int pos = 90;
    int pos2 = 0;
    if (w == 'a')
    { //add brace
      for (pos = 90; pos <= 102; pos += 1)
      {
        myServo2.write(pos);
        delay(2000);
      }
      for (pos2 = 0; pos2 <= 180; pos2 += 1)
      {
        myServo1.write(pos2);
        pos2 = pos2 + moveAmount;
        if (pos2 == 0 || pos2 == 180) {
          moveAmount = -moveAmount;
        }
      }
      delay(15);
    }//add brace
    if (w == 'z')
    { //add brace
      for (pos = 0; pos >= 90; pos -= 1)
      {
        myServo2.write(90);
        delay(20);

      }
    }//add brace
  }
}
// We'll take advantage of the built in millis() timer that goes off
// to keep track of time, and refresh the servo every 20 milliseconds
// The SIGNAL(TIMER0_COMPA_vect) function is the interrupt that will be
// Called by the microcontroller every 2 milliseconds
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();
    myServo2.refresh();//add this line for second servo
  }
}

Title: Re: Control servos through app trouble
Post by: Delta_G on Aug 10, 2018, 01:22 am


Code: [Select]
SoftwareSerial Serial(0,1); //RX|TX

Don't name your SoftwareSerial instance with the same name as the hardware serial instance.  Not sure if that's your problem, but it is bad enough to fix before going any further.

PS - Why are you running a software serial on the hardware serial pins?  If you're going to use those pins, then you might as well just use Serial instead of slow and buggy software serial. 
Title: Re: Control servos through app trouble
Post by: cattledog on Aug 10, 2018, 02:06 am
Quote
but when trying to send commands it seems as if I'm bombarded with random data
Can you describe in more detail what this means?

Can you describe in words without reference to the code, what you want each servo to do when you enter either 'a' or 'z'?  What moves, and at what speed?

There are problems with the code in that the for() loops are blocking new Serial input but non responsiveness is not what your are focusing on with the term "random data".

There appear to be some bugs in the code.

I think that in this section of code, the delay(15) wants to be inside the for loop
Code: [Select]
for (pos2 = 0; pos2 <= 180; pos2 += 1)
      {
        myServo1.write(pos2);
        delay(15);
        pos2 = pos2 + moveAmount;
        if (pos2 == 0 || pos2 == 180) {
          moveAmount = -moveAmount;
        }      
      }
     // delay(15);


As asked above, what do you want the motion of this servo to be? There are two places where pos2 is incremented and I don't think it produces the values were moveAmount changes sign. But again, I don't see this as a "random data" symptom.
Title: Re: Control servos through app trouble
Post by: cattledog on Aug 10, 2018, 02:09 am
Quote
PS - Why are you running a software serial on the hardware serial pins?  If you're going to use those pins, then you might as well just use Serial instead of slow and buggy software serial.
@ Delta_G

This code is for a Trinket. The OP is not using a USB/Serial converter, but communicating with the Trinket through a Bluetooth module.
Title: Re: Control servos through app trouble
Post by: Delta_G on Aug 10, 2018, 05:24 am
Oh, thought I saw UNO earlier.   Guess I mixed it up with another thread.

Carry on then.
Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 10, 2018, 04:53 pm
I want for one servo to move from 90 deg to 102 deg with the input 'a' and then after that the second motor will move from 0-180 deg then back to 0 then when input 'z' comes the first motor again will move back to the 90 degrees spot if that makes any sense and I appreciate the help and I agree I think I messed up on the servos

also, it seems when I run the program the " random data" seems to be something produced in the loop keeping a constant transmission of data without any input being implemented this seems to be the primary reason the program won't run correctly.
Title: Re: Control servos through app trouble
Post by: cattledog on Aug 10, 2018, 07:33 pm
I have tried to make the code more consistent my using pos1 for myServo1 and pos2 for myServo2. See if this code is what you want for movements.

Speeds are controlled by both the delays in the .write() command in the for() loops as well as the refresh speeds controlled by the timer interrupts. See the source code for the Adafruit_SoftServo.h library for details.

If the increments in the for() loops occur significantly faster than the timer, the physical increments will be larger than expected and the motion might be jerky. I've set all the for loop increments at 15ms, and the timer updates the actual position every 20 ms. You may want to set the for() loop delays to greater than 20ms.

Code: [Select]
#include <Adafruit_SoftServo.h>
#include <SoftwareSerial.h>

#define SERVO1PIN 3
#define SERVO2PIN 4

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

int pos1 = 0; //position for servo1
int pos2 = 0; //position for servo2

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

Adafruit_SoftServo myServo1, myServo2;

void setup() {
  Serial.begin(9600);
  while (!Serial);
  // 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(SERVO1PIN);
  myServo2.attach(SERVO2PIN);   // Attach the servo to pin 0 on Trinket

  myServo1.write(12); //0?
  myServo2.write(12); //90?
}

void loop()
{
  if (Serial.available() > 0)
  {
    char w = Serial.read();

    if (w == 'a')
    {
      for (pos2 = 90; pos2 <= 102; pos2 += 1)
      {
        myServo2.write(pos2);
        delay(15);
      }

      for (pos1 = 0; pos1 <= 180; pos1 += 1)
      {
        myServo1.write(pos1);
        delay(15);
      }
      
      
      for (pos1 = 180; pos1 >= 0; pos1 -= 1)
      {
        myServo1.write(pos1);
        delay(15);
      }
    }

    if (w == 'z')
    {
      for (pos2 = 102; pos2 >= 90; pos2 -= 1)
      {
        myServo2.write(pos2);
        delay(15);
      }
    }
  }
}
// We'll take advantage of the built in millis() timer that goes off
// to keep track of time, and refresh the servo every 20 milliseconds
// The SIGNAL(TIMER0_COMPA_vect) function is the interrupt that will be
// Called by the microcontroller every 2 milliseconds
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();
    myServo2.refresh();//add this line for second servo
  }
}



I'm unsure about the initial servo positioning at 12, and whether the jumps to starting positions 90 and 0 will be a problem.

Quote
also, it seems when I run the program the " random data" seems to be something produced in the loop keeping a constant transmission of data without any input being implemented this seems to be the primary reason the program won't run correctly.
How do you know this? What do you mean by "constant transmission of data". What is the app you are using to send the bluetooth data?
Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 10, 2018, 07:59 pm
"I'm unsure about the initial servo positioning at 12, and whether the jumps to starting positions 90 and 0 will be a problem."

what should i have the initial servo position placed?

and to test the assembly im using BT serial pro.
as for the random data in the serial monitor  i keep getting a constant stream of data
Title: Re: Control servos through app trouble
Post by: cattledog on Aug 10, 2018, 08:11 pm
Quote
what should i have the initial servo position placed?
I have no idea. You have the hardware. Experiment. If thee is no problem jumping from 12 to 90 or 0, then don't change anything.

Quote
and to test the assembly im using BT serial pro.
Pleas provide a link to that app.

Quote
as for the random data in the serial monitor i keep getting a constant stream of data
I'm not sure about what you mean by the "serial monitor". Are you referring to the screen of the BT serial pro? If not, what are you talking about?

Can you provide a sample of the screen output?



Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 10, 2018, 08:30 pm
I do mean the serial monitor on the app
also here is a video of my output its strange

im going to try to post a gif of the serial monitor so you can see what i mean
Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 10, 2018, 09:15 pm
here is what im getting in the serial monitor
Title: Re: Control servos through app trouble
Post by: AWOL on Aug 10, 2018, 09:48 pm
here is what im getting in the serial monitor
Text please, not nearly 2MB of image.
Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 10, 2018, 10:14 pm
here is a screen shot it just keeps running these random digits
Title: Re: Control servos through app trouble
Post by: cattledog on Aug 10, 2018, 11:29 pm
Thank you for the image and the animation. I see what you are experiencing, but don't understand the cause.

You said that the simple iphone/BT-HM10/Trinket blink code in post #23 worked properly. You did not see the "spam" behaviour.

Can you still run that simple sketch with the app behaving properly? If not, then something in an app setting may have changed.

If the bluetooth blink sketch runs but the servo sketch doesn't, we can sequentially add small pieces of the servo code back in to see what broke.

You may also want to try a different iphone BLE terminal app. Is this what you are currently running?
https://itunes.apple.com/us/app/hm10-bluetooth-serial-pro/id1221924372?platform=iphone&preserveScrollPosition=true#platform/iphone (https://itunes.apple.com/us/app/hm10-bluetooth-serial-pro/id1221924372?platform=iphone&preserveScrollPosition=true#platform/iphone)

Unfortunately, I live in Android world, and don't have an iphone to help test anything. I'm also more familiar with BT classic and don't know if there is anything in the BLE protocols that can cause this.

Good Luck.
Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 10, 2018, 11:41 pm
do you think it was the loop? i dont think its an apple thing it seems to single down to the code the blink test workder great but ill will test things out and see what happens
Title: Re: Control servos through app trouble
Post by: cattledog on Aug 10, 2018, 11:49 pm
Quote
do you think it was the loop?
I really don't see how the code can be interactive with the app, but for now there is a mystery. The most important this is to get back to something that works and we can build on.

Unfortunately, I thought we did that after the first blink code success.  :( 
Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 11, 2018, 12:14 am
I don't have it independently powered yet so I plug it in via the USB do you think I'm getting serial interference or may that be the reason I get the extra data? I just ran the code and it works its just really laggy due to the random serial digits


or do you think possibly the timmer at the bottom is the one producing the data and lagging up my program?
Title: Re: Control servos through app trouble
Post by: cattledog on Aug 11, 2018, 01:27 am
Quote
I don't have it independently powered yet so I plug it in via the USB do you think I'm getting serial interference or may that be the reason I get the extra data?
I'm not totally familiar with the Trinket, but here the reference on the pinout
https://learn.adafruit.com/introducing-trinket/pinouts (https://learn.adafruit.com/introducing-trinket/pinouts)

The soft servo libary sets the usb pins to outputs, so it should be OK
Quote
USB Pins
The next 2 pins are also used for USB programming. That means that when the Trinket is connected to a computer and in bootloader mode or in the middle of uploading a new program, they are used for sending data to/from the computer! It's possible to share these pins if you are careful. The best use of these pins is as outputs to things like LEDs. We didn't want to keep these pins off the board but we strongly recommend not using them unless you're sure you need them since you might have to disconnect any connections to reprogram the Trinket!
It's certainly worth trying to power the Trinket not through the USB connector. Or, just modify a usb cable to only contain power and ground (or perhaps a cell phone charging cable might only have the two wires).

Quote
I just ran the code and it works its just really laggy due to the random serial digits
I asked you to run the blink code. Is it now "laggy" and showing the mystery screen output?

Quote
do you think possibly the timmer at the bottom is the one producing the data and lagging up my program?
You seem to be getting ahead of yourself. The timer code should not be in the blink code.

If the blink code works without "spam" the timer can be the first thing put back in. If the blink code runs with spam we'll need to back up a bit to find out why. The app should not be producing extra data.

 
Title: Re: Control servos through app trouble
Post by: WallAppAlpha on Aug 11, 2018, 08:58 pm
Sorry I meant that the blink code ran fine but as I ran my code for the servos they tended to run laggy due to the extra data being transmitted ik going to try with an independent power source I feel that that is the root of the problem because my code works and is responsive just laggy and the BT issue
Title: Re: Control servos through app trouble
Post by: cattledog on Aug 11, 2018, 11:45 pm
Quote
the blink code ran fine but as I ran my code for the servos they tended to run laggy due to the extra data being transmitted
Great you now have a place to start and you add back small pieces of the servo code until something breaks. Keeps us informed about what you find.

It certainly can't hurt to try an independent power source. If one end of the usb cable is into the Trinket, what is the other end currently attached to? What is downloading the program to the Trinket when you are in boot mode? Is it by any change an ipad, iphone, or a Mac terminal which is also running the wireless BT?

For clarity, and perhaps some possible interaction due to reserved names in the ide, you may want to rename the Software serial instance to something like BT_Serial. However, since the blink example works with the SoftwareSerial Serial(0,1) call, it may not be the root cause of the problem.