I am working on a project and I am using this website as a reference to get my Netduino to communicate with my PC.
I've purchased this Bluetooth transceiver. It seems to be an updated version of the one used by the original post. 1.06 vs 1.04 on his website.
I set the Bluetooth's TXD to Pin0, RXD to Pin1, and VCC to 5V.
This is my code on the Netduino:
static SerialPort Bluetooth;
public static void Main()
{
Bluetooth = new SerialPort(SerialPorts.COM1, 9600, Parity.None, 8, StopBits.One);
Bluetooth.DataReceived += new SerialDataReceivedEventHandler(Bluetooth_DataReceived);
Bluetooth.Open();
Thread.Sleep(Timeout.Infinite);
}
static void Bluetooth_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
byte[] bytes = new byte[1];
while(Bluetooth.BytesToRead > 0)
{
Bluetooth.Read(bytes, 0, bytes.Length);
Debug.Print(bytes[0].ToString());
}
}
This is my code on my laptop: (it is a WPF application)
SerialPort serialBT;
private void Connect()
{
// COM7 is the outgoing port that corresponds to the Bluetooth transceiver
serialBT = new SerialPort("COM7", 9600, Parity.None, 8, StopBits.One);
serialBT.Open();
serialBT.Write(new byte[] { 23, 24, 25, 26 }, 0, 4);
Debug.Print("Values sent");
}
On the Netduino, when I send the byte array of 23, 24, 25, and 26 (just for testing purposes), the DataReceived event fires. However the values it received and prints out in the debug window are 6, 0, 0, and 248 instead of the 23, 24, 25, and 26 that it should be.
Other values I send are also just as mysteriously transformed to completely different ones.
I've tripled checked the proper COM settings for the Bluetooth transceiver and those are the correct settings. I've flipped the TXD and RXD pins since the original Arduino expects TXD to be Pin1 and RXD to be Pin0, but that causes no data to be received on the Netduino.
So.... I finally got it working. No change in the code. The answer seemed so simple but no one ever bothered to actually explain it; I just needed to switch the TXD and RXD pins.
COM1 for the Netduino means that PIN0 is the RX pin and PIN1 is the TX pin. Its expecting to receive data on PIN0 and send it on PIN1. The Bluetooth component will send data on its TX and the Netduino should receive it on the RX; The Bluetooth TX (send data) should be connected to the Netduino's RX (receive data) and the Bluetooth's RX (receive data) should be connected to the Netduino's TX pin (send data).