Avatar for Stoaty

Stoaty

Member since Jan 2020 • Last active Apr 2021
  • 1 conversations
  • 6 comments

Most recent activity

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

    OK, found the issue!

    It was my misunderstanding of the repeat option on setWatch... All working now once set to true, thank you!

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

    Yo @maby - I've tried subtracting the offsets from zero but they're not super consistent, I'm at a bit of a loss trying to figure out how to normalise the values myself.

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

    Hi!

    I'm working on using Puck 2's accelerometer in order to detect when I'm braking on my bike!

    As of yet, I haven't been able to turn off the Accelerometer using Puck.accelOff(). Accel reads seem to be blocking my code to turn it off - but I think it's more the case I'm doing something wrong.

    Here's my code:

    
    // NRF.findDevices(function(devices) {
    //   console.log(devices);
    // }, 1000);
    
    console.log(`Battery ${Puck.getBatteryPercentage()}%`);
    
    let accelerometerEnabled = false;
    
    // Are we busy?
    var busy = false;
    
    // The device, if we're connected
    var connectedDevice = false;
    
    // The 'tx' characteristic, if connected
    var txCharacteristic = false;
    
    // Function to call 'toggle' on the other Puck
    function sendDataOverBLE(data) {
      if (!busy) {
        busy = true;
        if (!connectedDevice) {
          NRF.requestDevice({ filters: [{ id: 'a1:a1:a1:a1:a1:a1 public' }] }).then(function(device) {
            console.log('got device');
            return device.gatt.connect();
          }).then(function(device) {
            console.log('connected');
            connectedDevice = device;
            return device.getPrimaryService("4fafc201-1fb5-­459e-8fcc-c5c9c331914b");
          }).then(function(service) {
            return service.getCharacteristic("beb5483e-36e1­-4688-b7f5-ea07361b26a8");
          }).then(function(characteristic) {
            txCharacteristic = characteristic;
            busy = false;
          }).catch(function(e) {
            console.log(e);
            connectedDevice = false;
            digitalPulse(LED1, 1, 500); // light red if we had a problem
            busy = false;
            if (connectedDevicected) { 
              connectedDevice.disconnect();
            }
          });
        }
        else {
          if (!accelerometerEnabled) { 
            connected.disconnect();
            busy = false;
            return; 
          }
          txCharacteristic.writeValue(data ? `${data.acc.x}` : "no data yet").then(function() {
            //digitalPulse(LED2, 1, 500); // light green to show it worked
            busy = false;
          }).catch(function(e) {
            console.log(e);
            digitalPulse(LED1, 1, 500); // light red if we had a problem
            busy = false;
          });
        }
      } else {
        // console.log('busy');
      }
    }
    
    function toggleAccelerometer() {
     if (accelerometerEnabled) {
       accelerometerEnabled = false;   
       Puck.accelOff();   
       digitalWrite(LED1,1);
       digitalWrite(LED1,0);
       console.log('Accel OFF');
       if (connected) connected.disconnect();
     }
     else {
       accelerometerEnabled = true;   
       Puck.accelOn(); // default is 12.5Hz, with gyro    
       digitalWrite(LED2,1);
       digitalWrite(LED2,0);   
       console.log('Accel ON');
     }
    }
    
    function checkAccelerometerEnabled(data) {
      if(accelerometerEnabled) { 
        sendDataOverBLE(data);
      }
    }
    
    // Call function when the button is pressed
    setWatch(toggleAccelerometer, BTN, { edge:"rising", debounce:50, repeat: false });
    
    // or Puck.accelOn(1.6); for 1.6Hz low power, without gyro
    Puck.on('accel', function(data) {
      if (accelerometerEnabled) { 
        checkAccelerometerEnabled(data);
        const x = data.acc.x;
        const y = data.acc.y;
        const z = data.acc.z;
        const xZero = 750;
        const yZero = 15;
        const zZero = -8200;
        console.log(x+xZero,y+yZero,z+zZero);
      }
      else {
        // console.log(x+xZero,y+yZero,z+zZero);
      }
    
    });
    
    

    No issues with sending the data over BLE to my ESP32 however - works like a charm!

    One other thing I wanted to know was how to "normalise" the accel's values, but I'll post that up in another convo.

  • in Bangle.js
    Avatar for Stoaty

    I just ripped some of these out of some old Tile keyrings!

    Unsuccessfully soldered one so far 🙈it seems there's a coating on top that doesn't like being soldered onto (I used liquid flux, but the connection was still mechanically weak and easily breaks off of the thin coating).

    EDIT:


    I managed to solder to the + terminal of the Piezo after watching a video that shows you can in fact scratch the coating with a razor blade - it's still a very brittle connection, but I managed to solder to the correct pins to test it out and got beeps!

    It was definitely louder, but there's no way i can solder the connections into the watch without something breaking (i already tried twice!)

    It was a fail, but I learned some stuff too, so it's ok!

  • in Bangle.js
    Avatar for Stoaty

    Courtesy of Gordon :-)

    Bangle.js: Opening and re-assembling
    https://www.youtube.com/watch?v=GJHC925y­ti0

  • in Bangle.js
    Avatar for Stoaty

    You can also use the Set Bangle.js Time button on the About page of the Bangle.js App Loader page

Actions