# making use of i2c

I am using an arduino board to get flow reading from a honeywell zephyr flow meter. When I implement my code I just get a consistent -2.5 value. The honeywell talks in hexadecimal and so I need to convert that to decimal so I have usable information I have attached my code for you to see. Not sure what is going on with the program. Any help will be great.

flowSensorI2CB.ino (1.22 KB)

I think you’re getting integer math’ed.

Try:

float flow = 20*((TempSum/16384.0)-.1)/.8;

I’m also suspicious of this…
int TempSum = (((MostSigByte << 8) | LeastSigByte) >> 4);

Okay I will give that a try and what has got you concerned about the

int TempSum = (((MostSigByte <<8) | LeastSigByte)>> 4);

Still getting a negative value when implemented the value changes now at the very least so its a start. I think it has something to do with the TempSum value any thoughts would be great.

What numbers are you getting back from the device?

Wait - you talk about a flow sensor… but your code refers to using a TMP75 temperature sensor. So which are you using? The int TempSum = (((MostSigByte << 8) | LeastSigByte) >> 4); does look correct for a TMP75 temperature sensor (because of it’s odd output format - a signed 12 bit number that needs to be turned into a signed 16 bit number) - but I’m not sure what that has to do with a flow rate…

I am using a flow sensor that was just some code took from some where else to try and implement and get the flow sensor to read properly. So would I need to setup that code differently for the flow sensor it is a honeywell zephyr if that helps any.

Yes, that line is specific for converting a signed 12 bit number provided as two bytes, where the low half of the low byte is the null, into a signed 16 bit int - that’s what it needs to do for the TMP75, but is probably not appropriate for that sensor you’re using.

You need to consult the datasheet for the sensor you’re using, and rewrite that line to convert what you’re getting into the form the next line (which I assume you derived from the datasheet) expects.

If it’s just a 16 bit unsigned number, you can convert the two bytes to an unsigned int like this:
unsigned int temp=(mostSigByte<<8)+leastSigByte;

Thanks gave that a try and it worked out :).