![]() |
Forum Index : Microcontroller and PC projects : Newie got a few questions
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Another what to most is probably a stupid question, but I'd like to be positive Pin 28 analog power - does this need to be connected to the +3.3v as well, or can I just use it to only power an analog device? (pot used in a speed sensor) Also pin 27 analog ground - does this need to be connected the the normal ground or can I use it as the ground for the analog device? The manual says it can be used as a clean ground but not sure if it "has" to be connected to the normal ground. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10070 |
Yes, but see the Colour Maximite circuit (pin 30) for a better arrangement Yes. To get good analogue readings makes sure 27 and 28 are decoupled very close to the pins |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thank you |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9493 |
There are no stupid questions, just stupid people who don't ask questions in the first place. ![]() ![]() ![]() All your questions so far are very valid ones - don't run yourself down. ![]() EDIT: Following up a little on your posts above, I never think it is a good idea to make MCU power pins a current path. That is, to feed power into one power pin, and suck power off at another power pin for something else. It seems to be generally accepted that all power and ground pins have to be connected together. That is just me though, but I expect that at least some other members here would also agree - I hope! ![]() The analogue ground circuit(10R + 100N to GND) that Geoff uses in his MM+ and Maximite series of units are certainly the way to go if you expect to be making any serious analogue measurements. Otherwise, I just directly connect AGND to the surrounding ground-plane, and A3v3 directly to standard rail voltage without the 10R and 100N. It does very much depend on what you plan to do. In other words, if you plan to use analogue measurements in your project, then use the 10R+100N. If you know you won't be using any analogue features, then just directly ground the AGND pin, and connect A3v3 directly to the supply voltage. If in any doubt as to what you are going to end up doing, then include the 10R+100N. Smoke makes things work. When the smoke gets out, it stops! |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Another one I've spent all day trying to work out for myself but cannot. How do I limit a number to say 2 decimal places? for instance using a gps in the location routine I only want 2 digits after the decimal place or say using a pressure sensor and it gives the pressure as say for instance 991.587 mB How can I round that down to one digit or 2? (obviously only if I don't need such a precise reading) |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 3999 |
You can arrange to display or print them that way but floating point numbers are NOT stored that way (i.e. they're not stored with a fixed number of decimals) and do not behave that way. Try the FORMAT$ function for now. John |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2927 |
Look at the STR$(a$,a,b) command where a = number of digits before decimal point, and b = number of digits after decimal point (for the string a$) This is for printing purposes only (for example when wishing to show data on the console screen (with PRINT) OR on data on a TFT screen (with TEXT)). So PRINT STR$(a$,3,2) will give you two decimal places (and three before the decimal point) on the console screen. More info on Page 77 of MicroMite User Manual v5.1 Is this what you're after?? WW |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thanks, thats perfect for now ![]() Has anyone used a GPS set the time on an RTC and periodically update it? would it be easy to sort it out (the code part) I know it's probably overkill, but I will have have a gps unit outside anyway so might as well make use of it and my reasoning for this (apart from I like being extremely precise when it comes to time) is the outside unit already will be streaming the time date and day of week, inside with a HC-12 (it's already done the calculations to get the day, DST and I won't have to worry about leap years or anything if it updates the RTC say once a day |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2927 |
Oh yes - many a time. Several ways to do it but the one I use most is this: Each time you get a 'valid' GPS record (and therefore have the GPS time & date info), simply set the TIME$ and DATE$ built into MMBASIC. Then every time you need to refresh the displayed time, simply use MMBasic's Time$/Date$ as required. This way, if you get an invalid GPS signal, the time and date will keep ticking along in MMBasic and hence your displayed time will be shown with only a slight 'drift' IF GPS signal remains invalid for extended time periods. As soon as next valid GPS signal received, then MMBasic will be set accurately once again. If you have an RTC too, then this could be set instead of MMBasic's Date$ & Time$. However, I have not included RTC's in my circuits with GPS Date/Time info as not needed mission critical time info in the instance that no GPS signal is present (for whatever reason) AND MMBasic has drifted too much. I have a uBlox 7 acting as a 'Time Server' in my house and it has run flawlessly for many months now. On the couple of power failures at my house, the GPS is lost, but the MMBasic still ticks happily along. As soon as power kicked back in then GPS re-syncs within a couple of minutes and I am none the wiser that the clock's time was wrong! Out of interest for others, another source of time I use is from a RPi/MicroMite combination; using the RPi's 'Date' command to then extract the data from the internet. Finally, an ESP8266 module can get the time/date info from an NTP server - I remember seeing code on TBS once but have not used this method myself. WW |
||||
HankR Senior Member ![]() Joined: 02/01/2015 Location: United StatesPosts: 209 |
Without having to generate strings, the classic way to do this in BASIC is to use the INT function. Here is a function called "ROUND" that will properly round a float value to two decimal places: FUNCTION ROUND(x)
ROUND = INT(x * 100 + 0.5) ROUND = ROUND/100 END FUNCTION Substitute 1000 for three decimal places, etc. The .5 term is to cause correct rounding up and not just a truncation of excess decimal places. There is a slightly more complex version of this algorithm that handles negative numbers just a little differently. This will get you started, though. |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
More confusion I've moved onto trying to set up the anemometer but I'm getting a problem straight away with this bit of code at the start [code] 'Constants Const wSpeedPin=6 Const wDirPin=8 'Define I/O 'Setpin redLed,Dout Setpin wSpeedPin, Intl,anemometerClick,Pullup [/code] When I try and run it comes up with this error [quote] [31] SetPin wSpeedPin, Intl,anemometerClick,Pullup Error: Pin 6 is reserved on startup [/quote] What am I doing wrong? |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Sorry IGNORE the previous - my stupidity I'm using an uM+ to test the code and hardware and didn't check the manual Pin 6 is one of the console pins |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
I do have a problem I cannot fix now [quote] [40] anem_count=0 Error: Variable or function not declared: ANEM_COUNT [/quote] My code has this near the start [code]' Global variables anem_count=0 anem_last=0 anem_min=1000 HGust=0 rain_count=0 rain_last=0 wCount=1 wdCount=1 [/code] I can't figure this one out myself |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2927 |
I'm not 100% sure about this, but maybe you can't have an underscore in the variable name. For now, rename all variables without the underscores and see what happens! WW |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2927 |
@geoffg I can't see anything in the User Manual regarding naming 'rules' for variables. If there are any length restrictions and/or character restrictions then it may be worth highlighting them on Page 33 ![]() |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10070 |
Yes you can I use them all the time. Have you got a statement "OPTION EXPLICIT" in your code? Probably yes if you copied anything off me ![]() That requires you to declare all variables before use e.g. DIM anem_count=0 This may seem like a pain but is much the best way of avoiding obscure bugs in your code |
||||
paceman Guru ![]() Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
@WW and @lew247 Underscore is OK - Page 48 of MMBasic V5.1 Manual, MMBasic Characteristics, Naming Conventions. Variable names and labels can start with an alphabetic character or underscore and can contain any alphabetic
or numeric character, the period (.) and the underscore (_). They may be up to 32 characters long. A variable name or a label must not be the same as a command or a function or one of the following keywords: THEN, ELSE, TO, STEP, FOR, WHILE, UNTIL, MOD, NOT, AND, OR, XOR, AS. Eg, step = 5 is illegal. Greg EDIT: You gotta be quick to beat Peter to the draw ![]() |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2927 |
Peter, Greg - Thanks for confirming you can use! Although its still worth mentioning on Page 33 in Manual to refer to Page 48 for naming conventions IMHO. That OPTION EXPLICIT gets me all the time ![]() |
||||
paceman Guru ![]() Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Yes, I'd agree with that. |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Weird - If I rem out or delete Option Explicit the program runs I have errors in the program as it's giving the wrong information and other things, BUT it runs no idea why! |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |