allora lo shield http://www.ebay.it/itm/Shield-Arduino-RS485-Interface-/261261382544?pt=Attrezzature_e_strumentazione&hash=item3cd4645390 è uno shiled e da quello che leggo usa la i pin 0 , pin 1 e pin2.
il prodotto SparkFun Transceiver Breakout - RS-485 - BOB-10124 - SparkFun Electronics l'ho cosi' impostato
rs485 brokenout arduino
3-5V 5V
RX-I PIN 0
TX-0 PIN 1
RTS PIN 2
GND GND
#include <SimpleModbusMaster.h>
#include <LiquidCrystal.h>
//////////////////// Port information ///////////////////
#define baud 9600
#define timeout 1000
#define polling 200 // the scan rate
// If the packets internal retry register matches
// the set retry count then communication is stopped
// on that packet. To re-enable the packet you must
// set the "connection" variable to true.
#define retry_count 10
// used to toggle the receive/transmit pin on the driver
#define TxEnablePin 2
//#define LED 9
#define LED 3
// This is the easiest way to create new packets
// Add as many as you want. TOTAL_NO_OF_PACKETS
// is automatically updated.
enum
{
PACKET1,
//PACKET2,
TOTAL_NO_OF_PACKETS // leave this last entry
};
// Create an array of Packets to be configured
Packet packets[TOTAL_NO_OF_PACKETS];
packetPointer packet1 = &packets[PACKET1];
// Data read from the arduino slave will be stored in this array
// if the array is initialized to the packet.
unsigned int readRegs[2];
LiquidCrystal lcd(12, 11, 9, 8, 7, 6); // PER LCD
void setup()
{
/*
ID:5 indica l'indirizzo dello slave modbus
READ_HOLDING_REGISTERS: FUNZIONE RICHIESTA LETTURA DATI
19: E' LA FUNZIONE 20 DIMINUITA DI UNO COME DA MANUALE
WORD: 2 SONO I VALORI DOPO L'INDIRIZZO DELLA FUNZIONE (NEL MIO CASO 19
readRegs: Dove andare a copiare i risultati) ***/
modbus_construct(packet1, 5, READ_HOLDING_REGISTERS, 19, 2, readRegs);
// write 1 register starting at address 1
// modbus_construct(packet2, 1, PRESET_MULTIPLE_REGISTERS, 1, 1, writeRegs);
// P.S. the register array entries above can be different arrays
/* Initialize communication settings: These are already defined in the Arduino global name space. */
// il miter usa il sistema di comunicazione SERIAL_8N1
modbus_configure(&Serial, baud, SERIAL_8N1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);
pinMode(LED, OUTPUT);
}
void loop()
{
modbus_update(); // si fà update dei dati
lcd.clear();
/**servono per debug*/
lcd.print("REQ:"); // numero richieste
lcd.print(packet1->requests);
lcd.print("SUC:"); // richieste con successo
lcd.print(packet1->successful_requests);
lcd.print("FAL:"); // richieste fallite
lcd.print(packet1->failed_requests);
/*dati che vengono letti */
lcd.print("R1:");
lcd.print(readRegs[0]);
lcd.print("R2:");
lcd.print(readRegs[1]);
delay(1000);
}
ho messo sia una resistenza da 120 ohm sia al 485 del rs485breakout che davanti al miter
ecco tutto quello che mi avete chiesto...
grazie mille per l'aiuto