Coding data from basic stamp 2 to LCD display
ad9409
Posts: 8
Ok, so I ran a sample code that runs from the basic stamp 2 to an LCD screen and it worked. The code used the function DATA to display onto the LCD screen.
So for example, it had a lot of coding lines but then used, DATA "Hello world", and using that, the LCD displayed "Hello world".
Then I wanted to display data that I gathered from an ADC that was connected to a sensor. When I used the function DEBUG...., the correct information displayed on the PC. But then when I replace DEBUG with DATA, the program is giving an error saying that it was expecting a constant.
What do I need to do to display the data gathering from the ADC to display on the LCD screen?
The LCD that I am using is LCM1602A which I believe is similar to the HD44780
Thanks
So for example, it had a lot of coding lines but then used, DATA "Hello world", and using that, the LCD displayed "Hello world".
Then I wanted to display data that I gathered from an ADC that was connected to a sensor. When I used the function DEBUG...., the correct information displayed on the PC. But then when I replace DEBUG with DATA, the program is giving an error saying that it was expecting a constant.
What do I need to do to display the data gathering from the ADC to display on the LCD screen?
The LCD that I am using is LCM1602A which I believe is similar to the HD44780
Thanks
Comments
If the LCD has a serial interface, then SEROUT can be used with any version of the Stamp. If it has a parallel interface, then something else would be required such as the use of a version "P" Stamp as Mr. Albach mentioned.
BTW - DEBUG is just a special form of SEROUT that sends data to the Stamp editor debug window.
I will post the code a little later today
...any chance of a schematic also?
I have another code that helps get the data information that I need:
I tried adding this code above and it works but since i'm using DEBUG, it displays it on the PC. I assumed DATA would display it on the LCD screen but that is not the case. The program gives me an error that it is expecting a constant where DEC is in the DEBUG.
And I do not have a a schematic to go along with it, sorry about that.
The only thing DATA can do is store the constant or string of constants that follows it to the Stamp's EEPROM memory during program loading. It cannot write to the LCD, it just writes to EEPROM, nothing else.
When the above program is loaded into the Stamp, PBasic catches the DATA statement and places what follows into EEPROM storage. In your program under the heading '
[ EEPROM DATA ]
is the line DATA "Hello, this is the LCD demo." ' Message to send to LCD.
PBasic takes whatever is between the quotation marks and places it into EEPROM memory. Since a starting location was not specified the location defaulted to location 0 in EEPROM. Further down in your program in Main: you have a FOR loop which extracts one location at a time from EEPROM and places it into a variable called char. This is done by the statement READ temp, char. temp is used as an index variable that points to which location to READ from the EEPROM. The next statement GOSUB send_Text goes to a sub-routine called send_Text that takes the contents of the variable char and sends it to the LCD, then returns to Main: for more until the FOR loop is complete.
You cannot substitute the command DEBUG with DATA. All that will get you is an error.
In your code for the ADC you have defined a BYTE variable named result. Yet your program shifts in 9 bits from the ADC into result, which holds only 8 bits. Maybe this is what you want, I don't know.
In order to display the ADC result on the LCD you will have to copy result into char and then call the send_Text subroutine. But first you will have to scale result in order to display the correct number.
-=<[Chris]>=-
The 9-bit shift is required by the ADC0831 because it doesn't send out the data until the second clock pulse. The leading zero bit is simply shifted out of the result.
The scaling by 1/2 for a Vref of 1.28 is to put the LM34 data in range for the Temp display. Since Vref is 1.28, an input voltage from the LM34 of 1.27v will generate an ADC output of 255. Dividing by two yields 127 which is 127°F.
Look at Chris' examples. You'll need to pull each digit out of the result using the DIG operator and adjust it by ASCII "0" - zero - to make it show on the display.