Shop OBEX P1 Docs P2 Docs Learn Events
Transferring values from Ultrasonic Distance Sensor to LCD — Parallax Forums

Transferring values from Ultrasonic Distance Sensor to LCD

Hi! so im going to a sort of recruiting confrence in Norway on monday in an attempt to recruit students to pursue Computer science here. in this attempt ive made a
Boe-Bot with 2 Micro controller cards. i have one for controlling the bot ofc the other one im using a Ultrasonic Distance Sensor to display lenghts. its cool enough in itself BUT i want to transfer the values it shows in CM and " to a Parallax 2 x 16 Serial LCD ( Backlit) screen. the code for the Sensor is this :
CmConstant CON 2260
InConstant CON 890

cmDistance VAR Word
inDistance VAR Word
time VAR Word

DO
PULSOUT 15, 5
PULSIN 15, 1, time

cmDistance = cmConstant ** time
inDistance = inConstant ** time

DEBUG HOME, DEC3 cmDistance, " cm"
DEBUG CR, DEC3 inDistance, " in"

PAUSE 100
LOOP

now i need a code for the LCD to kind of use this as a source. either i merge the programs but im not sure how. or i try to get it to use the Debug Terminal ( where the values show when i run the Sensor ) as a source. anyone got any idea? im flying to a collage on monday so im kinda stressed out :I

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2016-01-19 02:58
    Use the code for the Ultrasonic Distance Sensor, but change the DEBUG statements to SEROUT statements. Use the sample code for the Serial LCD (Serial LCD Template.BS2). There are a few lines of code that have to initialize the LCD (before the DO). Something like this will be equivalent:

    SEROUT TX,LcdBaud,[LcdLine1,DEC3 cmDistance," cm "]
    SEROUT TX,LcdBaud,[LcdLine2,DEC3 inDistance," in "]

    The constant declarations in the Template assume that the LCD is connected to I/O pin 0. Read the documentation for the LCD for details of how to use it.
  • Mike Green wrote: »
    Use the code for the Ultrasonic Distance Sensor, but change the DEBUG statements to SEROUT statements. Use the sample code for the Serial LCD (Serial LCD Template.BS2). There are a few lines of code that have to initialize the LCD (before the DO). Something like this will be equivalent:

    SEROUT TX,LcdBaud,[LcdLine1,DEC3 cmDistance," cm "]
    SEROUT TX,LcdBaud,[LcdLine2,DEC3 inDistance," in "]

    The constant declarations in the Template assume that the LCD is connected to I/O pin 0. Read the documentation for the LCD for details of how to use it.
    it shows something like ASCII and just spamms the screen full of ">" interesting is it changes when i put my hand infront of the sensor but nothing i can understand.

  • Mike GreenMike Green Posts: 23,101
    edited 2016-01-19 13:59
    Do you have the Baud jumper set correctly? The LcdBaud constant should be one of the special constants for your selected Baud and the Stamp model you're using. Check the table in the Basic Stamp Syntax and Reference Manual in the chapter on the SEROUT statement. For a BS2 at 9600 Baud it should be 84. At 19200 Baud, try 32.
  • Mike Green wrote: »
    Do you have the Baud jumper set correctly? The LcdBaud constant should be one of the special constants for your selected Baud and the Stamp model you're using. Check the table in the Basic Stamp Syntax and Reference Manual in the chapter on the SEROUT statement. For a BS2 at 9600 Baud it should be 84. At 19200 Baud, try 32.

    Thx! i used some example code that had 19200 baud set as 82 or something. that made the error. now it works just fine :)
Sign In or Register to comment.