pigpio-client icon indicating copy to clipboard operation
pigpio-client copied to clipboard

Add more i2c functions.

Open btsimonh opened this issue 2 years ago • 5 comments
trafficstars

I think these are all good now. Have a review, but maybe wait to pull until I have added an example (will be servo control via PCA9685, illustrates many but not all of the i2c functions)?

Note the comments on returns with data:

general note about returns with data. if using await fn(), you will get an array back [count, d0, d1, d2 ...] if using fn(callback), you will get (err, count, d0, d1, d2 ...)

btsimonh avatar Jan 27 '23 08:01 btsimonh

ok, added the example, added stuff to readme. I think it's ready for review :).

btsimonh avatar Jan 27 '23 09:01 btsimonh

hold off on this for a while... I've been using it to implement MPU6050 communication, and see a need for 1/ a few more functions which would make it easier to use, but depart from the raw interface (e.g. ability to read/write a word/long in BE format). 2/ the repetitive use of the i2c handle pushes me towards a 'class' like the gpio pin class which knows it's pigpio instance and i2c handle.... I'll look at adding this in addition to the raw functions, and maybe put the BE functions and other helpers in there?

br, Simon

btsimonh avatar Feb 02 '23 07:02 btsimonh

ok, it's ready.

Note: all block functions return an array of data the size of the data received. e.g.

i2c.readI2cBlockData(reg, 10, (err, data)=>{
  // data will be 10 bytes in an array
});
let b = i2c.readI2cBlockData(reg, 10);
// b will be 10 bytes in an array

This is different to the original, which called back with (err, count, d0, d1, d2 ...) or returned async with [count, d0, d1, d2...] I basically strip the count off, and make sure that both callback and promise return an array as the data element.

Please let me know your thoughts...

btsimonh avatar Feb 16 '23 09:02 btsimonh

Hi @guymcswain I've pushed a complex and comprehensive MPU6050 driver based on this i2c implementation. Would be great to have the PR accepted?

Also the script PR is not damaging... br, Simon

btsimonh avatar Feb 21 '23 18:02 btsimonh

also PCA9685-pigpio-client for servo control :)

btsimonh avatar Feb 22 '23 19:02 btsimonh