To know if everithing is connected in the right way do a simple test ( as you have the usb-to-485 converter ).
Connect everything together mega->converter->485bus<-usb-to-485<-pc ( leave also the pm1200 connected it won't hurt and it will be ready for the next step )
On the pc use a 'terminal' ( teraterm or the like ) configured to communicate with the usb-to-485 converter at 9600,8,E,1
On the arduino use the following sketch that transmits every 5 seconds a message and echoes what it receives
This is to test that communication over 485 is ok ( A and B are connected correctly ) and to test if the RX/TX of arduino converter are connected correctly
On the teraterm you should see a message every 5 seconds, on the arduino serial debug you sould see echoed everything you write in teraterm
/*
Test 485 converter.
*/
void setup()
{
Serial.begin(9600); // use Serial (port 0) for serial debug
Serial.println("Starting Serial1 test");
Serial1.begin(9600, SERIAL_8E1); // use Serial1 (port 1) for testing converter communication
}
unsigned long prevMillis;
int i = 0;
void loop()
{
unsigned long m = millis();
if ( m > prevMillis + 5000)
{
Serial1.print("msg : ");
Serial1.println(i++);
}
if (Serial1.available()) // If anything comes in Serial1...
{Serial.write(Serial1.read());} // ...it is echoed in Serial
}