Skip to content

Initialization Time #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
brian-eng opened this issue Nov 25, 2024 · 3 comments · Fixed by #45
Closed

Initialization Time #42

brian-eng opened this issue Nov 25, 2024 · 3 comments · Fixed by #45

Comments

@brian-eng
Copy link
Contributor

As part of the sensor initialization a reset is performed. This function has a call to time.sleep(2) between the EXIT and RESET commands. Why is there such a long wait there? This probably is not much of an issue when only using one sensor but when trying to use multiple sensors this delay really adds up quickly.

According to the datasheet

It is recommended to perform an ‘EX’ command and to wait 1ms, before issuing a ‘RT’ command. After the RT command, it is recommended to wait 1.5ms for the start-up sequence to complete.

Maybe that was meant as 2 ms? However, there is no delay after the reset itself.

@caternuson
Copy link
Contributor

Maybe 2ms was the intention, based on the POR timing from the datasheet?
image

Pretty common to be conservative and take the max value and round it up, which would support the idea of this intending to be a 2ms wait.

Also, Arduino's ms based delay() sometimes gets mixed up with Python's seconds based time.sleep() - for when code is ported, or if by someone used to writing Arduino code, etc.

But if that was the intention, the delay should be after sending the reset command. It's not even related to the sending of the EXIT command, since the delay has been there before that was even added (v1 release):

def reset(self):
"""
Performs a software reset of the sensor.
"""
if self._debug:
print("Resetting sensor")
time.sleep(2)
_status_last = self._transceive(bytes([_CMD_RT]))
return _status_last

Have you tried removing it?

@brian-eng
Copy link
Contributor Author

Have you tried removing it?

Yes, I have commented out the 2 second delay and it works fine on my end. However, I'm currently testing using Blinka on a RPi 5, so not exactly a standard CircuitPython setup.

I've also put a time.sleep(0.001) after the EXIT and time.sleep(0.002) ms after the RESET and that works as well.

@caternuson
Copy link
Contributor

Thanks. That also generally verifies that 2 second delay isn't really needed. Based on the datasheet, seems like a basic reset would be:

  • send EX (exit) command
  • send RT (reset) command
  • wait at least 1.5ms

So why is the 2s delay there? Don't know. You've tested without and it works. The Arduino library has no 2 second delay.

A PR to remove it seems fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants