Shop OBEX P1 Docs P2 Docs Learn Events
Create a needle graphic that follows wind direction — Parallax Forums

Create a needle graphic that follows wind direction

I'm building a weather station and would like to add a simple direction needle for the wind. I have a 16 point pole mounted sensor but sometimes, rather than reading the cardinal points, a simple needle would be nice. I've looked at the graphics object and a demo but to me it seems very complicated. Might there be another way? Else I need a little help!

«1

Comments

  •  tv.move(4,1)
      case Winput
        %1000_0000:
          tv.str(string("Wind is from the N       "))
        %1000_0001:
          tv.str(string("Wind is from the N NE     "))
        %0000_0001:
          tv.str(string("Wind is from the NE      "))
        %0000_0011:
          tv.str(string("Wind is from the E NE     "))
        %0000_0010:
          tv.str(string("Wind is from the E       "))
        %0000_0110:
          tv.str(string("Wind is from the E SE     "))
        %0000_0100:
          tv.str(string("Wind is from the SE      "))
        %0000_1100:
          tv.str(string("Wind is from the S SE     "))
        %0000_1000:
          tv.str(string("Wind is from the S       "))
        %0001_1000:
          tv.str(string("Wind is from the S SW     "))
        %0001_0000:
          tv.str(string("Wind is from the SW      "))
        %0011_0000:
          tv.str(string("Wind is from the W SW     "))
        %0010_0000:
          tv.str(string("Wind is from the W       "))
        %0110_0000:
          tv.str(string("Wind is from the W NW     "))
        %0100_0000:
          tv.str(string("Wind is from the NW      "))
        %1100_0000:
          tv.str(string("Wind is from the N NW     "))
    
  • RaymanRayman Posts: 13,800
    You can make a graphics area that is smaller than full screen (to save memory).
    Then, just draw a line using graphics.

    You could even double buffer to avoid flicker.
  • What about ASCii graphics? Attached is a crudely thrown together example that's 9 rows tall and 11 columns wide. Might have to get more creative than me to make the needle clear.
    403 x 331 - 40K
  • Cluso99Cluso99 Posts: 18,066
    I did a clock where I drew analog hands on a small LCD. Perhaps that may help. If so, search the P1 forum for 1.44" LCD.
  • Thanks all!
    After failure upon failure with finally a LITTLE bit of success in a small area, I'm beginning to learn. Using the graphics object and ideas from Cluso99, it just might get to how I want it.
    Aaron
  • https://forums.parallax.com/discussion/123709/commented-graphics-demo-spin

    Hope that helps you. It's got window methods that can show how to set up and draw to a smaller screen region
  • Cluso99Cluso99 Posts: 18,066
    For others...
    My LCD Drivers have routines to draw boxes and fill them in colors, draw lines at any angle which also has how I add arrows (as in drawing the hour/minute/second hands in a clock), etc.
  • I'm getting closer. I can draw a line but am having trouble making it easy to get to and since I haven't programmed lately, I've forgotten a lot of what I once knew. I keep looking at the codes you've sent and some is coming back but slowly!
    Thanks
    Aaron
  • Cluso99Cluso99 Posts: 18,066
    What bits are you having problems with?
    Hint: Post the part of the code.
  • Cluso99 wrote: »
    What bits are you having problems with?
    Hint: Post the part of the code.

    I can draw a single line by ( gr.line (50,50) '' Draw a line to point " )
    but can't figure out how to use the info from weather vane (16 points) to automatically change the angle of line. I've tried some of your code (and modified parts of it) but may not have the correct formula.
    This is Chip's "graphics demo" with most things removed
    
    '  constants
    _CX     = 30    'x coordinate of start point               
    _CY     = 30    'y   "             "     "
    
    _CL     = 4                    ' flag (line)length
    
    {
    Cluso's LCD code    (  ILI9163_spi_040(1).zip   ) 
    used a table of constants like this       (excerp)
    
    '                 ' sin(x) * 1024    ' degrees
    Z00     =    0    ' 0.0000 * 1024    '  0 
    Z01     =  107    ' 0.1045 * 1024    '  6
    Z02     =  213    ' 0.2079 * 1024    ' 12
    Z03     =  316    ' 0.3090 * 1024    ' 18
      }  
    
    VAR
    
      {TV stuff}
    
    
    OBJ  
      tv    : "tv"   
      gr    : "graphics"  
    
    PUB start | i, j, k, kk, dx, dy, pp, pq, rr, numx, numchr
    
      'start tv
      longmove(@tv_status, @tvparams, paramcount)
      tv_screen := @screen
      tv_colors := @colors
      tv.start(@tv_status)
    
      'init colors
      repeat i from 0 to 63
        colors[i] := $00001010 * (i+4) & $F + $2B060C02
    
      'init tile screen
      repeat dx from 0 to tv_hc - 1
        repeat dy from 0 to tv_vc - 1
          screen[dy * tv_hc + dx] := display_base >> 6 + dy + dx * tv_vc + ((dy & $3F) << 10)
    
      'init bouncing lines
      i := 1001
      j := 123123
      k := 8776434
      repeat i from 0 to lines - 1
        x[i] := ?j // 64
        y[i] := k? // 48
        repeat until xs[i] := k? ~> 29
        repeat until ys[i] := ?j ~> 29  
    
      'start and setup graphics
      gr.start
      gr.setup(16, 12, 128, 96, bitmap_base)
    
      repeat
    
        'clear bitmap
        gr.clear    
    
        'draw flag
        gr.colorwidth(1,thickness5)  'thick pivot  point
        gr.plot(_CX,_CY)   'center of pivot and start point of line  be drawn
       
        gr.colorwidth(1,1) 'thin line       'color 0 or 4 makes it disappear
        gr.plot(_CX,_CY)     'line starts at pivot plotted here           
                
        gr.line (50,50)        '' Draw a line to point  ''   x,y    - endpoint    
    
        'copy bitmap to display
        gr.copy(display_base)    
    
    DAT
                    'X coordinate              y coordinate
        'for NE quadrant
                'from pivot add (line length*sine factor)Then >> 10,
                'from pivot subtract (line length*sine factor)then >> 10
    {
    Cluso's LCD code used a table like this (excerp), and used it to set clock hand endpoint
    
    DAT
            org             0
    ' Hands (minutes) x & y co-ords
    MH00    byte  _CX + ((_CM * Z00) >> 10), _CY - ((_CM * Z15) >> 10) '00
            byte  _CX + ((_CM * Z01) >> 10), _CY - ((_CM * Z14) >> 10) '01
            byte  _CX + ((_CM * Z02) >> 10), _CY - ((_CM * Z13) >> 10) '02
            byte  _CX + ((_CM * Z03) >> 10), _CY - ((_CM * Z12) >> 10) '...
            byte  _CX + ((_CM * Z04) >> 10), _CY - ((_CM * Z11) >> 10)
            byte  _CX + ((_CM * Z05) >> 10), _CY - ((_CM * Z10) >> 10)
    
     }
    

  • Cluso99Cluso99 Posts: 18,066
    IIRC I setup the points for the hands and then drew the lines between these coordinates. I set a table for these.

    So you would need a table of the 16 points.

    You could use the minutes or seconds. Basically you would need the points for 0, 15, 30, 45 for N E S W, then 7.5, 22.5, 37.5, 52.5 for NE SE SW NE. To divide again you get 3.75, 11.25, etc.

    Now, to get approximately there, use 0, 4, 8, 12, 15, 18, 22, 26, 30, etc.

    Once you get this working, to get the actual 3.75 minute intervals (22.5 degrees) use SINE mathematics. IIRC I used an excel spreadsheet to pre-calculate the coordinates.
  • In Cluso's LCD program there is in the DAT block a table like this.
    DAT
            org             0
    ' Hands (minutes) x & y co-ords
    MH00    byte  _CX + ((_CM * Z00) >> 10), _CY - ((_CM * Z15) >> 10) '00
            byte  _CX + ((_CM * Z01) >> 10), _CY - ((_CM * Z14) >> 10) '01
            byte  _CX + ((_CM * Z02) >> 10), _CY - ((_CM * Z13) >> 10) '02
            byte  _CX + ((_CM * Z03) >> 10), _CY - ((_CM * Z12) >> 10) '...
            byte  _CX + ((_CM * Z04) >> 10), _CY - ((_CM * Z11) >> 10)
            byte  _CX + ((_CM * Z05) >> 10), _CY - ((_CM * Z10) >> 10)
    
    

    In that program each line of info is incremented as the seconds or minutes tick by.
    Is there a way to specify a certain line in a table like this without making a separate address for each line?

    Thanks
    Aaron
  • Cluso99Cluso99 Posts: 18,066
    edited 2018-04-07 14:07
    Sure, there are many ways to do something. However, if you want it to be fast, you have to resort to using predefined tables.
    You will only need a single table of 16 combinations.
    I don't currently have access to my code.
  • kwinnkwinn Posts: 8,697
    AGCB wrote: »
    In that program each line of info is incremented as the seconds or minutes tick by.
    Is there a way to specify a certain line in a table like this without making a separate address for each line?

    Thanks
    Aaron

    Sure, you can calculate the the end point (sin & cos) of the lines based on the time using trig functions, however it is simpler to have a table of the x and y values for one quadrant of the circle and change the sign of the x/y values to produce the other quadrants.

    In the case of the weather vane’s 16 points that would require 4 x and y values. For a clock 15 x and y values.

    In either case it probably takes less time and space to use a table than to use code to calculate the values.
  • RaymanRayman Posts: 13,800
    For a small wind direction indicator, does seem like table is best.

    There is a SIN table in the Prop though. Says how to use it on P.385 of Prop Manual.
  • Something like this is probably what you want. Unfortunately I don't have the source code anymore and it's been nearly 4 years since I have programmed anything on the Propeller.

    It isn't really complex though...

    1) Pick a Degree point you want to represent (0 to 360) and the radius (how far you want that point from center) ... plug that into the Coordic routine to determine the X and Y for that location. This defines the tip of the arrow

    2) Pick two other points that are +5 Deg and -5 Deg from the degree point and a radius that is slightly smaller ... use the coordic routine as in step 1 to obtain the other two X and Y points. This forms the sides of your arrow.

    3) Connect your points with the graphics line function and that's all.

    4) To extend the needle in the opposite direction, follow step 1 but choose a Deg value that is 180 Deg away from your DEG point.


  • @AGCB

    i have some Time and no TV :smile:

    I wrote a little Demo for VGA 320x240 (signaled as 640x480).

    Have Fun

    propeller.ws-nbg.de

    Greetings from Nuremberg, Germany

    Werner

  • Here's an interesting link about Cordic on the Propeller:

    https://forums.parallax.com/discussion/88799/some-cordic-documentation


    Might be some handy code in this object too:

    http://obex.parallax.com/object/791



  • zx81vgazx81vga Posts: 56
    edited 2018-04-07 18:47
    @AGCB

    sorry, i forgot the Preview.

    Greetings from Nuremberg, Germany

    Werner
    640 x 480 - 138K
  • Clock LoopClock Loop Posts: 2,069
    edited 2018-04-07 18:40
    zx81vga wrote: »
    and no TV :smile:

    @zx81vga

    Its amazing how, not watching TV .. COMPLETELY CHANGES EVERYTHING!


    Nice LCARS theme on your site!


    Nice code preview!

    Excellent content and nice job on providing example code!
  • Nice job Werner! Hope you had fun. I'll look closely at your code for learning purposes.

    Aaron
  • zx81vga wrote: »
    @AGCB

    i have some Time and no TV :smile:

    I wrote a little Demo for VGA 320x240 (signaled as 640x480).

    Have Fun

    propeller.ws-nbg.de

    Greetings from Nuremberg, Germany

    Werner

    Werner
    Would you please explain a little about this
    wind_N            byte $20, $20, $20, $88, $20, $20, $20
                      byte $20, $20, $20, $86, $20, $20, $20
                      byte $20, $20, $20, $86, $20, $20, $20
                      byte $20, $20, $20, $85, $20, $20, $20
                      byte $20, $20, $20, $20, $20, $20, $20
                      byte $20, $20, $20, $20, $20, $20, $20
                      byte $20, $20, $20, $20, $20, $20, $20
    
    wind_NNE          byte $20, $20, $20, $20, $8F, $20, $20
                      byte $20, $20, $20, $20, $8E, $20, $20
                      byte $20, $20, $20, $8C, $8D, $20, $20
                      byte $20, $20, $20, $85, $20, $20, $20
                      byte $20, $20, $20, $20, $20, $20, $20
                      byte $20, $20, $20, $20, $20, $20, $20
                      byte $20, $20, $20, $20, $20, $20, $20
    
    Aaron
    P.S. I was in Stuttgart when I was in the army 45 years ago.

  • zx81vgazx81vga Posts: 56
    edited 2018-04-08 06:02
    @AGCB

    i create 16 Tables for the 16 Wind Directions.

    Every Table is an Array 7x7.

    In the Table are ASCII-Character's eg. $20 = Space, $85 = Rotating-Point...

    The Character's are in the File CP437_8.BMP
    The Char's for N and NNE are marked green.

    I fill the Screen-Needle-Area with the current Wind Direction. eg. wind_NNE

    See the attached Pictures.

    Greetings from Nuremberg, Germany

    Werner

    P.S.

    The Tables occupy 196 Long's


  • I've searched for that VGACOLOR_320x240_CURSOR Object but can't find it. Is that of your own doing? Is it available for copy? Please point me in the right direction.
    Aaron
  • @AGCB

    VGACOLOR_320x240_CURSOR.spin is included in windneedle.zip (attached)

    I changed Chip Gracey's VGA High-Res Text Driver v1.0

    Greetings from Nuremberg, Germany

    Werner
  • On a Quickstart board, is the PLL a separate IC or built in to the propeller chip? I've got a QS that no longer works with PLL16x. All other speeds work fine but TV seems to need 80Mhz.

    If a separate IC, how do I identify it?

    Thanks
    Aaron
  • PublisonPublison Posts: 12,366
    edited 2018-04-11 22:20
    PLL is built into the Propeller.
    Just make sure you have
    _xinfreq      = 5_000_000
    
  • OK. It had been working but now only works at the lower speeds. I may have over volted it
  • RaymanRayman Posts: 13,800
    The PLL is often the first thing to fail when too high a voltage is applied to a Prop pin.

    If it works with RCFast but not PLL, that's a pretty good sign the PLL is dead...
  • Cluso99Cluso99 Posts: 18,066
    The Prop is quite robust so it's more likely a code problem. If you post your code perhaps someone will find the problem.
    Otherwise, try a simple led flasher and time the flash to see if it works with RC, the xtal.
Sign In or Register to comment.