I use an Arduino Nano with some sensors and send data to a PC using the serial port. I just got a new Arduino Nano 33 BLE and tried the same code but its not working. So for testing I just wrote some simple test code on the Arduino Nano 33 BLE side:
void setup()
{
Serial.begin(57600);
}
void loop()
{
if (Serial.available())
{
char c = Serial.read();
Serial.write(c);
}
}
This just sends back whatever arrives through the COM port. Using the Arduino IDE Serial Monitor this works very well with the Arduino Nano 33 BLE. I also made this very simple C# test code (Windows Forms app):
SerialPort serialPort = new SerialPort("COM17", 57600);
serialPort.ReadTimeout = 4000;
serialPort.WriteTimeout = 4000;
serialPort.Encoding = Encoding.ASCII;
serialPort.DataReceived += SerialPort_DataReceived;
serialPort.Open();
if (serialPort.IsOpen)
{
Debug.Print("COM port open");
}
This C# code works perfect with my good old Arduino Nano but it doesn't work with the Arduino Nano 33 BLE. I have the COM port open message so the port exists and it is open, but then nothing else, no timeout, nothing. I already lost one day trying out all sorts of combinations but it just doesn't work, my C# app can't communicate with the Arduino Nano 33 BLE. It looks like a serial port issue so I think I'll put it on hold for now...
EDIT: The rest of my test code, for reference:
private void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
Debug.Print(serialPort.ReadExisting());
}
catch (Exception exception)
{
Debug.Print(exception.Message);
}
}
private void buttonSend_Click(object sender, EventArgs e)
{
try
{
serialPort.WriteLine("HELLO");
}
catch (Exception exception)
{
Debug.Print(exception.Message);
}
}
SerialPort_DataReceived
defined?serialPort.WriteLine("HELLO");
is actually executed? From what you described the problem is in your C# app, not in the Arduino partUsing the Arduino IDE Serial Monitor this works very well with the Arduino Nano 33 BLE
... that means that the data is getting to your computer ... what you do with the data after it gets there is off topic here