Shop OBEX P1 Docs P2 Docs Learn Events
Converting DEBUG from the computer to an old Scott Edwards LCD — Parallax Forums

Converting DEBUG from the computer to an old Scott Edwards LCD

Last night I worked through an extremely exciting exercise in the Parallax book, "Basic Analog and Digital". Chapter 3 "Build Your Own Digital DC Volt Meter". Here is the last line of the code right before the RETURN. Display:
DEBUG HOME
DEBUG "8-bit binary value: ", BIN8 adcBits
DEBUG CR,CR, "Decimal value: ", DEC3 adcBits
DEBUG CR, CR, "DVM Reading: " 'New line
DEBUG DEC1 v, ".", DEC2 v2, " Volts" 'New line
RETURN
This code gives in the DEBUG the Binary value, Decimal value, and actual Volt value to the hundredth. Suppose I don't want to take my desk to computer to get a volt reading. Suppose I want to take a small LCD. I have the old Scott Edwards LCD that Parallax used to sell, and it is programmed different than the new Parallax LCD. Back in 2004 I used to know how to code the old LCD, and now trying to get back up to speed. I am wanting to show "only" the DVM reading on the LCD, meaning the actual volts. I know the first part of the code would have to be N9600 con $4054 I am unsure of how to code it to the LCD, without screwing up the main code I want to keep. Do I need two complete codes? In the last part of the code after Display: What do I need to delete, and what do I need to add? I am thinking delete the binary value, and decimal value, and leave the other two lines of code. But I need help with the code to send the information the the LCD. Pins 0,1,2 of the Basic Stamp are used up, so it would have to be one of the other pins. Help!

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2016-07-15 20:40
    Keith,

    All you need to do is add a SEROUT either before or after the DEBUG line you're copying and include the same formatters and parameters as the DEBUG statement, but using SEROUT.

    For example, if you wanted to send the DVM reading to the LCD, right before the RETURN add:

    SEROUT LCD, N9600, ["DVM Reading:" DEC1 v, ".", DEC2 v2, "Volts"]
  • Thanks Chris, I will try it.
  • 
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '----[ Declarations ]
    adcBits VAR Byte
    v VAR Byte
    r VAR Byte
    v2 VAR Byte
    v3 VAR Byte

    '
    [ Initialization ]
    CS PIN 0
    CLK PIN 1
    DataOutput PIN 2

    DEBUG CLS 'Start display.
    '
    [ Main Routine ]
    DO
    GOSUB ADC_Data
    GOSUB Calc_Volts
    GOSUB Display
    LOOP
    '
    [Subroutines ]
    ADC_Data:
    HIGH CS
    LOW CS
    LOW CLK
    PULSOUT CLK, 210
    SHIFTIN DataOutput,CLK,MSBPOST,[adcBits\8]
    RETURN

    Calc_Volts:
    v = 5 * adcBits / 255
    r = 5 * adcBits // 255
    v2 = 100 * R / 255
    v3 = 100 * r // 255
    v3 = 10 * v3 / 255
    IF (v3 >=5) THEN v2 = v2+1
    IF (v2 > 100) THEN
    v = v+ 1
    v2 =0
    ENDIF
    RETURN

    Display:
    DEBUG HOME
    DEBUG "8-bit binary value: ", BIN8 adcBits
    DEBUG CR,CR, "Decimal value: ", DEC3 adcBits
    DEBUG CR, CR, "DVM Reading: " 'New line
    DEBUG DEC1 v, ".", DEC2 v2, " Volts" 'New line
    RETURN
  • Chris adding SEROUT LCD, N9600, ["DVM Reading:" DEC1 v, ".", DEC2 v2, "Volts"] right before the last return won't work. You have to initialize a pin for the LCD. I initialized Pin 3. Then you have to define a constant N9600 CON $4054 When I put that in declarations things get crazy. You have to define N9600 somewhere or you get an error stating "Undefined Term". That old LCD runs from Baudmode-9600 bps inverted. Help.
  • Keith,

    Usually PINs are declared first, then CONstants, and finally VARiables.
    Also if you look at the BPI manual there is a PAUSE 1000 at the start of the program.
    In Initialization, just before DEBUG, it's a good idea to always put a PAUSE 1000 anyway to allow Windows enough time to setup the Serial ports.
    If you also look at the BPI manual, you will see there are 2 ways to use the Clear and Home commands since both take a long time.
    You can either add a PAUSE as the Demo does or immediately follow it with a Position command.

    Each time you want to display something you either need to clear the display, home the cursor, or set the position.
    Since you have 2 lines and 16 characters, did you want to display anything else?

    You might also want to double-check your wiring.
  • Thanks for replying Genetix. The above code is "not" my code, it is the code from the book: "Basic Anaglog and Digital" by Parallax. I am guessing Chris thought I had declared a pin for the LCD, and I had not. I am also guessing Chris thought I had defined the constant N9600 CON $4054, and I had not. So to get this working, I am trying to figure out changes and additions to the code. If I use Chris's suggestion, I would need to list LCD as pin 3 in the [initialization]. Then I would need to list the N9600 CON $4054 somewhere, and do it in a way that did not conflict with the 9600. If simply listed like this N9600 CON $4054 it makes my computer crazy when I try to run the code. Why, because N9600 is inverted. I wondered about where to put a PAUSE. Wondered if I need to Clear the LCD, or do a carriage return ? I am simply trying to get up to speed learning coding. What I have entered in the code to get the LCD working has not worked. I appreciate Chris's help, but what he told me to do is not working. I need help.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    Chris adding SEROUT LCD, N9600, ["DVM Reading:" DEC1 v, ".", DEC2 v2, "Volts"] right before the last return won't work. You have to initialize a pin for the LCD. I initialized Pin 3. Then you have to define a constant N9600 CON $4054 When I put that in declarations things get crazy. You have to define N9600 somewhere or you get an error stating "Undefined Term". That old LCD runs from Baudmode-9600 bps inverted. Help.

    Keith,

    Apologies, my assumption was that should all have been done long before the subroutine was called. I was merely describing how to direct the desired output to the LCD in addition to DEBUG.

  • Thanks for trying to help Chris. I think I can figure this out, except for dealing with the N9600 CON $4054. The code I have posted runs from 9600, not N9600 which is inverted. Everywhere I try to to put the N9600 into code, things get crazy, meaning the program was designed to run on 9600. I know the old LCD will work with the basic stamp instruction code, because I had this old LCD working back in 2004. My question is this: Where do I put the N9600 code where it does not interfere with the normal 9600? I plan on ordering the new Parallax LCD tomorrow, because code from the Smart Sensors Parallax book is written for the new Parallax LCD. Where and how do I deal with the N9600 in the code? Thanks.
  • Keith,

    One interesting feature of PBASIC is Aliasing where you can have a variable or constant use another variable or constant.
    Use BaudLCD for all your SEROUT commands and then you just need to change BaudLCD to T9600 later.

    I also added a PIN definition for LCD receive pin and some other baud rate settings that might be useful later.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    ' I/O Pin Definitions
    PinLCD          PIN     0   ' RX (Receive) Pin of Serial LCD
                                ' Test programs use P0 but we can use any pin
    
    ' Constant Definitions
    ' Inverted Baud Rate Settings for Seetron LCD
    N2400   CON     16780   ' 2400 Baud, 8-Bit, No-Parity, Inverted (Seetron LCD)
    N9600   CON     $4054   ' Baudmode for 9600 bps inverted serial. (Seetron LCD)
                            ' $4054 = 16468 = 9600 Baud, 8-Bit, No-Parity, Inverted
    ' True (noninverted) Baud Rate Settings for Parallax LCD
    T2400       CON     396   ' 2400 Baud, 8-Bit, No-Parity, True (noninverted)
    T9600       CON     84    ' 1200 Baud, 8-Bit, No-Parity, True (noninverted)
    T19K2       CON     32    ' 19.2K Baud, 8-Bit, No-Parity, True (noninverted)
    ' Other Baud Rate values that may come in handy later
    T1200       CON     813   ' 1200 Baud, 8-Bit, No-Parity, True (noninverted)
    T4800       CON     188   ' 4800 Baud, 8-Bit, No-Parity, True (noninverted)
    T38K4       CON     6     ' 38.4K Baud, 8-Bit, No-Parity, True (noninverted)
    
    BaudLCD         CON     N9600      ' Baud Rate for Serial LCD
                                       ' Set to 9600 Inverted for Seetron LCD
    
    ' Program Code
    SEROUT PinLCD, BaudLCD, [data_for_LCD_goes_here]
    
  • Here is what I am adding to the code-and where.
    Initialization.
    LCD PIN 3
    Constants.
    BaudLCD CON N9600 'Baud rate for serial LCD.
    I CON 254 ' Instruction prefix value.
    CLR CON 1 'LCD clear-screen instruction.
    Now for the instruction sent to the LCD, right before the last return in the code.
    pause 1000 'Time to initialize the LCD
    SEROUT LCD,BaudLCD,[I,CLR] 'Clear the LCD screen
    pause 1
    SEROUT LCD,BaudLCD,["DVM Reading:" DEC1 v, ".", DEC2 v2, "Volts"]
    Before I try it what is the verdict? Will it work? Do I need to add anything or change anything?
    I am assuming that once the code reaches RETURN, then we go back to the normal 9600 bps without any instruction. Is that correct?


  • Just use two constants, BaudLCD for N9600 and another, say BaudCOM, for 9600 in other parts of the program. It will not go back to the other value on RETURN. You need to have a constant for each baud you use, and put them in the appropriate SEROUT commands.
    SEROUT COM,BaudCOM,[data]
    SEROUT LCD,BaudLCD,[data]
    

    where data is what you are sending to either the COM pin or the LCD pin, as appropriate.
  • Sapphire, thanks for trying to help. I tried to run the program and an error stopped the program from running.
    The error said: "Undefined Symbol" and darkened in blue the N9600----Where I had listed constants.
    Constants.
    BaudLCD CON N9600 'Baud rate for serial LCD.
    I CON 254 ' Instruction prefix value.
    CLR CON 1 'LCD clear-screen instruction.
    The error--- being a undefined symbol-- was the the N9600 in the above constants. I have no idea how to correct this error. Plus I am unsure as to how to get back to 9600. Do I get back by listing BaudCOM CON 9600 in the constants---and---where does that go in the code? I think the entire problem centers around switch Baudmodes. It appears that I don't know how to define the Baude rate, or how to switch from one rate to another. Help.
  • You have to define N9600 before you can use it. Look at Genetix's code above.

    You would do well to study the Basic Manual, beginning on page 95, Constants and Expressions.
  • Thanks tomcrawford. I now see that I should have listed it as:
    N9600 CON $4054 'Baudmode-9600 bps inverted.
    Then my SEROUT command would change to:
    SEROUT LCD,N9600,["DVM Reading:" DEC1 v, ".", DEC2 v2, "Volts"]
    I will try to run it with those changes.
  • Tried to run it with changes, by changing the constant to N9600 CON $4054 The program ran until it got to the line
    SEROUT LCD,N9600,["DVM Reading:" DEC1 v, ".", DEC2 v2, "Volts"] Then an error popped up. The error said, "Expect ']' and darkened the DEC1
    This is the exact code Chris suggested I run. So why is the error popping up and expecting a ']' at the DEC1?
    Here is Chris's code SEROUT LCD, N9600, ["DVM Reading:" DEC1 v, ".", DEC2 v2, "Volts"]
    The original code that displayed on the computer screen was this:
    Display:
    DEBUG HOME
    DEBUG "8-bit binary value: ", BIN8 adcBits
    DEBUG CR,CR, "Decimal value: ", DEC3 adcBits
    DEBUG CR, CR, "DVM Reading: " 'New line
    DEBUG DEC1 v, ".", DEC2 v2, " Volts" 'New line
    RETURN
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2016-07-27 17:57
    Sorry, there should be a comma after the quoted text and before the DEC1 modifier.
    SEROUT LCD,N9600,["DVM Reading:", DEC1 v, ".", DEC2 v2, "Volts"]
    
  • Thanks Chris. I may never get this figured out. I made the correction you suggested Chris, and another error message popped up when I tried to run the program. The error was listed as "Undefined Symbol" and referred to the DEC2 v2 in Chris's code which is below.
    SEROUT LCD,N9600,["DVM Reading:", DEC1 v, ".", DEC2 v2, "Volts"]
    One other thing I need to mention. When I ran the original code from the Parallax instruction book it ran perfectly. Problems started happening when I tried to get the Debug to display on my Scott Edwards LCD. At times the computer mouse screen pointer becomes uncontrollable until I unplug the USB connection going to the Basic Stamp module.
    Remember--everything ran perfect until I tried adding the Scott Edwards LCD. Yes, I am powering the LCD with a separate power supply that is sufficient for the current for the black light on the LCD. The Basic Stamp module is powered by a different power supply. Both power supplies share Vss. I do know the LCD works, because I programmed it and saw it working. What is the mystery to me is that the programmed worked until I tried to add the LCD, and I know the LCD worked before I tried to run it with this program. Something simple is probably screwing everything up. Help.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2016-07-27 21:24
    If your mouse input goes nuts when you connect the BASIC Stamp it is because you have the power on when connecting and the computer is thinking it is a Microsoft Serial Mouse, rather than a VCP.

    As for the errors, you're not showing the code exactly as it appears. Usually if something says undefined symbol, then you didn't declare that variable. However, I tried to use the same variables the DEBUG statements used. Are you using the same? My line of code wasn't meant to be a drop-in working line of code. It was to show you how to convert the DEBUG line into a SEROUT. It still requires you to use the pin and baud rate constants you should have already defined as well as the variable names that were already in use.

    P.S. - Please copy/paste the code with the error exactly as it appears or take a photo and post that.
  • Chris, you won't believe this, but I got it working! I looked at the last error message and figured out that I had not put a space in between this: DEC2 v2 I had it listed in the code as DEC2v2. When I put a space in between and ran the code, it worked. I am thrilled. Quitters never win and winners never quit! I am so 'green' at coding it hurts, but chalk this one up to my persistence! Also--you were correct about the problem with the mouse going nuts.
    I ordered the new Parallax LCD yesterday. When it gets here I will be able to work out of the Parallax book Smart Sensors---because all the code if for the new Parallax LCD. I'm feeling happy that I got it working!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    Keith,

    That's great! I'm glad you got everything solved. And it will surely be easier once you have the Parallax LCD to get started. But once you're a veteran, you'll find the SEETRON LCD to be useful in some project. It's just "different". :nerd:
Sign In or Register to comment.