![]() |
Forum Index : Microcontroller and PC projects : Newie got a few questions
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
This is what the outdoor unit is sending [quote] Print #2, "START" , "Searching" (while searching for a GPS lock)[/quote] Then when it has a lock it sends this [code] PRINT "CHECK1" Y1,M1,D1,H1,M2,S2 Pin(16) = 0 'HC-12 Power ON Pause 100 PRINT #1,"START", Y1,M1,D1,H1,M2,S2 Print #1,"TIME",Y1,M1,D1,H1,M2,S2 ' Send correct date/time to Indoor unit to set RTC[/code] The indoor unit sees the START Searching but never receives the PRINT #1,"START", Y1,M1,D1,H1,M2,S2 line |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
I found the problem - a REALLY STUPID mistake I was trying to send the data to the GPS unit instead of the HC-12 (tx/rx unit) com ports mixed up Arghh - sorry |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Now I fixed the problem with the com port numbers I still am getting the same error HOPEFULLY I've explained it better below The OUTDOOR UNIT sends data via COM2 a uhf tx/rx unit HC-12 The INDOOR UNIT receives data via COM1 a HC-12 set to the same channel etc as the other one Outdoor code (the relevant section) [code] DO Pin(23) = 0 'TURN GPS Power ON pause 100 ' delay to allow the HC-12 to turn on properly *not needed but here as a just in case* Print "Searching For GPS signal" 'CONSOLE **********THIS WORKS ******* Print #2, "START" , "Searching" 'HC-12 ************THIS WORKS prints on INDOOR UNIT RECEIVE PRINT "CHECK1" Y1,M1,D1,H1,M2,S2 'Date & time sent to CONSOLE *** THIS WORKS ON THE CONSOLE I CAN SEE THE CORRECT DATE AND TIME****** PRINT #2,"START",Y1,M1,D1,H1,M2,S2 'date ^ time sent to HC-12 *** DOES NOT SEND TO COM1 ***DOES NOT SEND*** Print #2,"TIME",Y1,M1,D1,H1,M2,S2 'Send correct date/time to HC-12 ****DOES NOT SEND TO COM1 ***DOES NOT SEND*** Print #2,"START",",",bme280_read_temp()",",pressure",",humidity",",wheading",",wSpeed",",wgust",",hgust",",mmrain",",mmrain2", ",hightemp",",hightemp2",",lowtemp",",lowtemp2",",UVindex",",batt ; ' Weather data ***SENDS TO COM1 Print "*********************************" Print Time$ Print Line1$ Print " Battery Voltage ";Str$(batt,3,2);" V" Print " Direction: ";Str$(wheading);" Degrees" Print " WindSpeed: ";Str$(wSpeed); " MPH" Print " Gust ";Str$(wgust,3,2); " MPH" Print " Highest Gust ";Str$(hgust,3,2); " MPH" Print " Rain Today ";Str$(mmrain,3,2);" mm" Print " Rain Yesterday ";Str$(mmrain2,3,2);" mm" Print " Temperature "; Str$(bme280_read_temp(),3,2)" C " Print " Highest Temp ";Str$(hightemp,3,2) " C" Print " Lowest Temp ";Str$(lowtemp,3,2) " C" Print " Hi Temp Yesterday ";Str$(hightemp2,3,2) " C" Print " LOW Temp Yesterday ";Str$(lowtemp2,3,2) " C" Print " Pressure "; Str$(bme280_read_pressure(),3,2)" mB " Print " HUMIDITY "; Str$(bme280_read_humidity(),3,2)"%" Print " UV Index: ";Str$(UVindex,3,2) Print "*******************************" End Sub Pin(23) = 1 'HC-12 power off Loop [/code] INDOOR UNIT CODE [code] CLS RGB(blue) 'Clear the screen to a Blue colour Open "COM1:19200" As #1 'Open port for HC-12 TX/RX DO IF LOC(#1)>1 THEN SERIAL1 END IF LOOP End Sub SERIAL1 Local D$ 'Define D$ only for use by this subroutine(ignores any D$ in main code) D$ = Input$(240, #1) Print D$; End Sub [/code] Console on INDOOR UNIT SEES THIS (which is CORRECT) [quote] Searching For GPS signal Searching For GPS signal Searching For GPS signal CHECK1 16 12 10 15 31 30 ********************************* 15:33:50 Sat 10-Dec-2016 Battery Voltage 3.98 V Direction: 60.9971 Degrees WindSpeed: 0 MPH Gust 0.42 MPH Highest Gust 0.42 MPH Rain Today 0.00 mm Rain Yesterday 0.00 mm Temperature 23.27 C Highest Temp 23.88 C Lowest Temp 23.88 C Hi Temp Yesterday 0.00 C LOW Temp Yesterday 0.00 C Pressure 1006.61 mB HUMIDITY 54.75% UV Index: 0.03 ******************************* [/quote] The OUTDOOR UNIT SEES THIS [quote] START Searching START Searching START Searching START , 23.88, 0, 0, 60.9971, 0, 0.416667, 0.416667, 0, 0, 23.88, 0, 23.88, 0, 0.03, 3.9752 [/quote] It's NOT seeing either of these (part of the OUTDOOR CODE ABOVE) PRINT #2,"START",Y1,M1,D1,H1,M2,S2 'date & time sent FROM HC-12 **** The outdoor unit does not send the data**** or Print #2,"TIME",Y1,M1,D1,H1,M2,S2 'Send correct date/time to HC-12 **** The outdoor unit does not send the data**** |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6269 |
Looking at your last code, Anything you PRINT to the console is received by the indoor unit. Anything you PRINT #2 to the COM2 is NOT received by the indoor unit. I think the HC-12 is connected to the console pins and not connected to the COM2 pins. IN your outdoor code, change the PRINT #2 to and see what happens Jim VK7JH MMedit |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
The com pins are correct When it sends Print #2, "START" , "Searching" That works When it sends Print #2,"TIME",Y1,M1,D1,H1,M2,S2 That does not work The indoor unit does not see anything beginning with the word TIME and I put the indoor code so it will print anything sent from outside and I know that Y1,M1,D1,H1,M2,S2 is sending the date and time because I can see it on the console on the outdoor unit before it sends to the indoor via the HC-12 |
||||
plover![]() Guru ![]() Joined: 18/04/2013 Location: AustraliaPosts: 306 |
lew247 The line that works has spaces the line that does not work has no spaces. In your last message it is not clear if you have typed the two lines or you have copy and pasted code, not withstanding there is an example on previous page [code] PRINT "CHECK1" Y1,M1,D1,H1,M2,S2 Pin(16) = 0 'HC-12 Power ON Pause 100 PRINT #1,"START", Y1,M1,D1,H1,M2,S2 Print #1,"TIME",Y1,M1,D1,H1,M2,S2 ' Send correct date/time to Indoor unit to set RTC [/code] The second last line has a space between start and Y1? I have no idea if this matters as it seems in other places where it works you have no spaces. Another idea which you may have tried, I have not read the whole thread only the last two pages. What would happen if you replace TIME temporarily with some other name? If that does not work, try one variable at a time if that is possible and then another one. ![]() |
||||
BobD![]() Guru ![]() Joined: 07/12/2011 Location: AustraliaPosts: 935 |
That is a good point. IIRC the use of variable names the same as keywords and commands (or similar) is not good practice and can sometimes cause troubles. Call it something like MYTIME or anything but TIME. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6269 |
I assume that you have the Indoor and Outdoor units back to front. Can you show us the line from the outdoor unit where you OPEN #2 While I agree that using keywords as variable names is a bad idea, I don't think it is the cause of the problem here. Jim VK7JH MMedit |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
[quote]Open "COM2:9600" As #1 ' OPEN the GPS serial interface Open "COM1:19200" As #2 'Open port for HC-12 TX/RX[/quote] The open works fine because I am seeing data on the indoor unit FROM the outdoor unit and yes they are side by side at the moment - about 0.3 Metre apart I actually have this line just before the "TIME" line and it's not being seen by the indoor unit either PRINT #2,"START",",","hello",",","Boo" Weird, but it has to be something simple |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2932 |
Can I advise that if you have: OPEN "COM2....." AS #1 and OPEN "COM1...." AS #2 then you swap these around so that COM1 is #1; and COM2 is #2 ![]() This will avoid a lot of confusion in your PRINT #1 & PRINT #2 code lines. You will obviously need to change all the lines of code that relate to a '#' filenumber (i.e. PRINT #, INPUT$(x,#) This is not going to solve the issue you have, but it makes it easier to read the code bearing in mind you know what device is on each com port. |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Great idea, thanks - just did it Waiting for a lock on the GPS to see if the latest changes I made earlier this morning works or not for some reason it's taking a very long time to get a lock today and I'm even using an amplified gps antenna albeit still indoors |
||||
robert.rozee Guru ![]() Joined: 31/12/2012 Location: New ZealandPosts: 2431 |
ummm, you are using HC-12 modules for communications, yes? a silly question: you do have pairs of modules that are configured the same? the HX-12 defaults to 9600 baud, and will not respond to data at 19,200 unless reconfigured. cheers, rob :-) |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Yep, both modules configured exactly the same I used the brilliant HC-12 Config.exe program to do it, brilliant program I actually have 4 set up to the same config in case one breaks or goes faulty |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6269 |
put a space after the #2, becomes I have lost track of the # numbers you are using so adjust as required. I think the space character is one difference between the lines that do transmit and the ones that don't transmit. Also, what version of MMBasic are you running on each device? Jim VK7JH MMedit |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
I found the problem ![]() Something so simple I should have spotted it days ago I wasn't leaving the power to the HC-12 on long enough to send the time data All working now ![]() However it's now thrown up another problem Line1 is the current local time as decoded from the GPS time The code I am using to get the data to send to the outdoor unit is this [code] H1 = Val(Left$(LINE2$(1), 2)) ' extract the hour M2 = Val(Mid$(LINE2$(1), 4, 2)) ' extract the min S2 = Val(Mid$(LINE2$(1), 7, 2)) ' extract the sec[/code] The current time as got when I PRINT LINE2 is 9:03:27 and the data as received by the indoor unit is 16 , 12 , 12 , 9 , 3 , 7 (year, month, day, hour, min, second The time is incorrect because the correct time is 09:03:27 and the seconds only show 7 and not 27 The missing 0 for the hour and minute isn't a problem The problem is the time sent is incorrect because the hour could be 1 or 2 digits, as could the minute or second Any idea how to sort the H1, M2 and S2 so it gets the correct hours, mins and seconds even if any of them has one or 2 digits? I've tried several ways of doing it but none of them work correctly and they end up missing one of the digits out |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2932 |
You can use the STR$ function to insert any necessary leading zero. Keep each element of the time (i.e. the hours, the minute, and the seconds) as strings by using the STR$ function from the data you extract (not sure if you currently extract as number or string!!) So for example STR$(H1,2,0,"0") will return H1 as a 2-digit string (prefixed with a '0' if necessary), and with zero decimal places (where H1 contains the number representing the hour). Hope you follow . . . ![]() |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
I did follow thanks and it did work but it still doesn't work at the same time It's now putting a leading zero in instead of the correct number Line2 is the correct local time in ONE or 2 digit format depending on the hour, min and second so the following doesn't work because it's always extracting the values at the same point no matter how many digits that have (Hope I've explained that properly) H1 = Val(Left$(LINE2$(1), 2)) ' extract the hour M2 = Val(Mid$(LINE2$(1), 4, 2)) ' extract the min S2 = Val(Mid$(LINE2$(1), 7, 2)) ' extract the sec |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2932 |
Post the line of code that contains the time (whether it be numeric or string). I have lost track as to whether it is in an array, or in variables, and as a string or is numeric. Don't post all your code - just the one line (or lines) that 'extract' the true time information! |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
It's from Geoff's GPS code Relevant section below [code]mins = GetMins(year, month, day, hour, min) mins = mins + TimeZone * 60 ' adjust for the timezone If mins < GetDST(year, dme, dhe) and mins > GetDST(year, dms, dhs) Then mins = mins + 60 'adjust for GMT (adds 1 hour) Line2 = GetTime$(mins) EndIf[/code] I just did PRINT GetTime$(mins) and the result was 10:09:48 So somehow I need to make H1, M2 and S2 get the digits from GetTime$(mins) I just tried several ways to do that and none of them worked I'm close but not close enough but thanks to you a lot closer than I was :) |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2932 |
From what you have sent, GetTime$(mins) is returning a correctly formatted string (i.e. with a leading zero for minutes in the example above). I am getting confused with what you are trying to do - earlier you implied wanting a leading zero for printing? You already have the time information already in GetTime$(mins) but if I understand you correctly then load a string$ such as wwTime$ with GetTime$(mins) and then extract the hours, minutes and seconds from wwTime$ into three strings such as wwH$, wwM$, wwS$ for printing as you need. Do this by using the Left$,mid$, right$ functions as you are doing already. IF you need the number from the time, then still do the above, but then set H1=val(wwH$), M2=val(wwM$), S2=val(wwS$). As a number, you don't need leading zeros ![]() Does this help you any further? WW |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |