Minggu, 18 Januari 2015

Bristol Digest, Vol 585, Issue 11

Send Bristol mailing list submissions to
bristol@mailman.lug.org.uk

To subscribe or unsubscribe via the World Wide Web, visit
https://mailman.lug.org.uk/mailman/listinfo/bristol
or, via email, send a message with subject or body 'help' to
bristol-request@mailman.lug.org.uk

You can reach the person managing the list at
bristol-owner@mailman.lug.org.uk

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Bristol digest..."


Today's Topics:

1. Re: Simple script query (DHT11 Sensor) (Peter Hemmings)


----------------------------------------------------------------------

Message: 1
Date: Sun, 18 Jan 2015 11:32:53 +0000
From: Peter Hemmings <peter@hemmings.eclipse.co.uk>
To: Bristol and Bath Linux User Group <bristol@mailman.lug.org.uk>
Subject: Re: [bristol] Simple script query (DHT11 Sensor)
Message-ID: <54BB99E5.5000600@hemmings.eclipse.co.uk>
Content-Type: text/plain; charset=windows-1252; format=flowed

On 17/01/15 17:36, Richard Stearn wrote:

snip
>
> It is a matter of how you represent the information in your program.
>
> 1.0 C = 10 deciC = 100 centiC = 1000 milliC
>

THAT, I should have known!!


> I have not studied what you are doing in detail, however you appear to
> have two values (humidity and temperature) both represented as a byte
> to the left of the decimal point and one byte to the right.

Correct

>
> The range of the above representation potentially covers from -128.99 to
> +127.99 or 0.00 to 255.99 (given the printf statement, only 0 .. 9 is used
> for the decimal part). So, if you multiply the LHS by 10 and add the RHS
> you have a value in deciC (10ths of a deg C).

I am not sure exactly how the print line works (see below).

Are the names limited by libraries etc, for example "deciC"
TEMP_OFFSET" and so must be exactly as typed?

Here are my assumptions:

>
> e.g.
>
> #define TEMP_OFFSET -27
> #define MULTIPLIER 10

Define variables

>
> int deciC;
>
> deciC = (dht11_val[2] * MULTIPLIER) + dht11_val[3];

calculate make the whole number byte into tenths and add the decimal
byte to give the total temperature in tenths of degrees C.

> deciC = deciC + (TEMP_OFFSET);

add tenths offset to deciC

> printf( "%d.%d\n", deciC / MULTIPLIER, deciC % MULTIPLIER );

Print the 2 values "deciC divided by 10 to give whole degrees, plus
"desic % MULTIPLIER".

How does this last part produce the decimal from deciC, and has it
limited significant places?

>
>
> If the RHS represented 0 .. 99 then use 100 as the multiplier and you have
> a value in centiC.
>
> Although the sensor is only rated for 0 .. 50 C, you might want to check
> what the output is when you stick it in the freezer. It might just curl
> up and report 0C, it might attempt to give a sane output. If it gives
> something sane then you will need to account for the sign in your
> manipulations.
>
> Or. You could do as Alex suggests and use a float or double representation.
> You will still need to account for sign of the temperature (if relevant).
>


Thanks for your perseverance

Regards


--
Peter H



------------------------------

_______________________________________________
Bristol mailing list
Bristol@mailman.lug.org.uk
https://mailman.lug.org.uk/mailman/listinfo/bristol

End of Bristol Digest, Vol 585, Issue 11
****************************************

Tidak ada komentar:

Posting Komentar