I want to send command command control imu vectornav vn-100

I can't send a command I have a mks tiny bee device with esp32.
by sending data via rx tx to imu Vectornac vn-100
What I want is to pass command from mks to imu command via Serialmonitor.

//mks tiny bee
#define tx 28
#define rx 27
// imu
#define RXD2 5 
#define TXD2 6
//$VNASY,1*5179 // command start
//$VNAST,0*4158 // command stop
String Data;


String dat1, datYaw, datPitch, datRoll ,datMagX ,datMagY ,datMagZ ,datAccX , //Retrieve various types of information sent by imu.
       datAccY ,datAccZ ,datGyroX ,datGyroY ,datGyroZ, Time;
char command ;
void setup()
{
  Serial.begin(115200);

  Serial2.begin(115200); 

}

void loop() 

{
  //send command through serial monitor
   if (Serial.available()) {
    char command = Serial.read();
    Serial.print(command);
    Serial2.write(command);
    
  }
  //Get the value sent from imu
  if (Serial2.available() > 0) {
 
    Serial.println();
    //Read the value sent from the imu.
    Data = Serial2.readStringUntil('\n');      //อ่านค่ามาเก็บที่ data
    dat1 = getValue(Data, ',', 0);
    datYaw = getValue(Data, ',', 1);
    datPitch = getValue(Data, ',', 2);
    datRoll = getValue(Data, ',', 3);
    datMagX = getValue(Data, ',', 4);
    datMagY = getValue(Data, ',', 5);
    datMagZ = getValue(Data, ',', 6);
    datAccX = getValue(Data, ',', 7);
    datAccY = getValue(Data, ',', 8);
    datAccZ = getValue(Data, ',', 9);
    datGyroX = getValue(Data, ',', 10);
    datGyroY = getValue(Data, ',', 11);
    datGyroZ = getValue(Data, ',', 12);
     Time = getValue(Data, ',', 13);
    
 //   Serial.print(""); Serial.print(" ");
    Serial.print("Yaw = ")   ;Serial.print(datYaw);Serial.print(" ");
    Serial.print("Pitch = ") ;Serial.print(datPitch);Serial.print(" ");
    Serial.print("Pitch = ")  ;Serial.print(datRoll);Serial.print(" ");
    //Serial.print("MagX = ")   ;Serial.print(datMagX);Serial.print(" ");
    //Serial.print("MagY = ")   ;Serial.print(datMagY);Serial.print(" ");
    //Serial.print("MagZ = ")   ;Serial.print(datMagZ);Serial.print(" ");
    //Serial.print("AccX = ")   ;Serial.print(datAccX);Serial.print(" ");
    //Serial.print("AccY = ")   ;Serial.print(datAccY);Serial.print(" ");
    //Serial.print("AccZ = ")   ;Serial.print(datAccZ);Serial.print(" ");
    //Serial.print("GyroX = ")   ;Serial.print(datGyroX);Serial.print(" ");
    //Serial.print("GyroY = ")   ;Serial.print(datGyroY);Serial.print(" ");
    //Serial.print("GyroZ = ")   ;Serial.print(datGyroZ);Serial.print(" ");
    Serial.print("time = ")   ;Serial.print(Time);Serial.print(" ");
    Serial.println();

  }
}
 //conversion function
String getValue(String data, char separator, int index)
{
  int found = 0;
  int strIndex[] = {0, -1  };
  int maxIndex = data.length() - 1;
  for (int i = 0; i <= maxIndex && found <= index; i++) {
    if (data.charAt(i) == separator || i == maxIndex) {
      found++;
      strIndex[0] = strIndex[1] + 1;
      strIndex[1] = (i == maxIndex) ? i + 1 : i;
    }
  }
  return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}

what happens when you run the code? nothing?
upload a schematic showing the wiring

Example command sent
can send but imu doesn't respond

#define tx 28
#define rx 27
char Asyooff[] = "$VNASY,0*4F "; //command sent
char tare[] = "$VNTAR*5F"; //command sent
void setup() {

 Serial.begin(115200);
//imu
  Serial2.begin(115200);
}

void loop() {
  
 Serial.println(Asyooff);
  Serial2.write(Asyooff,sizeof(Asyooff));
}

when you open Serial2 try specifing the Tx and Rx pins, e.g.

 Serial2.begin(115200, SERIAL_8N1, rx, tx);

on the ESP32 micros I have I cannot see G28
using pins G26 and G27 works OK
which ESP32 are you using?

esp32 in mks tiny bee

looking at the schematic it looks as though pins 27 and 28 are used by an LCD?
if you don't have any SPI devices attached could you use pins 29, 30 or 31

if i run the following on an ESP32 NodeMCU

#define tx 28
#define rx 27
char Asyooff[] = "$VNASY,0*4F "; //command sent
char tare[] = "$VNTAR*5F"; //command sent
void setup() {
 Serial.begin(115200);
//imu
  Serial2.begin(115200, SERIAL_8N1, rx, tx);
}

void loop() {  
 Serial.println(Asyooff);
  Serial2.write(Asyooff,sizeof(Asyooff));
}

I get the print to the serial monitor

08:54:20.772 -> $VNASY,0*4F 
08:54:20.772 -> $VNASY,0*4F 
08:54:20.807 -> $VNASY,0*4F 
08:54:20.807 -> $VNASY,0*4F 
08:54:20.807 -> $VNASY,0*4F 
08:54:20.807 -> $VNASY,0*4F 
08:54:20.807 -> $VNASY,0*4F 

is there an LCD on your ESP32 board?
can you give a link to a specification of the board?
can you upload a photo or give a link to one?

avoid uploading screen images - copy and paste the text

board i use

i can do it
I can command the imu

#define RXD2 5
#define TXD2 6
#define rx 27
#define tx 28
char command ;
void setup() {

  Serial.begin(115200);
  
  Serial2.begin(115200);
  
}

void loop() { //Choose Serial1 or Serial2 as required
  if (Serial.available()) {
    char command = Serial.read();
    Serial.print(command);
    Serial2.write(command);
    
  }
}

in your original code you were sending the commands continuously using loop()
possibly too fast for the device?
add a delay after sending a command?

As for the original code, I still don't have an understanding of why it's not working. But the new code is ordered from serial monitor. and put it in the command variable to send it to the imu

try a delay in the loop(), e.g.

void loop() {
  
 Serial.println(Asyooff);
  Serial2.write(Asyooff,sizeof(Asyooff));
  delay(5000);
}

gives the receiver time to execute the command before receiving the next one

I tried it and can pass the value but the imu doesn't respond.

do you need to terminate the command with a newline?, e.g.

char Asyooff[] = "$VNASY,0*4F\n "; //command sent

when you used the serial monitor to enter commands you probably terminated it with "NL and CR"

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.