Place to put your Basic demos and examples

Moderator: Mmiscool

User avatar
By sandfrog
#34704 Hello, a little Temperature and Light Project,

I use a TNC75AOA I²C-Sensor and a A905014 on the ADC, Schematic and Board under http://www.grautier.com/wiki/doku.php?id=raumsensor-wlan, this is my first Project with the ESP and Basic ;)

Its Works !!!

Code: Select all' Variablen
'
addr = 73                 ' I2C-Adresse 7bit Dezimal fuer den TNC75
mwkp = 1.5                ' Positive Messwertkorrektur fuer den TNC75
mwkn = 0                  ' Negative "                              "
'
' ADC
'
ai adc
wprint ("Licht: ")
adc = adc / 10.24
wprint (adc)
wprint (" %")
wprint ("<br>")
'
' I2C -> TNC75
'
i2c.begin(addr)
i2c.write(0)
i2c.end()
i2c.requestfrom(addr,2)
lsb = i2c.read()
msb = i2c.read()
'
' I2C Daten Auswertung -> TNC75 +0 - +125c
'
wprint ("Temperatur: ")
tmp = lsb / 2
tmp = tmp + mwkp
tmp = tmp - mwkn
wprint (tmp)
wprint (" C")
wprint ("<br>")
end                 


A littel code to Readout from Bash:

sh wlansensor.sh <ip> <sensor>

Code: Select alldata=$(wget -qO- http://${1}/run)
data=$(wget -qO- http://${1}/index.html)

### Werte holen ###
case "$2" in
   licht)
    data=$(echo $data | grep Licht: | awk '{print $3}' | cut -d "." -f 1)
   ;;
   lichtdz)
    data=$(echo $data | grep Licht: | awk '{print $3}')
    data=$(echo "scale=1; $data / 10" | bc)
   ;;
   temp)
    data=$(echo $data | grep Temperatur: | awk '{print $5}')
    data=$(echo "${data%?}")
   ;;
   *)
     echo "Parameter:"
     echo "wlansensor.sh <ip> <sensor>"
     echo "<Sensor> = licht=Lichtsensor lichtdz=Lichtsensor/10, temp=Temperatur"
   ;;
esac


### Wert ausgeben ###
echo $data

exit 0     


Edit: Readout from Bash
Edit: ADC Code
Edit: i2c Code
Remove the BDC and use the hex() Funktion is Faster ;)
Last edited by sandfrog on Sat Jan 02, 2016 4:56 am, edited 7 times in total.
User avatar
By Mmiscool
#34709 Can you elaborate on the problem with the math and post an example with the smallest amount of code to demonstrate the problem.

Nice work by the way.
User avatar
By forlotto
#34785 @mmiscool
what he is saying it sounds like to me is that his math functions will allow him to do math for certain things.

i can not calc with two Numbers e.g. x.xx only whit full numbers or only one e.g. x.xx.


Ahhh there is no ability to do any math functions with decimals or float etc only whole numbers in his personal build of basic.

If I am reading him right.

@Snadfrog
Could you give mmiscool a simple example of an equation that is not working with the current build of basic.
I am assuming 10.00 + 10.00 is working but 10.25 + 10.99 is not working is this correct?
or are you saying that:
1.99 + 1.34 works because it is a sigle digit and a decimal works but a double digit 12.34 + 15.78 does not work?
One thing is for certain whole numbers seem to work just fine eg. 19 + 22 for instance.

Show a small bit of code that is not functioning within your code you might want to post this in the bugs section ass well as it may get addressed and seen easier as well do what you will just a suggestion.

Note I may be completely wrong here but to be honest I don't even understand your last comment made myself .

Just trying to help your situation here and possibly make things a bit easier to understand.

I am quite a bit German by genetics but know nothing about German language wish I could be of more help your project looks interesting a temp sensor over serial it appears.

Here is some info that may help:



float and double are floating binary point types. In other words, they represent a number like this:

10001.10010110011

The binary number and the location of the binary point are both encoded within the value.

decimal is a floating decimal point type. In other words, they represent a number like this:

12345.65789

Again, the number and the location of the decimal point are both encoded within the value – that's what makes decimal still a floating point type instead of a fixed point type.

The important thing to note is that humans are used to representing non-integers in a decimal form, and expect exact results in decimal representations; not all decimal numbers are exactly representable in binary floating point – 0.1, for example – so if you use a binary floating point value you'll actually get an approximation to 0.1. You'll still get approximations when using a floating decimal point as well – the result of dividing 1 by 3 can't be exactly represented, for example.

As for what to use when:

For values which are "naturally exact decimals" it's good to use decimal. This is usually suitable for any concepts invented by humans: financial values are the most obvious example, but there are others too. Consider the score given to divers or ice skaters, for example.

For values which are more artefacts of nature which can't really be measured exactly anyway, float/double are more appropriate. For example, scientific data would usually be represented in this form. Here, the original values won't be "decimally accurate" to start with, so it's not important for the expected results to maintain the "decimal accuracy". Floating binary point types are much faster to work with than decimals.


Precision is the main difference.

Float - 7 digits (32 bit)

Double-15-16 digits (64 bit)

Decimal -28-29 significant digits (128 bit)

Decimals have much higher precision and are usually used within financial applications that require a high degree of accuracy. Decimals are much slower (up to 20X times in some tests) than a double/float.

Decimals and Floats/Doubles cannot be compared without a cast whereas Floats and Doubles can. Decimals also allow the encoding or trailing zeros.

float flt = 1F/3;
double dbl = 1D/3;
decimal dcm = 1M/3;
Console.WriteLine("float: {0} double: {1} decimal: {2}", flt, dbl, dcm);

Result :

float: 0.3333333
double: 0.333333333333333
decimal: 0.3333333333333333333333333333