Welcome! Log In Create A New Profile

Advanced

Add 2-axis joystick to Marlin?

Posted by geemoto 
Add 2-axis joystick to Marlin?
June 28, 2015 11:35PM
I'm looking to add a 2-axis joystick to control folder navigation (and maybe print head if supported) in Marlin firmware. I know there is native support for an encoder, but I'm wondering if there is some way to modify the firmware to add joystick support (if it isn't already there). They joystick wiring diagram for the custom sprinter firmware from a local shop is here: [file.mixshop.com] and the custom sprinter firmware is here [forum.mixshop.com]

I'm not sure if this is an easy or hard job? Which files would I be looking to modify?

Edited 1 time(s). Last edit at 06/29/2015 09:38AM by geemoto.
Re: Add 2-axis joystick to Marlin?
June 29, 2015 09:01PM
I found the relevant pin map here:

[d1fftcfaq4zs1.cloudfront.net]

The LCD connects and works great. The select button also works great. I guess I'm just going to have to convert the digital input for the digital output from the encoder to an analog output from the joystick. Any idea which code I'd modify for this? I'm using the #define G3D_PANEL code and the relevant pins are:
#define BTN_EN1 31 //This is select
#define BTN_EN2 33 //I think this is left on encoder
#define BTN_ENC 35 //I think this is right on encoder
Re: Add 2-axis joystick to Marlin?
June 30, 2015 02:03AM
I´m not sure, if you have to read the joystick as analog input. Just read it as a digital value. Everything below the threshold is "0", everything above is "1".
The main problem you´ll find is:
the encoder provides pulses, but the joystick doesn´t.
How do you implement up/down function?
You´d have to rewrite the hole LCD-menue or borrow it from the sprinter-FW? Marlin is an offsprint of sprinter AFAIK. Maybe it is worth looking into the custom sprinter code?
-Olaf
Re: Add 2-axis joystick to Marlin?
June 30, 2015 11:24AM
Quote
o_lampe
I´m not sure, if you have to read the joystick as analog input. Just read it as a digital value. Everything below the threshold is "0", everything above is "1".
The main problem you´ll find is:
the encoder provides pulses, but the joystick doesn´t.
How do you implement up/down function?
You´d have to rewrite the hole LCD-menue or borrow it from the sprinter-FW? Marlin is an offsprint of sprinter AFAIK. Maybe it is worth looking into the custom sprinter code?
-Olaf

I tried connecting the joystick directly to the digital encoder inputs with no luck. Basically, I just need to read the analog signal and convert it to a digital signal in the appropriate method. After some digging, I think the method I'm looking to modify is below. Still looking into its modification, or maybe it would be simpler to just buy an encoder.

Wow, only 12$ for the LCD, encoder and SD reader from eBay...really doesn't make code modification seem too worthwhile

void lcd_buttons_update()
{
#ifdef NEWPANEL
    uint8_t newbutton=0;
    if(READ(BTN_EN1)==0)  newbutton|=EN_A;
    if(READ(BTN_EN2)==0)  newbutton|=EN_B;
  #if BTN_ENC > 0
    if((blocking_enc>1;
          if(READ(SHIFT_OUT))
              newbutton_reprapworld_keypad|=(1<<7);
          WRITE(SHIFT_CLK,HIGH);
          WRITE(SHIFT_CLK,LOW);
      }
      buttons_reprapworld_keypad=~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
	#endif
#else   //read it from the shift register
    uint8_t newbutton=0;
    WRITE(SHIFT_LD,LOW);
    WRITE(SHIFT_LD,HIGH);
    unsigned char tmp_buttons=0;
    for(int8_t i=0;i<8;i++)
    {
        newbutton = newbutton>>1;
        if(READ(SHIFT_OUT))
            newbutton|=(1<<7);
        WRITE(SHIFT_CLK,HIGH);
        WRITE(SHIFT_CLK,LOW);
    }
    buttons=~newbutton; //invert it, because a pressed switch produces a logical 0
#endif//!NEWPANEL

    //manage encoder rotation
    uint8_t enc=0;
    if (buttons & EN_A) enc |= B01;
    if (buttons & EN_cool smiley enc |= B10;
    if(enc != lastEncoderBits)
    {
        switch(enc)
        {
        case encrot0:
            if(lastEncoderBits==encrot3)
                encoderDiff++;
            else if(lastEncoderBits==encrot1)
                encoderDiff--;
            break;
        case encrot1:
            if(lastEncoderBits==encrot0)
                encoderDiff++;
            else if(lastEncoderBits==encrot2)
                encoderDiff--;
            break;
        case encrot2:
            if(lastEncoderBits==encrot1)
                encoderDiff++;
            else if(lastEncoderBits==encrot3)
                encoderDiff--;
            break;
        case encrot3:
            if(lastEncoderBits==encrot2)
                encoderDiff++;
            else if(lastEncoderBits==encrot0)
                encoderDiff--;
            break;
        }
    }
    lastEncoderBits = enc;
}

Edited 1 time(s). Last edit at 06/30/2015 11:36AM by geemoto.
Sorry, only registered users may post in this forum.

Click here to login