sandeepmistry / node-chip-io

Johnny-Five IO Plugin for the Next Thing Co. C.H.I.P.
MIT License
96 stars 28 forks source link

update pins.json so the VCC-1V8 pin can be read as analog. Updated ax… #33

Open tyler-g opened 7 years ago

tyler-g commented 7 years ago

Allow VCC-1V8 pin to be read as 12-bit ADC

Based on some great information here: https://bbs.nextthing.co/t/chips-internal-adc/2136/59

The LRADC pin on the CHIP only allows for 6-bit (0-63) resolution. To allow for more precise reading, I've updated the axp209 controller so that if you request to read VCC-1V8 as analog, the axp209 tick will then call a special function to read the appropriate i2c register.

It will read 0 unless certain registers are written to allow for this. This is done in the _configureVcc18Adc which is called in the AXP209 open. I just put it there for testing, but it would be better if we could expose it somehow.

This is not quite merge ready – need to figure out where to put the configure and reset calls. I didn't do much, just ported over the information in the above linked nextthing thread :)

Also, if anyone has suggestions on the efficiency of this, please feel free to send PRs or comments. I know we would want to keep the tick function as minimal as possible. Note that even though I've added to this tick function, it will only attempt to read if you've requested that read, for example like this:

var fsr = new five.Sensor({
      pin: "VCC-1V8"
  });
  fsr.on("data", function(value) {
      console.log(value);
  });

I've tested this with an actual FSR sensor and it works great.

mattdsteele commented 6 years ago

@sandeepmistry @tyler-g Hi folks! Sorry to zombie this, but I've just run into the "reading analog from LRADC doesn't give me enough fidelity" issue with a project of mine, and it looks like this PR might help resolve it.

Is there anything I can do to help get this across the finish line?