TJ
New Member
Posts: 7
|
Post by TJ on Dec 2, 2019 21:01:04 GMT -5
When I had my old pc it had a Parallel Port and I ran 8 relays using , open "Project 2010" for graphics as #main print #main,
out 888,0 'all off command or stop out 888,8 'relay closed close #main2 close #main
Now I am trying to use , Using Arduino as a Slave , example ,included in Liberty Basic , it works great with my Arduino relay board and servo's too , its more complex than I need , but , what I am trying to do is have one button to press to send a program to the Arduino , I no my port , servo value , ext ,so I would write that in ahead of time
open "LB Ultra Simple Arduino Demo" for dialog as #main print #main, open "COM" ; port ; ":9600,n,8,1,ds0,cs0,rs" for random as #ArduinoCOMPort4 ad.com.ports(4) = 1 end I
simply put if I know my , com port , servo out , ect and I use the Scketch used in Using Arduino as a Slave what would a simple code be that would talk to the Arduino
|
|
|
Post by Rod on Dec 3, 2019 4:22:45 GMT -5
Michael uses lots of functions, for a beginner its probably hard to extract the necessary code. This is the code line that sets a servo position, it calls other functions so you will need to have all of those functions at the foot of your code. But you can simply have a button, and for its handler use this line. return.value = AD.Servo(Com.port.Selection, Pin.Selection, Val.To.Send) Com.port.Selection is a variable holding your com port number Pin.selection is a variable holding the pin number the servo is attached to Val.To.Send is a value between 0-180 to set the servo position. You can use Michael's other functions to read the pin to find out what the servo is currently set to, you might want to move the servo gradually to the new position sending a series of position moves rather than have it bang round to the new setting. Or you can simply remember what you set it to in your code. But think startup, where are the servos? Have you found the LBPE There are a couple of projects working with the Arduino. Study the Sketches, there are two on the LBPE. If you see what messages they accept you will better understand what to send the Arduino. alycesrestaurant.com/lbpe/ArduinoAsSlaveBoard.html#Getting Started with the functions---Setting a servo output alycesrestaurant.com/lbpe/Fun%20with%20the%20Arduino.html
|
|
|
Post by Rod on Dec 3, 2019 8:06:22 GMT -5
This is as simple as I can get. Untested but it might work. What I have not done is read any of the messages coming back from the Arduino. Michael has it set to return "1" every time you send a servo message. These "1"s will simply stack up in the input buffer. Later you can try reading the port to measure stuff. Its all in the article.
nomainwin WindowWidth = 400 WindowHeight = 400 UpperLeftX = int((DisplayWidth-WindowWidth)/2) UpperLeftY = int((DisplayHeight-WindowHeight)/2) button #1.bl, "Left", [left], UL, 100, 100, 200,20 button #1.br, "Right", [right], UL, 100, 130,200, 20 textbox #1.tb 100, 160, 200, 20 open "Servo Manager" for window as #1 print #1, "trapclose [quit]" port=11 'set to your own port number open "COM" ; port ; ":9600,n,8,1,ds0,cs0,rs" for random as #ard
'give the port time to establish timer 500, [donepausing] wait
[donepausing] timer 0
'set servo to mid point, simply send it the message "servo 1 90" 'note that i am preserving spaces when I build the message pin=1 'pin servo is attatched to pos=90 'servo position #ard "servo "+str$(pin)+" "+str$(pos) #1.tb pos wait
[left] pos=pos-1 if pos<0 then pos=0 #ard "servo "+str$(pin)+" "+str$(pos) #1.tb pos wait
[right] pos=pos+1 if pos>180 then pos=180 #ard "servo "+str$(pin)+" "+str$(pos) #1.tb pos wait
[quit] close #ard close #1 end
|
|
TJ
New Member
Posts: 7
|
Post by TJ on Dec 3, 2019 20:11:01 GMT -5
Rod , I can't thank you enough for your time , your solution worked for me the first time , my servo goes where it needs to . I will work this into my robot program and then on to operating a 8 channel relay board connected to Arduino . I have done a lot of robots over the year and many under water robots all using liberty basic , but , now my parallel port days are over , now onto usb and Arduino to help my grandsons learn , just as soon as I learn . Thank You again Tom Jacobs
|
|
TJ
New Member
Posts: 7
|
Post by TJ on Dec 4, 2019 7:54:19 GMT -5
Rod , I have one more issue with the Arduino ,the servo work's great ,now I need to add a relay , button , this is the code you sent me that workds for the servo , I use the Scketch used in ,Using Arduino as a Slave
nomainwin WindowWidth = 400 WindowHeight = 400 UpperLeftX = int((DisplayWidth-WindowWidth)/2) UpperLeftY = int((DisplayHeight-WindowHeight)/2) button #1.bl, "Left", [left], UL, 100, 100, 200,20 button #1.br, "Right", [right], UL, 100, 130,200, 20 textbox #1.tb 100, 160, 200, 20 open "Servo Manager" for window as #1 print #1, "trapclose [quit]" port=11 'set to your own port number open "COM" ; port ; ":9600,n,8,1,ds0,cs0,rs" for random as #ard
'give the port time to establish timer 500, [donepausing] wait
[donepausing] timer 0
'set servo to mid point, simply send it the message "servo 1 90" 'note that i am preserving spaces when I build the message pin=1 'pin servo is attatched to pos=90 'servo position #ard "servo "+str$(pin)+" "+str$(pos) #1.tb pos wait
[left] pos=pos-1 if pos<0 then pos=0 #ard "servo "+str$(pin)+" "+str$(pos) #1.tb pos wait
[right] pos=pos+1 if pos>180 then pos=180 #ard "servo "+str$(pin)+" "+str$(pos) #1.tb pos wait
[quit] close #ard close #1 end
|
|
|
Post by Rod on Dec 4, 2019 9:11:39 GMT -5
Well looking at the message the Sketch expects its looking for "set 2 1" ie set pin 2 to 1, ie on. So a few simple changes to the code gets two buttons, one to set and one to reset the relay. You can build the gui any way you wish. I'm sure you are getting the hang of direct interaction. Just look at the Sketch and how it handles the command, param0, the pin, param1 and the argument param2, "set 2 1"
nomainwin WindowWidth = 400 WindowHeight = 400 UpperLeftX = int((DisplayWidth-WindowWidth)/2) UpperLeftY = int((DisplayHeight-WindowHeight)/2) button #1.bl, "Left", [left], UL, 100, 100, 200,20 button #1.br, "Right", [right], UL, 100, 130,200, 20 textbox #1.tb 100, 160, 200, 20 button #1.bset, "Set Relay",[setrelay],UL,100,210,200,20 button #1.breset, "Reset Realay",[resetrelay],UL,100,240,200,20 open "Servo Manager" for window as #1 print #1, "trapclose [quit]" port=11 'set to your own port number open "COM" ; port ; ":9600,n,8,1,ds0,cs0,rs" for random as #ard
'give the port time to establish timer 500, [donepausing] wait
[donepausing] timer 0
'set servo to mid point, simply send it the message "servo 1 90" 'note that i am preserving spaces when I build the message pin=1 'pin servo is attatched to pos=90 'servo position #ard "servo "+str$(pin)+" "+str$(pos) #1.tb pos wait
[left] pin=1 'pin servo is attatched to pos=pos-1 if pos<0 then pos=0 #ard "servo "+str$(pin)+" "+str$(pos) #1.tb pos wait
[right] pin=1 'pin servo is attatched to pos=pos+1 if pos>180 then pos=180 #ard "servo "+str$(pin)+" "+str$(pos) #1.tb pos wait
[setrelay] pin=2 'pin relay is attached to #ard "set "+str$(pin)+" 1" wait
[resetrelay] pin=2 'pin relay is attached to #ard "set "+str$(pin)+" 0" wait
[quit] close #ard close #1 end
|
|
TJ
New Member
Posts: 7
|
Post by TJ on Dec 6, 2019 11:19:50 GMT -5
Thanks so , everything you sent me has worked and I am figuring out this servo and relay programing with Arduino thanks to your help. Just a question ,is it possible to operate the Arduino using wifi? Thank You Tom Jacobs
|
|
TJ
New Member
Posts: 7
|
Post by TJ on Dec 11, 2019 14:48:44 GMT -5
Is it possible to opperate the Arduino using wifi instead of usb? Running a 8 relay board and it works great using usb
|
|
|
Post by Chris Iverson on Dec 11, 2019 18:38:30 GMT -5
I think it would be possible, but it would require rewriting a lot of code on the Arduino side of things, to manage a wifi connection. There are wifi shields and other connectors you can use to get wifi on an Arduino, so I don't see why it couldn't work.
|
|