Page 1 of 1

How to software Serial and servo conflict!!

PostPosted: Tue Dec 15, 2015 11:04 am
by phamb587
Hey guys!
Im following the instruction how to solve the problem according to :
http://tutorial.cytron.com.my/2015/09/0 ... interrupt/
However, my servo is still slightly shake and receive data becomes slower.
Im doing a project to communicate between 2 arduino boards via Bluetooth . I want to control servo by potentiometer via Bluetooth.
+Master ( Uno board) connects with potentiometer and then Master sends data to Slaver.
+Slaver ( Mega board) connects with servo and control servo whenever it receives the data from slaver.
+ In my slaver, I wire bluetooth Rx pin and Tx pin to Pin 10 and Pin 11 of Mega respectively.
In my code, I try to set detach and make delay >800. However, the servo just shakes one time / s and the process of receiving data is slower.
Here my RX code
CODE: SELECT_ALL_CODE
#include <SoftwareSerial.h>

#include <Servo.h>

#define BT_SERIAL_TX 10

#define BT_SERIAL_RX 11

SoftwareSerial BluetoothSerial(BT_SERIAL_TX, BT_SERIAL_RX);

Servo myservo;

int val;

int array[2];

void setup()
{

Serial.begin(9600);

BluetoothSerial.begin(9600);



}

void loop()

{
myservo.detach();
int incoming = BluetoothSerial.read();
myservo.attach(7);
  if (BluetoothSerial.available()>0){
 
  array[0]= BluetoothSerial.parseInt();
  myservo.write(array[0]);
  Serial.println(array[0]);
  delay(1000);
}

}

In I know it is wrong to post a completed code accordig to rules in Cytron forum, but I want to make sure that it is easier to helpers.
Sincere thanks in advance

Re: How to software Serial and servo conflict!!

PostPosted: Tue Dec 15, 2015 1:25 pm
by Apis210
Hi, Can you post your hardware setup?

Re: How to software Serial and servo conflict!!

PostPosted: Tue Dec 15, 2015 3:28 pm
by bengchet
Hi,

You might need to check your coding. The flow should be as below:

1. Check if there is any data from master
2. If data present, store the data as angle to a variable
3. Start activating servo motor by using attach(), run the motor with angle value stored, make it run for like 1 second, then deactivate servo by using detach()
4. if no incoming data, don't do anything...

Hope it helps!

Thanks and Good luck. :D

Re: How to software Serial and servo conflict!!

PostPosted: Tue Feb 16, 2016 9:35 am
by arunima29
hi i am using LSA08 line sensor with ps2 shield with its joystick and a servo is interfaced with it.
the line follower code works well without reading of any ps2 pin but as soon as i read some ps2 pin it does not write any angle for the servo.
i have used detach code as instructed in tutorial.
is it possible that the problem is while reading pins in digitalRead function?
what can be done to resolve this problem?

Re: How to software Serial and servo conflict!!

PostPosted: Wed Feb 17, 2016 11:16 am
by Idris
Hi arunima29,

Could you share your hardware photos with clear wiring and connection?
And also your code.

If you have a clear video to explain/show the problem, it's really help much.

Thanks.