VB.net and Arduino communication problem
i think may have been looking @ thing long , might ignoring obvious.
here code below does. have set when type in number in text box, sends number arduino. parrots number @ me. if number 33 turns led on, if 34, turns led off.
whats happening, while led seems t control fine, data getting parroted me odd. first time type , hit send, message box comes up, , displays 34 3 (if typed in 45 show 45 3, 22 show 22 3, ect). second time put in number message box show 0 0.
the code way me figure out how communication works, @ point stumped.
here code below does. have set when type in number in text box, sends number arduino. parrots number @ me. if number 33 turns led on, if 34, turns led off.
whats happening, while led seems t control fine, data getting parroted me odd. first time type , hit send, message box comes up, , displays 34 3 (if typed in 45 show 45 3, 22 show 22 3, ect). second time put in number message box show 0 0.
the code way me figure out how communication works, @ point stumped.
quote
const int dirpin = 3;
const int steppin = 4;
int = 0;
int b = 0;
int c = 0;
int d = 0;
int val = 0;
void setup(){
pinmode(dirpin, output);
pinmode(steppin, output);
serial.begin(9600);
pinmode(8, output);
}
void loop() {
if (serial.available() > 0) {
a = serial.read();
val = a;
serial.println(val);
if (val == 33) {
digitalwrite (8, high);
}
if (val == 34) {
digitalwrite (8, low);
}
// if (val == 5001){
// digitalwrite (8, high);
// }
// if (val == 5002){
// digitalwrite (8, low);
// }
}
serial.flush();
}
code: [select]
dim testvar string
private sub senddatabtn_click(sender system.object, e system.eventargs) handles senddatabtn.click
testvar = gotosteptextbox.text
dim btyearr() byte = bitconverter.getbytes(cint(gotosteptextbox.text))
if not serialport1.isopen then
serialport1.open()
end if
serialport1.write(btyearr, 0, btyearr.length)
'serialport1.close()
end sub
private sub serialport1_datareceived(sender object, e system.io.ports.serialdatareceivedeventargs) handles serialport1.datareceived
dim recstr string = ""
dim datareceived boolean
datareceived = false
while not datareceived
dim recval integer
recval = serialport1.readbyte()
if recval = 10 or recval = 13 then
datareceived = true
else
recstr = recstr + chr(recval)
end if
end while
messagebox.show(recstr & " " & cchar(recstr))
end sub
end class
try this:
i think serial.println(); problem writes carriage return , don't know else port. try serial.write();
void loop() {
if (serial.available() > 0)
{
= serial.read(); //no need use (val).
serial.flush(); //clears buffer after reading have ready next arriving number.
serial.write(a); //writes number port.
}
if (a == 33)
{
digitalwrite (8, high);
a=0; //clears once used have ready next arriving value.
}
if (a == 34)
{
digitalwrite (8, low);
a=0;
}
}
i think serial.println(); problem writes carriage return , don't know else port. try serial.write();
void loop() {
if (serial.available() > 0)
{
= serial.read(); //no need use (val).
serial.flush(); //clears buffer after reading have ready next arriving number.
serial.write(a); //writes number port.
}
if (a == 33)
{
digitalwrite (8, high);
a=0; //clears once used have ready next arriving value.
}
if (a == 34)
{
digitalwrite (8, low);
a=0;
}
}
Arduino Forum > Using Arduino > Interfacing w/ Software on the Computer > VB.net and Arduino communication problem
arduino
Comments
Post a Comment