This is my first post to the forum. What a great resource!
I have two Adruino Uno's with Xbee shields. Both Xbee modules are series 2. I have one module set up as a Coordinator and one as a Router. I have a 10K potentiometer hooked up to one Arduino and a Towerpro Micro Servo SG90 hooked up to the other Arduino as shown in the image.
I am using this code for the transmitter
//Sending
int val = 0;
byte mapVal = 0;
int potPin = 0;
void setup()
{
Serial.begin(19200);
pinMode(potPin, INPUT);
}
void loop()
{
val = analogRead(potPin);
mapVal = map(val,0,1023,0,179);
Serial.write(mapVal);
delay(2);
}
The issue is that I am getting a very big (1-2 second) delay from the time I turn the pot to when the servo reacts. Even if I try to turn the pot very slowly there is still a delay and it is not at all smooth. It tends to jump to the new position rather than smoothly translate. I have read some posts on here about this problem and I have tried the code from these posts but all the code I have tried makes it worse, not better. I am new at this, it's been a very very long time since I have written code (in Pascal!) so it's best to treat me as a noob. Thanks in advance for any help!
You are still sending data faster than the XBees can handle error processing. Increase the delay to 10 milliseconds. Strange as it may seem, the overall response time will improve greatly.
You have configured the XBees to talk only to each other, right?
Thank you for getting back to me so quickly. I will try changing the delay to 10ms and report back my findings. As for the two Zigbee modules communicating directly... I have the Destination Low and Destination High on both the coordinator and router is set to:
DL FFFF
DH 0
The SH for the Router is: 13A200
The SL for the Router is: 40B8F650
So I can set the DL for the Coordinator to 40B8F650 and the DH to 13A200
The SH for the Coordinator is: 13A200
The SL for the Coordinator is: 40B7A04E
I can set the DL for the router to 40B7A04E and the DH to 13A200
Is this the best thing to do? I'll only make one change at a time starting with the delay, then report back that change first.
I have the Destination Low and Destination High on both the coordinator and router is set to:
DL FFFF
DH 0
Well, that explains the delay. What you are doing is broadcasting every message to every XBee. The fact that you only have one other XBee is irrelevant. Broadcast messages are low priority.
Make DL/DH on one XBee match SL/SH on the other (and vice versa). Then, the XBees will only be talking to each other. And, they will do so much faster.
Ok....so I added the 10ms delay. There was no difference. Then I did what you suggested...
PaulS:
Make DL/DH on one XBee match SL/SH on the other (and vice versa). Then, the XBees will only be talking to each other. And, they will do so much faster.
It worked!!! Can you explain to me what the difference is? I am thinking that when the DL was set to FFFF and the DH was set to 0 it would braodcast to FFFF then incrementally broadcast until it reached 0? So going through every increment from FFFF to 0 would add a lot of processing time therefore adding a huge lag?
Picture the coordinator as a coach on a football field. Every time the coach wants to talk to the quarterback, he has to get everyone's attention - all the football players, all the cheerleaders, all the fans, etc. Every needs to stop what they are doing, huddle around, listen to useless chatter that doesn't concern them, then resume what they were doing.
That's broadcast mode. How often is the coach going to be able to do that?
Now, suppose that the coach can talk to JUST the quarterback. Or just the left side wide receiver. Or just the head cheerleader. Or just one rowdy fan. In each case, the coach only needs to get the attention of one person. Of course, that is going to happen a lot faster.