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 Rich!

Uartwrite Question?

Trying to send the below code via serial to my SSC-32 servo board to test servo movement... it gives me an error because $pw is greater than 255 (max for a byte which I do understand)... It's probably me not getting it, but how do I send numbers greater than 255?

This is the error "Error on line 6: Value was either too large or too small for an unsigned byte."


Code:


$pw=1000
$m =2500
UARTInit(0,1,9600)
:start
$pw=1000
UARTWrite(0,1,"#0P",$pw,"T",$m,13)
sleep(2500)
$pw=2000
UARTWrite(0,1,"#0P",$pw,"T",$m,13)

sleep(2500)
Goto(start)

AI Support Bot
Related Content
Synthiam
Based on your post activity, we found some content that may be interesting to you. Explore these other tutorials and community conversations.
United Kingdom
#1  
Bearing in mind I've not used the UARTWrite function yet nor the SCC32 but...

Have you tried;

Code:


UARTWrite(0,1,"#0 "+$pw+" T "+$m,0x0D)

In other words, having the whole "#0 1000 T 2500" part sent in one go rather than piece by piece.

Note, I prefer to use hex for ascii characters hence the 0x0D rather than the 13 for a carriage return. 13 may work fine.

Also, are you missing the "P" so should it be

Code:


UARTWrite(0,1,"#0 P "+$pw+" T "+$m,0x0D)


or with your code

Code:

UARTWrite(0,1,"#0", "P",$pw,"T",$m,13)



Edit: I guess you edited before I finished typing and added that P in:)
United Kingdom
#2  
Suggestion #2... change

$pw = 1000

to

$pw = "1000"


I'll have a proper look tomorrow but I need sleep, just thought I'd throw a couple of ideas at you before I head up though (it's also an insight in to how I guess at things if I don't know.
#3  
Crap.... you're a genius Rich... this worked...

Code:

UARTWrite(0,1,"#0P"+$pw+"T"+$m,13)



Cheers and thanks....:)
#4  
This now works....

Code:


$pw="1000"
$m ="2500"
UARTInit(0,1,9600)
:start
$pw="1000"
UARTWrite(0,1,"#0P"+$pw+"T"+$m,13)
sleep(2500)
$pw="2000"
UARTWrite(0,1,"#0P"+$pw+"T"+$m,13)

sleep(2500)
Goto(start)
United Kingdom
#5  
Awesome:)

Just out of curiosity, why not use SendSerial? Not that it makes much of a difference (in fact, I don't even know what the difference would be other than the command used and it's syntax).
#6  
No reason, just got used to using the Uart commands when I was messing with my iRobot Create.... kind of a habit now... I guess I could just go back to sendserial....

Cheers
#7  
Can you use the Sendserial command on Uart 0 port of V4?
#8  
You have to specify the Digital port when using the SendSerial command. Don't know which d port is associated with UART 0.
#9  
Uart 0 is the regular Uart port located on the lower right side. Not one of the digital ports.


User-inserted image
#10  
Uart 1 send is on port D5, receive is on D6.... Uart port 2 send is D18 and receive is D19... UART port 0 as Dave pointed out is the black 4 pin port on the right side of the picture he provided above...

@Dave, I don't think you can use SendSerial on UART port 0.... It doesn't seem to have a port designation (like D0 - D23) and the SendSerial command needs that as it's first parameter....
United Kingdom
#11  
You would need to use UARTWrite on UART0
#12  
"You would need to use UARTWrite on UART0"

@Rich and @RichardR, that's what I thought. I just wanted to clarify this point. When the Sendserial command was brought up a few posts back I thought I had missed something. I've been using my Kangaroo/Sabertooth board combo on UART0 and using the UART commands with much success and am very happy with it. I just always like to know if there are any other ways to do something.

On a related note (you guys probably know this); When using the UART0 port it always has to be initialized the first time you use it after power up by using the UARTInit command.

Example: UARTInit(0, 0, 9600 ).

Once initialized you don't have to send that command again till the next power up.
#13  
Dave, a few posts back I mentioned that you needed a digital port defined in order to use the SendSerial commands. I understood the question and also knew where the UART 0 connection is located since I'm using it for sending Roomba commands. The point I was attempting to make (although poorly) was that since the UART 0 ports are not identified as single Digital ports like UART 1 and UART 2 are, that the SendSerial command cannot be used.

You are also correct that the UART port only needs one Init command as long as the EZB(4) remains powered.
#14  
Thanks @Robot-Doc, I understand now. You did not do a poor job. Your advice is always welcomed and concise. ;)