Master-Slave Arduino networking

Build example: Networked Solar PV+SHW+Emon

Introduction

A simple serial communications network for the Arduino.  Using tristate buffers to allow multiple Arduino's to communicate along the same 2 wire serial connection. 

Documentation in development: See Ken Boak's blog posts for more info: 

Developers

  • Ken Boak
  • Suneil Tagore
  • Trystan Lea

Hardware

 

Software

Download Library and example code on github

https://github.com/openenergymonitor/rfm12net/tree/master/Wired%20version 

Download Network library and PV + LCD example: NetworkV2.zip

On the master:

To open a connection with a slave of given slave ID:    
net.open(slaveID);
To read a single register on the slave:                         
double currentA = net.readRegisterD(26);     //D for double
To read multiple registers in one command: 
   Serial.println("r,26,27,28"); net.waitForData(); 
   double currentA = net.readArgD();
   double currentB = net.readArgD();
   double voltage = net.readArgD();

To write a string to a certain register, in this case register 15 forwards the string to the lcd
net.write(15,"?x00?y0PV Display____"); 
To set say digital pin 10 to HIGH:
net.write(10,1);
 
On the Slave

The main thing on the slaves is the registers, there are two registers: The read register and the write register
 
Lets say we want to read analog pin 0 on the slave arduino from the master: First on the master:
int value = net.readRegisterI(20); //20 -25 are analog pins 0 to 5
The slave receives a r,20 command which tells it to check index 20 in the read register
The slave does an analog read and returns the result:
if(index>19 && index<26) Serial.print(analogRead(index - 20));
Register index 26 up are application dependent variables, if we want to make currentA on the pv slave available to the master we add the line:
if(index == 26) Serial.print(currentA);
the master can then call : 
double currentA = net.readRegisterD(26);   
to retrieve it.



 

Berry's picture

Re: Master-Slave Arduino networking

Hi Tristan,

You are running a really nice projekt and I am watching it for quite a while, but for non High-End-Programmers or -Nerds it not so easy to follow Your very special technical minds.
I've got a certain question to this networking Arduinos.

First I tried to realize that with a SN175176-Chip but I didn't succeed. Then I took
2pcs DIGITAL CONVERTER TTL TO RS485 SIGNALS AUTO RxTx from rss-online, really great and easy to use modules. They work with every serial communication I tried-- but not with Yours....

Link:(http://www.ebay.de/itm/2pcs-DIGITAL-CONVERTER-TTL-TO-RS485-SIGNALS-AUTO-...)

I tried Your Master.pde without the (net.open(lcd)-part) and the SlavePV.pde. After debugging I figured out that my problem is that the serial string (@,11) goes to the slave, is answered with (?), network is available and now the master comes up with (r,26,27,28) to get the answer that the SlavePV. But the SlavePV has still the value (arg0==@) from the first (net.startArg(cmd); char arg0 = net.readArgC();). The next Serial string with (r,26,27,28) is not read yet. I tried with Serial.flush and different things like reading (cmd = net.readCmd) again -- but I did not succeed.

Can You give me a helping hand?

Thanks a lot

Berry