You are reading a single comment by @AaronB and its replies. Click here to read the full conversation.
  • Hi,
    I stumbled upon THIS webpage for the electric imp.
    Github link to the code
    It has implemented the read function using :

    function read_weight(){
        //This is bit banged so we 
        //bind calls to local variables
        //to speed things up.
        //Takes about 2.2mS to do the read
        local sw  = spi.write.bindenv(spi);
        local dr  =;
        local val = 0;
        for(local i = 24; i >= 0; i--){
            val += dr() ? math.pow(2, i) : 0;
        return (val-ZERO_OFFSET)/GAIN;  //Value in grams

    It does point out that I should have typed >0 in the for statement not 1...
    I will test my code again with the refinements suggested by Gordon later tonight hopefully and will report back.

    Many thanks,



Avatar for AaronB @AaronB started