P2 Christmas Lighting Project (Beginner/Intermediate Spin2 Coding) -- Week 4 Files Available Now

1235»

Comments

  • YanomaniYanomani Posts: 1,118
    Happy New Year to you too!

    In the meantime, I was perusing some off-the-shelf rotary encoders datasheets, and it turns out my concepts on contact bouncing needs some healthy updating.

    When it comes to contact noise, even the cheaper encoders appear to be able to keep it within the vicinity of 2.0 - 5.0 mS, so those numbers should be kept in mind, when crafting the most convenient filter configurations.

    By simply relying on the -3_to_+3 phisical-pin-to-smart-cell mapping, you should be able to do simultaneous experiments with a wider selection of filterings, in order to find a sweet spot.
  • I put the Quadrature encoder on a scope and found that they must be digital devices as I did not see any contact type noise. I saw nice even square waves on each pin.

    What I did see was that sometimes there would be an A pulse but no B pulse or if going in the other direction a B pulse with no A pulse.

    At first I thought that this was a 5 volt device and that powering it with 3.3 volts was a issue. It did not make any difference.

    Mike
    824 x 447 - 21K
  • YanomaniYanomani Posts: 1,118
    Hi iseries

    Any hint about the brand/model of the encoder you're using, in order to grab and display those signals?


    Henrique
  • I've attached an image file that I made that shows the character-set for the LCD we got as part of this project.

    I found a reasonably good copy of the character-set table and added additional information and examples for working with the Custom Characters (Character codes #0 thru #7) that you can define.

    Note: Character codes #8 thru #15 are duplicate copies of what are defined in #0 thru #7.

    jonnymac's "jm_lcd_pcf8574.spin2" driver works great with the Noyito Technologies 1602 IIC LCD.

    I hope you find the image/table useful when working with the LCD.
    1000 x 1000 - 421K
  • Hi

    Thought I would dig out one of my el-cheapo ebay encoders.
    Very noisy but tame-able with re-reading until n number of reads without a change. I use an adjustable constant for this and just tweek for best results.

    However having said that, this noisy encoder is completely tamed by adding a 0.1uF cap from the a/b pins to 0v, and using a pin pullup of 15k, no noise suppression software needed.
    As long as you don't attach a motor to the shaft you can't turn the shaft by hand quick enough to beat it.

    Dave
  • Roy ElthamRoy Eltham Posts: 2,975
    edited 2021-01-06 07:08
    Played around a bit using JonnyMac's Spin2 driver for the LEDs but calling it from FlexProp C. Hooked up my 241 LED ring set setup like a tree.
    Had to add various delays, otherwise everything flashed by too fast, and might have caused epilepsy attacks. :)


  • JonnyMacJonnyMac Posts: 7,323
    Nice, Roy!
  • I played a little more, and added the encoder using Jon's Spin2 driver for that.
    The encoder picks between the various modes you can see in the video above, and if you push the button then it toggles the encoder to adjusting the brightness instead of changing mode.

    I've attached the source file below, should compile and run with recent versions FlexProp, and uses the same pinouts for the encoder and LEDs as Jon's demos. I used the same or similar naming conventions for most things, and you can adjust everything in the #define's near the top of the code.
    However, it's set for 241 LEDs (and 100 candles), so you will likely need to change those down to lower numbers to match your LED setup. I recommend NUM_CANDLES be around 40% of N_PIXELS (e.g. use ~20 candles for 50 LEDs).

    Once Jon teaches us about using his code for the display, I'll add that in too.
  • Roy Eltham wrote: »
    ...
    Really cool, Roy!


  • JonnyMacJonnyMac Posts: 7,323
    Code for Week 3 is uploaded!
  • Dave,

    You commented -
    "However having said that, this noisy encoder is completely tamed by adding a 0.1uF cap from the a/b pins to 0v, and using a pin pullup of 15k, no noise suppression software needed.
    As long as you don't attach a motor to the shaft you can't turn the shaft by hand quick enough to beat it."

    I’m a software type try to learn electronics. Could you post a drawing of the circuit? So it's a bit clearer in my mind.

    Thanks,
    James

  • Another great presentation, really enjoy your style of discussing the P2 and coding. I’m starting to employ your coding style more as it is easier to review old code that hasn’t been visited in a while.
  • tritoniumtritonium Posts: 404
    edited 2021-01-07 02:10
    Hi jahenke

    This is how I did it.
    The capacitor value can be changed to suit your situation. For a noisy hand encoder 0.1uF worked well for me.
    I suspect a much smaller value may work.
    The resistors shown are either provided by you externally or by the prop using its programmable internal pullup in smartpins. As regards values the faster the coder spins the smaller the resistor needs to be. So using a better quality encoder driven by a motor, 2k pullup and 0.001uF might be better. Foe very high quality opto / capacitive / hall then no capacitor or debounce may be found to be satisfactory.

    I started by using software debounce-
    (if you're a software guy then this may look crude! :) )
    '
    	do
     		newread=input(acpin,bcpin)
    	loop until newread<>oldread
    	lcnt=mxcnt	                    'mxcnt is a constant found by trial and error
             do
    		if newread<>input(acpin,bcpin) then
    			lcnt=mxcnt          'top up downcounter
    		else
    			lcnt-=1
    		end if
    	loop until lcnt=0
    

    you'l need to click on the image to see it full size

    Dave
    471 x 338 - 44K
  • JonnyMacJonnyMac Posts: 7,323
    DiverBob wrote: »
    Another great presentation, really enjoy your style of discussing the P2 and coding. I’m starting to employ your coding style more as it is easier to review old code that hasn’t been visited in a while.
    Thank you, Bob!
  • Dave,

    Thanks, that really helped, and it's helping to set the words to how the wiring really goes.

    I don't mind crude code - and trying to show in a non-code editor is always a problem.

    Thanks, again.
    James
  • JonnyMacJonnyMac Posts: 7,323
    This was posted in another thread, but as this week's topic was I2C with the P2, I thought I'd share it here. This company provides low-cost I2C widgets.

    https://electricdollarstore.com/
  • Dave MatthewsDave Matthews Posts: 92
    edited 2021-01-11 11:13
    Many thanks to JonnyMac and Parallax, inc. for the great presentations, the P2 Edge, the Edge Module Breadboard, and the fantastic P2!

    Dave, KI4PSR
  • JonnyMacJonnyMac Posts: 7,323
    Many thanks to JonnyMac and Parallax, inc. for the great presentations, the P@ Edge, the Edge Module Breadboard, and the fantastic P2!
    Dave, KI4PSR
    Thank you, Dave!
  • JonnyMac wrote: »
    This was posted in another thread, but as this week's topic was I2C with the P2, I thought I'd share it here. This company provides low-cost I2C widgets.

    https://electricdollarstore.com/

    This is an interesting store, thanks for the heads up
  • JonnyMacJonnyMac Posts: 7,323
    Code for Week 4 is up. Be sure to update your Library as I've added files, and updated at least one of them.
Sign In or Register to comment.