Just found a pair of "old" NRF51822-04 ... any good?



  • Hi there! It's been a long time, I've been away from this forum for a while, tinkering with Zigbee and HomeAssistant... but I'm planning my new garage, so here I am.

    I've found, as title says, three stamp-sized Nordic chips: are they still any good? I don't need much coverage, but I'd try something newer than the 328p's I have on MyNode PCBs.

    Thanks to all!

    Marco


  • Hardware Contributor

    Hello, @ghiglie yes you can use them with MySensors but they are not great for battery-powered sensors due to a hardware bug. If you use them as main-powered sensors they are fine, and range is decent with those.



  • Though the power bug @Nca78 mentioned is easily bypassed with proper software settings. Just don't rely on built in sleep function, because in case of nfr51822 it doesn't disable all hardware and drains power.


  • Admin

    @ghiglie Check out these links if you haven't used NRF5 before. They should help you get started.
    https://forum.mysensors.org/topic/9266/guide-nrf5-nrf51-nrf52-for-beginners
    https://www.openhardware.io/view/376/MySensors-NRF5-Platform

    I found the ST-LINK programmer to be easier to work with (using Windows) that the J-LINK



  • Hi all,
    sorry for being so late, again... 😄

    @nca78 said in Just found a pair of "old" NRF51822-04 ... any good?:

    Hello, @ghiglie yes you can use them with MySensors but they are not great for battery-powered sensors due to a hardware bug. If you use them as main-powered sensors they are fine, and range is decent with those.
    @monte said in Just found a pair of "old" NRF51822-04 ... any good?:
    Though the power bug @Nca78 mentioned is easily bypassed with proper software settings. Just don't rely on built in sleep function, because in case of nfr51822 it doesn't disable all hardware and drains power.

    Oh, ok, I'll keep it in mind. I'm a good copy'n'paste-r , so as soon as I get to work on a chip, I'll look for the sleep code. Thanks for pointing that!
    I'm really look for battery powered sensors, as for mains powered ones I use "easier" chips as ESPs, mainly on bigger dev modules (such as NodeMCU) since I have more space.

    @petewill said in Just found a pair of "old" NRF51822-04 ... any good?:

    @ghiglie Check out these links if you haven't used NRF5 before. They should help you get started.
    https://forum.mysensors.org/topic/9266/guide-nrf5-nrf51-nrf52-for-beginners
    https://www.openhardware.io/view/376/MySensors-NRF5-Platform

    I found the ST-LINK programmer to be easier to work with (using Windows) that the J-LINK

    I have a ST-LINK I bought since I saw this chips mentioned in @NeverDie 's threads , but then I tried some STM32 blue pills and finally got a working Black Magic Probe.
    Now I just have to deal with the soldering, but I saw something like an adapter with pushpins...

    I'll keep you updated!



  • Well, I'm sorry I'm sooo late, but I had to stop all my testing.
    I'll definitely be back after ordering some new tools during Chinese New Yes sales...!



  • Let us know if NRF51822-04 is any good.



  • Well, for now, no updates! Working with pro-minis is still much more fun with my humble skills. I'm a good soldering-pad destroyer when it comes to SMD.

    In the while, I can't find a sort of adapter for SMD versione of NRF5 boards, like the flasher for ESP8266. Is there something like that out there?



  • @Holosteric & @ghiglie I am actively working on the NRF51822. I am testing @NeverDie 's PIR and Temp/Humidity sketches. The example sketches of Mysensors didn't work well for me.
    I will report the results.
    Main sketch

    // SUMMARY: This demo sketch runs on the AM612 PIR v607 PCBto transmit battery voltage (heartbeat) and motion detections to a MySensors gateway using MySensors protocols.
    
    // Note: because this is a passive node, node ID must be set manually to a unique sensor node ID:
    #define MY_NODE_ID 143  // Passive mode requires static node ID
    
    //#define MY_CORE_ONLY
    
    #define MY_PASSIVE_NODE
    
    #define MY_RADIO_NRF5_ESB
    
    #define IS_NRF51  //true iff the target is an nRF51.  If an nRF52, then comment this line out!
    
    
    #define PIR_DETECTION_PIN 2 
    #define SHORT_WAIT 50
    
    #include <MySensors.h>
    //#include <Wire.h>
    #include <Adafruit_BME280.h>
    
    // Enable debug prints
    //#define MY_DEBUG
    
    
    volatile bool motion_change=false;
    
    Adafruit_BME280 bme; // use I2C interface
    Adafruit_Sensor *bme_temp = bme.getTemperatureSensor();
    Adafruit_Sensor *bme_pressure = bme.getPressureSensor();
    Adafruit_Sensor *bme_humidity = bme.getHumiditySensor();
    
    void disableNfc() {  //only applied to nRF52
    
    #ifndef IS_NRF51
      //Make pins 9 and 10 usable as GPIO pins.
      NRF_NFCT->TASKS_DISABLE=1;  //disable NFC
      NRF_NVMC->CONFIG=1;  // Write enable the UICR
      NRF_UICR->NFCPINS=0; //Make pins 9 and 10 usable as GPIO pins.
      NRF_NVMC->CONFIG=0;  // Put the UICR back into read-only mode.
    #endif
    }
    
    
    void turnOffRadio() {
      NRF_RADIO->TASKS_DISABLE=1;
      while (!(NRF_RADIO->EVENTS_DISABLED)) {}  //until radio is confirmed disabled
    }
    
    void turnOffUarte0() {
    #ifndef IS_NRF51  
      NRF_UARTE0->TASKS_STOPRX = 1;
      NRF_UARTE0->TASKS_STOPTX = 1;
      NRF_UARTE0->TASKS_SUSPEND = 1;
      NRF_UARTE0->ENABLE=0;  //disable UART0
      while (NRF_UARTE0->ENABLE!=0) {};  //wait until UART0 is confirmed disabled.
    #endif
    
    #ifdef IS_NRF51
      NRF_UART0->TASKS_STOPRX = 1;
      NRF_UART0->TASKS_STOPTX = 1;
      NRF_UART0->TASKS_SUSPEND = 1;
      NRF_UART0->ENABLE=0;  //disable UART0
      while (NRF_UART0->ENABLE!=0) {};  //wait until UART0 is confirmed disabled.
    #endif
    }
    
    void turnOffAdc() {
    #ifndef IS_NRF51
      if (NRF_SAADC->ENABLE) { //if enabled, then disable the SAADC
        NRF_SAADC->TASKS_STOP=1;
        while (NRF_SAADC->EVENTS_STOPPED) {} //wait until stopping of SAADC is confirmed
        NRF_SAADC->ENABLE=0;  //disable the SAADC
        while (NRF_SAADC->ENABLE) {} //wait until the disable is confirmed
      }
    #endif
    }
    
    
    void turnOffHighFrequencyClock() {
        NRF_CLOCK->TASKS_HFCLKSTOP = 1;
        while ((NRF_CLOCK->HFCLKSTAT) & 0x0100) {}  //wait as long as HF clock is still running.
    }
    
    
    void mySleepPrepare() {  //turn-off energy drains prior to sleep
      turnOffHighFrequencyClock();
      turnOffRadio();
      turnOffUarte0();
    }
     
    
    void activateLpComp() {
      NRF_LPCOMP->PSEL=3; // monitor AIN0 (i.e. pin P0.02 on nRF52832 PIR Motion Sensor v607).
      while (!(NRF_LPCOMP->PSEL==3)) {} //wait until confirmed
      NRF_LPCOMP->REFSEL=3;  // choose 1/2 VDD as the reference voltage
      while (!(NRF_LPCOMP->REFSEL==3)) {} //wait until confirmed
      NRF_LPCOMP->ANADETECT=0;  //detect CROSS events on PIR detection pin
      while (NRF_LPCOMP->ANADETECT!=0) {} //wait until confirmed
      NRF_LPCOMP->INTENSET=B1000;  //Enable interrupt for CROSS event
      while (!(((NRF_LPCOMP->INTENSET)&B1000)==B1000)) {} //wait until confirmed
      NRF_LPCOMP->ENABLE=1;  //Enable LPCOMP
      while (!(NRF_LPCOMP->ENABLE==1)) {} //wait until confirmed
      NRF_LPCOMP->TASKS_START=1;  //start the LPCOMP
      while (!(NRF_LPCOMP->EVENTS_READY)) {}  //wait until ready
      
      NVIC_SetPriority(LPCOMP_IRQn, 15);
      NVIC_ClearPendingIRQ(LPCOMP_IRQn);
      NVIC_EnableIRQ(LPCOMP_IRQn);
    }
    
    void suspendLpComp() { //suspend getting more interrupts from LPCOMP before the first interrupt can be handled
      if ((NRF_LPCOMP->ENABLE) && (NRF_LPCOMP->EVENTS_READY)) {  //if LPCOMP is enabled
        NRF_LPCOMP->INTENCLR=B0100;  //disable interrupt from LPCOMP
        while (((NRF_LPCOMP->INTENCLR)&B0100)==B0100) {} //wait until confirmed
      }
    }
    
    void resumeLpComp() { //suspend getting interrupts from LPCOMP
      NRF_LPCOMP->INTENSET=B0100;  //Enable interrupt for UP event
      while (((NRF_LPCOMP->INTENSET)&B1000)!=B0100) {} //wait until confirmed
    }
    
    
    #define CHILD_ID 1   // Id of the motion sensor child
    #define ID_S_MULTIMETER        28
    #define CHILD_ID_TEMP 2
    #define CHILD_ID_HUMID 3
    #define CHILD_ID_BARO 4
    // Initialize motion message
    
    MyMessage msg(CHILD_ID, V_TRIPPED);
    MyMessage msg_S_MULTIMETER_V_VOLTAGE(ID_S_MULTIMETER,V_VOLTAGE);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgHumid(CHILD_ID_HUMID, V_HUM);
    MyMessage msgPressure(CHILD_ID_BARO, V_PRESSURE);
    
    float batteryVoltage=0;  
    float temperature=0;
    int humidity=0;
    float pressure=0;
    
    
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("PIR BME Sensor", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID, S_MOTION);
    
      wait(SHORT_WAIT);
      
      present(ID_S_MULTIMETER,S_MULTIMETER,"Electric Station");
      wait(SHORT_WAIT);
      present(CHILD_ID_TEMP, S_TEMP, "PIR TEST Temperature", true);
      wait(SHORT_WAIT);
      present(CHILD_ID_HUMID, S_HUM, "PIR TEST Humidity", true);
      wait(SHORT_WAIT);
      present(CHILD_ID_BARO, S_BARO, "PIR TEST Pressure", true);
      wait(SHORT_WAIT);
    }
    
    
    void setup()
    {
      hwInit();
    
      hwPinMode(PIR_DETECTION_PIN,INPUT);
       if (!bme.begin(0x76))
      {
        while (1) delay(100);
    
      }
      disableNfc();  //remove unnecessary energy drains
      turnOffAdc();  //remove unnecessary energy drains
      activateLpComp();
      NRF_CLOCK->INTENSET=B11;  //enable interrupts for EVENTS_HFCLKSTARTED and  EVENTS_LFCLKSTARTED
      NRF_CLOCK->TASKS_HFCLKSTART=1;  //start the high frequency crystal oscillator clock
      while (!(NRF_CLOCK->EVENTS_HFCLKSTARTED)) {} //wait until high frequency crystal oscillator clock is up to speed and working
    
      motion_change=false;
    }
    
    
    
    void mySleep(uint32_t ms) {
       mySleepPrepare();  //Take steps to reduce drains on battery current prior to sleeping
       sleep(ms);
    }
    
    
    bool motionDetected=false;
    void loop() {
    //    sensors_event_t temp_event, pressure_event, humidity_event;
    //    bme_temp->getEvent(&temp_event);
    //    bme_pressure->getEvent(&pressure_event);
    //    bme_humidity->getEvent(&humidity_event);
    //    temperature=bme.readTemperature();
    //    humidity=bme.readHumidity();
    //    pressure=bme.readPressure()/100.0F;
      mySleep(300000);  //sleep for 5 minutes
    
      if (motion_change) {
        motionDetected=!motionDetected;
        if (motionDetected) {
    //      digitalWrite(LED_BUILTIN,HIGH);  //turn-on LED to signify motion detected
          send(msg.set("1"));  // motion detected
        }
        else {
    //      digitalWrite(LED_BUILTIN,LOW);  //turn-off LED to signify motion no longer detected
          send(msg.set("0"));  // send all-clear to prepare for future detections
        }    
        
        NRF_LPCOMP->EVENTS_CROSS=0;
        motion_change=false;
      }
      else { //must be a scheduled wake-up.  Time to report voltage as a heartbeat.
        
    
        sensors_event_t temp_event, pressure_event, humidity_event;
        bme_temp->getEvent(&temp_event);
        bme_pressure->getEvent(&pressure_event);
        bme_humidity->getEvent(&humidity_event);
        temperature=bme.readTemperature();
        humidity=bme.readHumidity();
        pressure=bme.readPressure()/100.0F;
        wait(100);
        send(msgTemp.set(temperature,2));
        wait(100);
        send(msgHumid.set(humidity,2));
        wait(100);
        send(msgPressure.set(pressure,2));
        wait(100);
    
      batteryVoltage=((float)hwCPUVoltage())/1000.0;  //take voltage measurement after transmission to hopefully measure lowest voltage that occurs. 
        send(msg_S_MULTIMETER_V_VOLTAGE.set(batteryVoltage,3));  //send battery voltage with 3 decimal places
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
        
      }
    }
    
    
    // * Reset events and read back on nRF52
    //* http://infocenter.nordicsemi.com/pdf/nRF52_Series_Migration_v1.0.pdf
     
    #if __CORTEX_M == 0x04
    #define NRF5_RESET_EVENT(event)                                                 \
            event = 0;                                                                   \
            (void)event
    #else
    #define NRF5_RESET_EVENT(event) event = 0
    #endif
    
    
    // This must be in one line
    extern "C" { void LPCOMP_IRQHandler(void) {motion_change=true; NRF5_RESET_EVENT(NRF_LPCOMP->EVENTS_CROSS); NRF_LPCOMP->EVENTS_CROSS=0; MY_HW_RTC->CC[0]=(MY_HW_RTC->COUNTER+2);}}
    

    MyBoardNRF5.cpp

    /*
      If you don't use an nRF5 board, you can ignore this file.
      
      This file was part of the "My Sensors nRF5 Boards" board repository
      available at https://github.com/mysensors/ArduinoBoards If you have
      questions, please refer the documentation at
      https://github.com/mysensors/ArduinoHwNRF5 first.
      
      This file is compatible with ArduinoHwNRF5 >= 0.2.0
    
      This file allows you to change the relation between pins referenced in
      the Arduino IDE (0..31) and pins of the nRF5 MCU (P0.00..P0.31).
      
      If you can live with addressing the GPIO pins by using the Arduino pins
      0..31 instead of a custom mapping, don't change this file. If you have
      a lot of Arduino code with fixed pin numbers and you need to map these
      pins to specific pins of the nRF5 MCU; you need to change this file.
      
      If you fill the "g_APinDescription" Array with numbers between 0..31,
      the Arduino pins 0..31 are assigned to pins P0.00..P0.31 of the MCU.
      
      As an example, if you need to change the pin mapping for Arduino pin 5
      to P0.12 of the MCU, you have to write the 12 after PORT0 into the sixth
      position in the  "g_APinDescription" Array.
       
      The extended attributes only affects the nRF5 variants provided with
      official Arduino boards. The arduino-nrf5 variant ignores the extended
      attributes.
        
      The pin mapping effects commands like "pinMode()", "digitalWrite()",
      "analogRead()" and "analogWrite()".
      
      If you change the pin mapping, you have to modify the pins in
      "MyBoardNRF5.h". Especially the analog pin mapping must be replaced with
      your pin numbers by replacing PIN_AIN0..7 with a number of your mapping
      array. You can use the constants PIN_AIN0..7 in the "g_APinDescription"
      Array if you want to reference analog ports MCU independent. You cannot
      use the pins P0.00 and P0.01 for GPIO, when the 32kHz crystal is connected.
    
      
      ###########################################################################
    
      Copyright (c) 2014-2015 Arduino LLC.  All right reserved.
      Copyright (c) 2016 Arduino Srl.  All right reserved.
      Copyright (c) 2017 Sensnology AB. All right reserved.
    
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
      License as published by the Free Software Foundation; either
      version 2.1 of the License, or (at your option) any later version.
    
      This library is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
      See the GNU Lesser General Public License for more details.
    
      You should have received a copy of the GNU Lesser General Public
      License along with this library; if not, write to the Free Software
      Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    */
    
    
    
    #ifdef MYBOARDNRF5
    #include <variant.h>
    
    /*
     * Pins descriptions. Attributes are ignored by arduino-nrf5 variant. 
     * Definition taken from Arduino Primo Core with ordered ports
     */
    const PinDescription g_APinDescription[] =
    {
      { NOT_A_PORT, 0, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // LFCLK
      { NOT_A_PORT, 1, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // LFCLK
      { PORT0,  2, PIO_DIGITAL, (PIN_ATTR_DIGITAL | PIN_ATTR_PWM), ADC_A0, PWM4, NOT_ON_TIMER},
      { PORT0,  3, PIO_DIGITAL, (PIN_ATTR_DIGITAL | PIN_ATTR_PWM), ADC_A1, PWM5, NOT_ON_TIMER},
      { PORT0,  4, PIO_DIGITAL, (PIN_ATTR_DIGITAL | PIN_ATTR_PWM), ADC_A2, PWM6, NOT_ON_TIMER},
      { PORT0,  5, PIO_DIGITAL, (PIN_ATTR_DIGITAL | PIN_ATTR_PWM), ADC_A3, PWM7, NOT_ON_TIMER},
      { PORT0,  6, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT3
      { PORT0,  7, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT4
      { PORT0,  8, PIO_DIGITAL, (PIN_ATTR_DIGITAL | PIN_ATTR_PWM), No_ADC_Channel, PWM10, NOT_ON_TIMER},  //USER_LED
      { PORT0,  9, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // NFC1
      { PORT0, 10, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // NFC2
      { PORT0, 11, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // TX
      { PORT0, 12, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // RX
      { PORT0, 13, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // SDA
      { PORT0, 14, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // SCL
      { PORT0, 15, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // SDA1
      { PORT0, 16, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // SCL1
      { PORT0, 17, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // TP4
      { PORT0, 18, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // TP5
      { PORT0, 19, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT2
      { PORT0, 20, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT1
      { PORT0, 21, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT1
      { PORT0, 22, PIO_DIGITAL, (PIN_ATTR_DIGITAL | PIN_ATTR_PWM), No_ADC_Channel, PWM9, NOT_ON_TIMER},
      { PORT0, 23, PIO_DIGITAL, (PIN_ATTR_DIGITAL | PIN_ATTR_PWM), No_ADC_Channel, PWM8, NOT_ON_TIMER},
      { PORT0, 24, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT
      { PORT0, 25, PIO_DIGITAL, (PIN_ATTR_DIGITAL | PIN_ATTR_PWM), No_ADC_Channel, PWM11, NOT_ON_TIMER}, //RED_LED
      { PORT0, 26, PIO_DIGITAL, (PIN_ATTR_DIGITAL | PIN_ATTR_PWM), No_ADC_Channel, PWM11, NOT_ON_TIMER}, //GREEN_LED
      { PORT0, 27, PIO_DIGITAL, (PIN_ATTR_DIGITAL | PIN_ATTR_PWM), No_ADC_Channel, PWM11, NOT_ON_TIMER}, //BLUE_LED
      { PORT0, 28, PIO_DIGITAL, (PIN_ATTR_DIGITAL | PIN_ATTR_PWM), ADC_A4, PWM3, NOT_ON_TIMER},
      { PORT0, 29, PIO_DIGITAL, (PIN_ATTR_DIGITAL | PIN_ATTR_PWM), ADC_A5, PWM2, NOT_ON_TIMER},
      { PORT0, 30, PIO_DIGITAL, (PIN_ATTR_DIGITAL | PIN_ATTR_PWM), ADC_A6, PWM1, NOT_ON_TIMER},
    #if defined(NRF52840)
      { PORT0, 31, PIO_DIGITAL, (PIN_ATTR_DIGITAL | PIN_ATTR_PWM), ADC_A7, PWM0, NOT_ON_TIMER},
      { PORT1, 32, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
      { PORT1, 33, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
      { PORT1, 34, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
      { PORT1, 35, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
      { PORT1, 36, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
      { PORT1, 37, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
      { PORT1, 38, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
      { PORT1, 39, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
      { PORT1, 40, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
      { PORT1, 41, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
      { PORT1, 42, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
      { PORT1, 43, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
      { PORT1, 44, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
      { PORT1, 45, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
      { PORT1, 46, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
      { PORT1, 47, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
      { PORT1, 48, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}
    #else
      { PORT0, 31, PIO_DIGITAL, (PIN_ATTR_DIGITAL | PIN_ATTR_PWM), ADC_A7, PWM0, NOT_ON_TIMER}
    #endif
    };
    
    // Don't remove this line
    #include <compat_pin_mapping.h>
    
    #endif
    

    MyBoardNRF5.h

    /*
      If you don't use an nRF5 board, you can ignore this file.
    
      This file was part of the "My Sensors nRF5 Boards" board repository
      available at https://github.com/mysensors/ArduinoBoards If you have
      questions, please refer the documentation at
      https://github.com/mysensors/ArduinoHwNRF5 first.
    
      This file is compatible with ArduinoHwNRF5 >= 0.2.0
    
      This file allows you to change the pins of internal hardware, like the
      serial port, SPI bus or Wire bus.
    
      All pins referenced here are mapped via the "g_ADigitalPinMap" Array
      defined in "MyBoardNRF5.cpp" to pins of the MCU.
      
      As an example, if you have at the third position in "g_ADigitalPinMap" the
      12, then all ports referenced in Arduino with 2 are mapped to P0.12. If you
      don't change the "g_ADigitalPinMap" Array, the Arduino pins 0..31 are
      translated to P0.00..P0..31.
       
      ###########################################################################
     
      This file is compatible with ArduinoHwNRF5 > 0.1.0
      Copyright (c) 2014-2015 Arduino LLC.  All right reserved.
      Copyright (c) 2016 Sandeep Mistry. All right reserved.
      Copyright (c) 2017 Sensnology AB. All right reserved.
    
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
      License as published by the Free Software Foundation; either
      version 2.1 of the License, or (at your option) any later version.
      This library is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
      See the GNU Lesser General Public License for more details.
      You should have received a copy of the GNU Lesser General Public
      License along with this library; if not, write to the Free Software
      Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    */
    
    #ifndef _MYBOARDNRF5_H_
    #define _MYBOARDNRF5_H_
    
    #ifdef __cplusplus
    extern "C"
    {
    #endif // __cplusplus
    
    // Number of pins defined in PinDescription array
    #if defined(NRF52840)
    #define GPIO_COUNT 2
    #define PINS_COUNT           (48u)
    #define NUM_DIGITAL_PINS     (48u)
    #define NUM_ANALOG_INPUTS    (8u)
    #define NUM_ANALOG_OUTPUTS   (8u)
    #else
    #define GPIO_COUNT 2
    #define PINS_COUNT           (32u)
    #define NUM_DIGITAL_PINS     (32u)
    #define NUM_ANALOG_INPUTS    (8u)
    #define NUM_ANALOG_OUTPUTS   (8u)
    #endif
    
    /* 
     *  LEDs
     *  
     *  This is optional
     *  
     *  With My Sensors, you can use
     *  hwPinMode() instead of pinMode()
     *  hwPinMode() allows to use advanced modes like OUTPUT_H0H1 to drive LEDs.
     *  https://github.com/mysensors/MySensors/blob/development/drivers/NRF5/nrf5_wiring_constants.h
     *
     */
    //#define PIN_LED1                (13)
    //#define PIN_LED2                (24)
    //#define PIN_LED3                (5)
    // #define PIN_LED4                (27)
    // #define PIN_LED5                (12)
    // #define PIN_LED6                (14)
    // #define PIN_LED7                (15)
    // #define PIN_LED8                (16)
    // #define USER_LED             	 (PIN_LED2)
    //#define RED_LED                (PIN_LED1)
    //#define GREEN_LED            	 (PIN_LED2)
    //#define BLUE_LED			         (PIN_LED3)
    // #define BLE_LED                 BLUE_LED
    //#define LED_BUILTIN          PIN_LED1
    
    /* 
     *  Buttons
     *  
     *  This is optional
     */
    //#define PIN_BUTTON            (2)
    // #define PIN_BUTTON2             (4)
    // #define PIN_BUTTON3             (5)
    // #define PIN_BUTTON4             (6)
    // #define PIN_BUTTON5             (7)
    // #define PIN_BUTTON6             (8)
    // #define PIN_BUTTON7             (9)
    // #define PIN_BUTTON8             (10)
    
    //#define AXEL_INT             (29)
    //#define MAGNET_INT             (28)
    //#define GERKON_INT             (3)
    
    /* 
     * Analog ports
     *  
     * If you change g_APinDescription, replace PIN_AIN0 with
     * port numbers mapped by the g_APinDescription Array.
     * You can add PIN_AIN0 to the g_APinDescription Array if
     * you want provide analog ports MCU independed, you can add
     * PIN_AIN0..PIN_AIN7 to your custom g_APinDescription Array
     * defined in MyBoardNRF5.cpp
     */
    static const uint8_t A0  = ADC_A0;
    static const uint8_t A1  = ADC_A1;
    static const uint8_t A2  = ADC_A2;
    static const uint8_t A3  = ADC_A3;
    static const uint8_t A4  = ADC_A4;
    static const uint8_t A5  = ADC_A5;
    static const uint8_t A6  = ADC_A6;
    static const uint8_t A7  = ADC_A7;
    
    /*
     * Serial interfaces
     * 
     * RX and TX are required.
     * If you have no serial port, use unused pins
     * CTS and RTS are optional.
     */
    #define PIN_SERIAL_RX       (9)
    #define PIN_SERIAL_TX       (10)
    // #define PIN_SERIAL_CTS      (13)
    // #define PIN_SERIAL_RTS      (14)
    
    /*
     * SPI Interfaces
     * 
     * This is optional
     * 
     * If SPI is defined MISO, MOSI, SCK are required
     * SS is optional and can be used in your sketch.
     */
    #define SPI_INTERFACES_COUNT 1
    
    #define PIN_SPI_MISO         (15)
    #define PIN_SPI_MOSI         (17)
    #define PIN_SPI_SCK          (20)
    #define PIN_SPI_SS           (22)
    
    static const uint8_t SS   = PIN_SPI_SS;
    static const uint8_t MOSI = PIN_SPI_MOSI;
    static const uint8_t MISO = PIN_SPI_MISO;
    static const uint8_t SCK  = PIN_SPI_SCK;
    
    /*
     * Wire Interfaces
     *
     * This is optional
     */
    #define WIRE_INTERFACES_COUNT 2
    
    #define PIN_WIRE_SDA         (15u)
    #define PIN_WIRE_SCL         (16u)
    
    //#define PIN_WIRE_SDA1        (30u)
    //#define PIN_WIRE_SCL1        (31u)
    
    static const uint8_t SDA = PIN_WIRE_SDA;
    static const uint8_t SCL = PIN_WIRE_SCL;
    
    #ifdef __cplusplus
    }
    #endif
    
    #endif```


  • The nRF51822 has been used successfully in many coin cell applications including beacons, wearable, etc. There were three versions of this device. Only REV 3 silicon is being shipped by Nordic. Any older parts should be avoided. If you are wondering what rev you have there is a chart in the compatibility section on the Nordic Semiconductor website. I would add that If supported by the sensors and such I would suggest looking as some of the newer parts in the nRF52 family. Some have a low membory variant that may work for you too. Using the DC/DC converter you can achieve about 6mA of receive and transmit current and sleep currents in the uA range and nA in power down.



  • @Jokgi for sure , next purchase for me would be the nrf52 series. As with @ghiglie , I too had bought the nrf51822 many years back and they were sitting in the drawer. This lockdown allowed me to discover them and hence I decided to use them.



  • Yes, I'm with @Puneit-Thukral . As soon I get more comfortable I'll buy some new parts: for now, I'm too much n00b ! I still reverse polarities, short circuit solder pads... 😆



  • Resuming my old thread. After killing some 328p (but I still spare one!), I got a fully working "multisensor" . Now it's nRF51 turn:

    I'm using a Black Magic Probe, made from a Blue Pill - it has May2020 code, "git pull" shows quite a lots of updates, but I'll keep like that. { Just a note: compile it with "make && make PROBE_HOST=swlink" so you'll be able to use the header! } . I have STLinkV2 clone for backup.

    My "setup": imgur.com/a/acT6iOZ

    @monte said in Just found a pair of "old" NRF51822-04 ... any good?:

    Though the power bug @Nca78 mentioned is easily bypassed with proper software settings. Just don't rely on built in sleep function, because in case of nfr51822 it doesn't disable all hardware and drains power.

    Sorry @monte, I'm totally n00b . Any link about this?



  • @ghiglie you can try this from my old post: https://forum.mysensors.org/post/92044
    I will need to write a firmware for 51822 in few weeks, so maybe I'll have something more polished. The most usefull information you can find on Nordic's forum, you can use snippets of code with arduino and it should work, because NRF5 port contains Nordic's SDK, and thus all functions and macroses, that are mentioned on that forum.



  • @monte said in Just found a pair of "old" NRF51822-04 ... any good?:

    @ghiglie you can try this from my old post: https://forum.mysensors.org/post/92044
    I will need to write a firmware for 51822 in few weeks, so maybe I'll have something more polished. The most usefull information you can find on Nordic's forum, you can use snippets of code with arduino and it should work, because NRF5 port contains Nordic's SDK, and thus all functions and macroses, that are mentioned on that forum.

    Thanks @monte! Very intesting. This nRF5 journey is getting quite difficult, programming for Nordic's chips is way harder than what I'm used to. Maybe I'll wait for your sketch! 😆



  • @ghiglie look at this from the point that the more difficult the task the more you will learn by accomplishing it 😉



  • @monte said in Just found a pair of "old" NRF51822-04 ... any good?:

    Though the power bug @Nca78 mentioned is easily bypassed with proper software settings. Just don't rely on built in sleep function, because in case of nfr51822 it doesn't disable all hardware and drains power.

    Sorry @monte, I'm totally n00b . Any link about this?

    @monte said in Just found a pair of "old" NRF51822-04 ... any good?:

    Though the power bug @Nca78 mentioned is easily bypassed with proper software settings. Just don't rely on built in sleep function, because in case of nfr51822 it doesn't disable all hardware and drains power.

    Oh, I know! But I lack time to tinker that much. 😕 I've just started on learning on Black Magic Probe and STLink differences and use cases... Maybe I just started the hard way, with a DK it would be, at least, less "pioneeristic".


Log in to reply
 

Suggested Topics

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

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts