Hello.
I’m trying to create an I2C driver for the TFMini Plus (distance sensor).
I have already managed to obtain the measurement and display it by running the command tfmini_i2c start -a 82 -R -X followed by the command listener distance_sensor
My TFMini Plus has the 0x52 Hex address (82 Dec)
However, I have not yet managed to make it run automatically when the firmware starts. I understand that this is done by adding the line tfmini_i2c start -a 82 -R 0 -X to the file ROMFS/px4fmu_common/init.d/rc.sensors
I currently have these lines in that file: if param greater -s SENS_TFMINI_I2C 0 then tfmini_i2c -a 82 -R 0 -X start fi
The SENS_TFMINI_I2C parameter is a parameter I created in the tfmini_i2c driver, and I have it set to 1.
If I put that same piece of code in the ROMFS/px4fmu_common/init.d/rcS file, the module does start (I’m checking by running the command tfmini_i2c status).
Am I doing something wrong or missing some detail?
The code I’m using is based in v1.16.0
Here’s a repo with the changes I’ve made at the moment:
I see the message “no instance started (no device on bus?)”. So I guess my device is not being detected during startup for some reason.
After some testing, I found that if I put a 50 ms delay just before calling the rc.sensors file (from rcS file), it works:
usleep 50000 # <-Here I set the delay
#
# board sensors: rc.sensors
#
set BOARD_RC_SENSORS ${R}etc/init.d/rc.board_sensors
if [ -f $BOARD_RC_SENSORS ]
then
echo "Board sensors: ${BOARD_RC_SENSORS}"
. $BOARD_RC_SENSORS
fi
unset BOARD_RC_SENSORS
Even so, I still don’t understand why it works with that delay. Maybe some other module/process is occupying the bus at the same time?
I also tried with 10ms and less, but it did not detect my sensor that way.