Converting DEBUG from the computer to an old Scott Edwards LCD
Keith Hilton
Posts: 150
in BASIC Stamp
Last night I worked through an extremely exciting exercise in the Parallax book, "Basic Analog and Digital". Chapter 3 "Build Your Own Digital DC Volt Meter". Here is the last line of the code right before the RETURN. Display:
DEBUG HOME
DEBUG "8-bit binary value: ", BIN8 adcBits
DEBUG CR,CR, "Decimal value: ", DEC3 adcBits
DEBUG CR, CR, "DVM Reading: " 'New line
DEBUG DEC1 v, ".", DEC2 v2, " Volts" 'New line
RETURN
This code gives in the DEBUG the Binary value, Decimal value, and actual Volt value to the hundredth. Suppose I don't want to take my desk to computer to get a volt reading. Suppose I want to take a small LCD. I have the old Scott Edwards LCD that Parallax used to sell, and it is programmed different than the new Parallax LCD. Back in 2004 I used to know how to code the old LCD, and now trying to get back up to speed. I am wanting to show "only" the DVM reading on the LCD, meaning the actual volts. I know the first part of the code would have to be N9600 con $4054 I am unsure of how to code it to the LCD, without screwing up the main code I want to keep. Do I need two complete codes? In the last part of the code after Display: What do I need to delete, and what do I need to add? I am thinking delete the binary value, and decimal value, and leave the other two lines of code. But I need help with the code to send the information the the LCD. Pins 0,1,2 of the Basic Stamp are used up, so it would have to be one of the other pins. Help!
DEBUG HOME
DEBUG "8-bit binary value: ", BIN8 adcBits
DEBUG CR,CR, "Decimal value: ", DEC3 adcBits
DEBUG CR, CR, "DVM Reading: " 'New line
DEBUG DEC1 v, ".", DEC2 v2, " Volts" 'New line
RETURN
This code gives in the DEBUG the Binary value, Decimal value, and actual Volt value to the hundredth. Suppose I don't want to take my desk to computer to get a volt reading. Suppose I want to take a small LCD. I have the old Scott Edwards LCD that Parallax used to sell, and it is programmed different than the new Parallax LCD. Back in 2004 I used to know how to code the old LCD, and now trying to get back up to speed. I am wanting to show "only" the DVM reading on the LCD, meaning the actual volts. I know the first part of the code would have to be N9600 con $4054 I am unsure of how to code it to the LCD, without screwing up the main code I want to keep. Do I need two complete codes? In the last part of the code after Display: What do I need to delete, and what do I need to add? I am thinking delete the binary value, and decimal value, and leave the other two lines of code. But I need help with the code to send the information the the LCD. Pins 0,1,2 of the Basic Stamp are used up, so it would have to be one of the other pins. Help!
Comments
All you need to do is add a SEROUT either before or after the DEBUG line you're copying and include the same formatters and parameters as the DEBUG statement, but using SEROUT.
For example, if you wanted to send the DVM reading to the LCD, right before the RETURN add:
SEROUT LCD, N9600, ["DVM Reading:" DEC1 v, ".", DEC2 v2, "Volts"]
' {$PBASIC 2.5}
'----[ Declarations ]
adcBits VAR Byte
v VAR Byte
r VAR Byte
v2 VAR Byte
v3 VAR Byte
'
[ Initialization ]
CS PIN 0
CLK PIN 1
DataOutput PIN 2
DEBUG CLS 'Start display.
'
[ Main Routine ]
DO
GOSUB ADC_Data
GOSUB Calc_Volts
GOSUB Display
LOOP
'
[Subroutines ]
ADC_Data:
HIGH CS
LOW CS
LOW CLK
PULSOUT CLK, 210
SHIFTIN DataOutput,CLK,MSBPOST,[adcBits\8]
RETURN
Calc_Volts:
v = 5 * adcBits / 255
r = 5 * adcBits // 255
v2 = 100 * R / 255
v3 = 100 * r // 255
v3 = 10 * v3 / 255
IF (v3 >=5) THEN v2 = v2+1
IF (v2 > 100) THEN
v = v+ 1
v2 =0
ENDIF
RETURN
Display:
DEBUG HOME
DEBUG "8-bit binary value: ", BIN8 adcBits
DEBUG CR,CR, "Decimal value: ", DEC3 adcBits
DEBUG CR, CR, "DVM Reading: " 'New line
DEBUG DEC1 v, ".", DEC2 v2, " Volts" 'New line
RETURN
Usually PINs are declared first, then CONstants, and finally VARiables.
Also if you look at the BPI manual there is a PAUSE 1000 at the start of the program.
In Initialization, just before DEBUG, it's a good idea to always put a PAUSE 1000 anyway to allow Windows enough time to setup the Serial ports.
If you also look at the BPI manual, you will see there are 2 ways to use the Clear and Home commands since both take a long time.
You can either add a PAUSE as the Demo does or immediately follow it with a Position command.
Each time you want to display something you either need to clear the display, home the cursor, or set the position.
Since you have 2 lines and 16 characters, did you want to display anything else?
You might also want to double-check your wiring.
Keith,
Apologies, my assumption was that should all have been done long before the subroutine was called. I was merely describing how to direct the desired output to the LCD in addition to DEBUG.
One interesting feature of PBASIC is Aliasing where you can have a variable or constant use another variable or constant.
Use BaudLCD for all your SEROUT commands and then you just need to change BaudLCD to T9600 later.
I also added a PIN definition for LCD receive pin and some other baud rate settings that might be useful later.
Initialization.
LCD PIN 3
Constants.
BaudLCD CON N9600 'Baud rate for serial LCD.
I CON 254 ' Instruction prefix value.
CLR CON 1 'LCD clear-screen instruction.
Now for the instruction sent to the LCD, right before the last return in the code.
pause 1000 'Time to initialize the LCD
SEROUT LCD,BaudLCD,[I,CLR] 'Clear the LCD screen
pause 1
SEROUT LCD,BaudLCD,["DVM Reading:" DEC1 v, ".", DEC2 v2, "Volts"]
Before I try it what is the verdict? Will it work? Do I need to add anything or change anything?
I am assuming that once the code reaches RETURN, then we go back to the normal 9600 bps without any instruction. Is that correct?
where data is what you are sending to either the COM pin or the LCD pin, as appropriate.
The error said: "Undefined Symbol" and darkened in blue the N9600----Where I had listed constants.
Constants.
BaudLCD CON N9600 'Baud rate for serial LCD.
I CON 254 ' Instruction prefix value.
CLR CON 1 'LCD clear-screen instruction.
The error--- being a undefined symbol-- was the the N9600 in the above constants. I have no idea how to correct this error. Plus I am unsure as to how to get back to 9600. Do I get back by listing BaudCOM CON 9600 in the constants---and---where does that go in the code? I think the entire problem centers around switch Baudmodes. It appears that I don't know how to define the Baude rate, or how to switch from one rate to another. Help.
You would do well to study the Basic Manual, beginning on page 95, Constants and Expressions.
N9600 CON $4054 'Baudmode-9600 bps inverted.
Then my SEROUT command would change to:
SEROUT LCD,N9600,["DVM Reading:" DEC1 v, ".", DEC2 v2, "Volts"]
I will try to run it with those changes.
SEROUT LCD,N9600,["DVM Reading:" DEC1 v, ".", DEC2 v2, "Volts"] Then an error popped up. The error said, "Expect ']' and darkened the DEC1
This is the exact code Chris suggested I run. So why is the error popping up and expecting a ']' at the DEC1?
Here is Chris's code SEROUT LCD, N9600, ["DVM Reading:" DEC1 v, ".", DEC2 v2, "Volts"]
The original code that displayed on the computer screen was this:
Display:
DEBUG HOME
DEBUG "8-bit binary value: ", BIN8 adcBits
DEBUG CR,CR, "Decimal value: ", DEC3 adcBits
DEBUG CR, CR, "DVM Reading: " 'New line
DEBUG DEC1 v, ".", DEC2 v2, " Volts" 'New line
RETURN
SEROUT LCD,N9600,["DVM Reading:", DEC1 v, ".", DEC2 v2, "Volts"]
One other thing I need to mention. When I ran the original code from the Parallax instruction book it ran perfectly. Problems started happening when I tried to get the Debug to display on my Scott Edwards LCD. At times the computer mouse screen pointer becomes uncontrollable until I unplug the USB connection going to the Basic Stamp module.
Remember--everything ran perfect until I tried adding the Scott Edwards LCD. Yes, I am powering the LCD with a separate power supply that is sufficient for the current for the black light on the LCD. The Basic Stamp module is powered by a different power supply. Both power supplies share Vss. I do know the LCD works, because I programmed it and saw it working. What is the mystery to me is that the programmed worked until I tried to add the LCD, and I know the LCD worked before I tried to run it with this program. Something simple is probably screwing everything up. Help.
As for the errors, you're not showing the code exactly as it appears. Usually if something says undefined symbol, then you didn't declare that variable. However, I tried to use the same variables the DEBUG statements used. Are you using the same? My line of code wasn't meant to be a drop-in working line of code. It was to show you how to convert the DEBUG line into a SEROUT. It still requires you to use the pin and baud rate constants you should have already defined as well as the variable names that were already in use.
P.S. - Please copy/paste the code with the error exactly as it appears or take a photo and post that.
I ordered the new Parallax LCD yesterday. When it gets here I will be able to work out of the Parallax book Smart Sensors---because all the code if for the new Parallax LCD. I'm feeling happy that I got it working!
That's great! I'm glad you got everything solved. And it will surely be easier once you have the Parallax LCD to get started. But once you're a veteran, you'll find the SEETRON LCD to be useful in some project. It's just "different". :nerd: