visual basic serial communication


hi all.
i've been searching on web problem. can't find anny tutorials works.

i have arduino duemilanove, temp sensor, 2 led lights , 2 pushbuttoms.

what wanna do, make software windows in visual basic.
and need communicate between arduino , computer.

i've made soft , managed turn led on of pressing buttoms on skreen, don't manage show temp sensor value in visual basic.
later i'd have several temp sensors showing on screen.

annyone know how read serial communication arduino?
heeeelp  :-/

-andy

* code *
--------------------------------------------------------------
* arduino *
#include <math.h>

int ledpin      = 10;           // number of led pin
int buttonpin2  = 2;            // number of pushbutton pin
int incomingbyte;

double thermistor(int rawadc) {
 double temp;
 temp  = log(((10240000/rawadc) - 10000));
 temp  = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * temp * temp ))* temp );
 temp  = (temp - 273.15);            // celcius
 //temp  = ((temp * 9.0)/ 5.0 + 32.0); // fahrenheit
 return temp;
}

void setup() {
 serial.begin(19200);
 // initialize led pin output:
 pinmode(ledpin, output);      
 // initialize pushbutton pin input:
 pinmode(buttonpin2, input);  
}

void loop(){
   if (serial.available() > 0) {
        incomingbyte = serial.read();
        if (incomingbyte == 'a') {
             digitalwrite(ledpin, high);
        }
        if (incomingbyte == 'b') {
             digitalwrite(ledpin, low);
        }
   }
      serial.println(int(thermistor(analogread(0))));
     //delay(100);      
}

--------------------------------------------------------------
* visual basic *
imports system.io
imports system.io.ports
imports system.threading

public class form1
   shared _continue boolean
   shared _serialport serialport

   private sub form1_load(byval sender system.object, byval e system.eventargs) handles mybase.load
       with serialport2
           .close()
           'set serial port want use.
           .portname = "com6" 'you must put 'com' before com number.

           'set baud rate, parity, data bits, , stop bits.
           .baudrate = 19200
           .parity = parity.none
           .databits = 8
           .stopbits = stopbits.one

           'set dtr , rts
           .dtrenable = true
           .rtsenable = true

           'set number of bytes before datarecieved event raised.
           .receivedbytesthreshold = 1

           'open serial port.
           .open()
       end with
   end sub

   private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click
       serialport2.write("a")
   end sub

   private sub button2_click(byval sender system.object, byval e system.eventargs) handles button2.click
       serialport2.write("b")
   end sub

end class
--------------------------------------------------------------
:d

code: [select]
temp  = log((([glow]10240000[/glow]/rawadc) - 10000));
rawadc int. 10000 int 10240000 not int. should add ul end of value, tell compiler 10240000 unsigned long value, doesn't try interpret int.

code: [select]
      serialport2
you have object named serialport2. call bunch of methods on object. if press f1, select index button, if needed, select drop down list filtered by:, select visual basic, , type serialport for: field, can select "serialport class" see methods serialport class has. there several related reading serial port.

there event, datareceived, can register event handler for. whenever serial data arrives, handler called, , can deal data.


Arduino Forum > Forum 2005-2010 (read only) > Software > Interfacing > visual basic serial communication


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums