Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 11:23 29 Mar 2024 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 : MMBasic Float Format

     Page 1 of 2    
Author Message
Vetinari
Newbie

Joined: 28/04/2022
Location: Germany
Posts: 9
Posted: 08:37am 06 May 2022
Copy link to clipboard 
Print this post

Hello, I have a temperature sensor running at my Pico and display the value on a 1602 LCD. As far as I understood the standard value format is Float. The value is displayed e.g. as „20“ or „20.5“ or similar. How can I force the values to be displayed as „20.00“? Is there a Float format command?
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8516
Posted: 08:49am 06 May 2022
Copy link to clipboard 
Print this post

see str$ and/or format$ in the manual
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5648
Posted: 08:50am 06 May 2022
Copy link to clipboard 
Print this post

You can force the display to give a set number of decimal places, but it makes no difference whatsoever to the resolution or accuracy. That's dictated by your temperature sensor. You can't, for example, get a display of 20.01 degrees if your sensor has a resolution of 0.5 degrees.

STR$(tempvalue,1,2) will return a string of tempvalue to 2 decimal places. 20 will be returned as "20.00".
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5648
Posted: 08:51am 06 May 2022
Copy link to clipboard 
Print this post

Bah... beaten me to it again. Now I know why he gives brief replies!  ;)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Vetinari
Newbie

Joined: 28/04/2022
Location: Germany
Posts: 9
Posted: 06:26pm 06 May 2022
Copy link to clipboard 
Print this post

Hi Guys, thank you so much. Great support here!

This: str$(tempr(14), 1, 2) was exactly the simple solution I was looking for.

I already thought about doing some complicated string manipulation :)
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1028
Posted: 09:28pm 06 May 2022
Copy link to clipboard 
Print this post

  Vetinari said  

This: str$(tempr(14), 1, 2) was exactly the simple solution I was looking for.



Hi Vetinari

If the length of the resulting temperature value string (or any other string value) is important, e.g. , for formatting, I would use:

str$(tempr(14), 2, 2) or even str$(tempr(14), 3, 2) to keep them the same length if the value drops below 10.

I got caught out a week or so ago when a data value went from 3 digits to 4 digits. I had only expected it to stay below 3 digits. It upset the overall length of a data stream I was transmitting & also the displayed values.

In my case I went from STR$(Value, 4, 0) to STR$(Value, 5, 0), (No decimal value) & made the necessary software adjustments at the receiving end & displays where necessary.

Brian
Edited 2022-05-07 07:41 by Chopperp
ChopperP
 
Vetinari
Newbie

Joined: 28/04/2022
Location: Germany
Posts: 9
Posted: 05:26am 10 May 2022
Copy link to clipboard 
Print this post

Thanks ChopperP,

I think STR$(Value, 3, 2) is a good solution in my case. Unfortunately I get 9.555 or similar below 10. But 3 digits after the decimal point is ok.
How can I display „°C“?
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 1721
Posted: 05:59am 10 May 2022
Copy link to clipboard 
Print this post

In MMBasic the "Back Quote" key (to the left of "1" and above "Tab" on a US keyboard) produces the degree symbol.
So

TEXT x, y,  STR$(Value, 3, 2)+" `C"

should work. See the Fonts section of the manual.
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1028
Posted: 05:59am 10 May 2022
Copy link to clipboard 
Print this post

Hi Vetinari

You shouldn't get .555. The last 5 is probably from a previous value. You may have to check the overall formatting. The user manual shows how to add extra characters including a " " if necessary.

Just add "`C " after the print STR$() statement. The "`" should come up as a degree symbol if not already so.

(Adding  the `C as shown above may get rid of the extra digit but you may need the space on the end. Experiment a bit).

I think I have gotten things right.

Brian
ChopperP
 
Vetinari
Newbie

Joined: 28/04/2022
Location: Germany
Posts: 9
Posted: 09:20am 12 May 2022
Copy link to clipboard 
Print this post

Hi ChopperP,

I experimented a lot but without any results yet. I don't know if this has something to do with my german keyboard or the fact that I'm coding in MacOS Terminal, but I don't get any visible sign by pressing the key for degree in terminal. Here it works fine, Shift + the degree key produces "°", but in Terminal not. I tried also "\xdf" which should produce the degree sign but this didn't work as well.

Then I tried to test the whole thing in Windows but it seems there is no suitable driver in my Windows 10, because connecting the Pico does not produce a new USB device, only an unrecognizable device with a "no driver found" message.

Could you please tell me on which page of the manual I can found the String format rules? I couldn’t find them ..
Edited 2022-05-12 19:48 by Vetinari
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1028
Posted: 10:58am 12 May 2022
Copy link to clipboard 
Print this post

Hi Vetinari

I've only had a bit of a play with bare bones Picos using Windows with a US keyboard so I can't help much there.

You'll find the STR$ stuff on page 131 of the Pico manual or P97 of the PicoVGA version.

Searching for "STR$" in the PDF copies will also give other examples.

With Micromites etc, I have at times not worried about the degree symbol for Displays & just used "xxxC".

Brian
ChopperP
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5867
Posted: 11:40am 12 May 2022
Copy link to clipboard 
Print this post

The degree symbol will not show on serial/PC terminals. They don't use the MMBasic fonts.
VK7JH
MMedit   MMBasic Help
 
Vetinari
Newbie

Joined: 28/04/2022
Location: Germany
Posts: 9
Posted: 06:20am 14 May 2022
Copy link to clipboard 
Print this post

Hi guys,

Thank's for your help. I got stuck, so here is my full code. Maybe you have a last idea otherwise I give up.

10 Bitbang Lcd init gp4, gp5, gp6, gp7, gp16, gp17
20 Bitbang Lcd 1, 2, „Temperature:“
30 Do
40 Bitbang Lcd 2, 6, Str$(Tempr(14), 3, 2) + „ C“
50 Pause(300)
50 Loop
60 Option autorun on

The display should be able to display the ° sign.
In the manual under „Graphics commands and functions“is mentioned: In all fonts the back quote character
(60 hex or 96 decimal) has been replaced with the degree symbol. But when I’m writing Str$(Tempr(14), 3, 2) + Chr$(96) + „C“ I get a ` instead of the °

Alternatives should be „0xDF“ for Hex or „0b00100111“ for Bin (if I transferred it right (higher bits: 1101 and lower bits: 1111 according to the sign table of the display) but I don’t know how in these cases the syntax has to be. Whatever I tried I got an error message.
Edited 2022-05-14 16:31 by Vetinari
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8516
Posted: 06:56am 14 May 2022
Copy link to clipboard 
Print this post

I think we missed the fact you were using a 1602 LCD and not a graphics display. This display has its own character generator so all the information about back quotes is irrelevant. The 1602 has a degree symbol in its internal character ROM you will need to send the correct ascii code to access it. You can send any ascii code using the CHR$(number) function, in this case DF

e.g.

  Quote  Bitbang Lcd 2, 6, Str$(Tempr(14), 3, 2)+ chr$(&HDF)+"C"

Edited 2022-05-14 16:58 by matherp
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5867
Posted: 07:01am 14 May 2022
Copy link to clipboard 
Print this post

I missed the bit where you were sending to a 1602LCD.
That makes things different.
All the usual colour LCD panels normally used rely on MMBasic creating the bitmaps for the characters.
In those cases, the built-in fonts are used and the degree symbol is swapped for the backtick.

I haven't used a 1602 type display for a long time but if the data sheet says 0xDF is the degree symbol, the that is what you send.

Bitbang Lcd init gp4, gp5, gp6, gp7, gp16, gp17
Bitbang Lcd 1, 2, "Temperature:"
Do
Bitbang Lcd 2, 6, Str$(Tempr(14), 3, 2) + " "+chr$(&hDF)+"C"
Pause(300)
Loop


The chr(&hDF) is sending the required character.

Don't use OPTION AUTORUN ON until you are very confident that your program is working reliably. That saves a lot of grief.

Jim
Edit I type too slowly!
Edited 2022-05-14 17:02 by TassyJim
VK7JH
MMedit   MMBasic Help
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3163
Posted: 07:16am 14 May 2022
Copy link to clipboard 
Print this post

Firstly, you using some strange 8-bit characters as string delimiters.  They should be straight ASCII double quote characters.  Eg: "Temperature:".  Those strange characters will confuse MMBasic.

Probably you are using a word processor to edit the text and it is using these characters instead of ASCI double quotes.  Use a simple editor such as Notepad or the editor built into MMBasic.  They will not mess with your text.

Secondly, "60 hex has been replaced with the degree symbol" only applies to the fonts built into MMBasic for use with colour LCD display panels.  You are using a two line LCD module which has its own font built in.  You will have to consult its datasheet to determine if it implements the degree symbol.

Geoff
Edit: Others beat me to it.
Edited 2022-05-14 17:19 by Geoffg
Geoff Graham - http://geoffg.net
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 1721
Posted: 07:29am 14 May 2022
Copy link to clipboard 
Print this post

"Firstly, you using some strange 8-bit characters as string delimiters."

Those are the German equivalent of double quotes, If I remember my high school language classes from more than 1/2 century ago correctly.
 
Vetinari
Newbie

Joined: 28/04/2022
Location: Germany
Posts: 9
Posted: 07:33am 14 May 2022
Copy link to clipboard 
Print this post

OK, great, thank's a lot!
Now it's working as desired :)
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1028
Posted: 09:03am 14 May 2022
Copy link to clipboard 
Print this post

I just finished test wiring up a 40 x 2 LCD to my working Pico & got the same as Vetinari did initially.

I then read the new info above & also got the desired result when reprogrammed.

Thanks all.

Brian
ChopperP
 
Vetinari
Newbie

Joined: 28/04/2022
Location: Germany
Posts: 9
Posted: 10:18am 14 May 2022
Copy link to clipboard 
Print this post

I ran a loop through all available characters of the display and Chr$(223) is also working :)
 
     Page 1 of 2    
Print this page
© JAQ Software 2024