Buonasera a tutti,
sono nuovo del forum e alle prime armi, mi chiamo Christian e sto provando a realizzare un progetto ma sto incontrando un problema a cui Google non sa rispondere.
Utilizzo un Arduino Uno Rev3 dotato di Ethernet Shield. E' mia intenzione utilizzare l'Arduino come Modbus Master per leggere i valori di una sonda industriale utilizzata per misurare un flusso di aria compressa. Questa sonda comunica in Modbus RS485.
Ho acquistato una scheda DSD TECH SH-U12 RS485-TLL 5V con chip MAX13487 e l'ho collegata ai pin 5V / GND per alimentarla e tramite libreria SoftwareSerial.h ho identificato il PIN 2 come pin RX d il pin 3 come pin TX. All'altro capo del modulo ho collegato i due fili Modbus A+ e B- della sonda di portata.
Smanettando su internet ho tagliato, copiato ed utilizzato un po' di codici cercando di adattarli al mio progetto, ma purtroppo il risultato che ottengo è sempre e solo il fastidiosissimo valore di 226.
Qualcuno è in grado di aiutarmi? Esiste una guida che possa spiegarmi come utilizzare questo modulo RS485? Avete un esempio di codice per leggere un registro Modbus dopo aver creato la seriale?
/*
Software serial multple serial test
Receives from the hardware serial, sends to software serial.
Receives from software serial, sends to hardware serial.
The circuit:
* RX is digital pin 2 (connect to TX of other device)
* TX is digital pin 3 (connect to RX of other device)
Note:
Not all pins on the Mega and Mega 2560 support change interrupts,
so only the following can be used for RX:
10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
Not all pins on the Leonardo support change interrupts,
so only the following can be used for RX:
8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
created back in the mists of time
modified 25 May 2012
by Tom Igoe
based on Mikal Hart's example
This example code is in the public domain.
*/
#include <SoftwareSerial.h>
#include <ModbusMaster.h>
SoftwareSerial mySerial(2, 3); // RX, TX
ModbusMaster node;
void setup()
{
delay(500);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Native USB only
}
//Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
node.begin(1, mySerial);
}
void loop() // run over and over
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
mySerial.println(node.readHoldingRegisters(1008, 2));
Serial.println(node.readHoldingRegisters(1008, 2));
}
Grazie mille.
Christian