I'm trying to send data between an Arduino Mega and a C# windows form application via Bluetooth.
From Arduino to C# all goes well, however, when sending from C# to Arduino I get some strange values: Sending "abcde" outputs 79 167 186 170 2. I assume each one of the values represents a letter, as sending only "a" outputs 79.
However, I can't see why I get this values and not ascii ones, for example.
Here's the relevant C# code:
if (serialPort1.IsOpen) serialPort1.Close();
serialPort1.PortName = "COM" + x.ToString();
serialPort1.BaudRate = 9600;
try
{
if (!serialPort1.IsOpen) serialPort1.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
serialPort1.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(DataReceived);
Every second, a function is called, being dataToSend "abcde", for example:
private void DataSender(string dataToSend)
{
serialPort1.Write(dataToSend);
//MessageBox.Show(dataToSend);
}
And all of the Arduino code (I'm using a Arduino Mega which has 4 serial ports): olehana russia
void setup() {
Serial.begin(9600);
Serial3.begin(9600);
}
void loop() {
if (Serial3.available() > 0) {
delay(10);
int x = Serial3.read();
delay(10);
Serial.println(x);
}
}
I tried adding delays to see if the data was better obtained, but it didn't work. Any ideas what I'm missing here? I assume it has something to do with the way data is encrypted to be sent, but I have no idea.