You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Nice - and that's all that's needed? No setup code or anything?

    You could actually simplify the code a bit further, because you can take advantage of the fact that I2C.writeTo takes bytes (so effectively does &0xFF for you).

    var voltage = 4095;
    voltage = E.clip(voltage,0,4095);
    // MCP4725 expects a 12bit data stream in two bytes (right aligned)
    I2C1.setup({scl:b6, sda:b7, bitrate:100000});
    I2C1.writeTo(0x60,[voltage >> 8,voltage]);
    

    It might be worth turning this into a module? It'd be tiny, but would at least make using the MCP4725 really easy for anyone who didn't want to worry about I2C commands.

About

Avatar for Gordon @Gordon started