I am working with C# and arduino. I am still a newbie on this. I wish someone can help me. So my project is to send some code to Arduino. Then apply delay on Arduino and send back some string/char back to C#. I gave a textbox on C# to show the result of reading. This is my code: C# code
Public form1()
{
initializeComponent();
Serialport1.Open();
}
public void Read()
{
while (Serialport1.IsOpen)
{
try
{
string message = SerialPort1.ReadLine();
textbox1.text = message;
}
catch (timeoutException)
{
}
}
}
private void button1_click(object sender, eventargs e)
{
SerialPort1.write("A");
read();
}
arduino code:
int data;
void setup()
{
Serial.begin(9600);
Serial.print("START\n");
}
void loop()
{
if(Serial.available())
{
data = Serial.read();
if(data=='A')
{
delay(3000);
Serial.print("B");
}
}
}
What I wish is textbox result write B, but nothing is come and the textbox keep blank. What did I do wrong? I hope someone can explain to me. Thank you