1

So I am making a user interface on vb 2010 that allows the user to type in a textbox the PWM they want a value between 0-255. I want to be able to take the value and change it as much as i want but there seems to be a problem i am only able to send one value without needing to debug the program again. The LED I am using as the test doesn't seem to be responding with the equivalent level brightness for the PWM that i use in the textbox. I hope to be able to control this with 8 separate relays as the end goal using some sort of switch statement. Any help would be very nice my current code: VB

 Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
    Shared _continue As Boolean
    Shared _serialPort As SerialPort
    Dim SerialPort1 As SerialPort
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SerialPort1 = New SerialPort
        SerialPort1.PortName = "COM4"
        SerialPort1.BaudRate = 9600
        SerialPort1.DataBits = 8
        SerialPort1.Parity = Parity.None
        SerialPort1.StopBits = StopBits.One
        SerialPort1.Handshake = Handshake.None
        SerialPort1.Encoding = System.Text.Encoding.Default
        SerialPort1.Open()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim input As String
        Dim returnvalue As String

        input = TextBox1.Text
        returnvalue = input


        SerialPort1.Write(input)
        SerialPort1.Close()


        MessageBox.Show(returnvalue)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim a As Integer
        a = SerialPort1.ReadChar()
        MessageBox.Show(a)
    End Sub
End Class



Arduino
   void setup() {
  // initialize serial communication:
  Serial.begin(9600);
   // initialize the LED pins:
      int thisPin = 2;
        pinMode(thisPin, OUTPUT);
      }

void loop() { 
    int inByte= 0;
    int V1;
  if (Serial.available()) {
     inByte = Serial.read();
     V1 = inByte;
      analogWrite(2, V1);
  }
}

Any help would be awesome ive been stumped on this for awhile
1
  • Q: Should you really be doing that SerialPort1.Close() in Button1_Click()??? Also: look here and here. Commented Jan 4, 2015 at 18:45

1 Answer 1

0

I have little experince with VB 2000. But I can answer the Arduino side. Looks like you are reading bytes in Arduino (1 at time)

 inByte = Serial.read();

But looks like you are sending text in the VB2000 App

 SerialPort1.Write(input)

Can you confirme that? If so, you need to transform the text input to Integer and then send 1 byte only.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes im sending text from vb 2010 to the arduino in the form of a number between 0-255 that will represent the pwm cycle so that i can chang e the brightness of an LED
After SerialPort1.Write(input) You dont need to use somethink like "flush" to really send the data?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.