Go Down

Topic: 2 servos with BT using trinket and hm-10 (Read 131 times) previous topic - next topic

WallAppAlpha

I'm running 2 servos through BT using an app my BT connection seems to work but my servos aren't working I'm new to Arduino but I've used other languages before I'm not sure if the library I used was used properly or if they may be a better route to take either way

Send Help!!!!!

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(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);
 
        }
    }
}
   
    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();
    }
}

PaulS

Code: [Select]
SoftwareSerial Serial(1,0); //RX|TX
It is stupid to do software serial on the hardware serial pins.

Code: [Select]
  Serial.begin(9600);
It is IMPOSSIBLE to do software serial on the hardware serial pins while doing hardware serial on them.

Why are you not using the standard Servo library?

How are you powering the servos?
The art of getting good answers lies in asking good questions.

Go Up