
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.
here is the error message I get using this code plagiarized from ARC examples :
the code first :
Code:
And now the error message I get :
Code:
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 :
Code:
Because it can't be an 8 bit unsigned int cause that only goes to 255.
What is the arduino sending?
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)
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.
Code:
*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.
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.
Arduino code :
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...
Code:
and finally, the console debug result:
Code:
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!
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()
1) Connect EZB UART 0 TX to ARDUINO RX
2) Connect EZB UART 0 RX to ARDUINO TX
Arduino Code:
Code:
EZB Code
Code:
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"
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)
Now... The only reading I get back in EZB is 97... which is char "a"...
What am I missing?
- EZB UART 1 TX connected to ARDUINO RX
- EZB UART 1 RX connected to ARDUINO TX
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.
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.
Always need a common ground. First rule!
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.