Data from the PINK to the LCD
Teronehc
Posts: 6
·Hi Im very new to programming and the Basic code. Using a BS2, the PINK and a 2x16 LCD screen, how can I read data from the PINK memory and display it on to the LCD screen? Please include a example code, it will make it more easier for me to understand.
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Rick
Have you looked at the documentation and existing examples for the PINK and for the LCD screen? There are also lots of examples of both in the Nuts and Volts columns (under the Resources tab on the main Parallax webpage). There's very little difference between using a DEBUG statement to show PINK information in the Stamp Editor debug window and using a SEROUT statement to show the same data on an LCD (if you're using a serial LCD). One of the better ways to get started with the Stamps is to try out the sample programs and to modify them little-by-little to make them into what you need for yourself.
···· eeAddr = Msg1
····· SEROUT TX, Baud, [noparse][[/noparse]"!NB0R05"]································ ·'·Send Command To Read Variable 05
····· SERIN· RX, Baud, 100, Timeout, [noparse][[/noparse]STR nbvar \16\CLS]··· ' Get Data With Timeout
····· DEBUG "Variable 5: ", STR nbvar,CR··························· ' Display Byte In Decimal for testing purposes
····· FOR idx1 = 0 TO 15
······· WRITE eeAddr, nbvar············································· ' write the·data from the pink to an assigned memory location variable
······· eeAddr = eeAddr + 1·············································· ' increment location
····· NEXT
· FOR idx1 = 0 TO 15······················································ ' First line message·to be displayed
····· char = LcdLine1 + idx1
····· GOSUB LCD_Command
····· READ (Msg1 + idx1), char··········································· ' eeram of first message
····· GOSUB LCD_Out
· NEXT
···· PAUSE 2500
····· SEROUT TX, Baud, [noparse][[/noparse]"!NB0R05"]······················ ' Send Command To Read Variable 05
····· SERIN· RX, Baud, 100, Timeout, [noparse][[/noparse]STR nbvar \16\CLS]· ' Get Data With Timeout
····· DEBUG "Variable 5: ", STR nbvar,CR·················· ' Display Byte In Decimal
·· eeAddr = Msg1
·· idx1=0
····· DO
······· WRITE eeAddr, nbvar(idx1)·············· ' write the recieved variable to the memory
······· eeAddr = eeAddr + 1···················· ' pionts to the next address
······· idx1 = idx1 + 1························ ' increments the index
····· LOOP UNTIL (nbvar(idx1)= 46)············· ' loops the read until a "."= 46 dec is incountered
· FOR idx1 = 0 TO 15··························· ' First line message: room number
····· char = LcdLine1 + idx1
····· GOSUB LCD_Command
····· READ (Msg1 + idx1), char·················· ' eeram of first message
····· GOSUB LCD_Out
· NEXT
It is very inefficient and potentially harmful (long term) to the EEPROM to keep writing the strings from the PINK to the EEPROM just to display them. You already have them in variable RAM anyway (array) so why not just write them from there?
Think of it this way…When you’re writing them from the array into EEPROM you’re accessing both the array and the EEPROM using indexing…Why not just index the characters directly from the array onto the screen?
As for the extra characters, it looks like you’re sending a fixed number of characters to the display instead of just what you want to print. The strings should be zero terminated, so why not just print until a zero is encountered? Of course, this means you’ll have to copy the zero back from the PINK Module as well.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
SEROUT TX, Baud, [noparse][[/noparse]"!NB0R20"] ' Send Command To Read Variable 05
SERIN RX, Baud, 100, Timeout, [noparse][[/noparse]STR nbvar \21\CLS] ' Get Data With Timeout
DEBUG "Variable 20: ", STR nbvar,CR ' Display Byte In Decimal
FOR idx1 = 0 TO 15 ' First line message: room number
char = LcdLine1 + idx1
GOSUB LCD_Command
READ nbvar(idx1), char ' eeram of first message
GOSUB LCD_Out
NEXT
PAUSE 2500 ' waits for 2.5 seconds
'
>
FOR idx1 = 1 TO 16 ' shift display
char = LcdDispR ' moves the first message off the lcd
GOSUB LCD_Command
PAUSE 100
NEXT
Where the LCD_OUT routine uses the char.lownib and char.highnib, but all that is displayed on the lcd are black squares where there should be text.
My second approach used the write to the EEPROM of the basic stamp ( Msg1 data 32(16) ). Here the message is displayed except the second character every time. Someone please show me what I am doing wrong in both approaches. Here is the code that I used:
SEROUT TX, Baud, [noparse][[/noparse]"!NB0R20"] ' Send Command To Read Variable 05
SERIN RX, Baud, 100, Timeout, [noparse][[/noparse]STR nbvar \21\CLS] ' Get Data With Timeout
DEBUG "Variable 20: ", STR nbvar,CR ' Display Byte In Decimal
eeAddr = Msg1
idx1=0
DO
WRITE eeAddr, nbvar(idx1) ' write the received variable to the memory
eeAddr = eeAddr + 1 ' pionts to the next address
idx1 = idx1 + 1 ' increments the index
LOOP UNTIL (nbvar(idx1)= 46) ' loops the read until a "."= 46 dec is encountered
FOR idx1 = 0 TO 15 ' First line message: room number
char = LcdLine1 + idx1
GOSUB LCD_Command
READ (Msg1 +idx1), char ' eeram of first message
GOSUB LCD_Out
NEXT
PAUSE 2500 ' waits for 2.5 seconds
'
>
FOR idx1 = 1 TO 16 ' shift display
char = LcdDispR ' moves the first message off the lcd
GOSUB LCD_Command
PAUSE 100
NEXT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support