Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Passing Data Between X-Duinos


  • Please log in to reply
7 replies to this topic

#1 tridy

tridy

    Advanced Member

  • Members
  • PipPipPip
  • 68 posts
  • LocationStockholm, Sweden

Posted 05 October 2015 - 09:31 AM

Hello.

 

What is the best way of transferring data from Arduino to Netduino?

I am using Arduino to receive some data, and I would like to send an "event" to Netduino with some parameters. Could be an 6 items array of short strings, or csv, or xml, or something similar. Do I have to write own sender/receiver/driver that will listen for high and lows and decode it or is there a more convenient way?

 

Would it be the same implementation for passing data between two Netduinos?

 

Thanks.



#2 KiwiDev

KiwiDev

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts
  • LocationNew Zealand

Posted 05 October 2015 - 07:18 PM

Hi Tridy

 

There are few different options for *duino to *duino connectivity, 

 

On the NetMF platform bit bashing digital lines is often not a happy place. 

 

For a wired link you could use a serial cable (with an RS232 or RS422/485 converter for longer range) which has a simple API on both ends, You just need to sort out protocol for retries, error detection etc.not rocket science but the edge cases can trip you up.

 

For a wireless link I use the nRF24L01 devices there are drivers available for Arduino & Netduino (Need to pay attention to byte ordering of addresses). Low power consumption with upto 1KM range or 2MBps datarate depending on you project/environment.

 

On the NetMF end the nRF24 device + driver takes care of plumbing for you and you call a method to send a message and an event is fired when a message arrives.

 

I use these nRF24L01 Shields on Arduino & Netduino devices

http://embeddedcooln...hop/rfx-shield/

 

nRF241L01 code for NetMF

https://nrf24l01.codeplex.com/

 

Arduino 

https://github.com/tmrh20/RF24

 

Have a look at my blog there are samples there for nRF24 on *duino devices.

 

Regards

 

@KiwiBryn

blog.devmobile.co.nz



#3 tridy

tridy

    Advanced Member

  • Members
  • PipPipPip
  • 68 posts
  • LocationStockholm, Sweden

Posted 05 October 2015 - 09:08 PM

Thanks for the reply.

 

Let me write a bit more about what I am actually trying to achieve.

 

I am planning to use one Arduino to listen and decode 433.92 RF signal, and another ?rduino sending RF 433.92 and IR signals. Neduino will be the server that will log some of the RF signals (temperature and humidity) and listen to RF signals from an RF remote media control and send RF signals to turn lights on and off, and in some cases IR signals to turn off the TV, for example. So, both Arduinos (Nano) will sit very close to Netduino, and I hoped to manage everything with just wiring, (TTL?) RX,TX, Digital ins and outs. I don't mind doing some error handling and related, but getting RS232 cables and shields sounds like an overkill a bit for what I hoped it could be. The communication has to be quite fast when reacting to the remote controls button presses, but not like microseconds fast.

 

So, what I am looking for is to wire up 2 Arduino Nanos and pass strings from one Arduino to Netduino and then sending strings from Neduino to the other Arduino. What is the easiest way of doing it with [short range] wires?

 

Thanks.



#4 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 06 October 2015 - 06:22 AM

I'd probably look at using TTL serial to do this.

 

One thing you will have to consider though is that although the Netduino can receive serial TTL at 5V level it will only transmit at 3.3V levels.  You may have to introduce a buffer or simple transistor amplifier to translate the signals up for the Arduino.  Should not be too difficult to achieve.

 

Regards,

Mark


To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#5 tridy

tridy

    Advanced Member

  • Members
  • PipPipPip
  • 68 posts
  • LocationStockholm, Sweden

Posted 06 October 2015 - 06:42 AM

I see. Thanks!

 

I will start with the receiving part first, using TTL.

Then I will get back here about the sending part :).

 

regards



#6 TechnoGuy

TechnoGuy

    Advanced Member

  • Members
  • PipPipPip
  • 51 posts
  • LocationCanada

Posted 06 October 2015 - 11:37 AM

Just wondering if you came across this earlier post in the Neduino forums with regard to connecting one of those 433 MHz modules to a Netduino:

 

433MHz / 2.4GHz communications with Netduino/Netduino Plus

http://forums.netdui...onetduino-plus/

 

Disclaimer:  I know nothing about the modules you're trying to use.  But it seems like you CAN connect directly to the Netduino rather than having to use an Arduino as an intermediary.

 

 

Arduino as Intermediary:  Physical Connections

 

I did a Google search and found this diagram which should be useful to you in connecting your Netduino to your Arduino.  Just substitute your Netduino for one of the Arduinos in the diagram & make the same connections.

 

Arduino to Arduino Serial Interconnect at TTL Level 

 

OBSERVE that the RX & TX wires are CROSSED (i.e. you connect them as follows):

  • Arduino RX - Netduino TX
  • Arduino TX - Netduino RX
  • Arduino GND - Netduino GND

 

Coding

 

Using serial, you would do something like this on the Arduino (you have many choices and don't have to do it in this particular way)

 

Serial.print("Temperature=");

Serial.print(temperature);

Serial.print("  Humidity=");

Serial.print(humidity);

Serial.println();

 

This would send a line of text that shows like this

Temperature=23.7  Humidity=39.1

 

Things are a bit more complicated on the Netduino side.  You'd create an instance of the SerialPort class and then open it.  Then you'd receive the data using event-driven I/O.  There is no line-oriented serial I/O in NETMF.

 

Assuming you're able to accumulate a whole line of data, then you'd have to parse it out (extract the different values that you sent).

 

You can find tons of SerialPort code snippets in the Netduino forums (search on "SerialPort").  Another good place to look is on sites like Stack Overflow and Code Project.  Here's a piece of code that somebody posted on Stack Overflow that you can examine:

 

http://stackoverflow...ication-with-pc

 

I hope this makes it a little clearer for you.


- Ian

 

My Current Dev Boards:

  • 3 x Netduino Plus 2
  • 1 x Netduino 3 WiFi

#7 tridy

tridy

    Advanced Member

  • Members
  • PipPipPip
  • 68 posts
  • LocationStockholm, Sweden

Posted 06 October 2015 - 03:38 PM

I looked at the postings and regarding 433.92 MHz communication, when receiving the signal from a wireless switch or a remote control, to decode it, it requires real time readings and record in microseconds for how long it was HIGH and LOW and this real-time-os is sowething that NETMF is not, so I had to get Arduinos for that. It took me long time to get used to c++ and I started to appreciate c# even more after that but I managed the receiving and sending tasks with 4 different protocols (Wavewan, Nexa, Oregon, X10), so now it's time to put it all together.



#8 tridy

tridy

    Advanced Member

  • Members
  • PipPipPip
  • 68 posts
  • LocationStockholm, Sweden

Posted 17 October 2015 - 11:26 PM

Alright, it worked. crossed RX and TX plus GND. The messages from Arduino end with 13 and 10 so I append them until these two come.

Here is the code.

 public class Program
    {
        private const int MAX_MESSAGE_SIZE = 50;
        private static SerialPort _serial;
        private static StringBuilder _messageBuilder;

        public static void Main()
        {
            _serial = new SerialPort(SerialPorts.COM1, 115200, Parity.None, 8, StopBits.One);
            _serial.Open();
            _messageBuilder = new StringBuilder(MAX_MESSAGE_SIZE);
            _serial.DataReceived += OnSerialDataReceived;
            Thread.Sleep(Timeout.Infinite);
        }

        static void OnSerialDataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            int bytesToRead = _serial.BytesToRead; 
            byte[] buffer = new byte[bytesToRead];
            _serial.Read(buffer, 0, bytesToRead);
            var isEndOfMessage = AppendMessageBytes(buffer);
            if(isEndOfMessage)
            {
                var message = _messageBuilder.ToString(0, _messageBuilder.Length - 2);
                _messageBuilder.Clear();
                Debug.Print(message);
            }
        }

        static bool AppendMessageBytes(byte[] messageBytes)
        {
            if (IsMessageOverflow(messageBytes.Length)) return true;

            foreach (byte b in messageBytes)
            {
                _messageBuilder.Append((char) b);
            }
            
            return messageBytes.Length > 1 && messageBytes[messageBytes.Length - 1] == 10 && messageBytes[messageBytes.Length - 2] == 13;
        }

        private static bool IsMessageOverflow(int newMessageSize)
        {
            if (_messageBuilder.Length + newMessageSize > MAX_MESSAGE_SIZE)
            {
                _messageBuilder.Clear();
                _messageBuilder.Append("ERROR  ");
                return true;
            }
            return false;
        }
    }

Thanks for the help!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.