Skip to content

Atlas Scientific pH Kit

Jake Hartnell edited this page Apr 8, 2017 · 5 revisions

Atlas Scientific pH Sensor

Johnny-Five + Grow.js example

Note: for this to work, the circuit needs to be I2C mode. Instructions for this can be found in the documentation.

// Require the Grow.js build and johnny-five library.
var GrowInstance = require('Grow.js');
var five = require('johnny-five');
var ascii = require('ascii-codes');

// Create a new board object, not if you're using a Raspberry Pi use raspi-io.
var board = new five.Board();

// When board emits a 'ready' event run this start function.
board.on('ready', function start() {
    var pH_reading;

    // Create a new grow instance.
    var grow = new GrowInstance({
        // API credentials for Grow-IoT
        uuid: 'PASTE_UUID_HERE',
        token: 'PASTE_TOKEN_HERE',

        properties: {},

        start: function () {
            // This must be called prior to any I2C reads or writes.
            board.i2cConfig();

            // Read response.
            board.i2cRead(0x63, 7, function (bytes) {
                var bytelist = [];
                if (bytes[0] === 1) {
                    for (i = 0; i < bytes.length; i++) {
                        if (bytes[i] !== 1 && bytes[i] !== 0) {
                            bytelist.push(ascii.symbolForDecimal(bytes[i]));
                        }
                    }
                    pH_reading = bytelist.join('');
                }
            });
        },

        log_ph_data: function () {
            // Request a reading
            board.i2cWrite(0x63, [0x52, 0x00]);


            // Send value to Grow-IoT
            grow.sendData({
              type: 'pH',
              value: pH_reading
            });
        }
    });
});