IMG_6114

Raspberry Pi to netduino serial communication

The Raspberry Pi and Netduino both got their strenghts, but what if they can talk to each other? I did a small proof of concept and got them to do serial communication via the pins.

Raspberry GPIO 14 (TX) is connected to Netduino digital 0.

Raspberry GPIO 15 (RX) is connected to Netduino digital 1.

Raspberry ground connects to Netduino ground.

Raspberry Node.js code (a bit simplified…):

var SerialPort = require("trivial-port");
var serialPort = new SerialPort({serialPort : "/dev/ttyAMA0", baudrate: 9600});
serialPort.initialize();
serialPort.write("2");

Netduino code:

public class Program
{
	static SerialPort serial;
	static OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

	public static void Main()
	{
		serial = new SerialPort(SerialPorts.COM1, 9600, Parity.None, 8, StopBits.One);
		serial.Open();
		serial.DataReceived += new SerialDataReceivedEventHandler(serial_DataReceived);
		Thread.Sleep(Timeout.Infinite);
	}

	static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
	{
		byte[] bytes = new byte[1];

		while (serial.BytesToRead > 0)
		{
			var x = serial.Read(bytes, 0, bytes.Length);
			char[] c = Encoding.UTF8.GetChars(bytes);
			led.Write(true);
			Thread.Sleep(100);
			led.Write(false);
		}
	}
}

Hooray!