fastspin Basic RTC
in Propeller 1
I thought I would try to do some User I/O, I am using an RTC(DS1302) for this program.
First off I get the error shown below with the program as listed. Next thing I noticed is a lack of a facility for doing "CRLF". I was trying to use "13" and "10", but I did not get very far. I also noticed when using input$(), there is no way to have it work with CR as the end of the input request. The way it is now, if you have a varying size on the input string, it forces you to create multiple 'if … end if' lines of code with the input$() having to match your string input. More to come after I figure out how fix the below lines of code.
For the program below I want to be able to manually(user I/O) set the date and time, if it needs to be updated.
So far when I use any Optimization setting, for this program, it seems to be working as expected.
Ray
First off I get the error shown below with the program as listed. Next thing I noticed is a lack of a facility for doing "CRLF". I was trying to use "13" and "10", but I did not get very far. I also noticed when using input$(), there is no way to have it work with CR as the end of the input request. The way it is now, if you have a varying size on the input string, it forces you to create multiple 'if … end if' lines of code with the input$() having to match your string input. More to come after I figure out how fix the below lines of code.
For the program below I want to be able to manually(user I/O) set the date and time, if it needs to be updated.
So far when I use any Optimization setting, for this program, it seems to be working as expected.
Ray
|-DS1302_full.spin
|-FullDuplexSerial.spin
G:/fastspin/programs/test5/test5.bas(31) error: syntax error, unexpected end of line
child process exited abnormally
rem test5.bas
'
' April 23, 2019
'
dim rtc as class using "DS1302_full.spin"
dim ser as class using "FullDuplexSerial.spin"
dim day1 as byte
dim month1 as byte
dim year1 as byte
dim dow1 as byte
dim minutes as byte
dim hour as byte
dim seconds as byte
dim dow
dim inBuff as string
rtc.init(10,11,9)
waitcnt(getcnt() + 10_000_000)
' User I/O
do
print "> ";
inBuff = input$(10)
if inBuff = "dtime" then
datetime()
else if inBuff = "settime"
dummy()
else if inBuff = "setdate"
dummy()
else
print "Do not understand!"
end if
' pausems 3000
loop
' Subroutines and Funtions
sub datetime
rtc.readDate(@day1, @month1, @year1, @dow1)
rtc.readTime(@hour,@minutes,@seconds)
print month1;"/";day1;"/";"20";year1;" ";hour;":";minutes;":";seconds
end sub
sub dummy
print "Empty"
end sub
Comments
Are you talking about input or output? For output you can just do "print" with nothing else; that will output an end of line. For input, you can use CHR$ or ASC to try to match a character with a specific ASCII value.
Use just plain "input", like:
dim as string mybuf dim as integer year, month, day print "enter a string> "; input mybuf print "you entered: ["; mybuf; "]" if mybuf = "setdate" then input "enter yyyy,mm,dd"; year, month, day print "year="; year; " month="; month; " day="; day endif
No Optimization - 13336 bytes
Default Optimization - 9136 bytes
Full Optimization - 8932 bytes
I would like to add in the CM2302 code, but using the Full Optimization option would probably trash the program, I think. I might have to try it just to see what happens.
Ray
rem test5.bas ' ' April 23, 2019 ' dim rtc as class using "DS1302_full.spin" dim ser as class using "FullDuplexSerial.spin" dim day1 as byte dim month1 as byte dim year1 as byte dim dow1 as byte dim minutes as byte dim hour as byte dim seconds as byte dim dow dim as string inBuff rtc.init(10,11,9) waitcnt(getcnt() + 10_000_000) print "Type 'help' for system menu." ' User I/O do print "> "; input inBuff if inBuff = "dtime" then datetime() else if inBuff = "setclock" then setclock() else if inBuff = "help" then menu() else if inBuff = "quit" then print "Program End!" exit do else print "Do not understand!" end if ' pausems 3000 loop ' Subroutines and Funtions sub datetime rtc.readDate(@day1, @month1, @year1, @dow1) rtc.readTime(@hour,@minutes,@seconds) print month1;"/";day1;"/";"20";year1;" ";hour;":";minutes;":";seconds end sub sub menu print "Menu" print "help - Show the menu." print "dtime - Show date and time." print "setclock - Set the date and time." print "quit - End the program." end sub sub setclock print "Set date and time." print "dow = 0 - sun." input "year(yy)";year1 input "month(mm)";month1 input "day(dd)";day1 input "dow(x)";dow1 input "hour(xx)";hour input "minutes(xx)";minutes input "seconds(xx)";seconds rtc.setDatetime(month1,day1,year1,dow1,hour,minutes,00) end sub sub dummy print "Empty" end sub
The program below I added the CM2302 code.
No Optimization - 22636 bytes
Default Optimization - 15116 bytes Note: The values produced for the temperature are incorrect.
Full Optimization - 14436 bytes Note: The values produced for the temperature are incorrect.
As for including "FullDuplexSerial.spin", I really wanted to see how that was handled , in terms of program size. I will probably try pairing this up with a Raspberry Pi, using the COM, for remote access. The COM will be running in its own CPU, not sure how much program memory will be necessary for this.
Ray
rem test5.bas ' ' April 23, 2019 ' /' program to test the RTC, CM2302, ..., with a user I/O faclity. '/ dim rtc as class using "DS1302_full.spin" dim dht22 as class using "DHTnn_Object.spin" 'dim ser as class using "FullDuplexSerial.spin" ' CM2302 dim as single temp,humid,status ' RTC dim day1 as byte dim month1 as byte dim year1 as byte dim dow1 as byte dim minutes as byte dim hour as byte dim seconds as byte dim dow dim as string inBuff dht22.StartDHTnn(2,22,@temp,@humid,@status) rtc.init(10,11,9) waitcnt(getcnt() + 10_000_000) print "Type 'help' for system menu." ' User I/O do print "> "; input inBuff if inBuff = "dtime" then datetime() else if inBuff = "setclock" then setclock() else if inBuff = "help" then menu() else if inBuff = "quit" then print "Program End!" exit do else if inBuff = "htemp" then htemp() else print "Do not understand!" end if ' pausems 3000 loop end ' Subroutines and Funtions sub datetime rtc.readDate(@day1, @month1, @year1, @dow1) rtc.readTime(@hour,@minutes,@seconds) print month1;"/";day1;"/";"20";year1;" ";hour;":";minutes;":";seconds end sub sub menu print "Menu" print "help - Show the menu." print "dtime - Show date and time." print "setclock - Set the date and time." print "quit - End the program." end sub sub setclock print "Set date and time." print "dow = 0-sun,1-mon,2-tue,3-wed,4-thu,5-fri,6-sat" input "year(yy)";year1 input "month(mm)";month1 input "day(dd)";day1 input "dow(x)";dow1 input "hour(xx)";hour input "minutes(xx)";minutes input "seconds(xx)";seconds rtc.setDatetime(month1,day1,year1,dow1,hour,minutes,seconds) end sub sub htemp dht22.DHTnn_Read() print "Temperature: ";((temp*9.0)/5.0 + 32.0);" *F";" Humidity: ";humid;" %" end sub sub dummy print "Empty" end sub
Eric
I wonder, in this case, would some kind of modification of the Spin code would resolve the Optimization problem. But it sounds like it would be creating a whole new set of problems for other Spin objects that you would try to use with fastspin Basic, modifying Spin code objects to run with fastspin Basic.
Ray
dht22.StartDHTnn(2,22,@temp,@humid,@status)
The 2 is for the pin number, and the 22 is for the model number. I tried to do something like:
let dhtpin = 2 let dhtmodel = 22 dht22.StartDHTnn(dhtpin,dhtmodel,@temp,@humid,@status)
The compiler came back with an error message. I also tried:#define dhtpin 2 #define dhtmodel 22
The compiler did not like that either. Is there a way to have those two items up in the declarations. Or maybe because I am doing this with a user I/O, have some thing that the user types in the pin number and the model number.Ray
What error messages did you get? Both of those approaches sound like they should work.
Since it seems to be float related, some dummy sensor values should be enough to give a simple fail-test case ?
Something weird is going on, this morning I tried the:
let dhtpin = 2 let dhtmodel = 22 dht22.StartDHTnn(dhtpin,dhtmodel,@temp,@humid,@status)
and this morning it worked as expected. Is the Win 10 Pro messing around with the spin2gui program?As for the DHTnn_Object.spin, to bad we don't have the C version for the dht22, which is in the simpletools lib, for comparison.
As for debugging, to find the optimization problem, I am not sure as to what I can do.
Ray
LOL, drat you Ray, now I have to clean the coffee spray off my laptop and work bench. If true that would be a new bug, even for Windows.
I hope that optimizer problem gets resolved, so I can move on with the program. At the moment if I add another Spin object, like the SD code, that will take me over the top, in the memory area.
Today, while I was trying out some different debugging things, like using the 'Full optimization' option I was getting: That almost sounds like a problem with the LMM, but I am not a developer, so I could be way off target.
Ray
Ray
rem test5.bas ' ' April 23, 2019 ' /' program to test the RTC, CM2302, ..., with a user I/O faclity. '/ dim rtc as class using "DS1302_full.spin" dim dht22 as class using "DHTnn_Object.spin" 'dim ser as class using "FullDuplexSerial.spin" ' CM2302 let dhtpin = 2 ' Set the pin number for CM2302 module. let dhtmodel = 22 ' Set the model number for CM2302 module. 'dim as single temp,humid,status dim as short temp,humid,status ' RTC dim day1 as byte dim month1 as byte dim year1 as byte dim dow1 as byte dim minutes as byte dim hour as byte dim seconds as byte dim dow dim as string inBuff 'dht22.StartDHTnn(2,22,@temp,@humid,@status) dht22.StartDHTnn(dhtpin,dhtmodel,@temp,@humid,@status) rtc.init(10,11,9) waitcnt(getcnt() + 10_000_000) ' Wait for terminal screen to catch up. print "Type 'help' for system menu." ' User I/O do print "> "; input inBuff if inBuff = "dtime" then datetime() else if inBuff = "setclock" then setclock() else if inBuff = "help" then menu() else if inBuff = "quit" then print "Program End!" exit do else if inBuff = "htemp" then htemp() else print "Do not understand!" end if ' pausems 3000 loop end ' Subroutines and Funtions sub datetime rtc.readDate(@day1, @month1, @year1, @dow1) rtc.readTime(@hour,@minutes,@seconds) print month1;"/";day1;"/";"20";year1;" ";hour;":";minutes;":";seconds end sub sub menu print "Menu" print "help - Show the menu." print "dtime - Show date and time." print "setclock - Set the date and time." print "quit - End the program." end sub sub setclock print "Set date and time." print "dow = 0-sun,1-mon,2-tue,3-wed,4-thu,5-fri,6-sat" input "year(yy)";year1 input "month(mm)";month1 input "day(dd)";day1 input "dow(x)";dow1 input "hour(xx)";hour input "minutes(xx)";minutes input "seconds(xx)";seconds rtc.setDatetime(month1,day1,year1,dow1,hour,minutes,seconds) end sub sub htemp print "First temp: ";temp; " Humidity: ";humid dht22.DHTnn_Read() print "First read temp: ";temp; " Humidity: ";humid print "Temperature: ";((temp*9.0)/5.0 + 32.0);" *F";" Humidity: ";humid;" %" end sub sub dummy print "Empty" end sub
Ray