Page 1 of 2

Running Ultrasonic click on UART protocol

Posted: Thu Aug 05, 2021 6:24 pm
by Yadnik
I am trying to run the ultrasonic click:https://www.mikroe.com/ultrasonic-2-click using UART protocol.However my program is just returning 0.
Can someone please have a look at my code and tell me where I may be going wrong.
Code:https://github.com/Yadnik1/Ultrasonic-U ... %20uart.py
Thank you very much.

Re: Running Ultrasonic click on UART protocol

Posted: Fri Aug 06, 2021 2:35 am
by jimmo
Yadnik wrote:
Thu Aug 05, 2021 6:24 pm
Can someone please have a look at my code and tell me where I may be going wrong.
Do you have a datasheet for this device, or a reference driver (e.g. Arduino) that implements the protocol?

Re: Running Ultrasonic click on UART protocol

Posted: Fri Aug 06, 2021 4:02 am
by Yadnik
Yes the link to the data sheet is : https://download.mikroe.com/documents/d ... 460-Q1.pdf
The library can be found at the end of this forum in zip format : https://e2e.ti.com/support/sensors-grou ... nd-arduino

Thank you very much!!

Re: Running Ultrasonic click on UART protocol

Posted: Fri Aug 06, 2021 5:12 am
by jimmo
Yadnik wrote:
Fri Aug 06, 2021 4:02 am
Yes the link to the data sheet is : https://download.mikroe.com/documents/d ... 460-Q1.pdf
The library can be found at the end of this forum in zip format : https://e2e.ti.com/support/sensors-grou ... nd-arduino
Thanks

Your code doesn't send a full command, just the sync byte. That forum post you linked to has a minimal example that shows the full payloads you need to send.

Re: Running Ultrasonic click on UART protocol

Posted: Tue Aug 10, 2021 3:21 pm
by Yadnik
I did incorporate the changes in my code from the code : https://e2e.ti.com/support/sensors-grou ... nd-arduino
However I am yet getting the same error i.e. my program returns only 0's
Can you please have a look at my code:https://github.com/Yadnik1/Ultrasonic-C ... %20uart.py and please tell what mistakes I may be making.

Re: Running Ultrasonic click on UART protocol

Posted: Tue Aug 10, 2021 7:59 pm
by scruss
I don't think the code (example, there are many like this) is doing what you think it is:

Code: Select all

buf10=bytearray(256)
  …
buf10= (0x55, 0x0A, 0x26, 0x00, 0xCF)

  …
            uart.write(b'\buf10')
b'\buf10' is likely to output b'\x08uf10', or the characters backspace u f 10 in sequence

bytes(buf10) should send b'U\n&\x00\xcf', which is probably more along the lines of what you want.

Re: Running Ultrasonic click on UART protocol

Posted: Thu Aug 12, 2021 12:50 pm
by Yadnik
I tried using bytes(buf10),however that gives me an error saying SyntaxError: can't assign to expression. My code currently looks like this:https://github.com/Yadnik1/Ultrasonic-C ... %20uart.py .
Can you please have a look and please tell me any alternative of assigning the hexadecimal values to the buffer.
Thank you very much!!

Re: Running Ultrasonic click on UART protocol

Posted: Fri Aug 13, 2021 2:06 am
by scruss
Yeah, you're doing that wrong. A way to do it (like I showed you) is:

Code: Select all

buf10= (0x55, 0x0A, 0x26, 0x00, 0xCF)
and when you need to use it, refer to

Code: Select all

bytes(buf10)
Also, please don't link to entire programs: post a minimal failing example in code tags. It's rather rude to expect people to scurry off and look at all your code and work out what's wrong with it. Also, isolating the smallest non-working part helps you understand the problem. Don't make it hard to be helped.

Re: Running Ultrasonic click on UART protocol

Posted: Fri Aug 13, 2021 12:53 pm
by Yadnik
Sorry scruss,
I will only post the part of code that does not work now onwards.

Re: Running Ultrasonic click on UART protocol

Posted: Fri Aug 13, 2021 12:56 pm
by Yadnik
I think this what you were saying:

utime.sleep_ms(1)
uart.write(bytes(buf25))
utime.sleep_ms(1)
uart.write(bytes(buf10))
utime.sleep_ms(1)

However this also is returning only 0's, any other suggestions you have.
Thank you!!