Shop OBEX P1 Docs P2 Docs Learn Events
BS2 serin/serout — Parallax Forums

BS2 serin/serout

gc3076gc3076 Posts: 44
edited 2006-01-25 18:59 in BASIC Stamp
can anyone suggest any information on using serin/serout or sample code. I am trying to input a 12 bit binary serial data from an external device and display a decimal output on a parallax serial LCD display.

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-18 19:15
    What does the stream from the device look like? Is it binary (would be two bytes to hold twelve bits)? If so, in what order do the bytes arrive? Or, is the information sent as a text string? If the latter, the BASIC Stamp has conversion functions that will work at 9600 baud and lower.

    And, as always, reading the sections on SERIN and SEROUT in the manual (their detailed) will go a long way toward developing your understanding of these commands. The manual (and help file) have several code snippets to demonstrate PBASIC features.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • edited 2006-01-18 19:27
    Use the DEC operator. Assuming you are using a BASIC Stamp 2 and your serial LCD is connected to P14, the code might look something like this:

    · value VAR Word
    ····.
    ····.
    ····.
    · SEROUT 14, 84, [noparse][[/noparse]22, 12]
    · PAUSE 5

    · DO

    ··· GOSUB Get_12_Bit_ADC_Value
    ··· SEROUT 14, 84, [noparse][[/noparse]128, DEC5 value]
    ··· PAUSE 250

    · LOOP
    ··· .
    ····.
    ··· .

    There are more tips and tricks of a similar sort in this post: Getting Started with the Parallax Serial LCD.

    Post Edited (Andy Lindsay (Parallax)) : 1/18/2006 7:34:08 PM GMT
  • gc3076gc3076 Posts: 44
    edited 2006-01-18 19:52
    the format is MSB sent first then LSB

    MSB (B7 [noparse][[/noparse]1] indicates·MSB - B6 EVEN PARITY - B5-B0 output of A/D convereter)

    LSB (B7 [noparse][[/noparse]0]·indicates LSB - B6 EVEN PARITY - B5-B0 output of A/D convereter)

    i.e. 1001 0110·· 0101 0101 equals -21.2 in decimal

    Post Edited (gc3076) : 1/18/2006 8:21:39 PM GMT
  • edited 2006-01-18 22:07
    It looks like it should be doable in PBASIC. I wrote a subroutine to receive the bytes and parse the bits, but I'm not seeing how %010110_010101 correpsonds to -21.2? Also, links to the documentation for the ADC you are using would be helpful.

    Post Edited (Andy Lindsay (Parallax)) : 1/18/2006 11:24:39 PM GMT
  • gc3076gc3076 Posts: 44
    edited 2006-01-19 14:01
    here is a link to the rs232/12 bit communication protocol

    http://www.spectronsensors.com/appsheets/SAN-213-0304.pdf
  • gc3076gc3076 Posts: 44
    edited 2006-01-19 17:23
    ?
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-19 17:37
    This is off the top of my head after looking at the data sheet (and assumes a BS2; see our template for conditional compilation directives to set the baudmode value for any BS2-family module).

    Here's what the Get_Sensor routine does: It waits for two bytes and then checks the high bit of the MSB to make sure that the bytes are properly aligned.· If that's the case, then the word variable is reassembled from the two bytes that contain six data bits each.· Please study the data shee carefully and compare it to this code.

    Sensor···· ·PIN··· 15

    SnsrBaud··· CON··· 84

    result···· ·VAR··· Word

    ...

    Get_Sensor:
    · SERIN Sensor, SnsrBaud, [noparse][[/noparse]result.HIGHBYTE, result.LOWBYTE]
    · IF (result.BIT15 = 0) THEN Get_Sensor
    · result.BIT6 = result.BIT8
    · result.BIT7 = result.BIT9
    · result.HIGHBYTE = (result.HIGHBYTE & %00111111) >> 2
    · RETURN

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • gc3076gc3076 Posts: 44
    edited 2006-01-19 18:12
    that's it, thanks so much for the help !!
  • edited 2006-01-19 21:53
    Hi

    Here is a test program (TestSpectroTilt3.bs2) to try with your·SPECTROTILT module and Parallax Serial LCD.· Make sure to update the Pin directives for your setup.· Also, if you're not using the BASIC Stamp 2, make sure to update the $STAMP, and BaudMode directives accordingly.

    The examples in the part datasheet appear to be incorrect because they truncate the D10 and D11 bits.· Either that, or the explanation is incorrect.··Assuming the explanation is correct, the binary value for -56.27 degrees·should be·1100_0110_0101_0101 and the·one for -37.7 degrees·should be·1000_1110_0011_0011.·

    Regards, Andy

    [color=#008000]' -----[noparse][[/noparse] Title ]--------------------------------------------------------------
    ' TestSpectroTilt3.bs2
    ' Test the SPECTROTILT module with the Parallax Serial LCD.
    ' Display values range from -70.14 to 70.11 degrees.
     
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
     
    ' -----[noparse][[/noparse] I/O Pins ]-----------------------------------------------------------
     
    [color=#000000]LcdPin         PIN     14[/color]
    [color=#000000]AdcPin         PIN     15[/color]
     
    ' -----[noparse][[/noparse] Constants ]----------------------------------------------------------
     
    [color=#000000]LcdBaudMode    CON     84[/color]
    [color=#000000]AdcBaudMode    CON     84[/color]
     
    [color=#000000]LcdStart       CON     22[/color]
    [color=#000000]LcdCls         CON     12[/color]
    [color=#000000]Line0          CON     128[/color]
    [color=#000000]line1          CON     148[/color]
     
    ' -----[noparse][[/noparse] Variables ]----------------------------------------------------------
     
    [color=#000000]angle          VAR     Word[/color]
    [color=#000000]index          VAR     Nib[/color]
    [color=#000000]parity         VAR     Bit[/color]
     
    ' -----[noparse][[/noparse] Initialization ]-----------------------------------------------------
     
    [color=#0000ff]PAUSE[/color][color=#000000] 500[/color]
    [color=#0000ff]SEROUT[/color][color=#000000] LcdPin, LcdBaudMode, [noparse][[/noparse]LcdStart, LcdCls][/color]
    [color=#0000ff]PAUSE[/color][color=#000000] 5[/color]
     
    ' -----[noparse][[/noparse] Main Routine ]-------------------------------------------------------
     
    [color=#0000ff]DO[/color]
     
      [color=#0000ff]GOSUB[/color][color=#000000] Get_Spec_Tilt[/color]
    [color=#000000]  angle = angle * 10 ** 22446[/color]
    [color=#000000]  angle = angle - 7014[/color]
     
      [color=#0000ff]SEROUT[/color][color=#000000] LcdPin, LcdBaudMode, [noparse][[/noparse]Line0, [/color][color=#ff0000]"angle = "[/color][color=#000000]][/color]
      [color=#0000ff]IF[/color][color=#000000] angle.BIT15 = 1 [/color][color=#0000ff]THEN[/color]
        [color=#0000ff]SEROUT[/color][color=#000000] LcdPin, LcdBaudMode, [noparse][[/noparse][/color][color=#ff0000]"-"[/color][color=#000000]][/color]
    [color=#0000ff]  ELSE[/color]
        [color=#0000ff]SEROUT[/color][color=#000000] LcdPin, LcdBaudMode, [noparse][[/noparse][/color][color=#ff0000]" "[/color][color=#000000]][/color]
    [color=#0000ff]  ENDIF[/color]
      [color=#0000ff]SEROUT[/color][color=#000000] LcdPin, LcdBaudMode, [noparse][[/noparse][/color][color=#000080]DEC2[/color][color=#000000] ABS(angle) / 100,[/color]
                                   [color=#ff0000]"."[/color][color=#000000],[/color]
                                   [color=#000080]DEC2[/color][color=#000000] ABS(angle) // 100][/color]
     
      [color=#0000ff]PAUSE[/color][color=#000000] 500[/color]
     
    [color=#0000ff]LOOP[/color]
     
    ' -----[noparse][[/noparse] Subroutine - Get_Spec_Tilt ]----------------------------------------
     
    [color=#000000]Get_Spec_Tilt:[/color]
     
    [color=#0000ff]  DO[/color]
        [color=#0000ff]SERIN[/color][color=#000000] AdcPin, AdcBaudMode, [noparse][[/noparse]angle.HIGHBYTE, angle.LOWBYTE][/color]
        [color=#0000ff]IF[/color][color=#000000] angle.BIT7 = 1 [/color][color=#0000ff]THEN[/color]
    [color=#000000]      angle = (angle >> 8) | (angle << 8)[/color]
    [color=#0000ff]    ENDIF[/color]
        [color=#0000ff]GOSUB[/color][color=#000000] Even_Parity[/color]
      [color=#0000ff]LOOP[/color] [color=#0000ff]UNTIL[/color][color=#000000] parity = 0[/color]
    [color=#000000]  angle.LOWBYTE = angle.LOWBYTE << 2[/color]
    [color=#000000]  angle = angle >> 2 & %0000111111111111[/color]
     
    [color=#0000ff]  RETURN[/color]
     
    ' -----[noparse][[/noparse] Subroutine - Even_Parity ]------------------------------------------
     
    [color=#000000]Even_Parity:[/color]
     
    [color=#000000]  parity = 0[/color]
      [color=#0000ff]FOR[/color][color=#000000] index = 0 [/color][color=#0000ff]TO[/color][color=#000000] 15[/color]
    [color=#000000]    parity = parity + angle.LOWBIT(index)[/color]
    [color=#0000ff]  NEXT[/color]
     
    [color=#0000ff]  RETURN[/color][/color] 
    
    


    Post Edited (Andy Lindsay (Parallax)) : 1/22/2006 12:38:09 AM GMT
  • gc3076gc3076 Posts: 44
    edited 2006-01-20 19:35
    still no go
  • gc3076gc3076 Posts: 44
    edited 2006-01-23 12:44
    TestSpectroTilt3.bs2 works like a charm. Thanks for the incredible support............
  • gc3076gc3076 Posts: 44
    edited 2006-01-24 20:07
    does anyone know if you can use the CCD Character Creator with a Parallax 2x16 serial LCD display ?

    If not I tried to use the following as a test using a ASCII chart from the below link.


    http://www.myke.com/lcd.htm

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    degree VAR Byte
    degree = %01111110

    SEROUT 14, 84, [noparse][[/noparse]degree]

    Post Edited (gc3076) : 1/24/2006 8:20:41 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-01-24 22:19
    Yes, you can use the custom character creator.· The main thing is that it outputs the correct values for the character and you can just paste those into your existing DATA statement where needed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • gc3076gc3076 Posts: 44
    edited 2006-01-25 15:04
    can anyone suggest a link because most of the documentation I am finding seems to be targeting sending special characters to a non-serial LCD. The documentation on the display (2x16 serial LCD pn:27977) says "coming soon custom LCD animation"
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-25 15:12
    I've attached a demo for the Parallax Serial LCD that shows how to download custom characters.· As you can see, the only difference betwee the DATA statments in this program and the output for the LCD Character Creator is the addition of the character code constant.· There was a discussion on this subject in this thread:

    http://forums.parallax.com/showthread.php?p=567287



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • gc3076gc3076 Posts: 44
    edited 2006-01-25 18:37
    any other code samples, less involved ?
  • edited 2006-01-25 18:59
    The last post in this Stamps in Class thread Getting Started with the Parallax Serial LCD·now has a PDF and a short example program.·
Sign In or Register to comment.