Search code examples
arduinors485motordriver

Arduino MKR (RS)485 error with Piezo Motor


I have a problem with my new project. The goal is to control my piezo motor with an Arduino MKR Wifi 1010 via RS485. For that reason I have these components:

Arduino MKR Wifi 1010 Arduino MKR 485 Shield Piezo Motordriver PM401 (Manual: https://piezomotor.com/wp-content/uploads/2019/03/150025_PMD401_Technical_Manual.pdf) Piezo LEGS motor

I tested the RS485 by using a USB adapter and the piezomotor software. That worked. But if it comes to code, I don't get any further.

The commands I want to send the piezodriver in ASCII Code is:
X127M2;
X127J200,0,100;
(They worked in the PiezoMotor DriveLab Software)

And I try to do it with this code:

#include <ArduinoRS485.h>

int counter = 0;

void setup() {
  RS485.begin(115200);
  Serial.begin(115200);
  RS485.receive();
}

void loop() {
  RS485.beginTransmission();
 
  if (RS485.available()){
    Serial.println(RS485.read());
  }
  else {
    Serial.write("Not available");
  }
  Serial.println(RS485.available());
  RS485.write('X127M2;');
  RS485.write('X127J200,0,100;');
  Serial.print("Count No: ");
  Serial.println(counter);
  RS485.endTransmission();
  counter ++;
  delay(2000);
}

In the terminal I got something like that:

88
8
Count No: 1
50
15
Count No: 2
67
22
Count No: 3

How do I know, that the MKR 485 Shield is sending the commands to the Piezodriver and not to nowhere? And the numbers of the terminal seems to me random. They also appear even if nothing is connected to the MKR 485 Shield.
So how can I find or set the address of the PM401 in the code?
Or do I have to send the commands completly different?
They have to be in ASCII send at 115200n81. Does the line RS485.write('X127M2;'); provide that?

I'm a bit lost, also cause I don't have a lot experince in that field, and try&error does not work here. Hope there are some tips out there :)


Solution

  • so I got it now, it was a stupid cable problem. The Y output from the MKR 485 Shield have to go to the Data + from the PMD401 and the Z to the Data -. Not the over way around, like its everywhere discriped.

    Here is the final test code for everybody outthere who will try the same:

    #include <ArduinoRS485.h>
    
    int counter = 0;
    
    void setup() {
      RS485.begin(115200);
      Serial.begin(115200);
      RS485.receive();
    }
    
    void loop() {
      RS485.beginTransmission();
     
      if (RS485.available()){
        Serial.println(RS485.read());
      }
      else {
        Serial.write("Not available");
      }
      RS485.write("X127M2;");
      delay(500);
      RS485.write("X127J200,0,200;");
      delay(2000);
      RS485.write("X127J-200,0,200;");
      Serial.print("Count No: ");
      Serial.println(counter);
      RS485.endTransmission();
      counter ++;
      delay(10000);
    }