I’m trying to output data from a digital mass flow sensor via I2C on Cuav 5+ to GCS. I wrote a LUA script (sfm3300-flow-meter.lua (2.5 KB)) to do so which is heavily based off the SN-GCJA5-particle-sensor Example posted in the Ardupilot github.
I’m getting “Line 75: bad argument #2 to ‘send_named_float’ (number expected, got nil)” error. The issue appears to be with reading the register. Per the sensor documentation, the flow measurement register is a 2 byte 0x1000. In the custom readRegister16 function I read each byte separately with the built-in read_registers function and then combine via bitwise operation as shown below:
Notes on the hardware config:
- 10k ohm pull up resistors to +V are configured on SDC and SCL lines
- I performed continuity checks with a multimeter to verfiy the correct wiring between sensor and CUAV I2C port pinouts.
- Verified data output from sensor by connecting to external DAQ and python script.
Flow sensor documentation:
SFM3300 I2C Functional Description
lsb has a offset of 0 and
msb with a offset of 10?
I would have expected your if on line 61 to catch the case where
mdot is nil and never get to line 75.
@iampete I could have the incorrect syntax here, but the intent was to read msb as 0x10 and lsb as 0x00. With addr set to 0x00 (flow_measurement address), lsb would be 0x00 + 0 = 0x00 and msb would be 0x00+10 = 0x10.
I don’t think that matches the data sheet. It might need the ability to read two bytes at once which we don’t yet have from scripting. If you can find a arduino, or other example I often find it much easyer to translate someone elses code than to understand the datasheet.
@iampete Got it that must be the issue. I was trying to find a workaround (i.e. splitting into 2 seperate bytes then combining).The data sheet specifies a 2 byte read cmd 0x1000:
I’ll look around and see if I can find any other ardunio examples out there