system
November 19, 2014, 8:54am
1
Hi, I've just created a program in C# that sends numbers to Arduino Uno to control a servo motor.
After a few seconds that the program is running, the COM 3 (and all other COMs I tried) don't exist anymore, then I can't reprogram Arduino Uno or communicate with it. But if I disconnect and reconnect the USB cable, it works again for other few seconds.
I've Windows 8, can you help me?
system
November 19, 2014, 9:47am
2
Hi, I've just created a program in C#
That you didn't show us.
that sends numbers to Arduino Uno
That is running code you didn't show us.
can you help me?
No.
system
November 19, 2014, 10:00am
3
PaulS:
That you didn't show us.
That is running code you didn't show us.
No.
C# program
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string k;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
serialPort1.Open();
}
private void button2_Click(object sender, EventArgs e)
{
k = "0";
serialPort1.WriteLine(k);
}
private void button3_Click(object sender, EventArgs e)
{
k = "45";
serialPort1.WriteLine(k);
}
private void button4_Click(object sender, EventArgs e)
{
k = "90";
serialPort1.WriteLine(k);
}
private void button5_Click(object sender, EventArgs e)
{
k = "135";
serialPort1.WriteLine(k);
}
private void button6_Click(object sender, EventArgs e)
{
k = "180";
serialPort1.WriteLine(k);
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
int i = 0;
label1.Text = Convert.ToString(trackBar1.Value);
i = trackBar1.Value;
i = i * 2;
k = Convert.ToString(i);
serialPort1.WriteLine(k);
}
private void button7_Click(object sender, EventArgs e)
{
serialPort1.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
arduino program
#include <Servo.h>
Servo myservo;
int val=1;
void setup()
{
Serial.begin(9600);
myservo.attach(9);
Serial.setTimeout(50000000);
}
void loop()
{
val = Serial.parseInt();
Serial.write(val);
myservo.write(val);
}
system
November 22, 2014, 11:35am
4
val = Serial.parseInt();
Serial.write(val);
Hope there is something to read. If there is, read it, and then send some binary data back.
Then, hope that you got some meaningful data, and write it to the servo.
Now, considering that your C# program does NOT read data from the serial port, as binary data or ASCII data, why are you sending data?
Why are you trying to read data that may not have arrived?
Why are you using the data that you might not have read?
Why is the timeout set to such a ridiculous value?