Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. A tiny BME node - BME280 on ATtiny85

A tiny BME node - BME280 on ATtiny85

Scheduled Pinned Locked Moved My Project
28 Posts 8 Posters 493 Views 12 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • icebobI Offline
    icebobI Offline
    icebob
    wrote on last edited by
    #15

    @fabyte awesome job. I'm working something similar. Could you share your main program code?

    1 Reply Last reply
    0
    • fabyteF Offline
      fabyteF Offline
      fabyte
      wrote on last edited by
      #16

      @icebob Sure, no thing:

      // -----------------------------------------------------------------------------
      // missing defines
      // -----------------------------------------------------------------------------
      #define SIGRD   RSIG    // Signature Row from Store Program Memory Control and Status Register
      #define EIFR    GIFR    // External/General Interrupt Flag Register
      #define WDTCSR  WDTCR   // WDT Control Register
      // #define TCCR1A TCCR1
      // #define TIFR1 TIFR
      extern void serialEventRun(void) __attribute__((weak));
      
      // -----------------------------------------------------------------------------
      // Configuration
      // -----------------------------------------------------------------------------
      
      // Disable features for reduzing memory footprint
      #define MY_SPLASH_SCREEN_DISABLED
      #define MY_DISABLE_RAM_ROUTING_TABLE_FEATURE
      #define MY_DISABLED_SERIAL
      
      #define MY_NODE_ID          0 
      #define MY_PASSIVE_NODE
      #define MY_DISABLE_REMOTE_RESET
      
      // Enable and select radio type attached
      #define MY_RADIO_RF24
      #define MY_RF24_CE_PIN      NOT_A_PIN
      #define MY_RF24_CS_PIN      4
      
      // BME280 settings
      #define BME_CS_PIN          3
      #define TINY_BME280_SPI
      
      // Sleep Time between reads (in milliseconds)
      #define SLEEP_TIME          120000
      
      // -----------------------------------------------------------------------------
      // MySensors
      // -----------------------------------------------------------------------------
      #include <MySensors.h>
      
      #define CHILD_ID_BME_T    1
      #define CHILD_ID_BME_H    2
      #define CHILD_ID_BME_P    3
      #define CHILD_ID_VOLTAGE  4
      
      MyMessage bmeTempMsg(CHILD_ID_BME_T, V_TEMP);
      MyMessage bmeHumMsg(CHILD_ID_BME_H, V_HUM);
      MyMessage bmePressMsg(CHILD_ID_BME_P, V_PRESSURE);
      MyMessage voltageMsg(CHILD_ID_VOLTAGE, V_VOLTAGE);
      
      // -----------------------------------------------------------------------------
      // BME 280
      // -----------------------------------------------------------------------------
      #define TINY_BME280_SPI_CLOCK   1000000 // 1 MHz
      #include <TinyBME280.h>
      tiny::BME280 bme280;
      
      // -----------------------------------------------------------------------------
      // Implementation
      // -----------------------------------------------------------------------------
      void setupSensor()
      {
      
        bme280.beginSPI(BME_CS_PIN);
      
        // read once to erase initial values
        delay(10);
        bme280.setMode(tiny::Mode::FORCED);
      }
      
      void readAndSendSensorValues()
      {
        bme280.setMode(tiny::Mode::FORCED);
      
        delay(8);
        while(bme280.isMeasuring())
          delay(2); //Hang out while sensor completes the reading
      
        send(bmeTempMsg.set(bme280.readFixedTempC()));
        send(bmeHumMsg.set(bme280.readFixedHumidity()));
        send(bmePressMsg.set(bme280.readFixedPressure()));
      }
      
      void readAndSendBatteryVoltage()
      {
        send(voltageMsg.set(hwCPUVoltage()));
      }
      
      // -----------------------------------------------------------------------------
      // Framework Funktions
      // -----------------------------------------------------------------------------
      void setup()
      {
        setupSensor();
      }
      
      void presentation()
      {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("ATtiny Sensor", "1.0");
      
        // Register all sensors to gateway (they will be created as child devices)
        present(CHILD_ID_BME_T, S_TEMP);
        present(CHILD_ID_BME_H, S_HUM);
        present(CHILD_ID_BME_P, S_BARO);
        present(CHILD_ID_VOLTAGE, S_MULTIMETER);
      }
      
      void loop()
      {
        readAndSendSensorValues();
        readAndSendBatteryVoltage();
      
        sleep(SLEEP_TIME);
      }
      
      // -----------------------------------------------------------------------------
      

      Don't forget to set your MY_NODE_ID appropriatly.
      BME values are sent as fixed point values and are converted to float on controller side.

      1 Reply Last reply
      0
      • fabyteF Offline
        fabyteF Offline
        fabyte
        wrote on last edited by fabyte
        #17

        Last year I began with the work on the SMD version of the tiny BME node. See pictures here:

        20200624_110630_small.jpg
        20200624_110645_small.jpg

        Problem was that the radio isn't transmitting very reliable and I think I broke it while programming the ATTINY (used 5V instead of 3.3V). I received a few values so I know it is working but I didn't have time to fix it properly which would mean just create a new one.

        Nca78N 1 Reply Last reply
        1
        • fabyteF fabyte

          Last year I began with the work on the SMD version of the tiny BME node. See pictures here:

          20200624_110630_small.jpg
          20200624_110645_small.jpg

          Problem was that the radio isn't transmitting very reliable and I think I broke it while programming the ATTINY (used 5V instead of 3.3V). I received a few values so I know it is working but I didn't have time to fix it properly which would mean just create a new one.

          Nca78N Offline
          Nca78N Offline
          Nca78
          Hardware Contributor
          wrote on last edited by
          #18

          @fabyte said in A tiny BME node - BME280 on ATtiny85:

          (used 5V instead of 3.3V).

          Usually after doing that the radio still seems to work, but it's not reliable anymore and it is gobbling a lot of power. It is quite vicious as you think it is still working, but the sensor dies quickly...

          1 Reply Last reply
          0
          • chamroeun ouC Offline
            chamroeun ouC Offline
            chamroeun ou
            wrote on last edited by
            #19

            Hi, I try to compile your code change for Mysensors against my Attiny85 but it failed with many errors like

            yHwAVR.cpp:74:2: error: 'EIFR' was not declared in this scope
              EIFR = _BV(interrupt);
            MyHwAVR.cpp:93:26: error: 'WDTCSR' was not declared in this scope
              const uint8_t WDTsave = WDTCSR;
            ...
            

            Please note that my environment is AttinyCore.

            How is your sensors after 1 year? What is your recommendation?

            1 Reply Last reply
            0
            • fabyteF Offline
              fabyteF Offline
              fabyte
              wrote on last edited by
              #20

              Hi @chamroeun-ou
              please try and add the following on top of your main.cpp:

              // -----------------------------------------------------------------------------
              // missing defines
              // -----------------------------------------------------------------------------
              #define SIGRD   RSIG    // Signature Row from Store Program Memory Control and Status Register
              #define EIFR    GIFR    // External/General Interrupt Flag Register
              #define WDTCSR  WDTCR   // WDT Control Register
              // #define TCCR1A TCCR1
              // #define TIFR1 TIFR
              extern void serialEventRun(void) __attribute__((weak));
              
              1 Reply Last reply
              0
              • chamroeun ouC Offline
                chamroeun ouC Offline
                chamroeun ou
                wrote on last edited by
                #21

                Ok, now it works with your BME-i2c code. not enough memory maybe due to update in AttinyCore which is bigger than your version. I think memory limit is the challenge.

                1 Reply Last reply
                0
                • chamroeun ouC Offline
                  chamroeun ouC Offline
                  chamroeun ou
                  wrote on last edited by
                  #22

                  To use Attiny, i think there's a need to optimize Mysensor for it as Mysensor consumes the most space of the 8K.

                  BearWithBeardB 1 Reply Last reply
                  0
                  • chamroeun ouC chamroeun ou

                    To use Attiny, i think there's a need to optimize Mysensor for it as Mysensor consumes the most space of the 8K.

                    BearWithBeardB Offline
                    BearWithBeardB Offline
                    BearWithBeard
                    wrote on last edited by BearWithBeard
                    #23

                    @chamroeun-ou I think it's actually quite fascinating that you can fit MySensors in less than 5kb of memory! Consider all the things the library does behind the scenes and that this includes all the required dependencies.

                    Try using your BME280 on the SPI bus, which you need anyway for the transceiver. This should shave off about 800 bytes or so. It still fits on ATtinys with 8kb flash using the example sketch posted above (direct link).

                    Processing attiny85 (platform: atmelavr; board: attiny85; framework: arduino)
                    -------------------------------------------------------------------------------------
                    PLATFORM: Atmel AVR (3.3.0) > Generic ATtiny85
                    HARDWARE: ATTINY85 8MHz, 512B RAM, 8KB Flash
                    PACKAGES:
                     - framework-arduino-avr-attiny 1.5.2
                     - toolchain-atmelavr 1.70300.191015 (7.3.0)
                    RAM:   [=======   ]  65.8% (used 337 bytes from 512 bytes)
                    Flash: [==========]  97.2% (used 7960 bytes from 8192 bytes)
                    
                    1 Reply Last reply
                    1
                    • chamroeun ouC Offline
                      chamroeun ouC Offline
                      chamroeun ou
                      wrote on last edited by
                      #24

                      @BearWithBeard , it's not my code. it is based on @fabyte 's code. Actually, I want to use SHT30 I2C but space is the biggest challenge.

                      There's a NRFLite(https://github.com/dparson55/NRFLite) which I think it may save space and can also work with 2 PIN for NRF24 as its created for Attiny but it may not work MySensors without code change.

                      My decision now is to use Attiny167 instead but the problem now is it's not working on Mysensors. I try this approach but not work https://github.com/mysensors/MySensors/pull/1485.

                      BearWithBeardB 1 Reply Last reply
                      0
                      • chamroeun ouC chamroeun ou

                        @BearWithBeard , it's not my code. it is based on @fabyte 's code. Actually, I want to use SHT30 I2C but space is the biggest challenge.

                        There's a NRFLite(https://github.com/dparson55/NRFLite) which I think it may save space and can also work with 2 PIN for NRF24 as its created for Attiny but it may not work MySensors without code change.

                        My decision now is to use Attiny167 instead but the problem now is it's not working on Mysensors. I try this approach but not work https://github.com/mysensors/MySensors/pull/1485.

                        BearWithBeardB Offline
                        BearWithBeardB Offline
                        BearWithBeard
                        wrote on last edited by
                        #25

                        @chamroeun-ou I'm sorry, I was under the impression that you want to rebuild the OP's project, since there was no mention of different sensors etc.

                        Regarding the ATtiny85: How would you have used both SPI and I2C together in the first place? Both are implemented through a single USI and have to share the same OI pins.

                        Regarding the ATtiny167: I don't think I have an ATtiny167 at hand currently, so I can't test if it'll actually work, but the OP's example code compiled fine for me. I just had to comment out the the external interrupt flag register redefinition (//#define EIFR GIFR), since it is implemented in the same way it is on the ATmega328P for example.

                        Processing attiny167 (platform: atmelavr; board: attiny167; framework: arduino)
                        -------------------------------------------------------------------------------
                        PLATFORM: Atmel AVR (3.3.0) > Generic ATtiny167
                        HARDWARE: ATTINY167 8MHz, 512B RAM, 16KB Flash
                        PACKAGES:
                         - framework-arduino-avr-attiny 1.5.2
                         - toolchain-atmelavr 1.70300.191015 (7.3.0)
                        RAM:   [=======   ]  65.0% (used 333 bytes from 512 bytes)
                        Flash: [=====     ]  50.5% (used 8274 bytes from 16384 bytes)
                        

                        The ATtiny167 has dedicated SPI and I2C interfaces and IO pins, so it should be possible to use it as a MySensors node with an SHTC30 sensor. There's plenty of free space, too.

                        1 Reply Last reply
                        0
                        • chamroeun ouC Offline
                          chamroeun ouC Offline
                          chamroeun ou
                          wrote on last edited by
                          #26

                          @BearWithBeard How do you get it compiled using Mysensors? which code you based on? I got many compiled errors:

                          In function 'void hwPowerDown(uint8_t)':
                          ../MySensors/hal/architecture/AVR/MyHwAVR.cpp:93:26: error: 'WDTCSR' was not declared in this scope
                          const uint8_t WDTsave = WDTCSR;
                          ^~~~~~
                          
                          /../MySensors/hal/architecture/AVR/MyHwAVR.cpp: In function 'uint16_t hwCPUFrequency()':
                          /../MySensors/hal/architecture/AVR/MyHwAVR.cpp:305:26: error: 'WDTCSR' was not declared in this scope
                          const uint8_t WDTsave = WDTCSR;
                          ^~~~~~
                          ..MySensors/hal/architecture/AVR/MyMainAVR.cpp: In function 'int main()':
                          Arduino/libraries/MySensors/hal/architecture/AVR/MyMainAVR.cpp:34:7: error: 'serialEventRun' was not declared in this scope
                          if (serialEventRun) {`
                          

                          For your question on SPI+IIC on Attiny85, someone has done it successfully by using NRF24 3 PIN so it's left with 2 PIN and use SoftWire library to force BME t use those two PINs.

                          Another sketch that I come across is like this: https://github.com/chaeplin/esp8266_and_arduino/tree/master/_51-attiny85-nrf24-lcd-getntp
                          But I can't get it to work maybe due to some pullup resistor or something.

                          BearWithBeardB 1 Reply Last reply
                          0
                          • chamroeun ouC chamroeun ou

                            @BearWithBeard How do you get it compiled using Mysensors? which code you based on? I got many compiled errors:

                            In function 'void hwPowerDown(uint8_t)':
                            ../MySensors/hal/architecture/AVR/MyHwAVR.cpp:93:26: error: 'WDTCSR' was not declared in this scope
                            const uint8_t WDTsave = WDTCSR;
                            ^~~~~~
                            
                            /../MySensors/hal/architecture/AVR/MyHwAVR.cpp: In function 'uint16_t hwCPUFrequency()':
                            /../MySensors/hal/architecture/AVR/MyHwAVR.cpp:305:26: error: 'WDTCSR' was not declared in this scope
                            const uint8_t WDTsave = WDTCSR;
                            ^~~~~~
                            ..MySensors/hal/architecture/AVR/MyMainAVR.cpp: In function 'int main()':
                            Arduino/libraries/MySensors/hal/architecture/AVR/MyMainAVR.cpp:34:7: error: 'serialEventRun' was not declared in this scope
                            if (serialEventRun) {`
                            

                            For your question on SPI+IIC on Attiny85, someone has done it successfully by using NRF24 3 PIN so it's left with 2 PIN and use SoftWire library to force BME t use those two PINs.

                            Another sketch that I come across is like this: https://github.com/chaeplin/esp8266_and_arduino/tree/master/_51-attiny85-nrf24-lcd-getntp
                            But I can't get it to work maybe due to some pullup resistor or something.

                            BearWithBeardB Offline
                            BearWithBeardB Offline
                            BearWithBeard
                            wrote on last edited by
                            #27

                            @chamroeun-ou I used the example sketch from the OP further up in this thread (direct link). The relevant defines are also mentioned in the software section of the first post.

                            You need to add the following to your sketch to get rid of the compiler errors:

                            #define WDTCSR  WDTCR   // WDT Control Register
                            extern void serialEventRun(void) __attribute__((weak));
                            

                            Note that ATtinys aren't officially supported by MySensors. Although they may work fine in many instances, you are basically on your own if you run into issues. There simply aren't many people who use MySensors on ATtinys.

                            You're much more likely to find help if you use a more common MCU, like the ATmega328P. You'll find a list of MySensors-supported architectures on the Overview page.

                            1 Reply Last reply
                            1
                            • chamroeun ouC Offline
                              chamroeun ouC Offline
                              chamroeun ou
                              wrote on last edited by
                              #28

                              @BearWithBeard said in A tiny BME node - BME280 on ATtiny85:

                              Overview page

                              @BearWithBeard thanks, now i got my Attiny167+Sht30 working with Mysensors and Mysensor gateway. Next step will be formatting the data for Thingsboard cloud.

                              1 Reply Last reply
                              1
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              12

                              Online

                              11.7k

                              Users

                              11.2k

                              Topics

                              113.0k

                              Posts


                              Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • MySensors
                              • OpenHardware.io
                              • Categories
                              • Recent
                              • Tags
                              • Popular