Running Ultrasonic click on UART protocol

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Yadnik
Posts: 65
Joined: Thu May 13, 2021 6:01 am

Running Ultrasonic click on UART protocol

Post by Yadnik » Thu Aug 05, 2021 6:24 pm

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.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Running Ultrasonic click on UART protocol

Post by jimmo » Fri Aug 06, 2021 2:35 am

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?

Yadnik
Posts: 65
Joined: Thu May 13, 2021 6:01 am

Re: Running Ultrasonic click on UART protocol

Post by Yadnik » 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

Thank you very much!!

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Running Ultrasonic click on UART protocol

Post by jimmo » Fri Aug 06, 2021 5:12 am

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.

Yadnik
Posts: 65
Joined: Thu May 13, 2021 6:01 am

Re: Running Ultrasonic click on UART protocol

Post by Yadnik » Tue Aug 10, 2021 3:21 pm

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.

User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Re: Running Ultrasonic click on UART protocol

Post by scruss » Tue Aug 10, 2021 7:59 pm

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.

Yadnik
Posts: 65
Joined: Thu May 13, 2021 6:01 am

Re: Running Ultrasonic click on UART protocol

Post by Yadnik » Thu Aug 12, 2021 12:50 pm

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

User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Re: Running Ultrasonic click on UART protocol

Post by scruss » Fri Aug 13, 2021 2:06 am

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.

Yadnik
Posts: 65
Joined: Thu May 13, 2021 6:01 am

Re: Running Ultrasonic click on UART protocol

Post by Yadnik » Fri Aug 13, 2021 12:53 pm

Sorry scruss,
I will only post the part of code that does not work now onwards.

Yadnik
Posts: 65
Joined: Thu May 13, 2021 6:01 am

Re: Running Ultrasonic click on UART protocol

Post by Yadnik » Fri Aug 13, 2021 12:56 pm

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

Post Reply