Avatar for psc1988

psc1988

Member since Jan 2020 • Last active May 2021
  • 6 conversations
  • 33 comments

Most recent activity

    • 3 comments
    • 629 views
  • in Puck.js, Pixl.js and MDBT42
    Avatar for psc1988

    Is it possible to set different intervals?

    I have two operations using setInterval().
    One is to read out a sensor via I²C and on the other hand I would like to let a LED blink, depents on the counter value, e. g. counter == 3 >>> LED should blink 3 times all 10 seconds.

    My problem is that the LED blinks continiously - I tried it with arguments but it does not work.

    ///Sensor_Data        
         setInterval(() => {
         i2c.writeTo(0x18, 0xAA, 0x00, 0x00); 
         setTimeout(() => {
         let output = i2c.readFrom(0x18, 5);
         var output_bit = output[1] *100 *100 + output[2]*100 + output[3];    
         var pressure1 = (output_bit-1200000)*(1-(-1));
         var pressure2 = pressure1/(1500000-1200000);
         var pressure_final = pressure2 + (-1) - 0.29;    
         log(pressure_final, counter);  
    ///Counter    
         if (pressure_final < -0.2) {
         status_counter = 1;
         }
         if ((status_counter == 1) && (pressure_final > -0.2) && (pressure_final < 0.2)) {
         counter = counter + 1;            
           if (counter + 1) {
           status_counter = 0;}
           }
             if (counter > 6){
             counter = 1;
             }
    
  • in Puck.js, Pixl.js and MDBT42
    Avatar for psc1988

    And finally the code with the psi-output value:

    var i2c = new I2C();
    i2c.setup({ scl : D29, sda: D28 });
    var output_bit;
    var output_max;
    var output_min;
    var P_max = 1;
    var P_min = -1;
    var pressure1;
    var pressure2;
    var pressure_final;
    setInterval(() => {
    i2c.writeTo(0x18, 0xAA, 0x00, 0x00);
      setTimeout(() => {
      let output = i2c.readFrom(0x18, 5);
        var output_bit = output[1] *100 *100 + output[2]*100 + output[3];
        console.log(output_bit);
        var pressure1 = (output_bit-1200000)*(1-(-1));
        var pressure2 = pressure1/(1500000-1200000);
        var pressure_final = pressure2 + (-1) - 0.4;   
        console.log(pressure_final);
      }, 100);
    }, 300);
    
  • in Puck.js, Pixl.js and MDBT42
    Avatar for psc1988

    Hi Robin,

    also thanks for your answer.

    Now with this code works to get a realtime 24-bit value without re-upload:

        var i2c = new I2C();
        i2c.setup({ scl : D29, sda: D28 });
        setInterval(() => {
          i2c.writeTo(0x18, 0xAA, 0x00, 0x00);
          setTimeout(() => {
            let a = i2c.readFrom(MPRL, 5);
            console.log(a);
          }, 100);
        }, 300);
    

    Now I try to calculate the pressure like in the description of the datasheet and the arduino library.
    Its strange I just played with the new code and the times of the timeout and interval function.

  • in Puck.js, Pixl.js and MDBT42
    Avatar for psc1988

    Then i get the values ([96, 0, 0, 0, 0]) in the console.

  • in Puck.js, Pixl.js and MDBT42
    Avatar for psc1988

    Hi Jean-Philippe,

    thanks for the fast feedback, that helps!

    But why the data in the console just change when I upload the code again? When i make a sip or puff activity, nothing will change.

  • in Puck.js, Pixl.js and MDBT42
    Avatar for psc1988

    Hi,

    can someone help me to get the sensor data of the MPRL sensor?

    I wrote some code by using the documentation of the sensor manufacturer:

    Find datasheet here:
    https://sps.honeywell.com/us/en/products­/sensing-and-iot/sensors/pressure-sensor­s/board-mount-pressure-sensors/micropres­sure-mpr-series

    var i2c = new I2C();
    i2c.setup({ scl : D29, sda: D28 });     
    i2c.writeTo(0xAA, 0x00, 0x00); 
    setInterval(function () {
    var x = i2c.readFrom(0x18, 5);  
    console.log(x);
    }, 200);
    

    What I get in the console :
    new Uint8Array([64, 139, 169, 98, 128])

    When I reupload the code and give a puff signal to the connected tube on the sensor the value 139 increase. When I do a sip in goes down. The other values 3 & 4 change randomly. the first and the last value is steady.

    The value 139 changes just when I reupload to the MDBT42Q module. What I need to do that the value is changing in realtime? Do I need to convert the value as well?

    Greetings

  • in Interfacing
    Avatar for psc1988

    I've asked about it, but I'm still waiting to hear back.

    You can read the hex addresses from the documentation.

    Do you think I could try it via a module?
    The combination of Bluetooth connection and readout should also work with a module.

    However, I have not really understood how this works with the modules on a local storage location. I know your documentation but don't know how it is meant to put the module in when you have created a new empty folder via Settings >>> Projects.

  • in Interfacing
    Avatar for psc1988

    Hi Gordon,

    so I just get zeros as values. I tried it with the hex code 0x04 (attention level).
    In the documentation in the link below I saw there are also a hex code to enable the outputs but I don´t konw how to integrate that into the espruino program.

    I added var buf = 0x04 in the code.

    Found this documentation on the thinkgear website with the codes:
    http://developer.neurosky.com/docs/doku.­php?id=thinkgear_communications_protocol­#data_payload

    
    var buf = 0x04 ;
    var gatt,characteristic;
    setWatch(function(e) {
    NRF.requestDevice({ filters: [{ adress: 'c4:64:e3:e8:d6:e9' }] }).then(function(device) {
      console.log("Found");
      return device.gatt.connect();
    }).then(function(g) {
      console.log("Connected");
      gatt = g;
      return gatt.getPrimaryService(
        "039afff0-2c94-11e3-9e06-0002a5d5c51b");­
    }).then(function(service) {
      return service.getCharacteristic(
        "039afff8-2c94-11e3-9e06-0002a5d5c51b");­
    }).then(function (c) {
      console.log("Got Characteristic");
      characteristic = c;
      characteristic.on('characteristicvaluech­anged', function(event) {
         processBrainData(event.target.value.buff­er);
      });
      return characteristic.startNotifications();
    }).then(function() {
      console.log("Connected.");
      enableOutput(buf1);
    });
          }, BTN, { repeat: true, edge: 'rising' });
    function processBrainData(buf) {
      var d = new Uint8Array(16);
      setInterval(function() {
      print(d.slice().map(x=>x.toString(16).pa­dStart(2,0)).join(" "));
    }, 500);
      }
    
Actions