• For the I2C slave, you could take a look at setWatch's data pin option (so you setWatch SCL and use SDA for data) - although things may still be a bit tricky to get it working nicely.

    What I always suggest for things like this is just to use Serial communications with the UART. This generally works really nicely:

    • Connect all the TX pins of slaves together, and all the RX pins
    • Add a 10k pullup resistor to the Slave TX line
    • Slave TX -> master RX, Slave RX -> master TX
    • Ensure that after you set up all the Serial ports on the slaves, you set the pin mode of the TX pins to opendrain
    • Create some kind of software system to ensure that the slaves only write data when they're asked to by the master. The simplest is just to use the built-in JS REPL to execute code that does some kind of if (id=myId) doSomething() type thing:

      // Slave
      var ID = 1; // change this for each slave
      
      // Master
      function sendCmd(id, cmd) {
      Serial1.println(`\x10if(id==${id})cmd;\n­`);
      }
      function gotResponse(d) {
      print("Got data ",JSON.stringify(d));
      }
      sendCmd(1,"print('Hello')");
      var lineData = "";
      Serial1.on('data',function(l) {
      lineData+=l;
      var d = lineData.split("\n");
      lineData = d.pop();
      d.forEach(gotResponse);
      });
      
  • Mon 2019.07.29

    RATS!! You would have to spoil our spacey dreams with an actual reliable way that would work, @Gordon !    wink, wink  ;-)

    All kidding aside, thank you for detailing how we ought to be doing this task. For my project, running short of pins and didn't want to add a MUX chip as well. But it is nice to have confirmation on how it should be done. Thank you for detailing that snippet.   

    rethink and redesign underway. . . .

  • @Gordon I plan to write binary data using the Uint16Array object. The master will send this to one slave, and the slave will respond back with a Uint16Array object. Total bytes in each direction will be < 100 bytes.

    Since I want to control the send and receive, I'm thinking of using Serial.write(data), then Serial.read() to receive the response from the slave. But Serial.read() appears to be a blocking call (no callback). So I'm not sure if my idea is the right approach. Thoughts?

About

Avatar for Gordon @Gordon started