Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 04:27 13 May 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Newie got a few questions

     Page 3 of 25    
Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10071
Posted: 05:41am 06 Mar 2016
Copy link to clipboard 
Print this post

  Quote  Weird - If I rem out or delete Option Explicit the program runs


This isn't weird, if you don't have OPTION EXPLICIT then the Micromite will create automatically a variable the first time it is used. This is why it is so important to use it in big programs. For example without OPTION EXPLICIT

myvariable = 1
...
...
...other code
...
newvariable=myvariabl*4

newvariable will be equal to 0.

Basic has automatically created the variable "myvariabl" which was actually a typo.

with OPTION EXPLICIT

DIM INTEGER myvariable = 1
...
...
...other code
...
newvariable=myvariabl*4

gives the "variable not declared error" so you can easily see your problem.

You will also see in my code I also use "OPTION DEFAULT NONE"

This means that I have to declare each variable as a string, integer, or float. Again this seems like adding work, but by doing it you know that the variable will always have the correct type for the use you want.
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 06:34am 06 Mar 2016
Copy link to clipboard 
Print this post

Thanks matherp,that explains it nice and easily
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 12:37pm 11 Mar 2016
Copy link to clipboard 
Print this post

Back again - (sorry)

How do I say this?

IF hour = 02 and if min = 05 then 'sync clock code goes here
end if
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6221
Posted: 02:01pm 11 Mar 2016
Copy link to clipboard 
Print this post

IF hour = 02 and min = 05 then
'sync clock code goes here
end if


You will also need some way to make sure that you only sync once per hour.
Otherwise you may end up setting the time hundreds of times during the one minute window.

How you do that will depend on the rest of your program flow.
One way is:
IF hour = 02 and min = 05 then
if lastsync <> hour then
'sync clock code goes here
lastsync = hour
end if
end if


It will only run the sync part once for each hour no matter how many times the routine is called.
lastsync needs to be a global variable if you are using a SUB or FUNCTION

Jim
VK7JH
MMedit
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 11:35pm 11 Mar 2016
Copy link to clipboard 
Print this post

Thanks TassyJim
I didn't realise that you could actually use IF AND THEN statements
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2927
Posted: 11:48pm 11 Mar 2016
Copy link to clipboard 
Print this post

A useful bit of advice about IF....AND...OR..... THEN ... Try and get in the habit of using brackets to separate the test conditions to eliminate potentially difficult to find bugs.

So it is 'useful' to do something like:

IF (....) AND ( (....) OR (...) ) THEN

NOTE: the brackets are not necessary in terms of logic providing you keep on top of things. However, I have been helping a few people recently where the lack of brackets was resulting in errors in the 'output'.

WW
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 03:07am 12 Mar 2016
Copy link to clipboard 
Print this post

  TassyJim said  You will also need some way to make sure that you only sync once per hour. Otherwise you may end up setting the time hundreds of times during the one minute window.
How you do that will depend on the rest of your program flow.
One way is:.....

Another option to Jim's method is to use the SETTICK command. The following will interrupt the main program hourly to do the syncing.

Greg

SETTICK 3600000,Syncsub
SUB Syncsub
.
.
END SUB

 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 03:21am 12 Mar 2016
Copy link to clipboard 
Print this post

I like the settick option, but I only want it to send the time once a day at 2:05AM
Saves me writing code on the indoor unit to change the time when DST/BST comes and goes when the outdoor unit with the gps already does that.

I might get it to only send the time on power up and then on the DST/BST change dates, not sure yet I'll decide later on when I start thinking about the indoor unit.
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 11:09am 12 Mar 2016
Copy link to clipboard 
Print this post

What is COM1: ENABLE ?
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2946
Posted: 01:33pm 12 Mar 2016
Copy link to clipboard 
Print this post

Hi Lew,

The enable is for use with RS485 operation which `can' use an enable pin..

You can safely ignore this for your RS232 work.

From memory it goes high when the TX wants to talk this goes to the enable pin on a RS485 driver chip.

The main use is it is possible to have multiple `slaves' on the same daisy chained line and they all listen and when they have something to say they can enable the TX line of the RS485 driver to send information back to the Master..

ie. They can all listen 100% of the time but only one can talk at a time.. Usually this is controlled by a POLLed protocol, the MASTER asks address 1 do you have something to send and waits, if no response after a set time then the MASTER asks address 2 do you have.... Etc etc..

Regards,

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 06:39am 13 Jul 2016
Copy link to clipboard 
Print this post

I'm stuck again

I want to print this
PRINT #2,Line2$,Line1$,wheading,wSpeed,wgust,hgust,mmrain,mmrain2,bme280_read_temp,bme280_read_pressure,hightemp,hightemp2,low temp,lowtemp2,bme280_read_humidity,UVindex,lux
to COM1 which I have enabled and it's working but it will not print to the com port.

[code]
print " Direction: ";STR$(wheading,3,2);" Degrees"
print " WindSpeed: ";STR$(wSpeed,3,2); " 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 " Pressure "; STR$(bme280_read_pressure(),3,2)" mB "
PRINT " Highest Temp ";STR$(hightemp) " C"
PRINT " Hi Temp Yesterday ";STR$(hightemp2) " C"
PRINT " Lowest Temp ";STR$(lowtemp) " C"
PRINT " LOW Temp Yesterday ";STR$(lowtemp2) " C"
PRINT " HUMIDITY "; bme280_read_humidity()"%"
print " UV Index: ",STR$(UVindex,3,2)
Print " Light ";STR$(lux,3,2);" LUX"[/code]

Error: A sub/fun has the same name: BME280_READ_TEMP

I've tried it with $ at the end of the name, I've tried it with brackets around it, and with $and brackets, but I cannot figure out what it doesn't like

IF I try and print Line2$,Line1$,wheading,wSpeed,wgust,hgust,mmrain,mmrain2 it works
it fails when I put the rest of the line in

EDIT:
I even tried this and it failed
[code]PRINT #2, STR$(bme280_read_pressure),STR$(bme280_read_temp),STR$(bme280_read_humidity)[/code]
Error: A sub/fun has the same name: BME280_READ_PRESSURE

I don't get why it fails when it will print to the console quite happily

EDIT 2:
I got it working by making 3 new "names" (variables?)
called temp, humidity and pressure
then did pressure = bme280_read_pressure, temp = bme280_read_temp and humidity = bme280_read_humidity
Then
PRINT #2, temp, pressure, humidity works

I also found out I need to put a "," between them so I can sort them on the indoor unit

I bet there is a much simpler and quicker way to do this, but I've no idea what it isEdited by lew247 2016-07-14
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 09:07am 25 Jul 2016
Copy link to clipboard 
Print this post

Back again with another question, which to me is hard but to others is probably simple/

I know how to get a specific result from a ?string"
an example is extracting the time from the $GPRMC a GPS

Is there a way to IGNORE the WHOLE string IF a part of the result includes "not found"

I want to do something, but ocassionally the result is the word "not found" instead of what I actually want.
This can or could happen at any of the parts I want to extract.

IF it was only in one position it "might" occur then I could obviously tell the MM to ignore it, but is there an "EASY" way to tell MM to ignore the whole string if any part of it contains the word "not found" ?

 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2927
Posted: 09:17am 25 Jul 2016
Copy link to clipboard 
Print this post

@lew247

Look at using the INSTR function.
Something like:

IF INSTR(GPS-In$,"not found")=0 THEN
'do your normal stuff here as GPS-In$ doesn't contain 'not found'
ELSE
'invalid data so do whatever
ENDIF


Hope this gives you an idea for proceeding

WW

EDIT: You may need to be careful of case sensitivity with 'Not Found', 'NOT FOUND', 'not found' etcEdited by WhiteWizzard 2016-07-26
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 09:22am 25 Jul 2016
Copy link to clipboard 
Print this post

Thanks Phil, I had no idea there was an ISTR function, I was looking in the command list
That's a great help, I should be able to do what I want now
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 12:50am 15 Aug 2016
Copy link to clipboard 
Print this post

Can anyone tell me WHY the voltage is being rounded up?

The code[code]DIM integer Batt2
DIM INTEGER BATT3
DIM INTEGER BATT
Batt2 = Pin(24)
Batt3 = Batt2 * 2
batt = Batt3
temp = tempr(3)
PRINT" Battery Voltage "; STR$(Pin(24))
PRINT " Battery Voltage ";STR$(batt);" V"
PRINT" Battery Voltage "; STR$(batt2);" V"
PRINT" Battery Voltage "; STR$(batt3);" V"[/code]

The printout{quote] Battery Voltage 1.78065
Battery Voltage 4 V
Battery Voltage 2 V
Battery Voltage 4 V[/quote]
Edited by lew247 2016-08-16
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2927
Posted: 12:54am 15 Aug 2016
Copy link to clipboard 
Print this post

Hi Lewis,

An integer has no decimal places. So 1.78065 is rounded up to the integer value of 2.

So Batt2 (integer) reads the pin and saves value of 2.
Batt3 = 2 * 2 (=4)
And hence Batt = Batt3 = 4

WW
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2927
Posted: 12:55am 15 Aug 2016
Copy link to clipboard 
Print this post

Sorry - forgot to mention; IF you change all three DIMs from INTEGER to FLOAT then you will get the decimal places.
Then use STR$ with the optional parameters to display the number of decimal places required

WW
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 12:59am 15 Aug 2016
Copy link to clipboard 
Print this post

Thanks WW
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 02:18am 15 Aug 2016
Copy link to clipboard 
Print this post

Another question

How can I do this?

If LOC(#3)<>0 then LOOP
If LOC(#2)<>0 then LOOP

The way I understand it is - if location 3 is empty it loops therefore not checking location 2

I'd like the program to keep checking both com ports while carrying on with the program and if it finds anything then come out of the respective loop into a sub
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9493
Posted: 02:29am 15 Aug 2016
Copy link to clipboard 
Print this post

Assuming you want to check #3 then #2, then you could do something like:

[Code]
Do
If LOC(#3)<>0 then
D$=INPUT$(LOC(#3),#3) 'Suck everything out of buffer so it is empty for next time
----- YOUR #3 code you want to happen if there is something in the buffer goes here -----
ENDIF
If LOC(#2)<>0 then
D$=INPUT$(LOC(#2),#2)
----- YOUR #2 code you want to happen if there is something in the buffer goes here -----
ENDIF
LOOP


That will go around in circles checking each COM port buffer, and then doing whatever needs to be done within the main DO/LOOP as it detects each one.

Provided the com port buffers are not time critical, it will deal with the data from handle #3 first, then handle #2 next.

This should do what you want, but I might have misunderstood how you want the code to flow.......Edited by Grogster 2016-08-16
Smoke makes things work. When the smoke gets out, it stops!
 
     Page 3 of 25    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025