• Hello,

    I've managed to hack my way to a solution for my project, but just hoping for some guidance from experts if this is the best way to do this. This is my first experience with microcontrollers and serial communication.

    I have an Espruino Pico with a BME280 attached, connected to a host computer via USB.

    I'm looking for a stable/energy efficient solution where I can run Node.js on the host, and grab sensor values from the Pico once a minute (currently 5 seconds while testing).

    Code on the Pico:

    var i2c = new I2C();
    i2c.setup({ scl: B6, sda: B7 });
    var bme = require("BME280").connect(i2c);

    Currently my best try on the Node.js code:

    const { spawn } = require('child_process');
    setInterval(callPico, 5000)
    function callPico() {
      const pico = spawn('espruino', [
        '--port', '/dev/tty.usbmodem00000000001A1',
        '--board', 'PICO_R1_3',
        '-e', 'console.log(bme.getData())',
      pico.stdout.on('data', (data) => {
        const line = data.toString().trim()
        if (
          line !== ''
          && line !== 'Explicit board JSON supplied: "PICO_R1_3"'
          && line !== 'Upload Complete'
        ) {
          const json = JSON.parse(line)
            temperature: json.temp,
            humidity: json.humidity
      pico.stderr.on('data', (data) => {
       console.error('ERROR:', data.toString());

    I also tried using the espruino node package like this:

    var esp = require("espruino");
    const PORT = '/dev/tty.usbmodem00000000001A1'
    esp.expr(PORT, 'bme.getData()', console.log);

    Which does eventually return the sensor values, but it spams the log with 100+ lines output (too many to copy/paste here!) and the process fails to exit, something to do with Noble scanning.

    Is there a better approach? Thanks for your help.


Avatar for daviestar @daviestar started