Asked
— Edited
Resolved by Steve1DH!
Hi all,
I'm trying to get serial feedback from a device. Does anyone know where on the V4 I should attach to read back serial information from device? I know I send a serial command to through one of V4's digital signal pins but where do I read it back from?
I thought it would be read from the same digital pin I sent the command. However @Toymaker made a comment in another thread that it may have to be read through one of the i2c ports.
Any insight is welcomed.
The V4 (like the V3) can only send serial on the digital pins... You'll need to use the V4's UART port for bi-directional serial transfer... I hope DJ puts up a tutorial soon on how to use the UART port...
I thought it would be read through on of V4 EZB's digital ports. I thought this because we send serial commands through the signal pin of a digital. Then Toymaker said it should read serial feedback from the i2c port. Now you say the UART port. confused I guess I need to get this cleared up.
Rich also mentioned using i2c... We all hoped for basic serial (send and receive) through the digital pins of the V4... To my knowledge you can still only send... DJ instead provided the v4 with UART ports... UART is what we can use for bi-directional serial data transfer... I myself am not quite sure how to use the UART port but devices like the iRobot Create and I am guessing the Kangaroo too should work with 2 way serial communication using this port... DJ said that tutorials on how to use the port are coming soon...
Looking in the "Learn" section in the Data Sheet for V4 I see the UART port. It shows a RX & TX connection along with a 3.3v and Gr. Looks like you may be right. Like you I'm unsure how to use this port. I guess I'll muck around in the script commands to see if I can come up with something.
Good thing the Kangaroo doesn't need power as the V3 only supplies 3.3 and not the 5v it will get from the Sabertooth.
That's the port Dave (Black port on the lower right of the board)... I am sure it will be straight forward to use... After all... It is made by EZ Robot, right?... We (I am) are probably over thinking things here anyway...
Here's something else that confuses me. In the specs EZ Robot states:
3 x i2c Port and 3 x High Speed UART Ports. I see the i2c ports. Where are the UARTs? They must be hard coded and be accessed through that mystery connection I'm looking for. confused
@Dave - UART 1and 2 -
Hope this helps.
There are script commands for the UART port; UARTInt UARTAvailable UARTRead UARTWrite
Examples and help are in the EZ-Script manual to the right of the script dialogue. There is also a sample project in the examples folder of ARC which shows how to use it.
OK, Now we're getting somewhere.
From what I'm reading in @Steve1DH's post above UART 1 is D5 & D6 (Tx, RX respectively) and D18 & D19 are UART 2 (Tx, RX respectively). That must make the black physical header pin UART 3?
I don't know how I missed that. I thought I read through the whole data sheet. Thanks Steve!
Also thanks @Rich for pointing me to the script commands. I knew there were there and was reviewing them as you were posting. However I had forgotten about the sample project. That will be a big help.
Steve, Gotta give this one to you. You answered my "whole" question.
The black UART is UART0
Ahh, that makes a huge difference. I forgot these circuit jockey's like to start at naming at 0.
As soon as I get my V4, I am going to experiment using the UART to see if I can read sensor data from my iRobot Create....
Sorry guys I was a little late to see this thread, thanks all for pitching in and figuring it out.
Just to confirm for you:
Uart0 is the black 4-pin 0.1" pitch female header at the top of the EZ-B
Uart1 is pins D5 & D6 (D5 is also the Dynamixel port)
Uart2 is D18 & D19
These UART ports are great for serial displays, communication to a PC, and just as @Richard R has mentioned they are for Roomba's as well!
And as @Rich mentioned there is a code example in ARC to help you on your way.
Thanks guys!
As Skater said, that's right about what ports are UART compatible. However, I would not recommend wasting an input capable UART on serial displays. All Digital Pins have the ability to output serial ttl data and displays only require output.
I have put a great amount of effort into EZ-Script manual and example projects. If you're stumped on something, I would recommend calmly following these steps...
Search the EZ-B datasheet for port descriptions, voltages
For connection or Wi-Fi questions, visit the Learn section and consult the tutorial videos
Search the EZ-B manual for words referencing your trouble. In this case, UART. The EZ-Script manual explains each UART command with example syntax and the available UART ports.
Search both Examples folders within ARC for the keyword. In this case, you would search UART and find a UART project example.
And of course, if those don't help - ask on here so I can see how to address it
Actually, Rich constantly reminds me (us) to RTFM and explore the examples that you have provided.... I really need to listen more...
Here's a huge secret, DJ's method above is how I manage to look like I know what I'm doing 99% of the time!
Rich you're too modest... I would say more like 99.9%
@ Dave - Thank You for the credit.
:P @DJ, your a scream!; "calmly following these steps". "Calmly" is my middle name.
Your right though. I could have probably found the answer to this question if I had just slowed down and re-read the spec sheet. I do get in a hurry at times. It usually results in a flash and smoke. eek
Also this is not for displays. I'm trying to set up a two way serial connection between EZB V4 and a Kangaroo / Sabertooth. I need the Roo to tell me where it is after I send a serial command to move to a set position.
Lol you indeed are one of the most patient people I've ever met. I write for the masses, knowing that future readers will stumble across my posts. Never think I'm directing anything at any specific someone. It's always generic.
Much like how I explain where the learn button is. Of course you all know. But someone new may not know... So I be specific for the future
Dave, I referred to I2C port as I am still using a V3 so my PIC does the conversion from I2C to bi-directional comms to the serial port of the Kangaroo, hope this helps.
@Tony, each time you post it always a huge help. Thanks, the confusion was my fault not yours. When I thought it through I came to that conclusion.
Ok... I can't find any example using uart method, neither in local examples nor in the cloud... is it me or they all disappeared?
Some basic quesitons :
I'm trying to TX buffer values (between 0 and 640) from an arduino (running a code to read motors' encoders) to EZB UART0. I hooked arduino's tx to EZB's rx and arduino's rx to tx (although I only need to receive data from arduino, but in the doubt... not sure if they both need to be connected).
I tried these codes so far, without success :
here is what I get :
FYI if you type what the Script Help says about UartReadBinary() you get an error message :
here is what it returns :
I'm desperately trying to get data returned. It works in the terminal EZB, I receive the counts from the encoders connected to the arduino. So, here is my real question (and since I couldn't find any example using UART keyword in the examples despite what was said earlier in this thread) :
How do I get to read what comes from this arduino the same way they are read and displayed in the serial terminal?
Thanks in advance
Ok, one step at a time I see the variable's value in the variable watch... so now need to figure out how to script with these values as a variable condition...
The cloud doesn't have any example projects. They ship with ARC. Look here: https://synthiam.com/Tutorials/Lesson/22?courseId=6
I'm not at home and on my phone so I can't give you code. But that link will help you find examples that do what you need
Thank you very much Dj! And enjoy your evening! I hope she's worth it!
Thanks! I'll write something if you're still spinning wheels later this evening
ok, if anyone else is arround, here is what I'm now facing : don't seem to be able to get ASCII strings...
here is the error message I get using this code plagiarized from ARC examples :
the code first :
And now the error message I get :
It's supposed to read these values :
"A=" then a number between 0 and 640 "B=" then a number between 0 and 640.
It seems that it can't read ASCII string values... maybe it's the "=" ?
** update : it is not... even after changing the code in arduino to only return numbers... I get this :
the question is missing some info. Is the arduino sending an unsigned 16 bit int? Signed 16 bit int? Or a string of characters?
Because it can't be an 8 bit unsigned int cause that only goes to 255.
What is the arduino sending?
oooooh! ok
it was initially sending a string of charaters AND a int (it seems int is by default signed in arduino).
Arduino int stores a 16-bit (2-byte) value by default.
I took out the string of characters but I still get this error message :
15: goto(loop) 3: :loop 5: $x = UartAvailable(1, 0) 7: print("Bytes in buffer: " + $x) > Bytes in buffer: 7 9: $y = UARTRead(1, 0, $x) 11: print("Received: " + $y) > Error on line 11: Missing String Quotes or Invalid Expression at index 15: " Done (00:00:02.4873538)
So based on the error, i have to assume the Arduino is sending two bytes to make an int. You will really have to check the arduino code to ensure this is true, otherwise everything i am writing is a waste of effort.
The data being read is binary, not ascii. So you cannot "print" a non ascii value because it has no corresponding character.
For example, you can look at an ASCII CHART to see what values map to readable characters...
In your code, the ASCII value may be 0, which is a null. You can't print a null. You can't print anything that you can't read with your eyeballs.
Also, attempting to read more than one unreadable byte value into a string will not work. You can't have a string equal ESCAPE and NULL and BELL etc etc...
*Note: Doesn't look like you've been using the Variable Watcher. I would recommend using it to view the values of the variables for debugging.
You will need to use Binary Read to read the data into an array of values. Then combine the 2 values to get a 16 bit integer.
*Disclaimer: i have no idea what is high or low byte from the ardiuno to convert the 2 bytes to a 16 bit int. You have to choose one that works.
I should also add that it sounds like the Arduino code is missing something very important to communication. There's no way to know when the first byte is transmitted and what to parse. It's like walking into a room and starting a sentence from the middle to a group of people.
This will never work because you don't know where the first byte is to parse.
Chances are, if this is the Arduino code that you're using, it was written poorly and will not work at all... ever
Some poorly written code that merely transmits data carelessly will be impossible to parse.
Thank you so much for your help Dj. I improved a little in that sense that I got that the data I'm getting from the arduino are decimals that I can convert back into char using a simple "$value - 48" which gives me the number in char value... but as you said it yourself, I need the real value... and, well... honestly, I do not grasp your code. I tried it but it returns odd results. The best is that I show you 1) Arduino C code (poor code, as you suggested, but mine so I like it anymay ) 2) my script and what I attempted to do so far and 3) the debug.
Arduino code :
EZB script from your script and some adaptation, including char conversion. It seems there's no equivalent to the C++ char function in EZB...
and finally, the console debug result:
Dunno if any body will have the will to help further on this... feels like I'm asking too much.
I do not understand, mainly, the << operator here... I know what it does, but don't see how it can help me convert dec results into the real values... The funny part is that if Arduino's debug returns the value 24, EZB terminal does to and shows on the right the equivalence in char table... but I can't get the char value (except with this "minus 48" as you can see). I'd need to merge the two results for $valEncoderB1 and $valEncoderB2 so I could get the int real number again... which is not optimal. Best is indeed to convert binary into dec, and that's where I'm lost.
Thanks again, even if you can't take the time for so much trouble!
That code will never work. First, look at the Serial.println() arduino command: https://www.arduino.cc/en/Serial/Println
It means PRINT LINE, which appends an ascii character to the end.
Second, it's for ascii, and you're not sending ascii.
the << is a bit shift because you claim the data being sent is a 16bit int which is 2 bytes. But, after reviewing the ARduino code, none of it will work.
Use SERIAL.WRITE()
Here, this is the proper way to do it.
Arduino Code:
EZB Code
Damn! Thank you Dj! I'm all moved by this kindness! Really! I'm going to try this right now. Awesome.
No prob!
That way will work great. The idea of resetting the encoder value on each read is smart. This is because it gives you the ability on each read to see how much each encoder is different from the other. So if you expect to go straight, and one encoder is off by a large number from the other, you can correct it with pwm.
Having the ezb actually request the read is smart. That's a bidirectional communication model. Which means the Arduino does it's thing, and the ezb occasionally checks up on it.
ezb: "Hey Arduino, send me your encoder tick count and start counting from zero again" arduino: "Here you go ezb"
yes, but for now it doesn't seem to work on my side. It's like arduino isn't receiving anything. Serial Terminal reads "a" in ARC but for some reason the condition doesn't work in arduino or more precisely it seems that it doesn't receive the "a" value. Tried in char format (97) just in case, nothing.
EZB's Terminal stops reading "a" if I disconnect Arduino Tx to EZB Rx wire...
AND... Well it was just that I forgot to define the board index properly in UartAvailable(1, 0)
You can't connect the terminal and the ezb and the arduino together at the same time.
almost there, almost there... indeed, terminal must not be running for it opens the port.
Now... The only reading I get back in EZB is 97... which is char "a"...
What am I missing?
sounds like the ezb is writing to itself. check the wiring...
I triple Check that part. Tomorrow thursday il be able to work on It but only remotely. I'll check again just to make sure.
There's a loop back happening somewhere indeed.
But, really, thank you so much. I knew all the operations and functions but really I'm not yet trained enough to think of them when I'd need them, although I started thinking of serial write right before I read ur advice in that matter which is a start of a beginning of understanding. Let's stay positive! Haha.
Cheers.
Yeah - it must be a wiring issue.
The Arduino and ARC code are both solid. The arduino loops for ever until it receives the command 'a' from ARC. Once it receives the command, it transmits the A and B trigger values and resets the counter.
It's an incredibly simple process - so the wiring will be the focus.
Resetting the counter after each query is the right way to monitor encoders. This is because it allows you to see which wheel is rotating quicker/slower since the last query. And if your sample time is ever 1,000 ms, then you can correct the speed with pwm.
If you wish to know the distance traveled, simply keep a running total in ARC of both encoder values.
Arduino has a separate power source. Maybe I should give both (EZB and Arduino) a common ground?
Oh most definitely yes and yes! Always always common ground. Apologies for not mentioning that before as I assumed they were the same power source.
Always need a common ground. First rule!
that was the issue. Needed a common ground... It seems to work now.
thanks a lot Dj!
Now, it took me so long to figure this out thanks to your help that this thread should be referred as a great tutorial for future users who would wish to establish similar com.
Best, Elfège.