Hola,
Alguien que tenga expertise con el encoder a2k de usdigital (https://www.usdigital.com/products/encoders/absolute/kit/a2k/), intento realizar la comunicación, pero solo tengo FF cómo respuesta. Ya pude comunicar rs485 de python a Arduino, pero no puedo recibir nada del encoder.
También he intentado comunicarme o leer el encoder sar-ml50a de Nikon, pero no logro comunicarme en absoluto.
Muchas gracias por su atención
El código es el siguiente:
#define RX 19 //For Arduino Mega
#define TX 18
//#define RxTx 3
#define Re 3
#define De 5
#define Transmit HIGH
#define Receive LOW
#define Pin13LED 13
uint8_t byteIn;
int byteOut;
void setup() /****** SETUP: RUNS ONCE ******/
{
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Serial ready for transmitting");
pinMode(Pin13LED, OUTPUT);
pinMode(Re, OUTPUT);
pinMode(De, OUTPUT);
//digitalWrite(RxTx, Receive); //Initialize transciever to receive data
RS485Receive();
Serial1.begin(9600); // set the data rate
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
digitalWrite(Pin13LED, HIGH); //On when not transmitting
if (Serial.available())
{
Serial.println("Sent"); //Serial indicator
byteOut = Serial.read(); //Locally store the transmitted string
RS485Transmit();
Serial1.write(byteOut); // Send byte to encoder
digitalWrite(Pin13LED, LOW); // Off momentarily
delay(10);
RS485Receive();
delay(250);
}
if (Serial1.available()) //Look for data from encoder
{
Serial.println("Received");
digitalWrite(Pin13LED, LOW); // Off momentarily
byteIn = Serial1.read(); // Read received byte
Serial.println(byteIn);
delay(10);
}
}
void RS485Transmit()
{
digitalWrite(Re, LOW);
digitalWrite(De, HIGH);
}
void RS485Receive()
{
digitalWrite(Re, HIGH);
digitalWrite(De, LOW);
}
No tengo el esquema, pero las conexiones son:
Un adaptador de TTL a rs485 en los pines definidos para rx, tx y RE, DE, de ahí se conecta al encoder con RS485, el cable A va a DataL, y el cable B va a DataH.
PD: Incluso probamos cambiando el orden de A y B por si estaba mal, pero no ayuda en el comportamiento