This is on continuation with a previous thread, but because I've changed directions, a quite a bit of debugging in this new direction I felt I should start a new thread since the new stuff can stand independently of the earlier thread.....
For reference, I'm using
I'm using Netduino Plus 2 (Firmware 4.3.1)
I'm using the JY-MCU Bluetooth board (v1.06)
The code I'm using is this:
public class Program
{
static ArrayList buffer = new ArrayList();
public static void Main()
{
var bluetoothSerialPort = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
bluetoothSerialPort.DataReceived += DataReceived;
bluetoothSerialPort.Open();
Thread.Sleep(Timeout.Infinite);
}
private static void DataReceived(object sender, SerialDataReceivedEventArgs e)
{
var bluetoothSerialPort = (SerialPort)sender;
// This code is not "production worthy"
// But for the purposes of diagnosing the issue it works
while (bluetoothSerialPort.BytesToRead > 0)
{
var byt = (byte)bluetoothSerialPort.ReadByte();
buffer.Add(byt);
bluetoothSerialPort.WriteByte(byt);
}
}
}
Some initial findings (The code above is not in play for this)
I've paired the Bluetooth board with my PC
I've powered the board using 5v
I've connected the RX and TX pins of the board to each other. (loop back)
Using Hyper Terminal (or similar) I connected to the correct serial port (the Bluetooth device), set baud rate etc.
Sending data from the terminal, results on the bluetooth board receiving and responding (due to RX and TX being connected) and I am able to see the response in the terminal window.
What I send is what I receive.
So I know that the bluetooth boards (I have two of them) are working
So the next step was to do the "loop back" using software/Netduino (just keeping it simple)
(The code above is now in play)
The TX and RX pins of the Bluetooth board are crossed over and connected to digital pins 0 and 1 (see previous post)
I've powered the bluetooth board via the Netduino 5v and ground.
Send data using the Serial Terminal program. What I see in the terminal screen is gibberish. The actual bytes I receive in code (using breaks points and seeing the bytes as they are read:
If I send "Hello" (without the quotes), I get the following bytes (consistently)
0
32
32
56
254
I've tried (in Code) using
COM1 with pins 0,1
COM2 with pins 2,3
COM3 with pins 7,8
No luck
I've also tried using this code in create an instance of a serial port
var bluetoothSerialPort = new SerialPort(SerialPorts.COM1);
Didn't make a difference.
So unless something is wrong with the code I've shown (and I've used multiple variations of code with same/similar results) I'm not able to explain/understand why or what.
Can someone help?