How to software Serial and servo conflict!!

Talk about Arduino board, sheilds. Sharing Arduino projects, program, problems, solutions, suggestions..... many more, all are welcome.

How to software Serial and servo conflict!!

Postby phamb587 » Tue Dec 15, 2015 11:04 am

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
phamb587
Fledgling
 
Posts: 1
Joined: Tue Dec 15, 2015 10:51 am

Re: How to software Serial and servo conflict!!

Postby Apis210 » Tue Dec 15, 2015 1:25 pm

Hi, Can you post your hardware setup?
Apis210
Apprentice
 
Posts: 32
Joined: Tue Dec 01, 2015 4:13 pm

Re: How to software Serial and servo conflict!!

Postby bengchet » Tue Dec 15, 2015 3:28 pm

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
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: How to software Serial and servo conflict!!

Postby arunima29 » Tue Feb 16, 2016 9:35 am

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?
arunima29
Fledgling
 
Posts: 1
Joined: Tue Feb 16, 2016 9:29 am

Re: How to software Serial and servo conflict!!

Postby Idris » Wed Feb 17, 2016 11:16 am

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.
Cytron Technologies invest time and resources providing tutorial, training and support for STEM education and maker movement. We need your support by purchasing products from Cytron Technologies. Thanks.
http://www.cytron.com.my
User avatar
Idris
Moderator
 
Posts: 409
Joined: Thu Mar 22, 2012 5:28 pm
Location: Pulau Pinang


Return to Arduino Based

Who is online

Users browsing this forum: No registered users and 14 guests

cron