Hola a todos.
antes de nada decir que soy novato en esto de arduino.
Estoy intentando conectar un arduino UNO con las placas MAX485 al MEGA como indica en esta pagina:
https://arduino-info.wikispaces.com/SoftwareSerialRS485Example
conectando las placas a los arduinos como indican en el esquema de esta pagina:
http://www.gammon.com.au/forum/?id=11428
He probado el ejemplo de la pagina y no me funciona .He estado probando un poco y he conseguido comunicacion desde el MEGA como master (rx:pin 19,tx:pin 18,control:pin3) al UNO como esclavo(rx:pin 10,tx:pin 11,control:pin3) pero solo me deja mandar datos ,no puedo recibirlos del UNO.Si intento hacerlo al reves ,es decir ,poner de maestro el UNO ya no me funciona.
Aqui dejo el ejemplo donde pulso un boton en el master y activa luz en esclavo.
MASTER:
/*-----( Import needed libraries )-----*/
#include <SoftwareSerial.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define SSerialRX 19 //Serial Receive pin
#define SSerialTX 18 //Serial Transmit pin
#define SSerialTxControl 3 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
#define boton 9
#define led 8
/*-----( Declare objects )-----*/
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
/*-----( Declare Variables )-----*/
int byteReceived;
int byteSend;
int estado;
int salida=0;
int estadoanterior=0;
void setup() /****** SETUP: RUNS ONCE ******/
{
// Start the built-in serial port, probably to Serial Monitor
Serial.begin(57600);
pinMode(boton, INPUT);
pinMode(led, OUTPUT);
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive); // Init Transceiver
// Start the software serial port, to another device
RS485Serial.begin(4800); // set the data rate
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
estado=digitalRead(boton);
digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
RS485Serial.write(estado); // Send byte to Remote Arduino
Serial.print("enviamos:");
Serial.println(estado);
digitalWrite(SSerialTxControl, RS485Receive); // Disable RS485 Transmit
}
ESCLAVO:
/************ESCLAVO***********/
/* YourDuino SoftwareSerialExample1Remote
- Used with YD_SoftwareSerialExampleRS485_1 on another Arduino
- Remote: Receive data, loop it back...
- Connect this unit Pins 10, 11, Gnd
- To other unit Pins 11,10, Gnd (Cross over)
- Pin 3 used for RS485 direction control
- Pin 13 LED blinks when data is received
Questions: terry@yourduino.com
*/
/*-----( Import needed libraries )-----*/
#include <SoftwareSerial.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define SSerialRX 10 //Serial Receive pin
#define SSerialTX 11 //Serial Transmit pin
#define SSerialTxControl 3 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
#define Pin13LED 9
/*-----( Declare objects )-----*/
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
/*-----( Declare Variables )-----*/
int byteReceived;
int byteSend;
int estado;
void setup() /****** SETUP: RUNS ONCE ******/
{
// Start the built-in serial port, probably to Serial Monitor
Serial.begin(57600);
pinMode(Pin13LED, OUTPUT);
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive); // Init Transceiver
// Start the software serial port, to another device
RS485Serial.begin(4800); // set the data rate
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
//Copy input data to output
if (RS485Serial.available())
{
byteSend = RS485Serial.read(); // Read the byte
Serial.print("recibimos:");
Serial.println(byteSend);
if(byteSend==1)
{
digitalWrite(Pin13LED, HIGH); // Show activity
}
else{
digitalWrite(Pin13LED, LOW); // Show activity
}
}// End If RS485SerialAvailable
}//--(end main loop )---
Me estoy haciendo un lio con tanta libreria suelta por ahi(afsoftserial,altsoftserial,easytransfer,simplemodbus…) ,asi que me decidi por softserial.he probado con otra comunicacion y sin la placa MAX485 ,I2C,…y comunico sin problema.Pero con esta dichosa placa no lo consigo
Algo estoy haciendo mal ,a ver si alguien me puede echar un cable.