A tiny BME node - BME280 on ATtiny85
-
@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_IDappropriatly.
BME values are sent as fixed point values and are converted to float on controller side. -
Last year I began with the work on the SMD version of the tiny BME node. See pictures here:


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.
-
Last year I began with the work on the SMD version of the tiny BME node. See pictures here:


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.
@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...
-
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?
-
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)); -
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.
-
To use Attiny, i think there's a need to optimize Mysensor for it as Mysensor consumes the most space of the 8K.
-
To use Attiny, i think there's a need to optimize Mysensor for it as Mysensor consumes the most space of the 8K.
@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) -
@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.
-
@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.
@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.
-
@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. -
@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.@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.
-
@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.