I am wondering what should I do to adapt the adafruit library written for the ADC ADS1115 I2C (16 bits TI) library to a ADS1118 SPI (16 bits TI) library Python.


I purchased a ADS1118 SPI and want to create a library. But I am not sure how to change the i2C part of the code into a SPI one...

Do you have any idea or codes that could hep me ?

  • Let me seee if I understand your question. You want to port a I2C library for one part to support a different part and protocol on the PI? Nov 20, 2015 at 23:50
  • Yes, the ADC are very similar except the protocol I2C or SPI...
    – Rixpuk
    Nov 21, 2015 at 6:26

1 Answer 1


This is probably a daunting task if you've never worked with a datasheet or coding for SPI before, because you need to learn the latter in the context of the former. There's no way to work your way up from a generic "hello world" here. You either get the device to work or you don't. However, you can still at first focus on the simplest stand-alone verifiable task conceivable and forget everything else. I don't know what that is in this case -- I don't have one of these devices, or any ADC experience, or any SPI experience, but bare with me anyway. I did learn I2C in C++ starting with an Adafruit assembled gizmo, the chip datasheet, and their python library. I don't think this is too far removed from that.

You are likely better off approaching this from the ground up, rather than viewing that lib as something you're going to "adapt". However, having it as a reference point will be very useful, particularly as it seems well documented and refers explicitly to the datasheet. You probably won't be able to lift much code directly from it unless you mimic the API very closely -- in which case that would be toward the end, once the appropriate pieces are in place, and not in the beginning.

I would not worry about understanding the details of the I2C interface. It is not complex and should be transparent enough to follow in relation to how the datasheet specs are used in the library. Start by learning about SPI in the abstract from a high level -- that is, not how it is implemented, how timing and synchronization works on the wires, etc., but how the protocol is used. By analogy, you do not have to understand how ethernet works in order to do network programming but you do need to understand the purpose and structure of (higher level) network protocols. Once you have a basic grasp of that, you will want to start looking at the SPI API in python.

You can then start putting that together with the datasheet, using the existing library as a guide. Come up with that simple verifiable task and contemplate an implementation while seeing if you can find it in the existing library, then go from there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.