Pages: [1]   Go Down
Author Topic: easy way to create gui for ardu?  (Read 6746 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 2
Posts: 226
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

is there like an easy way to create a gui for interacting with the ardu?
something without programming c. I know some visual basic.

I tell you what id imagine:
in excel i create buttons and a textfield, in a field i put in like a new timer setting. on pressing the button the timersetting gets changed. maybe that button+textfield gets translated into a simple serial command like (like in serial X + enter change variable X, then put in new value that just visualized in excel), but without the need of a terminal software.
is this possible, do you have maybe some sources?
Or r there better ways?
It doesnt have to be excel, just a userfriendly way to visualize the serial output with buttons and text fields for changing specific variables

in case this has been asked a 1000 times, how to i properly search the forum?

searching for gui results in 10000 hits with 99,9999% gui(de)
« Last Edit: July 23, 2012, 03:58:23 pm by lax123 » Logged

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

Hey,

This is a commonly asked question. And I had been in a similar position a few months ago. I am glad to be able to say that I managed to make a GUI with very little effort using Visual Basics.

From my experience:
1. Communication with the Arduino requires programmed on-board code that can understand Serial data sent through the Port. For example, when the Arduino get 100 bytes from the Serial.read() do "this".
2. You would need to access some sort of library that allows you to send data through the Ports. Since you are familiar with visual basics, I recommend looking at this reference http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx#Y200 . Visual Basics 2010 Express contains the libraries needed to use the SerialPort Class.

I hope this helps.
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 226
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thx a lot for the hint,

i just know a lil vba from excel for analysing data, write to cells, read and other simple stuff, but no experience with standalone vba yet.

do you have maybe a working example file or something like that? that would help me so much for my understanding
Logged

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

Hey,

Glad I helped. Unfortunately I do not have any example codes currently. There are however examples on the website I posted previously. I can basically tell you what you have to do:

You first have to define a new class of using SerialPort(), like so "Port = New SerialPort()". Then define the class definitions of Port, like "Port.PortName = SetPortName("COM3")", etc. Once you've defined what you need as shown in here http://msdn.microsoft.com/en-us/library/s14dyf47.aspx , you want to open the port with "Port.Open()". And "Port.Close()" when your done.

In terms of the Arduino Code, I would look for "Arduino Serial Communication".

Stuff like this makes me want to create a instructional video (don't count on it, I am super lazy). However, you can toss me a PM if you have specific questions.


Logged

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 5551
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you thought about using Processing?

http://processing.org/

You'd have to do a bit more work to build the GUI, of course, but since the Arduino project basically grew up out of Processing (and Wiring), and many people have interfaced the Arduino to the PC using Processing (meaning there is plenty of example code) - it might be worth looking into.
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Offline Offline
Full Member
***
Karma: 2
Posts: 226
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thx both of you,

looking at the processing it looks like looaads of work...

from my research, think ill go with "profi lab" as it supports serial and very nice and easy visualiziation

does someone know it?

Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 153
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here you go ;o)
... snipped from an old visual basic project.
It's not usable without the wiring and circuit setup, but it may inspire you on single task .. like communicating and such. Without delving too much into details I faintly recall that the code drives 2 motors that positions an infrared rang-finder to measure 'distances to' an object (effectively taking a 3d picture).


Code:

Public Class Form1

    Private mForward, mBackward, mSingleStep, mStop, mFullTurn As Boolean
    Private mSteps, mWaitTime, mRepeats As Integer
    Private mStepString As String = ""
    Private mWaitString As String = ""
    Private mRepeatString As String = ""

    Private currentStepper As Integer = 0
    ' Private current

    Private saveBool(3, 1) As Boolean
    Private saveByteValues(3, 1) As Byte
    Private startUpBypass As Boolean = True

    Private mBytesToSend(4) As Byte ' 5 bytes

    'Private recievedBytes(4) As Byte

    Private code As Integer
    Private value(3) As Byte
    Private recepValue As Integer

    Private dix As Collections.Generic.List(Of String)

    Private RangeData As Collections.Generic.List(Of Single)
    Private bool_Automate As Boolean = True
    Private val As Single
    Private Res_2 As Single
    Private refTable As New Collections.Generic.List(Of Single)

    Private binWriter As IO.BinaryWriter
    Private data_Initiated As Boolean = False

    'Private ev As ev
    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        For Each p In My.Computer.Ports.SerialPortNames
            If p = "COM15" Then
                SerialPort1 = My.Computer.Ports.OpenSerialPort("COM15")
                SerialPort1.Encoding = New System.Text.ASCIIEncoding
                If Not SerialPort1.IsOpen = True Then
                    SerialPort1.Open()
                End If
            End If
        Next
        saveBool(0, 1) = True
        saveBool(1, 1) = False
        saveBool(2, 1) = True
        saveBool(3, 1) = False
        saveByteValues(0, 1) = 1 'Repeat
        saveByteValues(1, 1) = 10 'wait
        saveByteValues(2, 1) = 1
        saveByteValues(3, 1) = 0



        '0 - first stepper
        '1 - second stepper

        '2 - What's up Doc
        '3 - Pause
        '4 - Done
        dix = New Collections.Generic.List(Of String)
        dix.Add("  forward")
        dix.Add("  backward")

        dix.Add("  What's up Doc?") '2
        dix.Add("  Pause")
        dix.Add("  Done")
        dix.Add("  Measure")
        RangeData = New Collections.Generic.List(Of Single)

        Button5.Enabled = False
        'elBut = Button5
        For x As Integer = 0 To 300 '- 0.002 * x
            Val = CSng((108 * 113 / (x + 2000 / (x * x))))
            refTable.Add(Val)
            '  Debug.Print(x.ToString & ") " & val.ToString)
        Next

    End Sub

    Private Sub testRefTable(ByRef RangeOutput As Single)
        '  Res_1 = 0
        Res_2 = 0
        Dim slvd As Boolean = False
        Dim slv As Boolean = True
        Dim frac As Single
        For x As Integer = 0 To 299

            If slv Then
                If refTable(x + 1) <= RangeOutput And RangeOutput < refTable(x) Then
                    frac = (RangeOutput - refTable(x)) / (refTable(x + 1) - refTable(x))
                    Me.Res_2 = x + frac ' (RangeOutput - refTable(x)) / (refTable(x + 1) - refTable(x)) 'interpolates
                    Debug.Print("res_2 " & Res_2.ToString)
                    Exit For
                End If
            End If
        Next
        'Stop
    End Sub
    'forward
    'kode(0)
    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        If RadioButton1.Checked Then
            mForward = True
            mBackward = False
        End If
    End Sub

    'backwards
    'kode(0)
    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
        If RadioButton2.Checked Then
            mForward = False
            mBackward = True
        End If
    End Sub

    'mSingleStep
    'kode(0)
    Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If RadioButton3.Checked Then
            mSingleStep = True
            mFullTurn = False
        End If
    End Sub

    'kode(0)
    'full step
    Private Sub RadioButton4_CheckedChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
        If RadioButton4.Checked Then
            mSingleStep = False
            mFullTurn = True
        End If
    End Sub

    Private Function StringToByte(ByVal streng As String) As Byte
        StringToByte = 0
        Try
            StringToByte = CType(streng, Byte)
        Catch ex As Exception
            Debug.Print("StringToNumber error : " & ex.Message)
            StringToByte = 0
        End Try
        Return StringToByte
    End Function

    'number of step/turns
    'kode(3 & 4)
    Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
        mStepString = TextBox1.Text
        If e.KeyCode = Keys.Return Then
            If Not mStepString = "" Then
                mSteps = CType(mStepString, Integer)
                'If 250 < mSteps Then
                '    mSteps = 250
                'ElseIf mSteps < 0 Then
                '    mSteps = 0
                'End If
            End If
        End If
    End Sub

    'number of repeat times
    'kode(1)
    Private Sub TextBox3_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox3.KeyUp
        'Dim str As String
        mRepeatString = TextBox3.Text
        If e.KeyCode = Keys.Return Then
            If Not mRepeatString = "" Then
                mRepeats = CType(mRepeatString, Integer)
                If 250 < mRepeats Then
                    mRepeats = 250
                ElseIf mRepeats < 0 Then
                    mRepeats = 0
                End If
                'doTurns()
            End If
        End If
    End Sub

    'kode(2)
    'rest-time
    Private Sub TextBox4_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox4.KeyUp
        mWaitString = TextBox4.Text
        If e.KeyCode = Keys.Return Then
            If Not mWaitString = "" Then
                mWaitTime = CType(mWaitString, Integer)
                If 250 < mWaitTime Then
                    mWaitTime = 250
                ElseIf mWaitTime < 0 Then
                    mWaitTime = 0
                End If
                'doTurns()
            End If
        End If
    End Sub
    'mSteps
    Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.LostFocus
        If Not mStepString = "" Then
            mSteps = CType(mStepString, Integer)
            'If 250 < mSteps Then
            '    mSteps = 250
            'ElseIf mSteps < 0 Then
            '    mSteps = 0
            'End If
        End If
    End Sub

    Private Function StepsToBytes(ByVal steps As Integer) As Byte()
        Dim litl As Integer = steps
        Dim big As Integer = 0
        Dim res(1) As Byte

        While 255 < litl
            litl = litl - 256
            big = big + 1
        End While
        res(0) = CType(litl, Byte)
        res(1) = CType(big, Byte)

        StepsToBytes = res
    End Function

    'mRepeats:
    Private Sub TextBox3_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox3.LostFocus
        If Not mRepeatString = "" Then
            mRepeats = CType(mRepeatString, Integer)
            If 250 < mRepeats Then
                mRepeats = 250
            ElseIf mRepeats < 0 Then
                mRepeats = 0
            End If
            mBytesToSend(1) = CType(mRepeats, Byte)
        End If
    End Sub
    'mWaitTime
    Private Sub TextBox4_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox4.LostFocus
        If Not mWaitString = "" Then
            mWaitTime = CType(mWaitString, Integer)
            If 250 < mWaitTime Then
                mWaitTime = 250
            ElseIf mWaitTime < 0 Then
                mWaitTime = 0
            End If
            mBytesToSend(2) = CType(mWaitTime, Byte)
        End If

    End Sub

    Private Sub LoadStepper(ByVal first As Boolean)

    End Sub



Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 153
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

    
Code:
Private Sub ReadForm()
        If RadioButton1.Checked Then 'forward
            saveBool(0, currentStepper) = True
        End If
        If RadioButton2.Checked Then 'backwards
            saveBool(1, currentStepper) = True
        End If
        If RadioButton3.Checked Then 'mSingleStep
            saveBool(2, currentStepper) = True
        End If
        If RadioButton4.Checked Then 'full step
            saveBool(3, currentStepper) = True
        End If

        '      forw                         single
        If RadioButton1.Checked And RadioButton3.Checked Then 'forward
            mBytesToSend(0) = 0
            '                                full
        ElseIf RadioButton1.Checked And RadioButton4.Checked Then
            mBytesToSend(0) = 2

            '            backw                single
        ElseIf RadioButton2.Checked And RadioButton3.Checked Then 'backwards
            mBytesToSend(0) = 1

            '            backw                full
        ElseIf RadioButton2.Checked And RadioButton4.Checked Then 'fullStep
            mBytesToSend(0) = 3

        End If
        '----------------------------
        mBytesToSend(1) = StringToByte(TextBox3.Text) ' CType(Repeat, Byte)
        mBytesToSend(2) = StringToByte(TextBox4.Text) ' CType(mWaitTime, Byte)
        saveByteValues(0, currentStepper) = mBytesToSend(1)
        saveByteValues(1, currentStepper) = mBytesToSend(2)
        Dim bts(1) As Byte
        'TextBox1
        Dim stps As Integer = CType(TextBox1.Text, Integer)
        bts = Me.StepsToBytes(stps)
        mBytesToSend(3) = bts(0) 'least significant
        mBytesToSend(4) = bts(1) ' most significant
        saveByteValues(2, currentStepper) = mBytesToSend(3)
        saveByteValues(3, currentStepper) = mBytesToSend(4)

    End Sub




    Private Sub Send4Bytes()
        'Stop
        SerialPort1.Write(mBytesToSend, 0, 5)
    End Sub

    Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        'Debug.Print("Data recieved")

        Dim val1, val2 As Byte
        'dataStandard:
        'first byte is code (for the dix)
        'next four is an integer (arduin long)
        'Debug.Print("BytesToRead " & SerialPort1.BytesToRead)
        Debug.Print(" ")
        If SerialPort1.BytesToRead = 3 Then
            code = SerialPort1.ReadByte
            'For i As Integer = 0 To 1
            val1 = CType(SerialPort1.ReadByte, Byte)
            val2 = CType(SerialPort1.ReadByte, Byte)
            ' Next
            If code = 5 Then
                val = CSng(val1 + val2 * 256)
                Me.testRefTable(val) 'Res_2 =
                If data_Initiated Then
                    Me.DataWrite(Res_2)
                End If
                RangeData.Add(Res_2)
            End If
            'recepValue = System.BitConverter.ToInt16(val, 0)
            If code = 4 Then
                Beep()
                Beep()
                'UnDim()
            End If
            Debug.Print(dix(code))
            'Debug.Print("value : " & (val1 + val2 * 256).ToString)
        ElseIf 3 < SerialPort1.BytesToRead Then
            SerialPort1.DiscardInBuffer()
            'Stop
        End If

    End Sub

    'Private Sub UnDim()
    '    Button5.Enabled = True
    '    Button2.Enabled = False
    'End Sub

    Private Sub SerialPort1_ErrorReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialErrorReceivedEventArgs) Handles SerialPort1.ErrorReceived
        Debug.Print("error recieving")
    End Sub

    'stop
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        mBytesToSend(0) = 4
        RangeData.Clear()
        Send4Bytes()
    End Sub

    'datawriting
    Private Sub StartDataWriter()

        Dim Dinf As New IO.DirectoryInfo("H:/ScanFiles")
        Dim nbr As Integer = Dinf.GetFiles.Count
        Dim str As String = TextBox2.Text & (nbr + 1).ToString

        Dim dataFileName As String = "H:/ScanFiles/" & str & ".scn"
        Dim fs As IO.FileStream = New IO.FileStream(dataFileName, IO.FileMode.CreateNew) 'Or IO.FileMode.Open

        binWriter = New IO.BinaryWriter(fs)
        '  dataMark = 0
    End Sub
    Private Sub DataWrite(ByVal value As Single)
        'If binWriter.BaseStream.
        binWriter.Write(value)

    End Sub

    'go
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If bool_Automate Then
            PrepareRoller()
            Button2.Enabled = False
            Button5.Enabled = True
            ' RangeData.Clear()
        Else
            Me.ReadForm()
        End If

        Send4Bytes()
    End Sub

    ''reset as home
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        mBytesToSend(0) = 5

        Me.Send4Bytes()
    End Sub

    ''go home .
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        mBytesToSend(0) = 6

        Me.Send4Bytes()
    End Sub

    Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged
        ReadForm()
        If startUpBypass Then
            startUpBypass = False
        Else
            If RadioButton5.Checked Then
                currentStepper = 0
            Else
                currentStepper = 1
            End If
            RadioButton1.Checked = saveBool(0, currentStepper)
            RadioButton2.Checked = saveBool(1, currentStepper)
            RadioButton3.Checked = saveBool(2, currentStepper)
            RadioButton4.Checked = saveBool(3, currentStepper)
            TextBox3.Text = saveByteValues(0, currentStepper).ToString
            TextBox4.Text = saveByteValues(1, currentStepper).ToString
            Dim myI As Integer = saveByteValues(3, currentStepper) * 256 + saveByteValues(2, currentStepper)
            TextBox1.Text = myI.ToString
        End If
    End Sub

    Private Sub PrepareRoller()
        mBytesToSend(0) = 0 'forward single
        mBytesToSend(1) = 144 ' CType(Repeat, Byte)
        mBytesToSend(2) = 10 ' CType(mWaitTime, Byte) ?????

        Dim bts(1) As Byte
        Dim stps As Integer = 1
        bts = Me.StepsToBytes(stps)
        mBytesToSend(3) = bts(0) 'least significant
        mBytesToSend(4) = bts(1) ' most significant
    End Sub

    Private Sub PrepareElevator()
        mBytesToSend(0) = 2 'forward full
        mBytesToSend(1) = 10 ' CType(Repeat, Byte)
        mBytesToSend(2) = 0 'waits 100 milliS

        Dim bts(1) As Byte
        Dim stps As Integer = 96
        bts = Me.StepsToBytes(stps)
        mBytesToSend(3) = bts(0) 'least significant
        mBytesToSend(4) = bts(1) ' most significant
    End Sub '
    'Elevate
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        PrepareElevator()
        Send4Bytes()
        Button5.Enabled = False
        Button2.Enabled = True
    End Sub

    'automate
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        bool_Automate = CheckBox1.Checked
    End Sub

    'Initiate datacollection
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If data_Initiated Then
            binWriter.Close()
            data_Initiated = False
            Button6.Text = "Initiate"
        Else
            data_Initiated = True
            'Button6.Enabled = False
            StartDataWriter()
            Button6.Text = "Stop collecting"
        End If


    End Sub

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
        binWriter.Close()
    End Sub


End Class

'kode(0)
'kode(1)

'forward/backward & singlestep/full : kode(0)

' 0-4 implies start
'forward singlestep                     0
'backwards singlestep                   1
'forward fullStep                       2
'backwards fullStep                     3

'stop                                   4
'reset as home                          5
'go home ... is calculated in arduino   6

'Internal to arduino:
'FirstStepper load variables            10
'second stepper load variables          11
'first stepper save variables           12
'second stepper save variables          13
' det kan forventes at når steper er stoppet
'at der kan ske et skift, altså at ved stop
'bliver variables saved. Ligeledes at et skift
'autoatically implies a stop
'skift stepper                          14

'number of repeats: kode(1)   byte
'wait 100 millis : kode(2)    byte
'number of steps : kode(3) & kode(4)   integer/Long
Logged

Offline Offline
Sr. Member
****
Karma: 6
Posts: 426
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can make a GUI fairly easily with http://koda.darkhost.ru/page.php?id=index

Use this http://www.autoitscript.com/forum/topic/128546-serial-port-com-port-udf/ to send data to and from the arduino.

Example here http://www.autoitscript.com/forum/topic/121086-analog-gauge-gdi-serial-input-for-arduino-more/page__hl__+arduino#entry949603

And this http://www.autoitscript.com/forum/topic/138727-arduino-gui-programmer/page__hl__%20arduino
« Last Edit: July 27, 2012, 05:43:26 pm by Lakes » Logged

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

Hello..
 I am making a project on electronic voting machine using RFID technology.
The programs are executed using the Arduino software.
I need to create a GUI for the whole project. Is it possible to create the GUI using LabVIEW or MATLAB interfacing it with the arduino program???

Logged

Pages: [1]   Go Up
Jump to: