Award
Congratulations Rich, for answering the question and has received an EZ-Credit award! Share what you have learned and create a tutorial to help others by clicking here.

How Do You Get Two Ezb's To Work Together?

Assistance Requested

Help bhouston with their question and receive $10 of EZ-Credit to get more robots and parts from our store. The following information was provided about their previous efforts searching tutorials for a resolution.

bhouston claims to have checked these sources:
 
#1

I have got two EZBv4's connected to my project. As you can see in the code below, I have an Ultrasonic sensor connected to controller #1 and I am trying to get it to move a servo one controller #0. When I run it, the servo does not move. Am I missing something in communicating between the two controllers?

Code:


$trigport = 1.D0
$echoport = 1.D1
$proxclose = 50 # Change for minimum distance

:start
:sensor check
$proxsense = GetPing($trigport, $echoport)

IF($proxsense < $proxclose)
servo(0.d2,112)
sleep(2000)
servo(0.d2,130)
sleep(2000)
servo(0.d2,112)
sleep(9000)

elseif($proxsense > $proxclose)
goto(sensor check)
sleep(3000)
endif

Goto(start)

I have found a few conversations, tutorials and activities that may help with your question. Take a look at these links. I've sorted them by what I believe to be most relevant but that is not always the case as I'm still learning.


Also, consider reviewing the Learn section for informative lessons and activities. Check it out!


#2

$trigport and $echoport need to be in quotes.

Code:


$trigport = "1.D0"
$echoport = "1.D1"



However, and I know that I am guilty of this but ports shouldn't really be defined by variables. If they aren't going to change in your project you might as well hard code them in.

Also, I'm not sure if it's the forums or if it's the way you intended but it doesn't show the less than sign in the if statement.

Code:


$proxclose = 50 # Change for minimum distance

:start
:sensor check
$proxsense = GetPing(1.D0, 1.D1)

IF($proxsense < $proxclose)
goto(sensor check)
sleep(3000)
endif

Goto(start)



And finally, where's the code to move the servo? It looks like it's missing the line

Code:

Servo(D0, 90)



Presuming the servo is on board 0 and needs to move to position 90.

note: if board 0 is used you needn't use the preceding 0. as part of the port number, it will always assume the board is board 0 unless otherwise stated.

#3

Sorry, my first post didn't show all of my code, it's all there now. I'll try what you suggested, Rich.

#4

@bhouston Ping me on skype

#5

@Rich, I tried this but the servo still doesn't respond.

Code:


$trigport = "1.D0"
$echoport = "1.D1"
$proxclose = 50 # Change for minimum distance

:start
:sensor check
$proxsense = GetPing($trigport, $echoport)

IF($proxsense < $proxclose)
servo(d2,112)
servospeed(d2,2)
sleep(2000)
servo(d2,130)
sleep(2000)
servo(d2,112)
sleep(9000)

elseif($proxsense > $proxclose)
goto(sensor check)
sleep(3000)
endif

Goto(start)


It does what it should when I run it on the console.

#6

The code should move the servo on port D2 of EZ-B0 when the ping sensor reports a value of less than 50. If it's not doing that check your servo and check your sensor.

Also, the elseif isn't needed. If the first argument is false (i.e. ping less than 50) then just using the goto(start) will work fine. The elseif is practically doing the same thing. The sleep after the goto in the elseif is redundant as it'll never get to be executed.

Try this code, it should work;

Code:


$proxclose = 50 # Change for minimum distance

:start
$proxsense = GetPing(1.D0, 1.D1)

IF($proxsense < $proxclose)
servo(d2,112)
sleep(2000)
servo(d2,130)
sleep(2000)
servo(d2,112)
sleep(9000)
endif

sleep(100)

Goto(start)



If it doesn't work try running just the following piece of code;

Code:


servo(d2,112)
sleep(2000)
servo(d2,130)
sleep(2000)
servo(d2,112)

#7

There's a lot of unnecessary logic in the code. This is a much simplier version...

Code:



# Change for minimum distance
$proxclose = 50

:start

$proxsense = GetPing(1.d0, 1.d1)

IF ($proxsense < $proxclose)

servo(d2,112)

servospeed(d2,2)

sleep(2000)

servo(d2,130)

sleep(2000)

servo(d2,112)

sleep(9000)

ENDIF

sleep(3000)

Goto(start)

#8

Thanks Rich and DJ, got it working now