Two Arduinos connected by RS485

528 views
Skip to first unread message

Damian Gołda

unread,
Jun 7, 2015, 4:55:38 PM6/7/15
to sou...@googlegroups.com
Hallo everybody,
I'm new in Souliss and I try to use this great project.
I've loaded ethernet e01_HelloWorld example to Uno + Ethernet Shield and it works OK - In android application I have one node with one typical and can switch on and off.
So I'm trying make next step and connect second Uno by RS485 (2xMAX485 chip). I'm using e01_GarageDoor_n1 and e01_GarageDoor_n2 examples with added :


#define USARTDRIVER_INSKETCH
#define USARTDRIVER Serial
#define USART_TXENABLE            1
#define USART_TXENPIN            2

at the very beginning of file.
But it'is not work - second node doesn't change state.

Could you give me a hint, how to debug or what to check?
Or maybe I should try another example?

I've tried to replace first uno to mega and enable debuging using Serial1 and usb-serial adapter, but there was no messages (only my test message).

Damian

Damian Gołda

unread,
Jun 8, 2015, 2:02:09 AM6/8/15
to sou...@googlegroups.com
I'm using last souliss from GitHub and Arduino 1.6.4.
My test is in https://github.com/dgolda/dg-home-automation

Di Maio, Dario

unread,
Jun 8, 2015, 3:03:41 AM6/8/15
to sou...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "souliss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to souliss+u...@googlegroups.com.
To post to this group, send email to sou...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/souliss/25015e97-a214-47f6-9e57-c2f13e87bcdf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Damian Gołda

unread,
Jun 15, 2015, 2:34:16 AM6/15/15
to sou...@googlegroups.com
Hallo again,

Of course I have  #include "conf/usart.h"

But still I have no single byte flying by RS485 (I use RS485-USB adapter to spy).
My question is, which node should start communication using RS485 - gateway or peer?

This is log from my gateway (MEGA, Ethernet Shield + MAX485) - I've enabled logs (and add more statements):

Serial started to DEBUG
(vNet)<Init>
(USART)<Init M5>
(USART)<Init M5 Startup delay>
(USART)<Init M5 Done>
(vNet)<SETADDR><|0x4D>
(MAC)<1A,A6,49,6B,0,4E,>
(IP)<C0,A8,2,4D,>
(USART)<vNet_SetCollisionAvoidanceIndex_M5>
52737, 65280
(vNet)<SETADDR><|0xCE01>
(USART)<SetAddress_M5>52737
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(vNet)checking vNet_DataAvailable Media5
(USART)vNet_DataAvailable_M5
(USARTDG)Trying to read
(USARTDG)BusFreeSlot
(MaCaco)<OUT><|0x5|0x0|0x0|0x57|0x18|0x>
(vNet)<Send>
(vNet)<OUTPATH><|0x1>
(vNet)<MEDIA><|0x1>
(vNet)<OUT><DADDR><|0x4E><|0xB|0x17|0x4E|0x4D>
(vNet)media:1
(vNet)checking vNet_DataAvailable Media5


I see that gateway event don't try to send anything using RS485 - is it OK?

So please explain me:
* whether gateway should send something to RS485 during startup?
* whether gateway should send something to RS485 when I change his input pin state?
* whether peer should send something to RS485 during startup?
* whether peer should send something to RS485 when I change his input pin state?

I cannot find whether is this hardware problem, library problem or my code problem...
Tonight I'll try to enable debug on peer (using software serial and serial-usb adapter).

Thank you for your help.

Damian

Di Maio, Dario

unread,
Jun 15, 2015, 4:40:29 AM6/15/15
to sou...@googlegroups.com
Hi Damian,

mostly depends on your sketch. If you have configured in your sketch any USART node as Peer, the gateway will look for them, otherwise will not send out any data.

From the Peer point of view, if you haven't any runtime Join, than it will wait for data.

Please include your sketches, check your connection according to the USART that you are using. Enable the TX pin in the driver.

Dario.

Damian Gołda

unread,
Jun 15, 2015, 4:53:36 PM6/15/15
to sou...@googlegroups.com
My sketches are slighly modified usart examples.
My sketch for Gateway (Mega+Ethernet shield+MAX485 on Serial1) is here:
https://github.com/dgolda/dg-home-automation/blob/master/e01_GarageDoor_n1/e01_GarageDoor_n1.ino

Sketch for Peer (Uno+Max485) is here:
https://github.com/dgolda/dg-home-automation/blob/master/e01_GarageDoor_n2/e01_GarageDoor_n2.ino

Debug log from Gateway after reset:

Serial started to DEBUG
(vNet)<Init>
(USART)<Init M5>
(USART)<Init M5 Startup delay>
(USART)<Init M5 Done>
(vNet)<SETADDR><|0x4D>
(MAC)<1A,A6,49,6B,0,4E,>
(IP)<C0,A8,2,4D,>
(USART)<vNet_SetCollisionAvoidanceIndex_M5>
52737, 65280
(vNet)<SETADDR><|0xCE01>
(USART)<SetAddress_M5>52737
(MaCaco)<OUT><|0x5|0x0|0x0|0x57|0x18|0x>
(vNet)<Send>
(vNet)<OUTPATH><|0x1>
(vNet)<MEDIA><|0x1>
(vNet)<OUT><DADDR><|0x4E><|0xB|0x17|0x4E|0x4D>
(vNet)media:1

when i connect pin 2 to vcc:
(MaCaco)<OUT><|0x14|0x0|0x0|0x27|0x1|0x>

(vNet)<Send>
(vNet)<OUTPATH><|0x1>
(vNet)<MEDIA><|0x1>
(vNet)<OUT><DADDR><|0x4E><|0xC|0x17|0x4E|0x4D>
(vNet)media:1
(MaCaco)<OUT><|0x14|0x0|0x0|0x27|0x1|0x>

(vNet)<Send>
(vNet)<OUTPATH><|0x1>
(vNet)<MEDIA><|0x1>
(vNet)<OUT><DADDR><|0x4E><|0xC|0x17|0x4E|0x4D>
(vNet)media:1


I cannot manage to run debug on Peer - program doesn't fit in memory - why don't you use _F for debug messages?
On Peer, when I connect pin 2 or 4 to vcc, leds on 7, 8 and 9 light on or off.

Souliss app configuration: local address 192.168.2.77 (gateway address)
When I drop DB and Get Souliss nodes I have 2 souliss nodes, totally 0 typicals.
And in Manual control I have 2 nodes, but both are empty.

I've tested RS485 communication and both nodes can send and receive data.
But using above sketches they don't wont...

Damian

Di Maio, Dario

unread,
Jun 16, 2015, 4:27:52 AM6/16/15
to sou...@googlegroups.com
Hi Damian,

there are two things that looks wrong in your sketch:
1) In your gateway you are not specifying the address of the Peer node, you are using SetAsPeerNode(Peer_address, 1); where the Peer_address  is 78. The address of the Peer node is 0xCE02 and this is why you get an empty node in SoulissApp.
2) From the description looks like the TXENPIN is located on pin3, rather is configured in the sketch on pin2.

Let me know,
Dario. 




--
You received this message because you are subscribed to the Google Groups "souliss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to souliss+u...@googlegroups.com.
To post to this group, send email to sou...@googlegroups.com.

Damian Gołda

unread,
Jun 16, 2015, 4:35:24 AM6/16/15
to sou...@googlegroups.com
Thanks a lot!

ad 1)
So in original example there is a mistake - see line 60:
https://github.com/souliss/souliss/blob/friariello/examples/usart/e01_GarageDoor_n1/e01_GarageDoor_n1.ino

ad 2)
Silly mistake. I was sure I set pin 3 for TXENABLE.

I will check it tonight. Thank you again!

Di Maio, Dario

unread,
Jun 16, 2015, 4:37:05 AM6/16/15
to sou...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "souliss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to souliss+u...@googlegroups.com.
To post to this group, send email to sou...@googlegroups.com.

Damian Gołda

unread,
Jun 16, 2015, 4:17:12 PM6/16/15
to sou...@googlegroups.com
Thank you Dario!
You were absolutely right!
I fixed my sketches and everything works as expected!
I found an error in your commit so I've created pull request #143.

Now I can learn and use Souliss in my home...

guyc

unread,
Jun 23, 2015, 6:58:45 PM6/23/15
to sou...@googlegroups.com


I tested today the communication between 2 nodes, starting from the example sketches garagedoor and the sketches from Damian.
On the app  the 5 nodes  appears , but all they are, with exception from node0, empty.

I receive only the slots from nodeO

node :
configuration :

// define the RS485 configuration
#define USARTDRIVER_INSKETCH
#define USARTDRIVER Serial1
#define USART_TXENABLE  1 //  -  If enabled, the TXENPIN is used before transmitting
#define USART_TXENPIN 3 //  -  The pin connected to driver



// Configure the framework

#include "bconf/StandardArduino.h"          // Use a standard Arduino
#include "conf/ethW5100.h"                  // Ethernet through Wiznet W5100
#include "conf/Gateway.h"                   // The main node is the Gateway
#include "conf/usart.h"                     // RS485


// Include framework code and libraries
#include <SPI.h>
#include "Souliss.h"


// Define the network configuration according to your router settings
uint8_t ip_address[4]  = {192, 168, 1, 77};
uint8_t subnet_mask[4] = {255, 255, 255, 0};
uint8_t ip_gateway[4]  = {192, 168, 1, 1};
#define Gateway_address 77

#define myvNet_address  ip_address[3]       // The last byte of the IP address (77) is also the vNet address
#define myvNet_subnet   0xFF00
#define myvNet_supern   Gateway_address

#define Gateway_RS485_address 0xCE01
#define PEERNODE1 0xCE02
#define PEERNODE2 0xCE03
#define PEERNODE3 0xCE04
#define PEERNODE4 0xCE05

in the setup of nodeO :

 Initialize();
   
    // Set network parameters
    //Souliss_SetIPAddress(ip_address, subnet_mask, ip_gateway);
     //SetAsGateway(myvNet_address);           // Set this node as gateway for SoulissApp
   //Souliss_SetAddress(Gateway_RS485_address, myvNet_subnet, 0x0000);  

// Set network parameters
    Souliss_SetIPAddress(ip_address, subnet_mask, ip_gateway);
    SetAsGateway(myvNet_address);                                   // Set this node as gateway for SoulissApp 
    SetAddress(Gateway_RS485_address, myvNet_subnet, 0);                    // Set the address on the RS485 bus
   
   
     // This node as gateway will get data from the Peer
      SetAsPeerNode(PEERNODE1, 1);
       SetAsPeerNode(PEERNODE2, 2);
        SetAsPeerNode(PEERNODE3, 3);
         SetAsPeerNode(PEERNODE4, 4);


for the test I only connected node3 :

configuration :
#define USARTDRIVER_INSKETCH 1
#define USARTDRIVER Serial1
#define USART_TXENABLE  1 //  -  If enabled, the TXENPIN is used before transmitting
#define USART_TXENPIN 3   //  -  The pin connected to driver

// Configure the framework
#include "bconf/StandardArduino.h"          // Use a standard Arduino
#include "conf/usart.h"                     //  USART RS485

// Include framework code and libraries
#include <SPI.h>
#include "Souliss.h"

// Define the network configuration

#define myvNet_subnet   0xFF00
#define myvNet_supern   Gateway_address
#define Gateway_RS485_address   0xCE01
#define PEERNODE1 0xCE02
#define PEERNODE2 0xCE03
#define PEERNODE3 0xCE04
#define PEERNODE4 0xCE05

setup :

 Initialize();

    // Setup the network configuration 
  SetAddress(PEERNODE3,  myvNet_subnet, Gateway_RS485_address);

The RS485 driver are connected  :

arduino           RS485        RS485        arduino
TX (pin 19) > DI         A----A    DI >       TX
RX(pin19)  > RO        B----B    RO>       RX

pin 3 > DE & RE

thanks

Di Maio, Dario

unread,
Jun 24, 2015, 4:54:43 AM6/24/15
to sou...@googlegroups.com

TX and RX both pin 19?

You have to use the TXENABLE on all nodes.

Dario.

From Mobile.

--
You received this message because you are subscribed to the Google Groups "souliss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to souliss+u...@googlegroups.com.
To post to this group, send email to sou...@googlegroups.com.

guyc

unread,
Jun 24, 2015, 10:33:38 AM6/24/15
to sou...@googlegroups.com


Dario,
On all the nodes TX is connected on pin 19 and RX on pin 18.

Txenable is set to 1 on all the nodes and TXENpin  =3

For the test only node0 and node 3 are connected.

I must do something wrong in the configuration or the setup.

Di Maio, Dario

unread,
Jun 24, 2015, 2:16:24 PM6/24/15
to sou...@googlegroups.com

Is TX and RX connected in the right way? Check for reverted wiring.

Dario.

From Mobile.

--
You received this message because you are subscribed to the Google Groups "souliss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to souliss+u...@googlegroups.com.
To post to this group, send email to sou...@googlegroups.com.

guyc

unread,
Jun 24, 2015, 4:17:01 PM6/24/15
to sou...@googlegroups.com
Dario,

TX and RX are connected the right way. Also TXenpin on pin 3.

I did already the test to connect the nodes directly. TX node0 to RX node3, RX nod0 to TX node3.
That why I'm thinking sommething must be wrong in the configuration or setup of the nodes.

guy

Op woensdag 24 juni 2015 20:16:24 UTC+2 schreef Dario Di Maio:

guyc

unread,
Jun 25, 2015, 5:40:18 AM6/25/15
to sou...@googlegroups.com


I updated the examples.
With the example garagedoors, the communication between the 2 nodes  was working via the serial port.

When I switch to the serial1 port, I have no communication.
I changed the code in the 2 nodes.

Di Maio, Dario

unread,
Jun 25, 2015, 6:04:07 PM6/25/15
to sou...@googlegroups.com

Try Serial2.

Dario.

From Mobile.

--
You received this message because you are subscribed to the Google Groups "souliss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to souliss+u...@googlegroups.com.
To post to this group, send email to sou...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages