Shop OBEX P1 Docs P2 Docs Learn Events
LCD issues — Parallax Forums

LCD issues

p_tp_t Posts: 15
edited 2013-02-05 08:46 in BASIC Stamp
I am currently working on a project with the education board. I am using a photo-transistor servo standard motor, LCD and a few LEDs. Basically I am replicating project 1 from Chapter 7 in Whats a Microcontroller book, except I am using the LCD instead of the debug terminal. My issues are, when I flash my light on the photo-transistor the servo goes to the designated position and vice versa when the light is off. During this, my LCD is rapidly blinking in between the light off and on, and it is also randomly beeping. I am not sure why it is doing it. Any help would be appreciated.

here is my code for the project. (Servo is connected to the servo header 12 pin and the lcd is connected to servo header 14 pin.)
SEROUT 14, 84, [22,12,17]
HIGH 11
HIGH 10
HIGH 9
valMax CON 4000
valMin CON 100
time VAR Word
PAUSE 1000
DO
HIGH 2
PAUSE 1 ' PAUSE 100 -> PAUSE 1
RCTIME 2, 1, time
'DEBUG HOME, "time = ", DEC5 time
'SEROUT 14, 84, [128,17,"time = ", DEC5 time]
time = time MAX valMax MIN valMin
IF time > (valMax - valMin) / 2 THEN
'DEBUG CR, "Open blinds "
SEROUT 14, 84, [150,17, "Open blinds"] ' Modify
PULSOUT 12, 500 ' Add
ELSE
'DEBUG CR, "Close blinds"
SEROUT 14, 84, [150,17, "Close blinds"] ' Modify
PULSOUT 12, 1000 ' Add
ENDIF
LOOP

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-02-03 07:51
    What serial LCD are you using? Why are you transmitting the 150 and 17 to it? Why are you initializing it with 22, 12, and 17? Perhaps the batteries are becoming weak and causing the Stamp to restart when the servo moves and draws more current and the program is starting over again?
  • p_tp_t Posts: 15
    edited 2013-02-03 08:52
    Mike Green wrote: »
    What serial LCD are you using? Why are you transmitting the 150 and 17 to it? Why are you initializing it with 22, 12, and 17? Perhaps the batteries are becoming weak and causing the Stamp to restart when the servo moves and draws more current and the program is starting over again?

    Mike,

    I am using 2 rows x 16 characters Backlit with Piezospeaker (#27977)
    150, is the position of the text on the LCD
    17 was only added because the light kept turning off however it was still blinking on and off when light was shined on the transistor
    I am initiating 22,12,17 because I want the LCD to turn on, clear previous program, and to turn on the back light.

    I am also a new user to parallax and to the forum, please forgive me if I missed any other information. Thank you for your response. I tried two different batteries. However, they are new fresh ones. I will try this solution as soon as I hit the store.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-02-03 09:36
    The LCD documentation says that you need a 5ms pause after sending 12 to the display and your code doesn't do this. Try

    SEROUT 14,84,[22,12]
    PAUSE 5
    SEROUT 14,84,[17]

    instead of

    SEROUT 14,84,[22,12,17]

    Make sure the switches on the LCD are set for 9600 Baud.
  • p_tp_t Posts: 15
    edited 2013-02-03 18:37
    Mike Green wrote: »
    The LCD documentation says that you need a 5ms pause after sending 12 to the display and your code doesn't do this. Try

    SEROUT 14,84,[22,12]
    PAUSE 5
    SEROUT 14,84,[17]

    instead of

    SEROUT 14,84,[22,12,17]

    Make sure the switches on the LCD are set for 9600 Baud.

    Mike, thanks again for your input, unfortunately I am still facing the problem when the light is shined on the phototransistor the lcd still blinks. I tried the new code and a fresh new battery.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-02-03 19:30
    There is no reason why your LCD should behave the way you describe when the phototransistor is active. The two paths from the IF statement are very similar and just move the servo and send a string to the display. The only thing that would explain the behavior you're seeing is if the Baud setting on the LCD didn't match the 9600 Baud the SEROUT is sending or if there's something wrong with the connection between the Stamp and the LCD. The latter would cause irregular errors, not every time the phototransistor is turned on. Please check the Baud setting of the LCD and check that the program being downloaded to the Stamp is the same as what you've shown here.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-02-04 08:35
    Also, try this...place a DEBUG at the beginning of the program that shows, "Program running...". Do you see that appear more than once while your program is running?
  • p_tp_t Posts: 15
    edited 2013-02-04 18:41
    Also, try this...place a DEBUG at the beginning of the program that shows, "Program running...". Do you see that appear more than once while your program is running?

    The debug doesn't give any issues. Another classmate is having the same issue as me as well. Is the photo transistor affecting it?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-02-05 08:46
    Part of the initialization for the serial LCD involves bringing the serial line high and then waiting for 100mS, however I do not see that in your code.
    [FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]HIGH TxPin ' Set pin high to be a serial port
    
    PAUSE 100 ' Pause for Serial LCD to initialize
    [/SIZE][/FONT][/SIZE][/FONT]
    

    As Mike pointed out, whenever using the clear screen command you must follow it with a PAUSE 5.

    Another thing that could be happening is that you're not allowing for any hysteresis in your program, so what could be happening is that when the time threshold is reached the servo engages and perhaps on the next loop the RCTIME is affected by the voltage drop and causes it to oscillate briefly between states.

    Speaking of which, there should be a minimum delay of 15mS between refreshes of the servo, however your loop doesn't allow that. In a sense, you're overdriving the servo.
Sign In or Register to comment.