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

If you were to get two netduinos to talk to each other, what would you use?


  • Please log in to reply
23 replies to this topic

#21 Frankie

Frankie

    Member

  • Members
  • PipPip
  • 16 posts
  • LocationArnhem, Netherlands

Posted 23 June 2012 - 11:58 AM

Connect pin 1 on netduino 1 to pin 2 on netduino 2, pin 2 on netduino 1 to pin 1 on netduino 2, and connect the grounds.

On the sender:

  1:          public static void Main()
   2:          {
   3:              SerialPort port = new SerialPort(SerialPorts.COM1,115200);
   4:              OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
   5:   
   6:              port.Open();
   7:   
   8:              while (true)
   9:              {
  10:                  led.Write(true);
  11:                  port.Write(buff, 0, buff.Length);
  12:                  Thread.Sleep(100);
  13:                  led.Write(false);
  14:                  Thread.Sleep(900);
  15:                  buff = Encoding.UTF8.GetBytes(DateTime.Now.TimeOfDay.ToString());
  16:              }
  17:          }

On the receiver:

  1:          public static void Main()
   2:          {
   3:   
   4:              SerialPort serial = new SerialPort(SerialPorts.COM1, 115200);
   5:              serial.ReadTimeout = 8;
   6:              serial.DataReceived += new SerialDataReceivedEventHandler(serial_DataReceived);
   7:              serial.Open();
   8:              while (true)
   9:              {
  10:   
  11:                  Thread.Sleep(Timeout.Infinite);
  12:              }
  13:   
  14:          }
  15:   
  16:          static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
  17:          {
  18:              int bytesReceived = ((SerialPort)sender).BytesToRead;
  19:              byte[] bytes = new byte[bytesReceived];
  20:              ((SerialPort)sender).Read(bytes, 0, bytes.Length);
  21:              string received = new string(System.Text.Encoding.UTF8.GetChars(bytes));
  22:              Debug.Print(received); 
  23:   
  24:          }


for those who are gonna try this good example:
i think florest meant the first and second pin, so use pin 0 and 1. ;)

#22 skyjumper

skyjumper

    Member

  • Members
  • PipPip
  • 15 posts

Posted 08 July 2012 - 04:16 AM

Is it too late to say AYE to SPI slave mode? For what its worth, I think an Arduino, Netduino or anything similar is much more useful if it can act as an I2C or SPI slave device. As someone pointed out, UARTs are a limited and precious resource, while I2C and SPI are much better for collecting data from sensors.

#23 Jack Chidley

Jack Chidley

    Advanced Member

  • Members
  • PipPipPip
  • 99 posts

Posted 09 July 2012 - 01:36 PM

Aye. Someone more experienced can educate me here. My thought would be to enable communications with Arduinos, either SPI Master/Slave as appropriate. Why? Glad you asked. There are lots of drivers written for Arduino. Sometimes it makes sense to rewrite these drivers for .net, sometimes it might just be easier to use the Arduino to drive the hardware instead. Then you would just need a cheap arduino chip and write a tiny app to handle the comms instead. SPI seems like the right vehicle for this kind of comms. I guess you could use tcp/ip or other networking too but SPI is cheaper, simpler and faster for short distances. Does this make sense? Jack

#24 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 09 July 2012 - 07:18 PM

Hi Jack, Yes, you could certainly use SPI or UART to talk to an Arduino (or other boards) via SPI. Regarding SPI Slave... The reason that SPI Slave is not supported in NETMF is due to the way that SPI generally works. Data is written and read at the same time. But the data that's read usually has to arrive at the master on very specific clock pulses. This requires microsecond timing and NETMF really isn't set up to support that scenario. That said, we're implementing go!bus over SPI...and providing for a go!bus SPI client connection on STM32F2/4-based modules. So perhaps that could be used for inter-board communication as well (basically a really fast UART with error checking and shared pins). Chris




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.