Shop OBEX P1 Docs P2 Docs Learn Events
Displaying Wind Data With The G12032 Serial Graphics LCD — Parallax Forums

Displaying Wind Data With The G12032 Serial Graphics LCD

Tronic manTronic man Posts: 7
edited 2004-12-25 23:11 in BASIC Stamp
I'm Trying To Convert The Program @ Scott Edwards Electronics Web Site (Displaying Wind Data With G12032 Serial Graphics LCD) Link http://seetron.com/sgx_an1.htm,· To Accept 16 Each Photo Transistors With IR Emitters Instead Of A 10K Pot For The Wind Direction.

I'm Using Two 74HC165 Shift Registers With The Photo Transistors, Based On Stampworks Manual Experiment #24b. I Have Tried Reading
The HEX Code And Using The LOOKDOWN / LOOKUP Method, But That Seems Not To Work.

Any Programming Help Would Be Much Appreciated.yeah.gif

Thanks, Tronic Man

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-25 17:35
    Start a piece at a time. Get the shift register inputs working first, then move on to the display.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Tronic manTronic man Posts: 7
    edited 2004-12-25 18:43
    Shift Register Inputs Is Working Fine.

    Here's The Debug Value Of Each Photo Transistor Blocked One At A Time.

    LOOKDOWN decimal,[noparse][[/noparse]76,108,124,132,139,142,138,136,12,204,172,156,141,143,154,148],theDir

    Thanks
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-25 18:53
    Okay ... are you getting 0 (North) to 15 in 'theDir' as you expect? I looked at Scott's code and that's what it's expecting -- you should be able to replace the code in 'GetWindDir' with yours; just note that the subroutine returns the value in 'newDir'.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Tronic manTronic man Posts: 7
    edited 2004-12-25 19:26
    Here's The Code I Modified.

    I Does Not Erase The Line It Drew Before Redrawing New Direction.

    The Direction Stops Responding But The Wind Speed Still Works.

    Thanks Jon For Your Input

    '{$STAMP BS2}
    ' Program: WND_GX1.BS2 (Display wind direction and speed)
    ' This program demonstrates the G12032 serial graphics LCD
    ' with the Parallax Basic Stamp II (R). It assumes that the G12032
    ' is set for 9600 bps (switch on pcb to "9600") and that it is
    ' connected to the Stamp as follows:
    '··········· G12032·················· Stamp
    '···········
    ······
    '··········· SER (serial in)········ I/O pin P0
    '··········· GND (ground)··········· Vss/GROUND
    '··········· +5····················· Vdd/+5V
    ' For the demo, we've also connected a couple of pots to pins P6 and
    ' P7 of the BS2. These simulate inputs from the wind direction and
    ' speed sensors. For this simulation, we use 10k pots and 0.1uF
    ' caps, with the caps wired to +5V as shown in the rctime section
    ' of the Stamp II manual.

    ' Before running this program, a couple of new EEPROM images must
    ' be downloaded to the display; EEPROM page 7 should be loaded with
    ' graphic WIND1.BMP, and EEPROM page 1 with a versions of CHARS1.BMP
    ' that has been edited to include a degree symbol at the end of
    ' the font (ASCII 128). See the accompanying text.

    ' This program shows how to read 16 inputs with just three Stamp pins using
    ' two 74HC165 shift registers. The serial output (pin 9) from one 74HC165
    ' is fed into the serial input (pin 10) of the second.
    '
    ' I/O Definitions
    '
    Clock CON 1 ' shift clock (74x165.2)
    DataIn CON 3 ' shift data (74x165.7)
    Load CON 4 ' input load (74x165.1)

    ' ===========Define names for LCD instructions==========
    CLR·· CON·· 12· ' Clear entire LCD screen.
    CTLC· CON· 3· ' Control-C: control character to end right-align.
    POS·· CON·· 16· ' Position cursor.
    RTALGN· CON· 18· ' Right-align.
    ESC····· CON·· 27· ' Escape code for graphics instructions.
    n9600··· CON· $4054· ' Baudmode for 9600 bps, inverted.
    CUT0···· CON· 64· ' 1-byte shortcut for 0 (64+0 = 64)
    SCRN7· CON· 71· ' 1-byte shortcut for 7 (EEPROM screen 7)
    CNTRX· CON· 169· ' X coord of wind vane center (as shortcut #).
    CNTRY· CON· 80· ' Y coord "· "··· "··· "····· "·· "······· "
    XMAX· CON· 20· ' Max value for graph X coord.
    BIG· CON· 67· ' Shortcut for 3 (big font).
    SMALL· CON· 64· ' Shortcut for 0 (small font).
    BLACK· CON· 65· ' Shortcut for 1 (black ink)
    WHITE· CON· 64· ' Shortcut for 0 (white ink)
    DEGR· CON· 128· ' ASCII code for degree symbol added to font.

    ' ===========Variables==================================
    newDir· VAR· Nib· ' Current wind direction (0-15; 0 is North).
    theDir· VAR· Nib· ' Old direction--use by lookup.
    tenths· VAR· Nib· ' Tenths of a degree.
    pointX· VAR· Byte· ' X coord of pointer end.
    pointY· VAR· Byte· ' Y coord of pointer end.
    rawDir· VAR· Word· ' Unscaled input from direction sensor.
    rawSpd· VAR· Word· ' "······· "···· "··· speed···· "
    bearing· VAR· Word· ' Wind direction in degrees.
    wndMPH· VAR· Byte· ' Wind speed in miles/hour.
    ripY· VAR· Byte· ' Current Y position of ripple graph.
    x1· VAR· Byte· ' 1st X coord for line plot
    y1· VAR· Byte· ' 1st Y coord for line plot
    x2· VAR· Byte· ' 2nd X coord for line plot
    y2· VAR· Byte· ' 2nd Y coord for line plot
    dirSt· VAR· Byte(3)· ' Three-byte string for wind direction.
    switch1 VAR Byte ' inputs switches 1
    switch2 VAR Byte ' inputs switches 2
    decimal VAR Byte

    ' ===========EEPROM Strings=================================
    ' These are three-letter abbreviations for the 16 compass
    ' points covered by our wind-direction indicator. By making
    ' all of the abbreviations three bytes long, we can easily
    ' select the appropriate string's starting point (3 times
    ' tHE Wind direction).
    N· DATA· " N "· ' North
    NNE· DATA· "NNE"· ' North-Northeast
    NE· DATA· " NE"· ' Northeast
    ENE· DATA· "ENE"· ' East-Northeast
    E· DATA· " E "· ' East
    ESE· DATA· "ESE"· ' East-Southeast
    SE· DATA· " SE"· ' Southeast
    SSE· DATA· "SSE"· ' South-Southeast
    S· DATA· " S "· ' South
    SSW· DATA· "SSW"· ' South-Southwest
    SW· DATA· " SW"· ' Southwest
    WSW· DATA· "WSW"· ' West-Southwest
    W· DATA· " W "· ' West
    WNW· DATA· "WNW"· ' West-Northwest
    NW· DATA· " NW"· ' Northwest
    NNW· DATA· "NNW"· ' North-Northwest

    Initialize:
    HIGH Load ' make output; initialize to 1

    ' ===========================================================
    '························ INITIALIZATION
    ' ===========================================================
    ' The line below is not really necessary except during
    ' interactive programming. It's purpose is to complete any LCD
    ' instructions that you may have interrupted by typing alt-R or
    ' pressing the BS2 reset button. When the program starts again,
    ' the LCD may be waiting for data to complete those instructions.
    ' The line below supplies dummy data, then immediately clears the
    ' SCREen.
    SEROUT 0,n9600,[noparse][[/noparse]CUT0,CUT0,CUT0,CUT0,CLR]

    PAUSE 1000· ' Wait a sec for LCD startup.

    ' Clear the LCD and call up EEPROM image 7, which is preloaded
    ' WITH the compass dial image.
    SEROUT 0,n9600,[noparse][[/noparse]CLR,ESC,"E",SCRN7,ESC,"F",SMALL,POS,75,"mph"]

    ' To prevent the program from needlessly erasing and redrawing the
    ' wind-direction pointer, the showWindDir routine draws only when the
    ' new direction is not the same as the old. To make sure that the
    ' very first direction reading draws, we take an initial reading,
    ' put the inverse in the old direction, and show. This 'primes
    ' the pump.'

    GOSUB getWindDir: theDir = ~newDir:GOSUB showWindDir

    ' ===========================================================
    '························ MAIN PROGRAM
    ' ===========================================================
    ' The main program is an endless loop that continuously acquires
    ' and displays the wind data. Subroutines handle all the
    ' engine-room details, making it easy to modify the program.
    agAIN:
    · GOSUB getWindDir· ' Read wind-direction sensor.
    · GOSUB showWindDir· ' Display the wind direction.
    · GOSUB getWindSpd· ' Read wind-speed sensor
    · GOSUB showWindSpd· ' Display the wind speed.
    · PAUSE 100··· ' Slow the update rate to prevent jitters.
    GOTO again


    ' ===========================================================
    '················· Display Wind Speed
    ' ===========================================================
    ' ShowWindSpd plots a vertical strip chart on the left edge
    ' of the screen to show short-term trends in wind speed.
    ' The graph is continuously updated, like an oscilloscope,
    ' so a black line is used to erase the oldest data on the screen.
    ' The routine also prints the wind speed as a three-digit number
    ' using the big font size and right-alignment feature.
    showWindSpd:
    ' Plot a white point whose distance from the left edge of the
    ' screen is proportional to the wind speed. Each pixel is 5mph.
    ' White pixels are plotted against a black background.
    x1 = cut0: y1 = RipY + cut0
    X2 = WndMPH/5 MAX xMax + cut0
    SEROUT 0,n9600,[noparse][[/noparse]ESC,"I",WHITE,ESC,"P",x2,y1]

    ' Now increment to the next vertical (y) position and print a black
    ' line to erase old data in preparation for the next plot. ANDing
    ' the y value with 31 (..& 31) makes it wrap around the screen
    ' vertically, since the screen y coordinates are 0-31.
    ripY = ripY + 1 & 31
    y1 = ripY + cut0
    X2 = XMax + cut0
    SEROUT 0,n9600,[noparse][[/noparse]ESC,"I",BLACK,ESC,"L",x1,y1,x2,y1]

    ' Finally, print the wind speed in the big font on the top line
    ' (position 5) in a right-aligned field 3 characters wide.
    ' TERMinate the right-align mode with a control-C.
    SEROUT 0,n9600,[noparse][[/noparse]ESC,"F",BIG,POS,69,RTALGN,"3",DEC wndMPH,CTLC]
    RETURN

    ' ===========================================================
    '················· Display Wind Direction
    ' ===========================================================
    ' ShowWindDir draws the wind-direction needle by erasing the
    ' previous needle and drawing in a new one. The present direction
    ' must be in newDir; the old direction will be in theDir--the
    ' variable used by the lookup tables in getPointerCoords.

    showWindDir
    ' If the direction is unchanged from the last plot, then return
    ' without updating the screen. This prevents the pointer from
    ' flickering as a result of being erased and redrawn in the
    ' same location.
    IF newDir <> theDir THEN updateDir
    RETURN··· ' If no change, return now.
    UPDATeDir:· ' Otherwise update the screen.
    GOSUB convertWindDir
    ' Erase the old direction pointer with a white line from center to
    ' THE old endpoint.
    SEROUT 0,n9600,[noparse][[/noparse]ESC,"I",WHITE,ESC,"L",CNTRX,CNTRY,pointX,pointY]
    ' Put the new endpoint into the one used by the 'convert' routine
    ' and plot the new pointer in black.
    THEDIr=newDir
    GOSUB convertWindDir
    SEROUT 0,n9600,[noparse][[/noparse]ESC,"I",BLACK,ESC,"L",CNTRX,CNTRY,pointX,pointY]

    ' Text display of wind direction: The convertWindDir routine loaded
    ' the three-letter abbreviation for the wind direction into the
    ' bytes of dirSt(). The following line sets the big font and
    ' PRINting position, then outputs the three bytes.
    SEROUT 0,n9600,[noparse][[/noparse]ESC,"F",BIG,POS,76,dirSt(0),dirSt(1),dirSt(2)]

    ' Numeric display of wind direction: ConvertWindDir loaded the wind
    ' direction in degrees into the variable bearing. The following line
    ' sets the small font, moves to screen position 74 (64+74 = 138),
    ' requests right-alignment within a 3-character space, then
    ' prints the bearing as a decimal number. To terminate the right-align
    ' mode, it sends an unused control character (ctlC). After the bearing,
    ' it sends ASCII 128, which we've defined as the degree symbol by
    ' EDITing and downloading EEPROM page 1.
    SEROUT 0,n9600,[noparse][[/noparse]ESC,"F",SMALL,POS,138,RTALGN,"3",DEC bearing,CTLC,DEGR]
    RETURN

    ' ===========================================================
    ' ConvertWindDir looks up the endpoint coordinates for the
    ' wind-direction pointer based on the contents of variable
    ' theDir. The coordinates are returned in pointX and pointY.
    ' Note that all coordinates are expressed as single-byte
    ' shortcuts (byte values of 64+n) for fast transmission to the
    ' G12032 display. Another lookup table gets the bearing in
    ' degrees. And a series of Read instructions get the 3-letter
    ' abbreviations for wind direction from EEPROM.
    coNVERTWindDir:
    decimal=switch1 + 23/2-switch2
    · LOOKDOWN decimal,[noparse][[/noparse]76,108,124,132,139,142,138,136,12,204,172,156,141,143,154,148],theDir
    · LOOKUP theDir,[noparse][[/noparse]169,171,173,174,174,174,173,171,169,167,165,164,164,164,165,167],pointX
    · LOOKUP theDir,[noparse][[/noparse]75,75,76,78,80,82,84,85,85,85,84,82,80,78,76,75],pointY
    · LOOKUP theDir,[noparse][[/noparse]0,22,45,67,90,112,135,157,180,202,225,247,270,292,315,337],bearing
    · READ (theDir*3), dirSt(0)· ' 1st byte of string into dirSt(0)
    · READ (theDir*3 +1), dirSt(1)· ' 2nd "··· "· "····· "··· "··· (1)
    · READ (theDir*3 +2), dirSt(2)· ' 3rd "··· "· "····· "··· "··· (2)
    RETURN

    ' ===========================================================
    '··············· Get Wind Direction and Speed
    ' ===========================================================
    ' A couple of pots are wired to provide simulated wind speed and
    ' direction data. In an actual application, these routines
    ' would be replaced with the appropriate code to acquire and scale
    ' the wind data. For this simulation, we use 10k pots and 0.1uF
    ' caps, with the caps wired to +5V as shown in the rctime section
    ' of the Stamp II manual.
    getWindDir:··· ' Output 0-15 in newDir, where 0 is due north.
    · PULSOUT Load, 5 ' latch inputs
    · SHIFTIN DataIn, Clock, MSBPRE, [noparse][[/noparse]switch2] ' get buttons
    · SHIFTIN DataIn, Clock, MSBPRE, [noparse][[/noparse]switch1] ' get switches
    RETURN

    getWindSpd:··· ' Output 0-999 in wndMPH (3-digit miles/hour).
    · HIGH 7: PAUSE 1· ' Discharge cap on pin 7.
    · RCTIME 7,1,rawSpd· ' Measure charge time (approx. 0-600)
    · WNDMPH = rawSpd/5· ' Scale to simulate wind speed (0-120)
    RETURN
  • RickBRickB Posts: 395
    edited 2004-12-25 21:15
    In the GetWindDir routine, the raw data is in variables switch1 and switch2, but the next routine, ShowWindDir expects data in NewDir as per the comment after the label GetWindDir. switch1 and switch2 don't get used until ConvertWindDir.
    I can't figure out what you are doing with switch1 & 2 in convertWindDir.

    Rick
  • Tronic manTronic man Posts: 7
    edited 2004-12-25 23:11
    Thanks Rick For The Input, I Figured Out What Was Missing.

    I Added To The getWindDir: Routine

    newDir = switch1 + 23/2-switch2

    And·I Removed decimal=switch1 + 23/2-switch2 From The convertWindDir: Routine

    And It Works Fine!!!hop.gif


    ·
Sign In or Register to comment.