<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Adafruit BME280 &amp; Sipy]]></title><description><![CDATA[<p dir="auto">Hi all</p>
<p dir="auto">I'm new with this board and I trying to  move all my project made in arduino to pycom siPy. But I'm triying to learn and overall read the sensors to build new project.</p>
<p dir="auto">Now I'm triying to read Adafruit BME280 or DFRobot BME280. See all what I did, and did not work:</p>
<p dir="auto">SiPy Firmware 1.20.2.r1<br />
Library <a href="http://BME280.py" target="_blank" rel="noopener noreferrer nofollow ugc">BME280.py</a></p>
<pre><code>import time
from ustruct import unpack, unpack_from
from array import array

# BME280 default address.
BME280_I2CADDR = 0x77

# Operating Modes
BME280_OSAMPLE_1 = 1
BME280_OSAMPLE_2 = 2
BME280_OSAMPLE_4 = 3
BME280_OSAMPLE_8 = 4
BME280_OSAMPLE_16 = 5

BME280_REGISTER_CONTROL_HUM = 0xF2
BME280_REGISTER_STATUS = 0xF3
BME280_REGISTER_CONTROL = 0xF4

MODE_SLEEP = const(0)
MODE_FORCED = const(1)
MODE_NORMAL = const(3)


class BME280:

    def __init__(self,
                 mode=BME280_OSAMPLE_8,
                 address=BME280_I2CADDR,
                 i2c=None,
                 **kwargs):
        # Check that mode is valid.
        if mode not in [BME280_OSAMPLE_1, BME280_OSAMPLE_2, BME280_OSAMPLE_4,
                        BME280_OSAMPLE_8, BME280_OSAMPLE_16]:
            raise ValueError(
                'Unexpected mode value {0}. Set mode to one of '
                'BME280_OSAMPLE_1, BME280_OSAMPLE_2, BME280_OSAMPLE_4,'
                'BME280_OSAMPLE_8, BME280_OSAMPLE_16'.format(mode))
        self._mode = mode
        self.address = address
        if i2c is None:
            raise ValueError('An I2C object is required.')
        self.i2c = i2c
        self.__sealevel = 101325

        # load calibration data
        dig_88_a1 = self.i2c.readfrom_mem(self.address, 0x88, 26)
        dig_e1_e7 = self.i2c.readfrom_mem(self.address, 0xE1, 7)
        self.dig_T1, self.dig_T2, self.dig_T3, self.dig_P1, \
            self.dig_P2, self.dig_P3, self.dig_P4, self.dig_P5, \
            self.dig_P6, self.dig_P7, self.dig_P8, self.dig_P9, \
            _, self.dig_H1 = unpack("&lt;HhhHhhhhhhhhBB", dig_88_a1)

        self.dig_H2, self.dig_H3, self.dig_H4,\
            self.dig_H5, self.dig_H6 = unpack("&lt;hBbhb", dig_e1_e7)
        # unfold H4, H5, keeping care of a potential sign
        self.dig_H4 = (self.dig_H4 * 16) + (self.dig_H5 &amp; 0xF)
        self.dig_H5 //= 16

        self.t_fine = 0

        # temporary data holders which stay allocated
        self._l1_barray = bytearray(1)
        self._l8_barray = bytearray(8)
        self._l3_resultarray = array("i", [0, 0, 0])

        self._l1_barray[0] = self._mode &lt;&lt; 5 | self._mode &lt;&lt; 2 | MODE_SLEEP
        self.i2c.writeto_mem(self.address, BME280_REGISTER_CONTROL,
                             bytearray([0x3c | MODE_SLEEP]))

    def read_raw_data(self, result):
        """ Reads the raw (uncompensated) data from the sensor.

            Args:
                result: array of length 3 or alike where the result will be
                stored, in temperature, pressure, humidity order
            Returns:
                None
        """

        self._l1_barray[0] = self._mode
        self.i2c.writeto_mem(self.address, BME280_REGISTER_CONTROL_HUM,
                             self._l1_barray)
        self._l1_barray[0] = self._mode &lt;&lt; 5 | self._mode &lt;&lt; 2 | MODE_FORCED
        self.i2c.writeto_mem(self.address, BME280_REGISTER_CONTROL,
                             self._l1_barray)

        # Wait for conversion to complete
        while self.i2c.readfrom_mem(self.address, BME280_REGISTER_STATUS, 1)[0] &amp; 0x08:
            time.sleep_ms(10)

        # burst readout from 0xF7 to 0xFE, recommended by datasheet
        self.i2c.readfrom_mem_into(self.address, 0xF7, self._l8_barray)
        readout = self._l8_barray
        # pressure(0xF7): ((msb &lt;&lt; 16) | (lsb &lt;&lt; 8) | xlsb) &gt;&gt; 4
        raw_press = ((readout[0] &lt;&lt; 16) | (readout[1] &lt;&lt; 8) | readout[2]) &gt;&gt; 4
        # temperature(0xFA): ((msb &lt;&lt; 16) | (lsb &lt;&lt; 8) | xlsb) &gt;&gt; 4
        raw_temp = ((readout[3] &lt;&lt; 16) | (readout[4] &lt;&lt; 8) | readout[5]) &gt;&gt; 4
        # humidity(0xFD): (msb &lt;&lt; 8) | lsb
        raw_hum = (readout[6] &lt;&lt; 8) | readout[7]

        result[0] = raw_temp
        result[1] = raw_press
        result[2] = raw_hum

    def read_compensated_data(self, result=None):
        """ Reads the data from the sensor and returns the compensated data.

            Args:
                result: array of length 3 or alike where the result will be
                stored, in temperature, pressure, humidity order. You may use
                this to read out the sensor without allocating heap memory

            Returns:
                array with temperature, pressure, humidity. Will be the one
                from the result parameter if not None
        """
        self.read_raw_data(self._l3_resultarray)
        raw_temp, raw_press, raw_hum = self._l3_resultarray
        # temperature
        var1 = (((raw_temp // 8) - (self.dig_T1 * 2)) * self.dig_T2) // 2048
        var2 = (raw_temp // 16) - self.dig_T1
        var2 = (((var2 * var2) // 4096) * self.dig_T3) // 16384
        self.t_fine = var1 + var2
        temp = (self.t_fine * 5 + 128) // 256

        # pressure
        var1 = self.t_fine - 128000
        var2 = var1 * var1 * self.dig_P6
        var2 = var2 + ((var1 * self.dig_P5) &lt;&lt; 17)
        var2 = var2 + (self.dig_P4 &lt;&lt; 35)
        var1 = (((var1 * var1 * self.dig_P3) &gt;&gt; 8) +
                ((var1 * self.dig_P2) &lt;&lt; 12))
        var1 = (((1 &lt;&lt; 47) + var1) * self.dig_P1) &gt;&gt; 33
        if var1 == 0:
            pressure = 0
        else:
            p = ((((1048576 - raw_press) &lt;&lt; 31) - var2) * 3125) // var1
            var1 = (self.dig_P9 * (p &gt;&gt; 13) * (p &gt;&gt; 13)) &gt;&gt; 25
            var2 = (self.dig_P8 * p) &gt;&gt; 19
            pressure = ((p + var1 + var2) &gt;&gt; 8) + (self.dig_P7 &lt;&lt; 4)

        # humidity
        h = self.t_fine - 76800
        h = (((((raw_hum &lt;&lt; 14) - (self.dig_H4 &lt;&lt; 20) -
                (self.dig_H5 * h)) + 16384) &gt;&gt; 15) *
             (((((((h * self.dig_H6) &gt;&gt; 10) *
                (((h * self.dig_H3) &gt;&gt; 11) + 32768)) &gt;&gt; 10) + 2097152) *
              self.dig_H2 + 8192) &gt;&gt; 14))
        h = h - (((((h &gt;&gt; 15) * (h &gt;&gt; 15)) &gt;&gt; 7) * self.dig_H1) &gt;&gt; 4)
        h = 0 if h &lt; 0 else h
        h = 419430400 if h &gt; 419430400 else h
        humidity = h &gt;&gt; 12

        if result:
            result[0] = temp
            result[1] = pressure
            result[2] = humidity
            return result

        return array("i", (temp, pressure, humidity))

    @property
    def sealevel(self):
        return self.__sealevel

    @sealevel.setter
    def sealevel(self, value):
        if 300 &lt; value &lt; 1200:  # just ensure some reasonable value
            self.__sealevel = value

    @property
    def altitude(self):
        '''
        Altitude in m.
        '''
        from math import pow
        try:
            p = 44330 * (1.0 - pow((self.read_compensated_data()[1] / 256) /
                                   self.__sealevel, 0.1903))
        except:
            p = 0.0
        return p

    @property
    def dew_point(self):
        """
        Compute the dew point temperature for the current Temperature
        and Humidity measured pair
        """
        from math import log
        t, p, h = self.read_compensated_data()
        t /= 100
        h /= 1024
        h = (log(h, 10) - 2) / 0.4343 + (17.62 * t) / (243.12 + t)
        return (243.12 * h / (17.62 - h)) * 100

    @property
    def values(self):
        """ human readable values """

        t, p, h = self.read_compensated_data()

        p = p / 256

        h = h / 1024
        return ("{}C".format(t / 100), "{:.02f}hPa".format(p/100),
                "{:.02f}%".format(h))

</code></pre>
<p dir="auto"><a href="http://boot.py" target="_blank" rel="noopener noreferrer nofollow ugc">boot.py</a> no data<br />
<a href="http://main.py" target="_blank" rel="noopener noreferrer nofollow ugc">main.py</a></p>
<pre><code>from machine import I2C
import bme280
i2c = I2C(0,I2C.MASTER, baudrate=100000)
bme = bme280.BME280(address=BME280_I2CADDR, i2c=i2c)
print('Temp = ', bme.temperature())

</code></pre>
<p dir="auto">But the error is:</p>
<pre><code>Traceback (most recent call last):
  File "main.py", line 4, in &lt;module&gt;
NameError: name 'BME280_I2CADDR' isn't defined
</code></pre>
<p dir="auto">Anybody knows what is happening?</p>
<p dir="auto">Thank's</p>
<p dir="auto">Eduard</p>
]]></description><link>https://forum.pycom.io/topic/6516/adafruit-bme280-sipy</link><generator>RSS for Node</generator><lastBuildDate>Thu, 12 Nov 2026 16:18:20 GMT</lastBuildDate><atom:link href="https://forum.pycom.io/topic/6516.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 01 Nov 2020 20:14:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Adafruit BME280 &amp; Sipy on Mon, 02 Nov 2020 20:15:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/robert-hh" aria-label="Profile: robert-hh">@<bdi>robert-hh</bdi></a><br />
I just applied the configuration from the library and now it works. I'm using Adafruit and DFrobot BME280 and changing the address to 77 they work perfect, Dew point only works on adafruit , very strange</p>
<p dir="auto">Thanks again for your help</p>
]]></description><link>https://forum.pycom.io/post/35326</link><guid isPermaLink="true">https://forum.pycom.io/post/35326</guid><dc:creator><![CDATA[ecabanas]]></dc:creator><pubDate>Mon, 02 Nov 2020 20:15:50 GMT</pubDate></item><item><title><![CDATA[Reply to Adafruit BME280 &amp; Sipy on Sun, 01 Nov 2020 20:29:31 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ecabanas" aria-label="Profile: ecabanas">@<bdi>ecabanas</bdi></a> said in <a href="/post/35312">Adafruit BME280 &amp; Sipy</a>:</p>
<blockquote>
<p dir="auto">bme = bme280.BME280(address=BME280_I2CADDR, i2c=i2c)</p>
</blockquote>
<p dir="auto">You have to write:</p>
<p dir="auto">bme = bme280.BME280(address=bme280.BME280_I2CADDR, i2c=i2c)</p>
<p dir="auto">If the I2c address of the board is 0x77, you do not have to specify it, since that is the default address of the library,</p>
<p dir="auto">Edit: This is the lib that I am using: <a href="https://github.com/robert-hh/BME280" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/robert-hh/BME280</a></p>
]]></description><link>https://forum.pycom.io/post/35313</link><guid isPermaLink="true">https://forum.pycom.io/post/35313</guid><dc:creator><![CDATA[robert-hh]]></dc:creator><pubDate>Sun, 01 Nov 2020 20:29:31 GMT</pubDate></item></channel></rss>