Shop Learn
P2 and Spin2 example for a 2-Axis Joystick project — Parallax Forums

P2 and Spin2 example for a 2-Axis Joystick project

Hi I'm a newby and recently proud owner of the P2 revb

Maybe this is not the right place to ask, if so please be kind to me :/

Tried my first baby steps with
1. Parallax standard and continuous servo's (works)
2. Parallax UV light sensor (works)

Now I'm working with the Parallax 2-Axis Joystick and having trouble finding the right starters info for Spin2 :'(
Does anyone know a good example program in Spin2 for the Joystick?
I've connected my Joystick to a Parallax 64020 P2 Edge Breakout Board

Later I will try to learn about connecting and controlling The Parallax feedback 360 high speed servo

Help is very appreciated :p

Comments

  • JonnyMacJonnyMac Posts: 8,091
    edited 2022-03-15 22:17

    The P2 has analog capability which makes using a joystick like that very easy. The attached object takes care of simple ADC details for you. This is just the object, you'll need to add it to a program and assign your pins. I suggest you start with one channel and use the start() method in the object. It will give you 0..3300 back as you move the joystick. You can use the startx() method to specify desired minimum and maximum reading from the ADC. With a joystick, for example, you could use -100 to +100 which would give you speed (in percent) and direction.

  • Thanks a lot Jon,

    the thing is, I'm a beginner and hope you can understand that "you'll need to add it to a program and assign your pins" is yet a bit too much for me.
    I've connected the two ADC's to smart pin 16 and 17 but can't seem to get it to work as a program like your jm_servo_multi_demo.spin2.
    Its connected to 3.3v

  • JonnyMacJonnyMac Posts: 8,091
    edited 2022-03-17 18:39

    Well, it is St. Patrick's Day, I'm Irish, and you are using a board with my name on it... so you're in luck. As you can see, doing the basics is simple and doesn't take a lot of code.

    Your job is to modify and play with the program so that you fully understand it and can move forward with any project.

    If, down the road, you're wanting to control a servo, you need to scale the joystick value to the servo pulse value. This is a method I use to do things like that:

    pub map(value, inmin, inmax, outmin, outmax) : result
    
    '' Maps value in range inmin..inmax to new value in range outmin..outmax
    
      if (value <= inmin)
        return outmin
      elseif (value >= inmax)
        return outmax
      else
        return (value - inmin) * (outmax - outmin) / (inmax - inmin) + outmin
    

    If you visit www.jonyjib.com you will see a lot of joystick-controlled camera platforms and accessories. All have Propellers (P1, and newest product uses the P2). I coded them all. Joysticks -- especially the low cost versions -- are rarely good out on the ends, and never spring back to the same place. For JonyJib projects, we trim the ends, and create a dead band in the middle based on the start-up position of the joystick.

    Have fun.

  • Jon, cheers !!!

    hope you had a good St. Patrick's Day, I for one did after your response.
    The joystick demo works like a charm, much appreciated indeed.
    Your my hero.

    Now I have working demo's of UV-sensors, Servo's and Joystick and examples to try out several other devices and sensors.
    Next on my list is the Parallax Feedback 360° High Speed Servo

    My goal is to integrate all lessons learned into a hardware abstraction layer and for that I must learn to play around with all devices combined and then assigning them to their own cog's.
    Some day I hope to be a P2/spin2 expert B) and with your code's I'm confident I'm on the right path.

    Parametric dead bands for joystick and light sensors will be necessary to incorporate into my program
    I was worried during my first steps but now my confidence has grown and I thank you for your extra info regarding Jonyjib.

    <3 P2/EMBB

  • JonnyMacJonnyMac Posts: 8,091
    edited 2022-03-18 17:34

    Glad I could help. I've done a number of talks for Parallax on the P2 that you can find on YouTube (see below). If you have the time, they might be worth watching. While most are about a specific topic, I tend to cover alternative programming strategies that are available to the P2 (e.g., straight Spin2, inline PASM2, smart pins, any combination).

    --
    --
    --
    --
    --
    --
    --
    --
    --
    --
    --

    --
    --
    --

  • Jon,

    I've been playing around with the Joystick and found a strange difference between the both pot meters Azimuth(X) and Altitude(Y)

    when I check the centers of both X and Y ADC's of the joystick the volts are not centered?
    for X centered the integer reads ~1654, moving the jog all the way left reads 760, all the way right reads 2800
    X center should be ~1780 but is close to the centered ~1654. Difference is 126

    for Y centered the integer reads ~1668, moving the jog all the way down reads 3050, all the way up reads 1014
    Y center should be ~ 2032 and lies further away from the centered ~1668. Difference is 364?
    could this be a faulty setup or are these differences normal for the 2-Axis Joystick or is this the needed dead band adjustment you were speaking of?

    Regards

  • @JonnyMac said:
    Glad I could help. I've done a number of talks for Parallax on the P2 that you can find on YouTube (see below). If you have the time, they might be worth watching. While most are about a specific topic, I tend to cover alternative programming strategies that are available to the P2 (e.g., straight Spin2, inline PASM2, smart pins, any combination).

    --
    --
    --
    --
    --
    --
    --
    --
    --
    --
    --

    --
    --
    --

    Jon,

    Thanks for these links, will work them thru. :) although it will take some time I presume.
    Dann

Sign In or Register to comment.