Shop OBEX P1 Docs P2 Docs Learn Events
Help with Basic stamp 2 code problem — Parallax Forums

Help with Basic stamp 2 code problem

im having problems trying to make a section of code work. its written in basic stamp and is being used in the basic stamp 2 kit from parallax. its supposed to calculate voltage difference between 2 reference points and the signal from a pair of variable gain amps and give a reading on an LCD display. all it gives is serial mode then a load of gibberish on the display so i think it could be a problem with the code. i have attached the code to this

any help/sugestions would be more than welcome
«1

Comments

  • There's a whole lot of information you haven't provided like what kind of display you're using and what Baud (and other) settings you're using. Just guessing from your SEROUT statements, you're trying to use 19,200 Baud which is marginal with the BS2. If the display can handle it, use 9600 Baud (84) or even 2400 Baud (396).
  • this is the lcd i have been advised to use http://www.robotshop.com/uk/devantech-2x16-i2c-serial-lcd-blue.html
    and i have used it in the device.
  • this is also the circuit the code is writen for. i have built the circuit to this schematic
  • Looking at the data sheet you pointed to, it says 9600 baud, 2 stop bits. So for sure you need to change baud to 84 (as Mike says). Then you might need to add some PACE value (see page 421 in the BASIC manual) to simulate the second stop bit.

    Also
    SEROUT LCD,32,[22,12,17] ' Clear and turn on backlight on LCD display
    doesn't seem to use the control characters described in the data sheet. 22 is "Enable start-up message", 17 is "clear column". Was this originally written for a parallax serial LCD?
  • thanks for that tom
  • how do i change the baud to 84 or do i have to buy a new lcd with that value
  • Mike GreenMike Green Posts: 23,101
    edited 2016-03-16 16:10
    Look at the Basic Stamp Syntax and Reference Manual chapter on SEROUT for a description of the 2nd parameter of the SEROUT statement. It's not literally the Baud value. It's a combination of several codes that specifies the Baud, number of stop bits, number of data bits, and parity. 84 specifies 9600 Baud, no parity, 8 data bits, and 2 stop bits (works with a device expecting 1 or 1.5 stop bits). The LCD you described should work with this. Some of the control codes (like 17) may take extra time to do. You may need a PAUSE after a SEROUT that sends these slow codes. The datasheet should describe these and indicate how much time they take.

  • i am a complete novice and i have had this code given to me so i wouldnt know where to start
  • Wherever it says
    SEROUT LCD, 32, [...output data...]
    

    change it to
    SEROUT LCD, 84, [...output data...]
    

    That will change the baud rate from 19,200 to 9600. But you still may need to simulate the second stop bit. You can try
    SEROUT LCD, 84, 1, [...output data...]
    
    The addition 1 inserts one millisecond between characters. It may take two. But you will still need to sort out the control characters.
  • You need a copy of the Syntax and Reference Manual and should look at "What's a Microcontroller?". Both are available on Parallax's webstore. They're available as books for sale, but the product page for each of the books has a link to a free downloadable PDF version. Fix the Baud constants in the SEROUTs and see what you get on the LCD.
  • thanks to you both i will try these ideas and get back to you
  • Mike Green wrote: »
    84 specifies 9600 Baud, no parity, 8 data bits, and 2 stop bits (works with a device expecting 1 or 1.5 stop bits). The LCD you described should work with this.

    Actually, it looks more like 3 1/2 stop bits. I'm surprised; I had not actually measured it before. Bottom line, you should't need the PACE parameter I mentioned.
  • i have changed the baud rate as suggested and is now shows what i want to see but it now travels on the screen from right to left any suggestions
  • i have added the link to the data sheet for the LCD that was used by the guy who wrote the original code
    https://www.parallax.com/sites/default/files/downloads/27979-Parallax-Serial-LCDs-Product-Guide-v3.1.pdf
  • tomcrawfordtomcrawford Posts: 1,129
    edited 2016-03-17 14:00
    The two LCDs use different control characters. You have to go through the existing (parallax) codes, figure out what they are intended to do, and substitute the equivalent devantech codes. In some cases of cursor controls, you will have to substitute a single character with two.

    btw, this is a really excellent example of why "magic numbers" suck is poor programming practice. Using CONs to define the control codes would have made the job easier.
  • i understand that about swapping the parallax numbers for the daventec but ive looked at both their data sheets and i just cant fine the corresponding control numbers
  • SEROUT LCD,32,[22,12,17] ' Clear and turn on backlight on LCD display
    Parallax     Function      Devantech
    22            cursor off     4
    12            clear             12
    17            backlite on    19
    128          line 0, char 0    2, 1
    

    148 and 151 are also set cursor commands. I didn't notice any others.
  • so where ever i see those values i should change them to the daventec ones just so im clear
  • so where ever i see those values i should change them to the daventec ones just so im clear


    Wherever they appear in a SEROUT statement.

  • ok so even the 128 148 and 151 command get changed to the 2,1 command
  • all i get now is * SERIAL then nothing
  • You have two choices ...

    You can painstakingly go through your code and the datasheets for both the Parallax display and Daventec display and change any Daventec controls to their Parallax equivalent one by one or

    You can get a Parallax display and use that as described in the project design.

    Parallax carefully tests their kits, projects, and sample code. When you substitute different parts, all bets are off. Unfortunately, serial LCD displays are one area where there's no accepted standard for control codes.

    Personally, I would sit down with the two datasheets and make a table like tomcrawford's, but with all the control functions I can find in the Parallax display's datasheet. Then I'd figure out which Daventec display functions are equivalent, maybe using more than one Daventec function for a Parallax function. Then I'd make the substitutions in the program and try it. You'd learn about the capabilities of each display and maybe get an idea of what the program is trying to do with the display formatting. This would take time and effort vs. the expense and time to get a Parallax display.
  • the problem ive got now though is that its giving the correct display but its showing it flashing and sometimes with a * instead of M in milligram so its showing *illigram 0 then flashes saying Milligram 0 then it goes back. i think i can live with it for now but im struggling to find a uk supplier of the parallax LCD. but ill keep looking
  • ok so even the 128 148 and 151 command get changed to the 2,1 command

    128 gets changed to 2,1 but
    148 gets changed to 2, 17 'line 2, character 1
    153 gets changed to 2, 22 (or so) 'line 2, character 5

    There are a bunch of constants great than 128; they all need to be changed appropriately. Some are in the range 128 to 144 or so; they refer to line 1. Some are in the range 148 to 160 or; they refer to line 2.

    I agree with Mike. Print out both data sheets on paper, along with the program. Search through the program for control characters (anything in a serout [output data] that is less than 32 or greater than 127) and change them. It is good exercise and you will learn something about data formatting. The SEROUT portion of the BASIC book should also be on the table.
  • If you do get a Parallax LCD, note that

    SEROUT LCD,32,[22,12,17] ' Clear and turn on backlight on LCD display

    will not work. You will need to change it to:
    SEROUT LCD, Baud, [22, 12]
    PAUSE 5            'give the LCD time to clear the screen
    [SEROUT LCD, Baud, [17]
    
  • Remember that tomcrawford's example above requires

    Baud CON 84 ' Baud constant for 9600 Baud, no parity, 8 bits, 2 stop bits

    somewhere near the beginning of your program. Similarly, you can define names for the LCD control codes to help make the SEROUT statements more understandable. If you look at a lot of Parallax's sample code, you'll see widespread use of these constant names for readability.
  • thanks i have printed out the docs like you suggested and im going to spend the morning looking at them and cross referencing them to the parallax and daventec docs. if i need any more help which is a possibility i will post a message again but for now thanks
  • YES YES YES. it has worked. i thank you both for the guidance in getting this correct. i have also created a spread sheet so that in future i can refer back to this
  • Good on you, mate. Be sure and help somebody with their problem whenever you can.
Sign In or Register to comment.