Solved !!!Unable to get full power in one direction wrong algorythm?

Good day,

I am trying to control motors wireless, I am able to transmit the signal and run it through a sketch on the arduino receiving but for some reason when applying the joystick in one direction I cant get full power from the motors. I cant troubleshoot with Arduino Uno via terminal.

So far I have only configure 1 output pin to test the signal going to the xbee/arduino receiving.

Help would be appreciated if you can figure out why one direction is not working properly and the other direction respond correctly

Problem:

xbee series 1 settings

Transmitter xbee settings

ATRE
ATMY1234
ATDL5678
ATDH0
ATID0
ATD02
ATIR64
ATWR

Receiver xbee settings:

ATRE
ATMY5678
ATDL1234
ATDH0
ATID0
ATWR

sketch in Arduino receiving

/*
XBeeAnalogReceiveSeries1
Read an analog value from an XBee API frame and set value accordingly.
*/

#include <Servo.h>

int servoVal;      
int servoVal2;


Servo ST1, ST2; 


void setup() {

  // Servo
  ST1.attach( 6, 1000, 2000);
  ST2.attach(5, 1000, 2000);  
  
Serial.begin(9600);
configureRadio(); // check the return value if you need error handling
}

boolean configureRadio() {
// put the radio in command mode:
Serial.flush();
Serial.print("+++");
delay(100);
String ok_response = "OK\r"; // the response we expect.
// Read the text of the response into the response variable
String response = String("");
while (response.length() < ok_response.length()) {
if (Serial.available() > 0) {
response += (char) Serial.read();
}
}
// If we got the right response, configure the radio and return true.
if (response.equals(ok_response)) {
Serial.print("ATAP1\r"); // Enter API mode
delay(100);
Serial.print("ATCN\r"); // back to data mode
return true;
} else {
return false; // This indicates the response was incorrect.
}
}
void loop() {
  

  
  
  if (Serial.available() >= 14) { // Wait until we have a mouthful of data
if (Serial.read() == 0x7E) { // Start delimiter of a frame
// Skip over the bytes in the API frame we don't care about
for (int i = 0; i < 10; i++) {
Serial.read();
}
// The next two bytes are the high and low bytes of the sensor reading
int analogHigh = Serial.read();
int analogLow = Serial.read();

int analogValue = analogLow + (analogHigh * 180);
servoVal = map(analogValue, 0, 1023, 0, 180);     // scale it to use it with the servo (result  between 0 and 180)
 
ST1.write(servoVal);                    	  	 // sets the servo position according to the scaled value  
}
}
}
int analogValue = analogLow + (analogHigh * 180);

You want:

int analogValue = analogLow + (analogHigh * 256);

Thank you very much it worked :slight_smile:

Unfortunately a new problem surfaced, with the changes made the motors are getting signal for some reason but i can control the speed in both direction. After looking with the multimeter I saw that 3.3 volt was sent to the motors, any idea why?

Ill go over everything again, any help is appreciated at this point.

Transmitter xbee series 1 settings

ATRE
ATMY1234
ATDL5678
ATDH0
ATID0
ATD02
ATIR64
ATWR

Receiver xbee series 1 settings:

ATRE
ATMY5678
ATDL1234
ATDH0
ATID0
ATWR

/*
XBeeAnalogReceiveSeries1
 Read an analog value from an XBee API frame and set the value accordingly.
 */

#include <Servo.h>

int servoVal;      
int servoVal2;


Servo ST1, ST2; 


void setup() {

  // Servo
  ST1.attach( 6, 1000, 2000);
  ST2.attach(5, 1000, 2000);  

  Serial.begin(9600);
  configureRadio(); // check the return value if you need error handling
}

boolean configureRadio() {
  // put the radio in command mode:
  Serial.flush();
  Serial.print("+++");
  delay(100);
  String ok_response = "OK\r"; // the response we expect.
  // Read the text of the response into the response variable
  String response = String("");
  while (response.length() < ok_response.length()) {
    if (Serial.available() > 0) {
      response += (char) Serial.read();
    }
  }
  // If we got the right response, configure the radio and return true.
  if (response.equals(ok_response)) {
    Serial.print("ATAP1\r"); // Enter API mode
    delay(100);
    Serial.print("ATCN\r"); // back to data mode
    return true;
  } 
  else {
    return false; // This indicates the response was incorrect.
  }
}
void loop() {




  if (Serial.available() >= 14) { // Wait until we have a mouthful of data
    if (Serial.read() == 0x7E) { // Start delimiter of a frame
      // Skip over the bytes in the API frame we don't care about
      for (int i = 0; i < 10; i++) {
        Serial.read();
      }
      // The next two bytes are the high and low bytes of the sensor reading
      int analogHigh = Serial.read();
      int analogLow = Serial.read();

      int analogValue = analogLow + (analogHigh * 256);
      servoVal = map(analogValue, 0, 1023, 0, 180);     // scale it to use it with the servo (result  between 0 and 180)

      ST1.write(servoVal);                    	  	 // sets the servo position according to the scaled value  
    }
  }
}

UPDATE,

I revised everything and made changes to the transmitter side. I was passing 5volts to the pot before and now I changed and pointed to the 3.3volts which fixed the problem. I can now send X signal from the joystick to the xbee.

Now the ultimate question : is it possible to now do the same for the y signal? I would like ideally to capture both X&Y and transmit.

Thank you

http://youtu.be/fx3SUvI77D4

anyone?

Good day,

Finally after many obstacles, faulty wires, wrong code etc… success :grin:.

I present to you communication between 2 arduinos with xbees series 1 with1 joystick passing analog X&Y to other arduino via xbees wireless!!! All using the EasyTransfer library from Bill Porter EasyTransfer Arduino Library « The Mind of Bill Porter

This sketch or method can be applied to many different project or other similar controlled bots with minimal coding expertise. I have search and red many books and none come even close to what you are about to see.

I hope you enjoy building your robots and making them controlled wireless.

Pre requisite:

2 xbees series 1 default settings(Out of the box!!) are ok but if you wish you can change the pan id but that is it!!!
1 joystick thumb joystick from ladyaya or equivalent 2 seperate joystick would work.

the way the sketch work you could have a mega arduino and include as much motors/servos/joystick/ button that you wish!!! have fun!!

2 arduino uno board
2 dc motors or servos
9 volts batterie
12/24 volts batterie

Please refer to schematic for wiring

Remote control Arduino sketch

#include <EasyTransfer.h>
EasyTransfer ET;

const int potpin1 = A0;
const int potpin2 = A1;

struct SEND_DATA_STRUCTURE{
int servo1val;
int servo2val;
};

SEND_DATA_STRUCTURE txdata;

void setup(){
  Serial.begin(9600);
  //  Serial.begin(115200);
  ET.begin(details(txdata), &Serial);
}

void loop(){

  int val1 = analogRead(potpin1);
  int val2 = analogRead(potpin2);
  val1 = map(val1, 0, 1023, 0, 180);
  val2 = map(val2, 0, 1023, 0, 180); 
  txdata.servo1val = val1;
  txdata.servo2val = val2;

  ET.sendData();
}

robot Arduino receiving

#include <Servo.h>
#include <EasyTransfer.h>
EasyTransfer ET;

Servo myservo1;
Servo myservo2;

Servo ST1, ST2; 

struct RECEIVE_DATA_STRUCTURE{
  int servo1val;
  int servo2val;
};

RECEIVE_DATA_STRUCTURE txdata;

void setup(){
  Serial.begin(9600);
  // Serial.begin(115200);

  ET.begin(details(txdata), &Serial);
  // Servo
  ST1.attach( 6, 1000, 2000);
  ST2.attach(5, 1000, 2000);
}

void loop(){
  if(ET.receiveData()){
    ST1.write(txdata.servo1val);
    ST2.write(txdata.servo2val);
  }
}

FirstBotController.fzz (8.17 KB)

FirstBotReceiver.fzz (7.88 KB)