Welcome to Synthiam!

Program robots using technologies created by industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation, and artificial intelligence easy.

Get Started
Asked — Edited
Resolved Resolved by DJ Sures!

How To Use The Uart Script Functions

I am trying to interface my Robotics Bioloid to the EZ-Bv4 using UART 0 to transmit/receive the 5 word Comm packet; FF 55 Data_l ~Data_l Data_h ~Data_h
~ represents Inverse (1's Complement), Data_l is the least significant hex value, Data_h is the higher significant hex value the Robotis boomerang controller sends when a button is pressed.
For example: FF 55 01 FE 00 is the value 01 (button U)
FF 55 00 FF 01 is the value 256 (Hex 10) (button 5)

I can not get the new UartReadRinary, UartWriteBinary to work correctly.

Is there to be a tutorial on the use of the Uart script functions?
Thanks for any help.


ARC Pro

Upgrade to ARC Pro

Harnessing the power of ARC Pro, your robot can be more than just a simple automated machine.

AI Support Bot
Related Content
Synthiam
PRO
Synthiam
#1  
Here is an example that will help you...

Code:


# Define the Button U
# --------------------------
DefineArray($ButtonU, 5)
$ButtonU[0] = 0xFF
$ButtonU[1] = 0x55
$ButtonU[2] = 0x01
$ButtonU[3] = 0xFE
$buttonU[4] = 0x00

# Define the Button 5
# --------------------------
DefineArray($Button5, 5)
$Button5[0] = 0xFF
$Button5[1] = 0x55
$Button5[2] = 0x00
$Button5[3] = 0xFF
$button5[4] = 0x01



# Init the hardware UART. You would only do this once
# but in this example i have to show that it must be done
# Also, i have no idea what baud rate you will be using
# --------------------------------------------------------
UartInit(0, 0, 9600)

# Send the Button U code
# ----------------------
UartWriteBinary(0, 0, $ButtonU)

# Now send the Button 5 code
# ---------------------------
UartWriteBinary(0, 0, $Button5)

#2  
Thanks DJ.

I get the general idea you show for writing to the Uart.
What about UartReadBinary?

BTW - Thanks for the very quick response!
PRO
Synthiam
#3  
Read Binary puts the data into the provided Array Variable - there is EZ-Script help with an example
#4  
I am a lot closer but still having problems:
1) If I don't press a controller button soon enough (several seconds) EZ-B4 disconnects and the red led flashes.

After a power cycle and 'connect' I start the get hex data script and hit button 5 I get this:

User-inserted image


and a RealTerm monitor connected to the RX of EZ-B4 shows this:


User-inserted image


Problem 2) RealTerm shows the HEX data but the script produced decimal data.

Here is the script:

Code:


# get hex data
uartinit(0, 0, 57600)

print("UART 0 Initialized at 57600 baud.")

:loop

$x = UartAvailable(0, 0)

sleep(500)

UARTReadBinary(0, 0, 6, $data)

$byte1 = $data[0]
$byte2 = $data[1]
$byte3 = $data[2]
$byte4 = $data[3]
$byte5 = $data[4]
$byte6 = $data[5]

sleep(200)
if ($byte1 == 255 AND $byte2 = 85)

print( $byte1 +" "+ $byte2 +" "+ $byte3 +" "+ $byte4 +" "+ $byte5+ " "+ $byte6 )

endif

sleep(200)

goto(loop)
#5  
You don't have to bother using hex.
Just use decimal values, the Bioloid uses unsigned integers 0 to 255 to communicate.

if you convert the hex to the decimal value you'll see the same values.

I discovered this when trying to control the dynamixels with python.
PRO
Synthiam
#6  
What is the meaning of $x is in your code sniplet...

Code:


$x = UartAvailable(0, 0)

sleep(500)

UARTReadBinary(0, 0, 6, $data)


Because you are not using $x anywhere - and the Read Binary is hardcoded to a value of 6 characters. This means you are 100% certain there is 6 characters available? You cannot be 100% certain without actually checking. So hardcoding a value of 6 is why you're program is crashing. You're requesting more information than what is available.

Perhaps something like this will make more sense...

Code:


:readLoop
$x = UartAvailable(0, 0)

if ($x < 6)
sleep(50)
goto(readLoop)
endif

UARTReadBinary(0, 0, 6, $data)
#7  
DJ, Thanks again.
Works like a champ! Also gave me better understanding of how the script function operates.

Now I am ready to 'UartWriteBinary'.
PRO
Synthiam
#8  
Woo!:) your progress is impressive