Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Pages: [1] 2   Go Down
Author Topic: interfacing VB.net or JAVA with Arduino  (Read 3273 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 1
Posts: 137
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am posting this for another person, I got a message about interfacing the arduino with either VB.net or JAVA and since I am not too much of programmer or software guy I am posting it here for pangetadrian.  Here's the question:

Quote
i would like to ask you if it is possible for arduino output to be an input on VB.net or JAVA programming language..and how..


for the reason that i am making a thesis about a virtual glove that will have a finger sensor when one or more finger is bend it will output somehing on arduino, and arduino will output it to vb.net or java...

another question, im going to make a program(using vb or java) that will take that output from arduino, and assign it as a keyboard stroke(when you strike a key on the keyboard)..so that everytime i move my finger a character or set of chacarters will output on a notepad or MSword..is it possible?..

hoping for your reply T_T
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 131
Posts: 8690
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's some VB code I've used

Code:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Long
        Dim s As String

        If Not SerialPort1.IsOpen() Then
            SerialPort1.Open()
        End If

        TextBox1.Text = ""
        TextBox1.Refresh()
        Do While i < 50
            SerialPort1.Write("<hello>")
            s = SerialPort1.ReadLine()
            TextBox1.Text = TextBox1.Text + s + vbCrLf
            TextBox1.Refresh()
            i = i + 1
        Loop

    End Sub

    Private Sub Form1_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
        If SerialPort1.IsOpen() Then
            SerialPort1.Close()
        End If

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SerialPort1.PortName = "Com33"
        SerialPort1.Open()
    End Sub
End Class

It was for a specific purpose but could be easily adapted to your mate's needs I would think.

______
Rob

Logged

Rob Gray aka the GRAYnomad www.robgray.com

0
Offline Offline
Full Member
***
Karma: 1
Posts: 137
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, hopefully he will find his way to this thread (sent him the link)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes!..thank you sirs..you've answered my prayers..will give it a try!  smiley
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 76
Posts: 7354
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You should seriously try the Processing. It is a sister project with Arduino. The Arduino guys took the Processing JAVA IDE and turned it into the current Arduino IDE. Processing is very easy to use and to draw stuff, 2D or 3D.

Here is a piece of my code, not complete but it shows you how to do serial port:

Code:
void draw()
{
  while (myPort.available() > 0)
  {
    if (inBuffer_full) println ("In buffer is full");
    inBuffer[write_pointer]=myPort.readChar();
    if ((write_pointer>0)&&(inBuffer[write_pointer]==0)) // The last byte from the transmission is a zero. Sense this zero and finish update the display.
    {
      String test1=new String(inBuffer);
      showData.jTtr_data.setText(test1);
      print(test1);
      write_pointer=0;
      break;
    }
    write_pointer++;
  }
}
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i have another problem..

here is the situation..

i have now a finger sensor(flex/bend sensors) using IR LEDs, when bend there will be a voltage drop and that voltage now will be compared to a reference voltage using a comparator, that comparator now will output either 0.25v or 6.25v(depending on the voltage comparison, i think thats logic 1 or 0 in digital input), and that output will be the inputed to the analog pins of ARDUINO,

how will i program arduino that when 6.25v is read from the analog input, it will light an LED (LED = high) and if 0.25 nothing will happen..
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 131
Posts: 8690
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can't feed the 6.25 directly into the Arduino. If you are only interesed in those two levels just reduce the signal with a zener or voltage divider.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i want to output HIGH on an LED if the analog input receives < 0.20volts and LOW if it receives > 0.20v..meaning if 0.10 or 0.15 or 0 is inputted on the analog input..the LED in pin13 will light up..i have read somewhere that 40 is the equivalent voltage for 0.20v

i got that 0.20v from a comparator, lm339 to be exact.. it outputs 0.20v or 4.2v..and that output from the comparator is inputted to the analog input of arduino..ive tried the code below..when i use potentiometer as the input in arduino, it works however when the output from the comparator is used it wont work..

this code wont work.

Code:
int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;       // value output to the PWM (analog out)
void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(A0);
  Serial.println(sensorValue, DEC);
  delay(0);
   if(sensorValue > 41){
  // turn the ledPin on
  digitalWrite(ledPin, HIGH);  
  // stop the program for <sensorValue> milliseconds:
  delay(0);        }
  if(sensorValue < 41){
  // turn the ledPin off:        
  digitalWrite(ledPin, LOW);  
  // stop the program for for <sensorValue> milliseconds:
  delay(0);         }        
  
}



anyone?...
« Last Edit: February 06, 2011, 03:55:23 pm by pangetadrian » Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 131
Posts: 8690
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Your 41 value is right.

What's with the delay(0)s ?

Code:
if(sensorValue > 41){
    if(sensorValue < 41){

What if the value is exactly 41?

Use

Code:
if(sensorValue > 41){
    digitalWrite(ledPin, HIGH); 
} else {
    digitalWrite(ledPin, LOW); 
}

But if the value is hovering around 41 the LED could pulse so fast it may look like it's on all the time.

For the moment I'd add a single delay(1000) but some hysterisis is a better way to go.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i want that output of the arduino to be inputted on an Programming language..VB.net to be exact..some say that is just using serial port..what will i code to send that output from arduino to vb.net..is it analog or digital that will be passed to vb.net?..

here is my code already..it will output high when the sensorvalue is less than 41

Code:

int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;       // value output to the PWM (analog out)
void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(A0);
  Serial.println(sensorValue, DEC);
  delay(0);
 if(sensorValue > 41){
    digitalWrite(ledPin, LOW); 
} else {
    digitalWrite(ledPin, HIGH); 
}       
delay();
 
}


Instead of using LED to the output..i want to send it to computer and later be read to VB.net..is it possible?..
« Last Edit: February 07, 2011, 06:00:36 am by pangetadrian » Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 131
Posts: 8690
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You're already sending the information to the PC

Code:
Serial.println(sensorValue, DEC);

You just aren't reading it yet. You need to write some VB code to read that data.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You're already sending the information to the PC

Code:
Serial.println(sensorValue, DEC);

You just aren't reading it yet. You need to write some VB code to read that data.

______
Rob


but that information is the value of the sensor (from 0-5volts,0-1023)...i want to send digital output to the computer for example 00010 in bin or 02h in hex..do i have to convert the output( the HIGH and LOW of LED) to digital or is it digital already?..i dont have a clue..plz help..
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 131
Posts: 8690
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I just posted some VB code on your other thread.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it worked..thanks to sir Graynomad..

heres what i did..

this is the code for arduino..

Code:
void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
}

void loop() {  //This will print bytes from 0-100
  for (int i = 0; i < 100; i++) {
Serial.print (i, BYTE);
delay(1000);
}     
}

while arduino is sending data to the computer..A vb.net software will be listening to what that port is sending (in my case COM5)

here are the codes for vb.net

Code:
Imports System.Threading
Imports System.IO
Imports System.Text
Imports System.IO.Ports

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Long
        Do
            i = SerialPort1.ReadByte
            RichTextBox1.Text = RichTextBox1.Text + "<" + Str(i) + ">"
            RichTextBox1.Refresh()
            TextBox1.Text = "Hellow World"
        Loop While i <> 100
         End Sub

    Private Sub Form1_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
        If SerialPort1.IsOpen() Then
            SerialPort1.Close()
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SerialPort1.PortName = "Com5"
        SerialPort1.Open()
    End Sub
   End Class

a serialport object is added to the form,with variable name "SerialPort1"..when the button1 is clicked..it will fetch the data that com5 is sending..(0-100 bytes based on the code above)..i dont really know how to convert that byte to string..

heres another problem i want to resolve..for example..i want to send "5" to com5(Serial.print (5, BIN)smiley-wink , when you open the serial monitor from arduino..it will output "101" which is the equivalent of 5 in Binary..but when fetch to the vb.net software..VB's output are 49,48,49....(49 is the ASCII code for 1 and 48 for 0)..how do i change that output from the software to BIN also..not 49,48,49 but instead 101..

pls correct me if im wrong..
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 131
Posts: 8690
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i dont really know how to convert that byte to string..

The "i" is binary,

Str(i)

Converts it to a string.

Serial.print (5, BIN)

Will send the "1"s and "0"s that make up the value as ASCII characters. This is almost totally useless unless you want to look at the bits for some reason.

If you just want the binary value you already have that

Serial.print (5, BYTE)

sends the number and

i = SerialPort1.ReadByte

reads it, "i" is a number, do with it what you will.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: [1] 2   Go Up
Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Jump to: