I am converting an Arduino code to python3. I am trying to read data from IMU 9250 sensor from the I2C interface of raspberry-pi. I am facing issue with the timing libraries of raspberry-pi and arduino. The
micros() api of Arduino gives time in microsecond as a 8 digit number. I used
datetime library available in python to get time in microseconds which gives a 6 digit number. I need it to be in 8 digit number for precise calculation purpose.
import datetime Now = datetime.datetime.now().microsecond # >>> 439014
I have tried getting time in milliseconds and converting it into microseconds using the
time library in python and moving ahead with the code, but the precision is lost with this approach.
How can i get time in microseconds as a 8 digit number python? If it is not possible to get the microseconds as a 8 digit number, then how should i approach with the problem?
Arduino code does not map well to the Pi for many reasons – principally because it is a multi-tasking OS. Python makes the task more difficult. Frankly you are better looking for a Pi solution or write new code.
You can get µSec precision timing on the Pi using the pigpio python library e.g. http://abyz.me.uk/rpi/pigpio/python.html#get_current_tick
This is similar to micros()
http://abyz.me.uk/rpi/pigpio/code/DHT.py is an clever example using this to perform a task normally difficult on the Pi
PS I don’t understand 8 digit or 6 digit comments. AFAIK both return an unsigned 32 bit quantity