MCP3424 18-bit ADC


@bko and using the values in the arithmetic expression always returns 0:

_resultat = (_resultat/2047)*(2.048/_PGA)*(180/33);

You’ll have to forgive my ignorance, I’ve never really worked with floating point or decimals numbers in code before :smile_cat:


Hi @joearkay

How is _resultat declared? Also as long? That would need to be changed as well but since the same variable is used for reading other things in the code above, a new variable for the float/double value would be the best thing.


@bko _resultat is a float and _PGA is uint8_t. Would it be a good idea to change _PGA to float as well?


This part quoted above requires _resultat to be an int type since you are using bit-level masking but later on you are doing floating point arithmetic. You just need two variables.

Try this:

case 12:
  int temp;
 temp = _Buffer[0]; //originally assigning _resultat to the first byte
 temp&=0b00001111;   //ANDING this to 'mask' the unwanted bits
 temp = temp << 8;    //Shifting 8 bits in the MSB direction
 temp |= _Buffer[1]; //OR to add byte 1 to the end of the first byte

 if (temp>2048-1) {
 temp=temp-4096-1;  //this fixes the sign to be negative when needed

_resultat = ((float)temp/2047.0)*(2.048/(float)_PGA)*(180.0/33.0); 


That sorted it, thank you so much!


@thanks for the backup @bko :grinning:


@joearkay If it is not too much trouble would you be willing to share your code?

I am just beginning to work with the MCP3424 and would greatly appreciate the help.

Also thanks for starting this thread! It has been quite informative! :smile:


Hi @zferrie, sorry for the slow response. I used the library provided by the Arduino IDE, found here:

There was a small amount of modification to be done (can’t remember what I had to change), from memory, but this library worked really well.

I hope that helps.


@joearkay No worries. Based on the thread i wasn’t 100% on which of the two originally mentioned libraries you ended up using. This gives me a good place to start.

Thanks for the help!


Hi @zferrie, no worries, let me know if you need any assistance. Like I said, I worked on this project a while ago and am no longer using the codebase, so don’t have a full version I can share.


@joearkay Sounds great! Thank you!