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
Canada
Asked — Edited

Uart Question When Tx And Receiving Unsigned Chr

There is an issue when sending ASCII code through the UART ports.
For some reason the ASCII code is getting lost in the translation.
It is hit or miss, some codes make it through fine and some don't get sent at all. Error saying that the expression is not in quotes.
If the code is sent the received transmission shows a question mark.
I have included an example with the ASCII code 255, it gets sent but RX is a ? and not the y with two dots above it.

If you can correct this issue with the scripting you would have me sold on the EZ B.

Great platform and fun to use.

Thanks DJ

Start
1: UARTInit(0,1,1000000)

7: $handshake=GetAsByte(255) # ASCII code 255

8: UARTWrite(0,1,$handshake) # not all codes will be TX

10: Print($handshake)

> ΓΏ # symbol that code represents

14: Sleep(1000)

16: $x = UartAvailable(0, 1)

18: print("Bytes in buffer: " + $x)

> Bytes in buffer: 1

20: $TX_DATA = UARTRead(0, 1, $x)

22: print("Received: " + $TX_DATA)

> Received: ? # RX Issue or TX issue

25: Print ("done")
> done

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.
PRO
Synthiam
#13  
What do you expect $data to look like when you do this?

Code:


$test1=GetAsByte(125)
$test2=GetAsByte(180)
$test3=GetAsByte(75)
$test4=GetAsByte(255)

$data=$test1+$test2+$test3+$test4


Tell me what you expect to see in $data?

Do you expect to see many bytes? Or do you expect to see the values of each variable added together?
#14  
The $data should come out as a list with 125,180,75,and 255.
It just saves typing a separate line for each value and sending it.

Even if I send the data one at a time a still don't RX the proper value.

I'm sorry I used python to send data to the Dynamixel servos and Arduino nano.
and it is working.
PRO
Synthiam
#15  
In all programming languages, that will add the values together into one value. Only strings can be appended with the + symbol. (including Arduino, which uses C++)

String example

Code:


$x = "banana"
$y = "apple"

$z = $x + $y


Math example...

Code:


$x = 1
$y = 5

$z = $x + $y


What do you think $z would equal in each example?
#16  
I understand but did you try running the script ?
What values are you RX in your console ?
PRO
Synthiam
#17  
Well, the value would be wrong from what you expect:) That's what i'm spending time helping you with.

Would you like me to give you the solution or would you prefer if I helped point you in the right direction so you can feel the achievement of discovering the answer yourself?:D
#18  
Please give me the solution.
PRO
Synthiam
#19  
darn it:) I was hoping you weren't going to say that! lol okay give me a bit because i'm in a dinner meeting
PRO
Synthiam
#20  
I added a nice debug viewer for you in the Variable Watcher. You can now see the hex values, which will help for your diagnosing.

The issue that you have been experiencing is writing and reading from the UART too quickly. This is because you are testing by connecting the TX and RX together of a UART. The EZ-B and it's connection to the controlling device is multi threaded. This means that commands are sent in another thread of the CPU. You will need to sleep() before reading from the UART.

Normally, you would always need to sleep() a little to wait for the other device to respond. The other device that you are connecting too over the UART will have a small fraction of thinking time. It will then respond over it's connection speed. The sleep() should not be significant, but it is something you will need to practice.

A smarter programming model is to wait until the desired number of bytes have been received before processing the packet.

I have attached an example you can preview. Here it is:)

auart.EZB
#21  
That makes sense to me to me now.
I keep forgetting how fast things really happen in the scripting.

Maybe instead of sleeping a bit I can read a bunch of sensors or run a motion for my robot?

Use that extra time to do something else.

Thanks DJ I'm learning a lot.
PRO
Synthiam
#22  
Hope you enjoy the new Variable Watcher in the latest ARC as well:) It lets you view the Hex values of the variable and length - super useful for what you are doing
#23  
I just got home from work and tried the example with the data I want to be able to TX.
Here's what I got.

All unsigned byte value to 127 are TX and RX correctly
Start
1: uartInit(0, 1, 1000000)
5: uartwrite(0, 1, "127")
7: sleep(100)
9: $x = uartavailable(0, 1)
11: $y = uartRead(0, 1, $x)
13: print("Bytes Read: " + $x)
> Bytes Read: 1
15: $test=GetByte($y)
17: print("Read: " + $test)
> Read: 127
Done (00:00:00.2496069)

All unsigned byte values from 128 to 255 are TX and RX incorrectly
Start
1: uartInit(0, 1, 1000000)
5: uartwrite(0, 1, "255")
7: sleep(100)
9: $x = uartavailable(0, 1)
11: $y = uartRead(0, 1, $x)
13: print("Bytes Read: " + $x)
> Bytes Read: 1
15: $test=GetByte($y)
17: print("Read: " + $test)
> Read: 63
Done (00:00:00.2183817

All unsigned byte values greater than 255 will get an error, which is correct
Start
1: uartInit(0, 1, 1000000)
5: uartwrite(0, 1, "256")
> Error on line 5: Value was either too large or too small for an unsigned byte.
Done (00:00:00.0311750)

Sorry to be a pain.
#24  
I will try to set up a development testing environment for this tonight. and will be able to test this out on the EZB4. I was crazy busy making a few other tutorial that i posted here.
PRO
Synthiam
#26  
I'll take a look at it tomorrow when i'm at the office - in my tests, I was pushing 255 with the uart without any issues - and receiving 255. But, i'll take a look to make sure there isn't something I have overlooked

What do you think about the new Variable Watcher? Now that you can view Hex values?
#27  
I have tested this and confirmed mtiberia findings.


Here is my Test Bed.

User-inserted image





This is my results












I hope this can help.



Could the issue have to do with 7bit and 8bit as 7bit can count only to 0-127
and 8bit can store 0-255? <- Just thinking....
#28  
I think you may be correct.
It's only when using the UART through the EZ script because EZ B can communicate with the dynamical servos that need the 8 bits to represent values from 0 to 255.
#31  
YESSSSSSS
Awseome thanks DJ !

Now you can give Masimo Banzi a run for his money.
I'm surprised he hasn't made you offer you can't refuse.

Forget about it.

Thanks
#32  
@mtiberia ...

Quote:

".I'm surprised he hasn't made you offer you can't refuse."
In a couple years it will be the other way around....
;)