Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 15:43 07 Jul 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 : (MM) BackPack Thermometer

Author Message
ucontroller
Newbie

Joined: 23/01/2017
Location: Australia
Posts: 3
Posted: 03:35pm 02 Feb 2017
Copy link to clipboard 
Print this post

As a newbie to MMBasic, I am trying to program an LCD BackPack to accept input from a DS18B20 temp sensor to display temp in degrees C. My very inelegant program does work, but at the lowest resolution (0.5 degrees), when the temperature increments or decrements slightly, the new temperature overlays the old temperature ie: if the old temp displayed was 24.5 the new temp displays 2255 instead of 25.

By inserting a CLS instruction in the read loop, the display reads correctly, but the ensuing 2Hz strobing is very disconcerting.

Any suggestions would be greatly appreciated, and for those who might be interested, the following is my attempt at coding.

OPTION AUTORUN ON
OPTION EXPLICIT
OPTION DEFAULT NONE

COLOUR RGB(WHITE), RGB(BLACK)
FONT 1, 5

DO
TEXT MM.HRes/2, MM.VRes/2, STR$(TEMPR(24)) CM
LOOP

 
busa
Regular Member

Joined: 12/02/2015
Location: Australia
Posts: 81
Posted: 04:12pm 02 Feb 2017
Copy link to clipboard 
Print this post

Try adding a 10 second pause in the loop
eg. PAUSE 10000
 
crez

Senior Member

Joined: 24/10/2012
Location: Australia
Posts: 152
Posted: 04:25pm 02 Feb 2017
Copy link to clipboard 
Print this post

instead of STR$(TEMPR(24)) CM
perhaps " "+STR$(TEMPR(24))+" " CM
would work to make sure you overwrite all of the previous number.
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 04:29pm 02 Feb 2017
Copy link to clipboard 
Print this post

Hi ucontroller,

The trick I use is to add some blank spaces to the start and end of the 'data' you are displaying.

You are using cm justification so eg "22" is shorter in length than "22.5". So if 22.5 was displayed and then temp drops to 22 you need to clear the screen to the left AND right of "22"

So load temp into a 'holding' string such as t$ then make
t$=" "+t$+" ". Then use t$ in your TEXT statement

Hope that makes sense!

WW
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3282
Posted: 04:50pm 02 Feb 2017
Copy link to clipboard 
Print this post

Another trick is to use the formatting capabilities of the SRT$() function. For example STR$(TEMPR(24), 2, 1) says use two digits before the decimal point and one after. This means that the resulting string will always be four characters long.

So, 23 will display as "23.0" (ie, trailing zero) and 6.5 will display as " 6.5" (ie, leading space).
Geoff Graham - http://geoffg.net
 
ajkw
Senior Member

Joined: 29/06/2011
Location: Australia
Posts: 290
Posted: 09:30pm 02 Feb 2017
Copy link to clipboard 
Print this post

Formatting the output is one thing, stopping the strobing is another

so perhaps try


OPTION AUTORUN ON
OPTION EXPLICIT
OPTION DEFAULT NONE

COLOUR RGB(WHITE), RGB(BLACK)
FONT 1, 5

SETTICK 1000, OUTPUT, 1

DO
LOOP

SUB OUTPUT
TEXT MM.HRes/2, MM.VRes/2, STR$(TEMPR(24)) CM

'Or

TEXT MM.HRes/2, MM.VRes/2, STR$(TEMPR(24), 2, 1) 'with Geoff's formatting option

END SUB


Edited by ajkw 2017-02-04
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 10:03pm 02 Feb 2017
Copy link to clipboard 
Print this post

The strobing is only caused by the CLS - and this was just an attempt by ucontroller to 'fix' his issue.

The CLS is not required. Just use a 'formatting' method - two options posted above.

Some people like a 'static' position for the temperature displayed (i.e. think of the decimal point as being in the same position no matter what the temperature.

Others like fixed decimal places - even if it is .0

For both of the above, use Geoff's method.

For Centralising the temperature, then use CM and the leading, trailing space method.

Other options available . . . .

WW
 
busa
Regular Member

Joined: 12/02/2015
Location: Australia
Posts: 81
Posted: 11:23pm 02 Feb 2017
Copy link to clipboard 
Print this post

Try this, it works for me

Do
t=TEMPR(24) ' temp sensor connected to pin 24
text MM.HRes/2, MM.VRes/2,str$(t,2,2)+"`C",CM 'formatted to 2 decimal places
pause 3000 ' 3 second pause
Loop
Edited by busa 2017-02-04
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 12:15am 03 Feb 2017
Copy link to clipboard 
Print this post

Note that the example above from busa has a slight issue if the temperature reaches 100' or above!

The same issue will occur as in '100.00'C' is longer than say "90.00'C" so when the temp drops back below 100 then there will be part of the 'C' remaining on the right hand side.

Not that the temperature will likely be that high I guess - but just a 'trap' that people may fall into!

To fix the above, just use str$(t,3,2) - unless your temperature will exceed 1000'C

Bottom line is to 'know you data boundaries' and use the appropriate figure in the STR$ function to ensure any 'old data' is covered up by 'spaces'.



 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 07:15pm 03 Feb 2017
Copy link to clipboard 
Print this post

This is an example of how I update one of my LCD's in a Sub.

It will accommodate 10 lines of text.
Some are commented out.

It also has a LED box at the bottom that can change colour.

[Code] '==========================Update LCD Display=================================
Sub UpdateLCD

Text MM.HRes/40, MM.VRes*1/10, "Water Temp = ", LB, 2, 1, RGB(Green)
Text MM.HRes/40, MM.VRes*2/10, "Input Temp = ", LB, 2, 1, RGB(Cyan)
Text MM.HRes/40, MM.VRes*3/10, "Output Temp= ", LB, 2, 1, RGB(Red)
Text MM.HRes/40, MM.VRes*4/10, "Difference = ", LB, 2, 1, RGB(Blue)
Text MM.HRes/40, MM.VRes*5/10, "Air Temp = ", LB, 2, 1, RGB(Cyan)
Text MM.HRes/40, MM.VRes*6/10, "Panel Temp = ", LB, 2, 1, RGB(Magenta)
Text MM.HRes/40, MM.VRes*7/10, "Solar mVolts ", LB, 2, 1, RGB(Yellow)
'Text MM.HRes/40, MM.VRes*8/10, "Line8", LB, 2, 1, RGB(Magenta)
'Text MM.HRes/40, MM.VRes*9/10, "Line9", LB, 2, 1, RGB(Magenta)
'Text MM.HRes/40, MM.VRes*10/10, PumpStat, LB, 2, 1, RGB(Green)

Text MM.HRes*39/40, MM.VRes*1/10, Str$(TmpCur,4,1), RB, 2, 1, RGB(Green)
Text MM.HRes*39/40, MM.VRes*2/10, Str$(TmpInp,4,1), RB, 2, 1, RGB(Cyan)
Text MM.HRes*39/40, MM.VRes*3/10, Str$(TmpOut,4,1), RB, 2, 1, RGB(Red)
Text MM.HRes*39/40, MM.VRes*4/10, Str$(TmpOut-TmpInp,4,1), RB, 2, 1, RGB(Blue)
Text MM.HRes*39/40, MM.VRes*5/10, Str$(TmpAmb,4,1), RB, 2, 1, RGB(Cyan)
Text MM.HRes*39/40, MM.VRes*6/10, Str$(TmpPan,4,1), RB, 2, 1, RGB(Magenta)
Text MM.HRes*39/40, MM.VRes*7/10, Str$(SolarVolts,4,1), RB, 2, 1, RGB(Yellow)
Text MM.HRes/2, MM.VRes*8/10, Bin$(StatFlags,8), CB, 2, 1, RGB(White)
Text MM.HRes/2, MM.VRes*9/10, Time$, CB, 2, 1, RGB(White)
Text MM.HRes/2, MM.VRes*10/10, SecsTime(PumpRunTime), CB, 2, 1, RGB(Green)
'Circle 304,224,15,0,,,Led2Colour 'Right LED
RBOX 279,209,40,30,4,,Led2Colour


End Sub
[/code]
 
ucontroller
Newbie

Joined: 23/01/2017
Location: Australia
Posts: 3
Posted: 09:05pm 04 Feb 2017
Copy link to clipboard 
Print this post

Thank you to all who responded to my post - as a newbie I am at the "monkey see - monkey do" stage, and I learnt from every input. Ideally, I wanted the output to the LCD to be in the format: 27.5(degrees)C, where 'degrees' is the small circle used to denote degrees. Unfortunately, the only font I have available is font#1, and the back quote character only returns the back quote character.

In an attempt to download some different fonts, I somehow crashed my MMBasic, so took the opportunity to download the latest version of MMBasic.

Ideally, I need a simple tutorial on where to find suitable fonts, and how to get them into the library.

Once again, any input would be greatly appreciated.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10215
Posted: 10:35pm 04 Feb 2017
Copy link to clipboard 
Print this post

  Quote  Ideally, I need a simple tutorial on where to find suitable fonts, and how to get them into the library.


In the download of the firmware from Geoff's site look in the directory "Embedded Fonts" for the file "Embedded Fonts.pdf". This should give you everything you need
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 10:59pm 04 Feb 2017
Copy link to clipboard 
Print this post

Strongly recommend 'playing' with FontTweak.exe in the Folder downloadable from Geoff's website.

TassyJim wrote a really neat program to make ANY symbol available for use.

You could either edit a character that you are not using in the current FONT that you are using, OR set up a new font number with just a single character for the Degrees symbol. If you make a 'wide' character then you can incorporate the 'little circle' and the 'C' (or 'F') and then just print this as a single character at the required location.

Many ways to do this but hopefully this gives you some ideas to play with.

With the work Geoff, Peter, and Jim have done, it is possible to do so much with graphics now; and once you understand the concepts, it is all very easy to implement too.

Good luck, and keep us posted . . .

WW
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2949
Posted: 01:05am 05 Feb 2017
Copy link to clipboard 
Print this post

Hi ucontroler,

You might be able to get the effect by printing a smaller 'O' by using a smaller font size and positioning it higher.

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

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 02:39am 05 Feb 2017
Copy link to clipboard 
Print this post

The standard built-in font (font #1) for normal MMBasic has the degree symbol - it replaced the old 'filled-in square' some time ago, ASCII(90) i.e. ASCII(&H60). As of the latest firmware V5.03.02 font #6 also has the degree symbol at ASCII(90) - see Change Log.

Greg
 
ucontroller
Newbie

Joined: 23/01/2017
Location: Australia
Posts: 3
Posted: 06:56pm 05 Feb 2017
Copy link to clipboard 
Print this post

Once again, thanks for your interest and suggestions, and thanks to you, I have finally reached the stage that not only does my thermometer work properly, but I now understand why. Incidentally, I downloaded several different fonts, two of which were supposed to have the degree character in place of the back quote, but all I could get was the back quote character. Using FontTweak, I discovered the degree character in one particular font was ASCII(90), and using that as CHR$(90) in my text line, -Bingo!

Now that you have pointed me in the right direction, I will start building my own fonts, and hopefully start producing something more practical. javascript:AddSmileyIcon('')
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 07:59pm 05 Feb 2017
Copy link to clipboard 
Print this post

  Quote   The standard built-in font (font #1) for normal MMBasic has the degree symbol - it replaced the old 'filled-in square' some time ago, ASCII(90) i.e. ASCII(&H60). As of the latest firmware V5.03.02 font #6 also has the degree symbol at ASCII(90) - see Change Log.


CHR$(&H5A) just in case you're trying &H60
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025