easiest way to command arduino from PC

I want a PC (windows7) to send an instruction to an arduino via USB?

The arduino will be used to position something via a motor, and the instruction sent will be simply position A or B.

The solution has to work everytime the PC is switched on without user input, and the user will be plugging and unplugging other USB devices.

I've used visualBasic, AutoHotKey, python before but it's all mostly forgotten so I'm willing to learn/use anything that's current, quick, easy, cheap. The fewer things I need to add to the system the better, if it can be done from a batch file that would be great!

Hi,

I’m using these blocks of code in VB with reference to the in / out routine on the Uno.

Could you do something with this, maybe convert to Batch file if you need to?

// https://forum.arduino.cc/index.php?topic=396450.0
// Serial Input Basics - updated
// Apr 25, 2016, 05:12 pm Last Edit: Apr 26, 2016, 11:27 am by Robin2
// Using Robins 'void RecvWithStartEndMarkers(') & 'void ParseData()'
// Example 5 - Receive with start- and end-markers combined with parsing


VB Code:

Public Sub Form_activate()
 
  lstInput.Clear
  Text1.Text = ""
 
  If myPortOpen <> "yes" Then
    Com1.CommPort = myComPort
    Com1.Settings = "9600,N,8,1"
    Com1.InputLen = 1
    Com1.RThreshold = 1
    Com1.SThreshold = 1
    Com1.RTSEnable = True
  
    Com1.PortOpen = True
    myPortOpen = "yes"

  End If

End sub



Public Sub Output1()                    'send 'Init'

  'start 8 second abort timer?
  Timer1.Interval = 8000                'Time in 'millisecs
  Timer1.Enabled = True                 'start on time
  
  xfer1 = "<1, 0, 0, 0>"
  
  Com1.Output = xfer1

Exit Sub

This isn’t complete, and I can post more if you want it, but it may be a starting point for you.

When the Uno gets this it responds with it’s own <1,0,0,0> to show that it’s ‘alive’ and then VB sends another set of numbers starting with ‘<2,…’, gets confirmation back then sends ‘<3,…’ or aborts, etc.

Peter

Thanks, I'm not great at batch files so using VB might be best idea anyway, looks like there is a free version so I'll have a go with it. The target machines should run the executable straight off as long as they've got .net right?

Hi,

It's been a while since I did anything like this but a batch file, vb.exe or a .vbs script in the PCs 'start up' routine should do it.

Peter

I found a thread on using batch files to send commands:

And it works.

So I'm happy for now, and can move onto the motor drive design.

I need to do some testing though to see what com port the arduino gets if it is left plugged in. If it changes then I might need VB or something to interrogate the ports and work out which is the arduino I want. How to change the way the arduino self describes itself? eg I might want it to come up as eg Arduino Motor Controller

jimmer:
I need to do some testing though to see what com port the arduino gets if it is left plugged in. If it changes then I might need VB or something to interrogate the ports and work out which is the arduino I want.

You can make the arduino uno uses the same com port every time you plug it in
the method is in the attached picture
if you need help with vb tell me i can even make the software and send it to you
Best wishes
Fidamon

Thanks fidamon,

That seemed to work, ie it kept the assigned port number (11) after restart. Even with other arduino's plugged in (I thought they might fight for the port).

But when I disconnected it, and plugged back in, it reverted to a low port number (3).

I need something that works reliably forever when the PC is out of my hands / in service. So maybe I will need a program that can read and identify which port the arduino motor controller is using.

jimmer:
But when I disconnected it, and plugged back in, it reverted to a low port number (3).

Try assigning a low number port Comm from the beginning , it will be better also for the VB because i me a problem with it when i tried to send commands to port 18
here is the topic

jimmer:
But when I disconnected it, and plugged back in, it reverted to a low port number (3).

I need something that works reliably forever when the PC is out of my hands / in service. So maybe I will need a program that can read and identify which port the arduino motor controller is using.

But on other thought
why not test every port that can be opened and send a command to it and when it gets the right answer your software on the pc Knows it found the right Arduino
something like

Private Sub GetArduinoComm()
On Error GoTo ErrHandler:
End Sub
Dim Counter As Integer
For Counter = 1 To 20
MSComm1.CommPort = Counter
If MSComm1.PortOpen = True Then
Else
MSComm1.PortOpen = True
MSComm1.Output = "I" & vbCrLf
Wait
End If
ErrHandler:
End Sub
Private Sub Wait()
Dim Start As Single

   Start = Timer
   Do While Timer < Start + 4
      DoEvents
   Loop
End Sub

Private Static Sub MSComm1_OnComm()

Dim abData() As Byte
Select Case Ser1.CommEvent
    Case comEvReceive 'receiveClose 1
    
       
        Totstring = Totstring & Ser1.Input
        If InStr(Totstring, vbCrLf) > 0 Then

If (InStr(Totstring, "Arduino1") > 0) Then
'this is the wanted  port capture it
Totstring = ""
End If

End Select
End Sub

but in this case you will need a piece of code in the Arduino sketch that will respond to the “I” when received by "Serial.println (“Arduino1”);
best wishes
Fidamon