Member #763158

Member Since: January 15, 2016

Country: United States

  • https://grabcad.com/library/wjk_body-1

    It only fits one battery size and you need a 3D Printer.

  • Is that the resistor to the green LED? if so I’m glad since it was really bright.

  • and Processing to test (you must change COM5 to your port. use an xbee explorer connected to your computer and send the joystick to the test code

    import processing.serial.*;
     Serial myPort;
    
    String serialInputString ="";
    boolean UP_BUTTON, DOWN_BUTTON, LEFT_BUTTON, RIGHT_BUTTON,L_TRIG,R_TRIG,JOYSTICK_BUTTON;
    
    float controllerWidth = 516;
    float controllerHeight = 280;
    float rawH=512,rawV = 512;
    float HOffSet,VOffSet = 0;
    
    void setup() {
      size(640, 640);
       myPort = new Serial(this, "COM5", 9600); //Set up serial
       myPort.bufferUntil('\n');  
      //dummySerialEvent();
    }
    
    
    void draw() {
      background(50,50,50);
      rectMode(CENTER);
      fill(200,100,100);
      rect(width/2,height/2, controllerWidth, controllerHeight, 7);
    
      drawButtons();
      drawJoystick(); 
      delay(5);
    }
    
    void drawButtons()
    {
     if (UP_BUTTON) {  fill(10,10,250); } else { fill(250,250,250); }
      rect(width/2+controllerWidth/4,height/2-50, 35, 35, 3);
     if (DOWN_BUTTON) {  fill(250,250,10); } else { fill(250,250,250); }
      rect(width/2+controllerWidth/4,height/2+50, 35, 35, 3);
    
     if (LEFT_BUTTON) {  fill(10,250,10); } else { fill(250,250,250); }
      rect(width/2+controllerWidth/4-50,height/2, 35, 35, 3);
     if (RIGHT_BUTTON) {  fill(250,10,10); } else { fill(250,250,250); }
      rect(width/2+controllerWidth/4+50,height/2, 35, 35, 3);
    
     if (L_TRIG) {  fill(10,250,250); } else { fill(250,250,250); }
      rect(width/2-105,(height-controllerHeight)/2, 55, 15, 3);
     if (R_TRIG) {  fill(10,250,250); } else { fill(250,250,250); }
      rect(width/2+105,(height-controllerHeight)/2, 55, 15, 3);
    }
    
    void drawJoystick()
    {
      if (JOYSTICK_BUTTON) {  fill(10,250,10); } else { fill(250,250,250); }
      ellipse(width/2-controllerWidth/4,height/2, 135, 135);
      HOffSet = map(rawH, 0, 1023,40, -40);
      VOffSet = map(rawV, 0, 1023, 40, -40);
      fill(10,10,10);
      ellipse(width/2-controllerWidth/4+HOffSet,height/2+VOffSet, 35, 35);
    }
    
    void serialEvent (Serial myPort)
    {
      serialInputString = myPort.readStringUntil('\n'); //Gets val
      processStrings(serialInputString);
    }
    
    /*
    void testSerialEvent()
    {
      processStrings("J0000000");
       processStrings("H1021");
       processStrings("V216");
    }
    */
    void processStrings(String theInput)
    {
      if (theInput.charAt(0) == 'J') { parseButtonValues(theInput); }
      if (theInput.charAt(0) == 'H') { parseHorizontalValue(theInput); }
      if (theInput.charAt(0) == 'V') { parseVerticalValue(theInput); }
    }
    
    void parseButtonValues(String buttonValues)
    {
      if (buttonValues.charAt(1) == '1') {L_TRIG = true;} else {L_TRIG = false;}
      if (buttonValues.charAt(2) == '1') {R_TRIG = true;} else {R_TRIG = false;}
      if (buttonValues.charAt(3) == '1') {UP_BUTTON = true;} else {UP_BUTTON = false;}
      if (buttonValues.charAt(4) == '1') {DOWN_BUTTON = true;} else {DOWN_BUTTON = false;}
      if (buttonValues.charAt(5) == '1') {LEFT_BUTTON = true;} else {LEFT_BUTTON = false;}
      if (buttonValues.charAt(6) == '1') {RIGHT_BUTTON = true;} else {RIGHT_BUTTON = false;}
      if (buttonValues.charAt(7) == '1') {JOYSTICK_BUTTON = true;} else {JOYSTICK_BUTTON = false;}
    }
    
    void parseHorizontalValue(String HValue)
    {
      float JSValues[] = float(split(HValue,"H"));
      rawH=JSValues[1];
    }
    
    void parseVerticalValue(String VValue)
    {
      float JSValues[] = float(split(VValue,"V"));
      rawV=JSValues[1];
    }
    
  • This is my version with just the buttons

    /* Wireless Joystick Buttons
     * 
     * license: Creative Commons Attribution-ShareAlike 4.0 (CC BY-SA 4.0)
     * Do whatever you'd like with this code, use it for any purpose.
     * Please attribute and keep this license. 
     * 
     * This is example code for the Sparkfun Wireless Joystick using XBee. 
     * Modified from the tank code found here https://learn.sparkfun.com/tutorials/wireless-joystick-hookup-guide
     * 
                                           X
                                         Y   A
                                           B
     */
    
    #define UP_BUTTON 8 // X
    #define DOWN_BUTTON 2 // B
    #define LEFT_BUTTON 4 // Y
    #define RIGHT_BUTTON 9 // A
    
    #define L_TRIG 6        // Pin used for left trigger
    #define R_TRIG 3        // Pin used for right trigger
    
    #define JOYSTICK_BUTTON 5
    
    #define V_JOYSTICK A3   // Pin used for left joystick
    #define H_JOYSTICK A2 
    
    
    void setup() {  
      Serial1.begin(9600); // Start serial communication with XBee at 9600 baud
      delay(10);
      Serial1.print("W7001\r\n"); // Set the bit in enable register 0x70 to 0x01
    
      pinMode(L_TRIG,INPUT_PULLUP); // Enable pullup resistor for left trigger
      pinMode(R_TRIG,INPUT_PULLUP); // Enable pullup resistor for right trigger
      pinMode(UP_BUTTON,INPUT_PULLUP);
      pinMode(DOWN_BUTTON,INPUT_PULLUP);
      pinMode(LEFT_BUTTON,INPUT_PULLUP);
      pinMode(RIGHT_BUTTON,INPUT_PULLUP);
      pinMode(JOYSTICK_BUTTON,INPUT_PULLUP);
    }
    
    void loop() {
      int16_t horizontalJS, verticalJS;    // We'll store the the analog joystick values here
      char hor[10],vert[10]; // character buffers used to set motor speeds
    
      char joySTBuf[9];
      joySTBuf[0] = 'J';
     (digitalRead(L_TRIG)==0) ? joySTBuf[1] = '1' : joySTBuf[1] = '0';
     (digitalRead(R_TRIG)==0) ? joySTBuf[2] = '1' : joySTBuf[2] = '0';
     (digitalRead(UP_BUTTON)==0) ? joySTBuf[3] = '1' : joySTBuf[3] = '0';
     (digitalRead(DOWN_BUTTON)==0) ? joySTBuf[4] = '1' : joySTBuf[4] = '0';
     (digitalRead(LEFT_BUTTON)==0) ? joySTBuf[5] = '1' : joySTBuf[5] = '0';
     (digitalRead(RIGHT_BUTTON)==0) ? joySTBuf[6] = '1' : joySTBuf[6] = '0';
     (digitalRead(JOYSTICK_BUTTON)==0) ? joySTBuf[7] = '1' : joySTBuf[7] = '0';
      joySTBuf[8]='\0'; // this is the null character. this tells other stuff the char array is at the end. (in case you didn't know.)
    
    
    horizontalJS = analogRead(H_JOYSTICK);
    verticalJS = analogRead(V_JOYSTICK);
    
    sprintf(hor,"H%d",horizontalJS);
    sprintf(vert,"V%d",verticalJS);
    
     Serial1.println(joySTBuf);
     delay(2);
     Serial1.println(hor);
     delay(2);
     Serial1.println(vert);
     delay(2);
    
    }
    
  • Nice!

    Have you considered having code for just sending the values of the buttons and joysticks out? Then you could have other stuff talk to the common format of the joystick without needing to recode your joystick each time.

    I’m making the code myself starting from Alex’s Tank, so if you want you can have mine once I test it if you like.

  • This is really cool, thanks for inventing it.

    Is there a CAD (.step) file of the physical thing available? I’d like to make a thing that goes around it.

  • I found this right after placing my order. i’m going t make one of these, looks fun.

  • This is actually very useful. got something that looked like an arduino shield, so I soldered header pins into it and epoxied it to a 2.5lb metal disk to make a stand for soldering stuff. many of the other boards I use by gluing stuff to them so I have an ‘example’ board to put in my pocket and test fit without risking my real boards to extra handling

    The sucky thing is all the boards you don’t want count as ewaste so you can’t put the unwanted extra boards in the regular trash.

  • is there going to be a sparkfun mega?

Persistence of Vision Project

Member #763158 16 items

These components are singles of the persistence of vision...