PuckPad

Posted on
  • Thought I'd share my progress on my latest project the PuckPad. Currently a breadboard project which I'll hopefully move onto a custom PCB once I've ironed out all the issues ( and found another adafruit joypad pcb available in the UK ).

    The puck will read the relevant pins every 750ms ( will be 200ms outside of testing ) and update the custom BLE characteristic.

    // Author : Adam 
    // Project: PuckPad
    // Firmware: 0.10
    // BLE Services : Battery, Device and Custom controller
    // 
    //  Battery: 0x180F ->  0x2A19
    //  Device:  0x180A - > 0x2A29 (Manufactor Name)
    //                  - > 0x2A26 (Firmware Version)
    //  Custom: 0x9AD0 -> 0x9AD1 ( Int8 * 4 ) left xy right xy
    //                 -> 0x9AD2 ( 0 or 1 ); extra BTN
    //
    //
    // Puckpad has two analog joysticks and two buttons.
    // The pad will simply send each joysticks XY vlaues to a proxy IOS application to fly a parrot drone.
    //
    //   GND -> GND
    //   3V  -> 3V
    //   D2  -> X left joypad
    //   D31  -> Y left joypad
    //   D30  -> X right joypad
    //   D29  -> Y right joypad
    //   D28  -> BTN
    
    pinMode( D30, "input_pulldown" ); //currently not in use 
    pinMode( D29, "input_pulldown" ); // currnetly not in use
    
    var fwVersion = "0.9";
    var flashy = [150,200,150,200,150];
    var vflashy = [50,50,50];
    var connected = false;
    var refreshRate = 750;
    var isReading = false;
    var loopy = null;
    
    var xyxy = [0x00,0x00,0x00,0x00];
    
    var padBTN = 'D28';
    var pins = [ 'D2','D31','D30','D29'];
    // joypad     LX   LY    RX    RY  
    
    NRF.on('connect', function(addr) {
      connected = true;
      updateBattery();
      digitalPulse(LED3,1,flashy);
      
    });
    
    NRF.on('disconnect', function(addr) {
      connected = false;
      isReading = false;
      digitalPulse(LED1,1,flashy);
     }
    );
    
    NRF.setServices({
      0x180F : {
        0x2A19: {
          readable: true,
          notify: true,
          value : [100]
        }
      },
      0x9AD0 : {
        0x9AD1 : {
          readable: true,
          notify: true,
          value: xyxy
        },
        0x9AD2 : {
          readable : true,
          notify: true,
          value: [0x00]
        }
      },
      0x180A : {
        0x2A29 : {
          readable: true,
          value: 'PuckPad'
        },
        0x2A26 : {
          readable: true,
          value: fwVersion
        }
      }
    });
    
    function updateBattery () {
      NRF.updateServices({
      0x180F : {
        0x2A19: {
          notify: true,
          value : [Puck.getBatteryPercentage()]
        }
      }
    });
    }
    
    function updateXYXY(){
    
      xyxy.forEach(function(pinData,index) {
        xyxy[index] = Math.floor(analogRead(pins[index]) * 100);
      });
      
      // some manual calibration 
      xyxy[0] += 1;
      xyxy[1] += 2;
      xyxy[2] += 1;
      xyxy[3] += 1;
    
      NRF.updateServices({
        0x9AD1 : {
          0x9AD1 : {
            notify: true,
            value: xyxy
          }
        }
      });
    }
    
    function updateBTN1 (buttonIs) {
     NRF.updateServices({
      0x9AD0 : {
        0x9AD2 : {
          notify: true,
          value: buttonIs
        }
      }
    });
    }
    
    setWatch(function(e){
      isReading = !isReading;
      if (connected) { 
        if (isReading) {
          digitalPulse(LED3,1,vflashy);
          updateXYXY();
          loopy = setInterval(updateXYXY,refreshRate);
        } else {
        clearInterval(loopy);
        digitalPulse(LED1,1,vflashy);
        }
      } else {
        digitalPulse(LED2,1,flashy);
      }
    }, BTN, {repeat:true, debounce:50, edge:"falling"});
    
    

    TODO

    • Add second joystick
    • Complete IOS app - pure software controller working just need to connect to the puck and get the values.
    • Create custom PCB - adafruit have already created a single PCB file
    • Check battery usage

    I'll hopefully post back my progress in the coming weeks :)


    3 Attachments

    • IMG_0452.jpg
    • IMG_0453.jpg
    • IMG_0454.jpg
  • Nice - thanks for posting up!

    Did you consider using the Bluetooth HID option? I think it works with iOS and you might be able to do something that doesn't require an app.

    Although having said that it's pretty useful to know how to do everything - doing an app and getting the Puck.js working.

  • It did cross my mind, but wasn't sure how it handled analog input so thought I'd role my own. Could also of bought a Parrot controller for £40 but there's no fun in that :-)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

PuckPad

Posted by Avatar for Adam79 @Adam79

Actions