Inmoov wireless glove control servo issues

Hello party people. We are working on the right arm of the Inmoov project. Currently we have the entire right arm printed and assembled. Each servo works independently when wired directly (not using WIFI). However, we are attempting to implement wireless control of the arm using 5 flex sensors. The servos for the fingers are MG 996r. Servos for the wrist, elbow and shoulder are HS-805BB. Joystick control for the wrist, elbow and shoulder is from this joystick. We are using two Arduino Nano's for the TX and RX modules. The wireless modules on both Nano's is NRF24L01 with adapter. We are using a voltage divider circuit for the flex sensors. Currently, the system will transmit and receive the correct data for servo positioning. We have both serial monitors on two separate computers and can verify transmission. The problem is the servo positioning is not writing to the arm. We have been using 4 AA batteries to run the hand servos. We discovered the reliable datagram and Servo.h library use the same timer1. So we tried to implement ServoTimer2 library. Please offer your expertise!

Glove code:

//Transmitter code - Control glove

#include <RHReliableDatagram.h>
#include <RH_NRF24.h>
#include <SPI.h>

//Define the addresses for the radio channels
#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2

//Define analog connection pins for the flex sensors
int thumb = A0;
int index = A1;
int middle = A2;
int ring = A3;
int pinky = A4;

//Define connection pins for the joystick
int wrist_x = A5;
int elbow_y = A6;
int shoulder_sw = 2;

// Singleton instance of the radio driver
RH_NRF24 RadioDriver;

// Sets the radio driver to NRF24 and the client address to 1
RHReliableDatagram RadioManager(RadioDriver, CLIENT_ADDRESS);

// Declare unsigned 8 bit controller array. The number corresponds to the number of servos controlled
uint8_t controller[8];

// Define the message buffer named buf
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];

void setup() 
{
  Serial.begin(9600);                                                       // Setup serial monitor
  if (!RadioManager.init())                                                 // Initialize RadioManager with defaults - 2.402 GHz (Channel 2), 2Mbps, 0dBm
    Serial.println("init failed");                            
}

void loop()
{
  Serial.println("Reading arm position values ");                           // Reading the servo values from the robotic arm

  controller[0] = map(analogRead(thumb), 485, 750, 544, 2400);                 // Setting the min/max limits of the flex sensor and mapping within servo limits
  controller[1] = map(analogRead(index), 600, 800, 10, 170);
  controller[2] = map(analogRead(middle), 600, 800, 10, 170);
  controller[3] = map(analogRead(ring), 600, 800, 10, 170);
  controller[4] = map(analogRead(pinky), 600, 800, 10, 170);
  controller[5] = map(analogRead(wrist_x), 0, 1023, 544, 2400);
  controller[6] = map(analogRead(elbow_y), 0, 1023, 10, 170);
  controller[7] = digitalRead(shoulder_sw);                                 // Shoulder control is currently a push button

  Serial.println("----------");                                             // Displaying the individual controller values in the serial monitor
  Serial.print("Thumb:");
  Serial.println(controller[0]);
  Serial.print("Index:");
  Serial.println(controller[1]);
  Serial.print("Middle:");
  Serial.println(controller[2]);
  Serial.print("Ring:");
  Serial.println(controller[3]);
  Serial.print("Pinky:");
  Serial.println(controller[4]);
  Serial.print("Wrist:");
  Serial.println(controller[5]);
  Serial.print("Elbow:");
  Serial.println(controller[6]);
  Serial.print("Shoulder:");
  Serial.println(controller[7]);
  
  Serial.println("Sending arm position data to the server");
  
  if (RadioManager.sendtoWait(controller, sizeof(controller), SERVER_ADDRESS))   // Send a message containing controller data to the server
  {                                                                      
    uint8_t len = sizeof(buf);                                              // Wait for a reply from the server
    uint8_t from;
    if (RadioManager.recvfromAckTimeout(buf, &len, 2000, &from))
    {
      Serial.print("got reply from : 0x");
      Serial.print(from, HEX);
      Serial.print(": ");
      Serial.println((char*)buf);
    }
    else
    {
      Serial.println("No reply, is the server running?");                   // Send a reply back to the originator client
    }
  }
  else
      Serial.println("sendtoWait failed");
  delay(100);                                                               // Wait before next transmission
}

Arm code:

//Receiver code (Robotic arm)
 
// Include RadioHead ReliableDatagram & NRF24 Libraries
#include <RHReliableDatagram.h>
#include <RH_NRF24.h>
 
// Include dependant SPI Library 
#include <SPI.h>

// Include alternate servo library to prevent Timer1 conflict with the RadioHead library
#include <ServoTimer2.h>

//Assign a variable name for each servo
ServoTimer2 thumb;
ServoTimer2 index;
ServoTimer2 middle;
ServoTimer2 ring;
ServoTimer2 pinky;
ServoTimer2 wrist;
ServoTimer2 elbow;
ServoTimer2 shoulder;
 
// Define addresses for radio channels
#define CLIENT_ADDRESS 1   
#define SERVER_ADDRESS 2
 
// Create an instance of the radio driver
RH_NRF24 RadioDriver;
 
// Sets the radio driver to NRF24 and the server address to 2
RHReliableDatagram RadioManager(RadioDriver, SERVER_ADDRESS);
 
// Define a message to return if values received
uint8_t ReturnMessage[] = "Controller Data Received"; 
 
// Define the Message Buffer
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
 
void setup()
{
  // Setup Serial Monitor
  Serial.begin(9600);

  // Define the servo connections
  thumb.attach(3);
  index.attach(5);
  middle.attach(6);
  ring.attach(9);
  pinky.attach(A0);
  wrist.attach(A1);
  elbow.attach(A2);
  shoulder.attach(A3);
  
  // Initialize RadioManager with defaults - 2.402 GHz (channel 2), 2Mbps, 0dBm
  if (!RadioManager.init())
    Serial.println("init failed");
} 
 
void loop()
{
  if (RadioManager.available())
  {
 // Wait for a message addressed to us from the client
    uint8_t len = sizeof(buf);
    uint8_t from;
    if (RadioManager.recvfromAck(buf, &len, &from))
 //Serial Print the values of controller
    {
      Serial.print("got request from : 0x");
      Serial.print(from, HEX);
      Serial.print(" Thumb: ");
      Serial.print(buf[0]);
      Serial.print(" Pointer: ");
      Serial.print(buf[1]);
      Serial.print(" Middle: ");
      Serial.println(buf[2]);
      Serial.print(" Ring: ");
      Serial.println(buf[3]);
      Serial.print(" Pinky: ");
      Serial.println(buf[4]);
      Serial.print(" Wrist: ");
      Serial.println(buf[5]);
      Serial.print(" Elbow: ");
      Serial.println(buf[6]);
      Serial.print(" Shoulder: ");
      Serial.println(buf[7]);

//writes the position to the servos sent from the control glove
      thumb.write(buf[0]); 
      index.write(buf[1]);
      middle.write(buf[2]);
      ring.write(buf[3]);
      pinky.write(buf[4]);
      wrist.write(buf[5]);
      elbow.write(buf[6]);
      shoulder.write(buf[7]);
 
      // Send a reply back to the originator client, check for error
      if (!RadioManager.sendtoWait(ReturnMessage, sizeof(ReturnMessage), from))
        Serial.println("sendtoWait failed");
    }
  }              
}

IIRC ServoTimer2 write() only takes a pulse length in microseconds (equivalent to servo.writeMicroseconds()). So sending it values between 10 and 170 isn't going to do anything useful.

Steve

Thanks for the quick reply Steve!. However, we did implement the the pulse length on one of the servos (in the code now). Still no luck.