mysensors node attiny841 and nrf24l01+



  • I created a number of mini sensor node boards using an attiny841 and a nrf24l01+. Originally I was going to write my own program using the RF24 library but just recently decided to use mysensors. Below is my code for a simple door/window sensor.

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * DESCRIPTION
     *
     * Simple binary switch example 
     * Connect button or door/window reed switch between 
     * digitial I/O pin 3 (BUTTON_PIN below) and GND.
     * http://www.mysensors.org/build/binary
     */
    
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_RFM69
    
    #include <MySensors.h>
    #include <Bounce2.h>
    
    #define CHILD_ID 5
    #define REED_SWITCH_PIN  3  // Arduino Digital I/O pin for button/reed switch
    
    Bounce debouncer = Bounce(); 
    int oldValue=-1;
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(CHILD_ID,V_TRIPPED);
    
    void setup()  
    {  
      // Setup the button
      pinMode(REED_SWITCH_PIN,INPUT);
      // Activate internal pull-up
      digitalWrite(REED_SWITCH_PIN,HIGH);
    
      // After setting up the button, setup debouncer
      debouncer.attach(REED_SWITCH_PIN);
      debouncer.interval(2);
    
    }
    
    void presentation() {
      sendSketchInfo("Garage Door Sensor", "1.0");
      // Register binary input sensor to gw (they will be created as child devices)
      // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
      // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
      present(CHILD_ID, S_DOOR);  
    }
    
    
    //  Check if digital input has changed and send in new value
    void loop() 
    {
      debouncer.update();
      // Get the update value
      int value = debouncer.read();
    
      if (value != oldValue) {
         // Send in the new value
         send(msg.set(value==HIGH ? 1 : 0));
         oldValue = value;
      }
    }
    

    In the arduino IDE, I am getting the following errors when I try to compile. Before I start digging into the library files, is it possible to use mysensors with the nrf24l01 on the attiny841?

    In file included from C:\Users\cdrum\Documents\Arduino\libraries\MySensors/MySensors.h:64:0,
    from C:\Users\cdrum\Desktop\MySensors Sketches\WindowDoorSwitch_attiny\WindowDoorSwitch_attiny.ino:36:
    C:\Users\cdrum\Documents\Arduino\libraries\MySensors/hal/architecture/AVR/MyHwAVR.cpp: In function 'void clearPendingInterrupt(uint8_t)':
    C:\Users\cdrum\Documents\Arduino\libraries\MySensors/hal/architecture/AVR/MyHwAVR.cpp:73:2: error: 'EIFR' was not declared in this scope
    EIFR = _BV(interrupt);
    ^~~~
    C:\Users\cdrum\Documents\Arduino\libraries\MySensors/hal/architecture/AVR/MyHwAVR.cpp:73:2: note: suggested alternative: 'GIFR'
    EIFR = _BV(interrupt);
    ^~~~
    GIFR
    C:\Users\cdrum\Documents\Arduino\libraries\MySensors/hal/architecture/AVR/MyHwAVR.cpp: In function 'void hwPowerDown(uint8_t)':
    C:\Users\cdrum\Documents\Arduino\libraries\MySensors/hal/architecture/AVR/MyHwAVR.cpp:96:19: error: 'WDCE' was not declared in this scope
    WDTCSR |= (1 << WDCE) | (1 << WDIE);
    ^~~~
    C:\Users\cdrum\Documents\Arduino\libraries\MySensors/hal/architecture/AVR/MyHwAVR.cpp:96:19: note: suggested alternative: 'WDIE'
    WDTCSR |= (1 << WDCE) | (1 << WDIE);
    ^~~~
    WDIE
    C:\Users\cdrum\Documents\Arduino\libraries\MySensors/hal/architecture/AVR/MyHwAVR.cpp:117:18: error: 'WDCE' was not declared in this scope
    WDTCSR |= (1 << WDCE) | (1 << WDE);
    ^~~~
    C:\Users\cdrum\Documents\Arduino\libraries\MySensors/hal/architecture/AVR/MyHwAVR.cpp:117:18: note: suggested alternative: 'WDIE'
    WDTCSR |= (1 << WDCE) | (1 << WDE);
    ^~~~
    WDIE
    C:\Users\cdrum\Documents\Arduino\libraries\MySensors/hal/architecture/AVR/MyHwAVR.cpp: In function 'bool hwUniqueID(uint8_t (*)[16])':
    C:\Users\cdrum\Documents\Arduino\libraries\MySensors/hal/architecture/AVR/MyHwAVR.cpp:277:31: error: 'OSCCAL' was not declared in this scope
    *((uint8_t *)uniqueID + 3) = OSCCAL;
    ^~~~~~
    C:\Users\cdrum\Documents\Arduino\libraries\MySensors/hal/architecture/AVR/MyHwAVR.cpp:277:31: note: suggested alternative: 'OSCCAL0'
    *((uint8_t *)uniqueID + 3) = OSCCAL;
    ^~~~~~
    OSCCAL0
    C:\Users\cdrum\Documents\Arduino\libraries\MySensors/hal/architecture/AVR/MyHwAVR.cpp: In function 'uint16_t hwCPUVoltage()':
    C:\Users\cdrum\Documents\Arduino\libraries\MySensors/hal/architecture/AVR/MyHwAVR.cpp:299:2: error: 'ADMUX' was not declared in this scope
    ADMUX = (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1));
    ^~~~~
    C:\Users\cdrum\Documents\Arduino\libraries\MySensors/hal/architecture/AVR/MyHwAVR.cpp:299:2: note: suggested alternative: 'ADMUXA'
    ADMUX = (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1));
    ^~~~~
    ADMUXA
    C:\Users\cdrum\Documents\Arduino\libraries\MySensors/hal/architecture/AVR/MyHwAVR.cpp: In function 'uint16_t hwCPUFrequency()':
    C:\Users\cdrum\Documents\Arduino\libraries\MySensors/hal/architecture/AVR/MyHwAVR.cpp:336:18: error: 'WDCE' was not declared in this scope
    WDTCSR |= (1 << WDCE) | (1 << WDE);
    ^~~~
    C:\Users\cdrum\Documents\Arduino\libraries\MySensors/hal/architecture/AVR/MyHwAVR.cpp:336:18: note: suggested alternative: 'WDIE'
    WDTCSR |= (1 << WDCE) | (1 << WDE);
    ^~~~
    WDIE
    exit status 1
    Error compiling for board ATtiny441/841 (No bootloader).

    Thank You!


  • Mod

    Welcome to the community @drummin89

    It might be possible with enough work, for code that uses very little ram and flash. But many users are struggling to make MySensors sketches work on atmega328, which has 4x more ram and 2.5x more flash.

    There are some forum threads on the same topic, for example https://forum.mysensors.org/topic/333/attiny-supported/1?=1607318133104 and https://forum.mysensors.org/topic/6922/running-mysensors-on-attiny85/5?=1607317730360



  • Hello,
    You can use this solution.
    I use this with attiny84 and attiny84A, for temperature sensor and opening sensor.
    http://domotique-diy.overblog.com/


Log in to reply
 

Suggested Topics

  • 87
  • 1
  • 6
  • 5
  • 5
  • 7

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts