Hello, I've recently been working on an arduino project which is interfaced on a computer in C#, communication between arduino is an XBee so serial in other words. I have noticed that it takes around a second or so to transfer a very little amount of data over from the computer to the arduino. Xbees are set at 57.6k baud so it shouldn't be a problem. They were at 9600 and it was roughly the same speed so I assumed something else is slowing it down but don't know what. Here's the arduino code and the C# code.
#include <LiquidCrystal.h>
String line;
LiquidCrystal lcd(22, 23, 24, 25, 26, 27);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
Serial.begin(9600);
Serial3.begin(57600);
}
void loop()
{
if(Serial3.available()>2)
{
line = Serial3.readString();
lcd.clear();
lcd.setCursor(0,0);
Serial.print(line);
lcd.print(line);
if (line == "O 13")
{
digitalWrite(29,HIGH);
}
else
{
digitalWrite(29,LOW);
}
}
}
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;
using System.Speech.Recognition;
namespace testvoicerec
{
public partial class Form1 : Form
{
SpeechRecognitionEngine speechRecon = new SpeechRecognitionEngine();
public Form1()
{
InitializeComponent();
serialPort1.Open();
}
private void Form1_Load(object sender, EventArgs e)
{
speechRecon.SetInputToDefaultAudioDevice();
Choices colors = new Choices();
colors.Add(new string[] { "stop", "blink", "13", "12", "11", "10", "9", "8", "7", "clear" });
GrammarBuilder gb = new GrammarBuilder();
gb.Append(new GrammarBuilder(colors), 1, 3);
Grammar g = new Grammar(gb);
speechRecon.LoadGrammar(g);
speechRecon.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
speechRecon.RecognizeAsync(RecognizeMode.Multiple);
}
void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text == "clear")
{
label1.Text = "";
}
else if (e.Result.Text.Contains("blink"))
{
serialPort1.Write(e.Result.Text.Replace("blink", "O"));
label1.Text = e.Result.Text.ToString();
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
serialPort1.Close();
}
}
}
C# code isn't the best as I am currently testing a few things at once, but even if I try to put the serialPort1.Write(); on a button or something, I still get the same delay so the problem isn't from the speech recognition.
All that gets transfered over is like "O 13" or "O 12" so any reason why it would take approximatly a second to transfer?
Thanks