You are reading a single comment by @DrAzzy and its replies. Click here to read the full conversation.
  • I2C addresses (like 0x63) are hexadecimal (base 16). You can use the number represented as base 10 or hexadecimal (or binary, ie, 0b01100011) interchangably.

    ie, 0x63 evaluates to 99 - you can do I2C1.sendTo(0x63,...) or I2C1.sendTo(99,...) - they're exactly the same. Which format you use matters only for the purposes of code readability. (in fact, if you use the code minification option, it converts all the hexadecimal values in your code to decimal, since that saves 1-2 bytes of code size per instance)

    I2C1.readFrom() returns an array of bytes. When you do I2C1.readFrom(99,10), that will request 10 bytes from the device, returning them as an array of 10 bytes. It's up to you to turn that array into something meaningful. A "null" is probably a byte with a value of 0.

    You can find a lot of examples of using I2C in the source code for the modules ( http://espruino.com/modules ). Also, have you read the reference, or just the tutorial? The reference ( http://espruino.com/Reference ) is a great resource, and I think it would have answered at least the question about the format data is returned

    As to why one would use it, it's because it's easy to convert between binary and hexadecimal in your head. It's a real help when you're writing code to control a device where you need to send one byte where each bit sets some feature.

  • @DrAzzy Thank you! i2c isn't difficult after all. One more question, I will eventually have multiple modules hooked up to the same i2c bus. Will each module require its own pullup resister?

About

Avatar for DrAzzy @DrAzzy started