This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PGA460: Emulating the code in MicroPython

Part Number: PGA460
Other Parts Discussed in Thread: ENERGIA, CC1352P

Hi Team,

We would like to ask your help regarding the customer's inquiry below.

I am trying to run the Ultrasonic 2 click:www.mikroe.com/ultrasonic-2-click .Based on TI's PGA460 SoC.I am trying to run it on the UART protocol on MicroPython and my code looks as follows:github.com/.../ultrasonic uart.py .I have taken references from the example Energia library :e2e.ti.com/.../pga460-q1-pga460-q1-and-arduino
However I am getting an errors in the program and am sceptical whether I have correctly emulated the code in MicroPython.It would be very helpful If some technical guide could please have a look.Thank you!!

Thank you for your support!

Regards,

Danilo

  • Hello Danilo,

    Thanks for your question. I am not familiar with the way that MicroPython operates so I cannot provide much details if their code was correctly emulated, but if they could indicate what the errors are I might be able to assist and also what MCU are they are using could be helpful.

    Best,

    Isaac

  • Hi Isaac,

    Thank you for your response. Here are the details of the error.

    I am using the CC1352P MCU and I am running the Zephyr Port of MicroPython:github.com/.../README.md on it.My code is github.com/.../ultrasonic uart.py from where I have emulated the code is e2e.ti.com/.../pga460-q1-pga460-q1-and-arduino .I am not getting any error as such.The problem is that my code instead of giving distance, is only returning 0's as an output.The output of the program looks as follows:github.com/.../Screenshot 2021-08-14 at 12.47.10 AM.png .It would be grateful if you could please have a look at just the function level and please tell me if I am not making any mistake in emulating the example.Thank you very much

    Regards,

    Danilo

  • Hello Danilo,

    Give me some time to review the code at a function level, to see if I may have any comments on that.

    Just a couple of notes:

    1) Are we sure that the CC1352P is capable of working with MicroPython? It might be worth it post another thread regarding that device in specific to see if it is known to function with MicroPython.

    2) Has the customer been able to read and write registers appropriately? They can ensure that their device is being read properly by reading the DEV_STAT0 Register (Address = 4Ch) and reading the REV_ID as well as the OPT_ID. This is a read only register so the value should not change from the reset value.

    Best,

    Isaac

  • Hey Danilo,

    I reviewed the customers implementation at a high level, as far as syntax I am not able to comment much on that but what I am able to comment on are a few parts of the code:

                t = 0
                buf = bytearray(2)
                while t < 1000:
                    t = t + 1
                    utime.sleep_ms(5)
                if t < 1000:
                    uart.readinto(buf, 2)           
                dist = buf[0] * 256 + buf[1]
                if dist > 1100:
                        dist = -1                
                return(dist)

    I am not sure what this snippet of code is doing, it seems like this trying to read in the distance data?

    If that is the case the problem with that is that it comes before the command: uart.write(buf17) is the command that enables the PGA460 to broadcast an ultrasonic burst and listen command so it essentially begins a measurement. After this command delay the controller slightly longer than your anticipated ToF in the example provided by Akeem he delayed 100 ms. After that has been done then run command uart.write(buf5). This will begin readback of the registers with any peak data.

    In the code provided:

                uart.write(buf17)
                utime.sleep_ms(1)
                uart.write(buf5)

    A measurement is began, with a 1ms delay and then ultrasonic measurement results command is processed but then no data is read back. This is a likely reason why the data they obtained reflected 0.

    Best,

    Isaac