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. nRF5 action!

nRF5 action!

Scheduled Pinned Locked Moved My Project
1.9k Posts 49 Posters 630.9k Views 44 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.
  • alowhumA Offline
    alowhumA Offline
    alowhum
    Plugin Developer
    wrote on last edited by
    #1538

    Note: to hack it you need a J-Link device:
    https://github.com/micooke/arduino-nRF5-smartwatches/blob/master/nrf52_disable_read_protection.txt

    1 Reply Last reply
    1
    • Nca78N Nca78

      So I made a version of script with MySensors library, it's not a final version and needs some cleaning and improvements but it seems to work well (I didn't test so much yet :)) and shows basic usage. Comments should be enough to understand what to change to adapt to your board. Current script is for my board:

      • BUTTON_1 on pin 1, it's a hall sensor for door so no pullup and sensing on up=>down and down=>up changes
      • BUTTON_2 on pin 3, push button with pullup and debouncing, sensing only on up=>down when button is pressed. At the moment it just makes some light blinking to show it's detected.
      • led on pin 2.

      I join the main script file and the MyBoardNRF5 files, for using with MyBoardNRF5 nrf51822. Files to include are described in the main script file, but don't forget to add a weak attribute in the WInterrupt.c file before the GPIOTE_IRQHandler so it can be overridden.

      __attribute__ ((weak))
      void GPIOTE_IRQHandler()
      

      On my Windows PC this file is in C:\Users[your user name]\AppData\Local\Arduino15\packages\sandeepmistry\hardware\nRF5\0.5.1\cores\nRF5

      Main script file:

      // Include app_gpiote and related files from NRF5 SDK 12
      extern "C" {
      #include "app_gpiote.h"
      #include "nrf_gpio.h"
      #include "app_error.h"
      }
      
      // Files to include from SDK:
      // app_error_weak.h + .c
      // app_gpiote.h + .c
      // app_util.h
      // nordic_common.h
      // nrf_error.h
      // nrf_gpio.h
      // sdk_errors.h
      // app_error.h + .c
      //   for this last one (c file) I decided to stop the endless list of includes so I commented the following includes:
      //   #include "sdk_errors.h", #include "nrf_log.h", #include "nrf_log_ctrl.h"  lines
      
      #include <nrf.h>
      
      #define IS_NRF51  //true if the target is an nRF51.  If an nRF52, then comment this line out!
      #define APP_GPIOTE_MAX_USERS 1  // max users for app_gpiote, we only use one
      #define MY_RADIO_NRF5_ESB
      #define MY_NODE_ID 60   // To avoid getting a new ID at each flashing of the sensors...
      
      #include <MySensors.h>
      
      
      // variables for app_gpiote calls
      uint32_t err_code;
      static app_gpiote_user_id_t m_gpiote_user_id;
      uint32_t PIN_BUTTON1_MASK; // Mask for PIN_BUTTON1 input
      uint32_t PIN_BUTTON2_MASK; // Mask for PIN_BUTTON2 input
      
      // defines variables for MySensors
      #define SN "22Board Door Basic"
      #define SV "0.2"
      // Sensor messages
      #define CHILD_ID_DOOR 1
      MyMessage doorMsg(CHILD_ID_DOOR, V_TRIPPED);
      bool last_sent_value;
      bool door_status;
      long last_button2_event = 0;
      
      // Cause of interrupt
      volatile byte interrupt_cause = 0;
      
      
      // Settings to avoid killing coin cell in case of connection problem
      #define MY_TRANSPORT_WAIT_READY_MS  10000
      #define MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS 5000
      
      // Battery settings
      #define BATTERY_ALERT_LEVEL 30  // (%) Will triple blink after sending data if battery is equal or below this level
      // Parameters for VCC measurement
      #define BATTERY_VCC_MIN  2400  // Minimum expected Vcc level, in milliVolts. 
      #define BATTERY_VCC_MAX  2900  // Maximum expected Vcc level, in milliVolts.
      // This a a coefficient to fix the imprecision of measurement of the battery voltage
      #define BATTERY_COEF 1000.0f  // (reported voltage / voltage) * 1000
      uint16_t currentBatteryPercent;
      uint16_t lastBatteryPercent = -1;
      // Enables/disables sleeps between sendings to optimize for CR2032 or similar coin cell
      #define USE_COIN_CELL
      
      
      // Called before initialization of the library
      void before() {
        hwPinMode(LED_BUILTIN, OUTPUT_D0H1);
        blinkityBlink(2, 3);
      }
      
      // Setup node
      void setup(void) {
      
        //Configure button pins as inputs
        nrf_gpio_cfg_input(PIN_BUTTON1, NRF_GPIO_PIN_NOPULL);
        nrf_gpio_cfg_input(PIN_BUTTON2, NRF_GPIO_PIN_PULLUP);
        APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS);               //Only initialize once. Increase value of APP_GPIOTE_MAX_USERS if needed
      
        // Initialize value of pin (for DRV5032 hall sensor HIGH = no magnet nearby = door opened);
        door_status = digitalRead(PIN_BUTTON1);
        last_sent_value = !door_status; // so we always send value in first loop
      
        // Registers user and pins we are "watching"
        //   gpiote_event_handler is handler called by interrupt, see method below
        PIN_BUTTON1_MASK = 1 << PIN_BUTTON1; // Set mask, will be used for registration and interrupt handler
        PIN_BUTTON2_MASK = 1 << PIN_BUTTON2; // Set mask, will be used for registration and interrupt handler
        //  app_gpiote_user_register(p_user_id, pins_low_to_high_mask, pins_high_to_low_mask, event_handler)
        //  to have no trigger for high=>low or low=>high change on your button, pass 0 instead
        //  here I check PIN_BUTTON1 on both low=>high and high=>low changes and PIN_BUTTON2 only on high=>low change when someone presses the button
        err_code = app_gpiote_user_register(&m_gpiote_user_id, PIN_BUTTON1_MASK, PIN_BUTTON1_MASK | PIN_BUTTON2_MASK, gpiote_event_handler);
        APP_ERROR_CHECK(err_code);  // will reset if user registration fails
      
        // Enable SENSE and interrupt
        err_code = app_gpiote_user_enable(m_gpiote_user_id);
        APP_ERROR_CHECK(err_code);  // will reset if SENSE enabling fails
      
        // initialize last event for button2 debounce
        last_button2_event = millis();
      }
      
      void presentation()  {
        sendSketchInfo(SN, SV);
        present(CHILD_ID_DOOR, S_DOOR);
      }
      
      // Sleep between sendings to preserve coin cell
      //  if not using button cell just make sure the #define USE_COIN_CELL is commented at the beginning of the sketch and it will do nothing
      void sleepForCoinCell() {
      #ifdef USE_COIN_CELL
        sleep(400);
      #endif
      }
      
      // main loop
      void loop(void)
      {
        // for sending battery level at first run
        if (lastBatteryPercent < 0) {
          sendBatteryStatus();
          sleepForCoinCell();
        }
      
        if (interrupt_cause == PIN_BUTTON1) {
          // if door status changed, we send door message
          if (door_status != last_sent_value) {
            sendDoorStatus();
          }
        }
        else if (interrupt_cause == PIN_BUTTON2) {
          if (millis() < last_button2_event || (millis() - last_button2_event > 100)) {
            last_button2_event = millis();
            blinkityBlink(2, 3); // not so useful, just for testing :)
          }
        }
        else {  // end of sleeping period, we send battery level
          sendBatteryStatus();
        }
      
        // Low battery warning or confirm status of door
        if (lastBatteryPercent < BATTERY_ALERT_LEVEL) {
          blinkityBlink(3, 1);
        }
        else {
          blinkityBlink((last_sent_value == true ? 2 : 1), 1);
        }
      
        // Go to sleep
        mySleepPrepare();
        interrupt_cause = 0; // reset interrupt cause
        sleep(300000);
      }
      
      void sendDoorStatus() {
        send(doorMsg.set(door_status));
        last_sent_value = door_status;
      }
      
      #define CHILD_ID_VOLT 254
      MyMessage voltMsg(CHILD_ID_VOLT, V_VOLTAGE);
      void sendBatteryStatus() {
        uint16_t batteryVoltage = hwCPUVoltage();
      
        if (batteryVoltage > BATTERY_VCC_MAX) {
          currentBatteryPercent = 100;
        }
        else if (batteryVoltage < BATTERY_VCC_MIN) {
          currentBatteryPercent = 0;
        }
        else {
          currentBatteryPercent = (100 * (batteryVoltage - BATTERY_VCC_MIN)) / (BATTERY_VCC_MAX - BATTERY_VCC_MIN);
        }
        if (currentBatteryPercent != lastBatteryPercent) {
          sendBatteryLevel(currentBatteryPercent);
          lastBatteryPercent = currentBatteryPercent;
        }
      }
      
      // "Interrupt handler"
      //  not real handler, but call inside handler to
      void gpiote_event_handler(uint32_t event_pins_low_to_high, uint32_t event_pins_high_to_low)
      {
        MY_HW_RTC->CC[0] = (MY_HW_RTC->COUNTER + 2); // Taken from d0016 example code, ends the sleep delay
        if ((PIN_BUTTON1_MASK & event_pins_low_to_high) || (PIN_BUTTON1_MASK & event_pins_high_to_low)) {
          interrupt_cause = PIN_BUTTON1;
          door_status = !door_status;
        }
        else if ((PIN_BUTTON2_MASK & event_pins_low_to_high) || (PIN_BUTTON2_MASK & event_pins_high_to_low)) {
          interrupt_cause = PIN_BUTTON2;
        }
      }
      
      
      
      /**
         Utility functions for NRF51/52, from nerverdie's code here
         https://forum.mysensors.org/topic/6961/nrf5-bluetooth-action/1307
      */
      
      
      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()
      {
        turnOffHighFrequencyClock();
        turnOffRadio();
        turnOffUarte0();
      }
      
      
      void blinkityBlink(uint8_t pulses, uint8_t repetitions) {
        for (int x = 0; x < repetitions; x++) {
          // wait only in case there's been a previous blink
          if (x > 0) {
            sleep(500);
          }
          for (int i = 0; i < pulses; i++) {
            // wait only in case there's been a previous blink
            if (i > 0) {
              sleep(100);
            }
            digitalWrite(LED_BUILTIN, HIGH);
            wait(20);
            digitalWrite(LED_BUILTIN, LOW);
          }
        }
      }
      
      

      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
      #define PINS_COUNT           (32u)
      #define NUM_DIGITAL_PINS     (32u)
      #define NUM_ANALOG_INPUTS    (8u)
      #define NUM_ANALOG_OUTPUTS   (8u)
      
      /* 
       *  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                (2)
      // #define PIN_LED2                (25)
      // #define PIN_LED3                (26)
      // #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_LED3)
      // #define GREEN_LED               (PIN_LED4)
      // #define BLUE_LED                (PIN_LED1)
      // #define BLE_LED                 BLUE_LED
      #define LED_BUILTIN          PIN_LED1
      
      /* 
       *  Buttons
       *  
       *  This is optional
       */
      #define PIN_BUTTON1             (1)
      #define PIN_BUTTON2             (3)
      // #define PIN_BUTTON3             (5)
      // #define PIN_BUTTON4             (6)
      // #define PIN_BUTTON5             (7)
      // #define PIN_BUTTON6             (8)
      // #define PIN_BUTTON7             (9)
      // #define PIN_BUTTON8             (10)
      
      /* 
       * 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       (29)
      #define PIN_SERIAL_TX       (28)
      // #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 0
      
      #define PIN_SPI_MISO         (6)
      #define PIN_SPI_MOSI         (3)
      #define PIN_SPI_SCK          (4)
      #define PIN_SPI_SS           (5)
      
      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 1
      
      #define PIN_WIRE_SDA         (9u)
      #define PIN_WIRE_SCL         (10u)
      /*
      #define PIN_WIRE_SDA1        (15u)
      #define PIN_WIRE_SCL1        (16u)
      */
      static const uint8_t SDA = PIN_WIRE_SDA;
      static const uint8_t SCL = PIN_WIRE_SCL;
      
      #ifdef __cplusplus
      }
      #endif
      
      #endif
      

      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[]=
      {
        { PORT0,  0, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM0, NOT_ON_TIMER},  // AREF0 ADC/LPCOMP reference input 0
        { PORT0,  1, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A2, PWM1, NOT_ON_TIMER},
        { PORT0,  2, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A3, PWM2, NOT_ON_TIMER},
        { PORT0,  3, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A4, PWM3, NOT_ON_TIMER},
        { PORT0,  4, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A5, PWM4, NOT_ON_TIMER},
        { PORT0,  5, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A6, PWM5, NOT_ON_TIMER},
        { PORT0,  6, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A7, PWM6, NOT_ON_TIMER}, // AREF1 ADC/LPCOMP reference input 1
        { PORT0,  7, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM7, NOT_ON_TIMER},
        { PORT0,  8, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM8, NOT_ON_TIMER},
        { PORT0,  9, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM9, NOT_ON_TIMER}, 
        { PORT0, 10, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM10, NOT_ON_TIMER},
        { PORT0, 11, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM11, NOT_ON_TIMER},
        { PORT0, 12, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
        { PORT0, 13, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
        { PORT0, 14, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
        { PORT0, 15, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
        { PORT0, 16, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
        { PORT0, 17, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
        { PORT0, 18, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
        { PORT0, 19, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
        { PORT0, 20, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
        { PORT0, 21, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
        { PORT0, 22, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
        { PORT0, 23, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
        { PORT0, 24, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
        { PORT0, 25, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
        { PORT0, 26, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A0, NOT_ON_PWM, NOT_ON_TIMER},
        { PORT0, 27, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A1, NOT_ON_PWM, NOT_ON_TIMER},
        { PORT0, 28, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER},
        { PORT0, 29, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}
      };
      
      // Don't remove this line
      #include <compat_pin_mapping.h>
      
      #endif
      
      korttomaK Offline
      korttomaK Offline
      korttoma
      Hero Member
      wrote on last edited by
      #1539

      @nca78 I tried to follow your instructions in post #1514 but I must be doing something wrong when I add files from the NRF5 SDK to my sketch folder because I keep getting some errors about missing files, so I keep adding and now I got to this point:

      WARNING: Spurious .ci folder in 'MySensors' library
      WARNING: Spurious .mystools folder in 'MySensors' library
      In file included from C:\Users\Tomas\Documents\Arduino\NRF5SceneCtLC2Protoboard\NRF5SceneCtLC2Protoboard.ino:4:0:
      
      nrf_gpio.h:67: error: #error "Not supported."
      
       #error "Not supported."
      
        ^
      
      exit status 1
      #error "Not supported."
      
      • Tomas
      Nca78N 1 Reply Last reply
      0
      • korttomaK korttoma

        @nca78 I tried to follow your instructions in post #1514 but I must be doing something wrong when I add files from the NRF5 SDK to my sketch folder because I keep getting some errors about missing files, so I keep adding and now I got to this point:

        WARNING: Spurious .ci folder in 'MySensors' library
        WARNING: Spurious .mystools folder in 'MySensors' library
        In file included from C:\Users\Tomas\Documents\Arduino\NRF5SceneCtLC2Protoboard\NRF5SceneCtLC2Protoboard.ino:4:0:
        
        nrf_gpio.h:67: error: #error "Not supported."
        
         #error "Not supported."
        
          ^
        
        exit status 1
        #error "Not supported."
        
        Nca78N Offline
        Nca78N Offline
        Nca78
        Hardware Contributor
        wrote on last edited by
        #1540

        @korttoma sorry it seems I messed up with the files, this one is not from sdk.
        Please take the one here, I'll clean up and reorganize later:
        https://github.com/bitcraze/crazyflie2-nrf-mbs/blob/master/include/nrf/nrf_gpio.h

        korttomaK 1 Reply Last reply
        0
        • Nca78N Nca78

          @korttoma sorry it seems I messed up with the files, this one is not from sdk.
          Please take the one here, I'll clean up and reorganize later:
          https://github.com/bitcraze/crazyflie2-nrf-mbs/blob/master/include/nrf/nrf_gpio.h

          korttomaK Offline
          korttomaK Offline
          korttoma
          Hero Member
          wrote on last edited by
          #1541

          @nca78 still not getting anywhere with this. Would you mind ziping your sketch folder, then I should have all the correct files (right?). If I still have issues to compile I must be missing some library or are using the wrong version of something.

          • Tomas
          Nca78N 1 Reply Last reply
          0
          • korttomaK korttoma

            @nca78 still not getting anywhere with this. Would you mind ziping your sketch folder, then I should have all the correct files (right?). If I still have issues to compile I must be missing some library or are using the wrong version of something.

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

            @korttoma said in nRF5 Bluetooth action!:

            @nca78 still not getting anywhere with this. Would you mind ziping your sketch folder, then I should have all the correct files (right?). If I still have issues to compile I must be missing some library or are using the wrong version of something.

            Sure, but unfortunately I cannot upload a zip file here, please send me your email by private message.

            Ok here is a google drive link, it should be easier:
            https://drive.google.com/open?id=1IhLIx0nHd5KZR9dJ9qA0-_SMGmjEpbKj

            korttomaK 1 Reply Last reply
            2
            • T Toyman

              @alowhum there is a whole "movement" of people who are trying to reprogram them. Key issue is openability (how hard is to open it)
              The last easily openable watches are based on nrf51822, but the good thing is that programming pins are easily accesable and even marked SWD/SCLCK.
              Search Ali for ID107HR and google for "roger clark smartwatch"
              I am yet to find a watch that would be both nrf52 based AND easily openable

              NeverDieN Offline
              NeverDieN Offline
              NeverDie
              Hero Member
              wrote on last edited by NeverDie
              #1543

              @toyman said in nRF5 Bluetooth action!:

              I am yet to find a watch that would be both nrf52 based AND easily openable

              Maybe this one?
              https://www.alibaba.com/product-detail/Leather-Smart-Wristband-Bracelet-NORDIC-NRF52832_60726090170.html?spm=a2700.7724857.main07.29.6deb404ewQickL

              or, perhaps a little easier, this one?
              https://www.alibaba.com/product-detail/2018-NEW-Messages-Sync-smart-bracelet_60733935490.html?spm=a2700.7724857.main07.70.6deb404ewQickL

              or this?
              https://www.alibaba.com/product-detail/Intelligent-heart-rate-sport-smart-healthy_60734390506.html?spm=a2700.details.maylikever.9.7ec0487aXxyeI2

              I'm guessing that a typical jeweler would have the right tools to open it. Maybe get a little help with that part of it? I doubt it would cost much.

              Fortunately, there seem to be a plethora of different inexpensive nRF52832 watches available. Gobs of them.
              https://www.aliexpress.com/item/CACGO-K2-Smart-Watch-Bluetooth-4-0-Nordic-NRF52832-Chip-Sleep-Heart-Rate-Blood-Pressure-Blood/32853451564.html

              https://www.aliexpress.com/item/CACGO-K2-Bluetooth-Smartwatch-Waterproof-IP68-Heart-Rate-Blood-Pressure-Blood-Oxygen-Smart-Watch-for-iOS/32851202681.html?spm=2114.10010108.1000014.2.667554e38QctWv&traffic_analysisId=recommend_3035_null_null_null&scm=1007.13338.98644.000000000000000&pvid=b215db98-0db7-446e-a11f-3548284b4575&tpp=1

              T 1 Reply Last reply
              0
              • NeverDieN NeverDie

                @toyman said in nRF5 Bluetooth action!:

                I am yet to find a watch that would be both nrf52 based AND easily openable

                Maybe this one?
                https://www.alibaba.com/product-detail/Leather-Smart-Wristband-Bracelet-NORDIC-NRF52832_60726090170.html?spm=a2700.7724857.main07.29.6deb404ewQickL

                or, perhaps a little easier, this one?
                https://www.alibaba.com/product-detail/2018-NEW-Messages-Sync-smart-bracelet_60733935490.html?spm=a2700.7724857.main07.70.6deb404ewQickL

                or this?
                https://www.alibaba.com/product-detail/Intelligent-heart-rate-sport-smart-healthy_60734390506.html?spm=a2700.details.maylikever.9.7ec0487aXxyeI2

                I'm guessing that a typical jeweler would have the right tools to open it. Maybe get a little help with that part of it? I doubt it would cost much.

                Fortunately, there seem to be a plethora of different inexpensive nRF52832 watches available. Gobs of them.
                https://www.aliexpress.com/item/CACGO-K2-Smart-Watch-Bluetooth-4-0-Nordic-NRF52832-Chip-Sleep-Heart-Rate-Blood-Pressure-Blood/32853451564.html

                https://www.aliexpress.com/item/CACGO-K2-Bluetooth-Smartwatch-Waterproof-IP68-Heart-Rate-Blood-Pressure-Blood-Oxygen-Smart-Watch-for-iOS/32851202681.html?spm=2114.10010108.1000014.2.667554e38QctWv&traffic_analysisId=recommend_3035_null_null_null&scm=1007.13338.98644.000000000000000&pvid=b215db98-0db7-446e-a11f-3548284b4575&tpp=1

                T Offline
                T Offline
                Toyman
                wrote on last edited by
                #1544

                @neverdie AFAIK, they are all heavily glued to meet IPX67

                1 Reply Last reply
                1
                • T Offline
                  T Offline
                  Toyman
                  wrote on last edited by
                  #1545

                  Just curious design consideration, based on my question to Nordic:

                  https://devzone.nordicsemi.com/f/nordic-q-a/33448/led-power

                  LED consumption will not exceed 0.5ma if the pin is configured as s0s1

                  NeverDieN 1 Reply Last reply
                  0
                  • T Toyman

                    Just curious design consideration, based on my question to Nordic:

                    https://devzone.nordicsemi.com/f/nordic-q-a/33448/led-power

                    LED consumption will not exceed 0.5ma if the pin is configured as s0s1

                    NeverDieN Offline
                    NeverDieN Offline
                    NeverDie
                    Hero Member
                    wrote on last edited by NeverDie
                    #1546

                    @toyman Maybe that's enough to light a subset of the pixels on the display?

                    In theory these nRF52832 BLE are OTA re-programmable. If someone left the door open for that, then you wouldn't have to crack the case or fight with the glue. Well, maybe someday...

                    T 1 Reply Last reply
                    0
                    • NeverDieN NeverDie

                      @toyman Maybe that's enough to light a subset of the pixels on the display?

                      In theory these nRF52832 BLE are OTA re-programmable. If someone left the door open for that, then you wouldn't have to crack the case or fight with the glue. Well, maybe someday...

                      T Offline
                      T Offline
                      Toyman
                      wrote on last edited by
                      #1547

                      @neverdie I was thinking about that, but that's not gonna work. Why? The bootloader that accepts OTA has a private key. The key in the software should match the key.

                      NeverDieN 2 Replies Last reply
                      0
                      • T Toyman

                        @neverdie I was thinking about that, but that's not gonna work. Why? The bootloader that accepts OTA has a private key. The key in the software should match the key.

                        NeverDieN Offline
                        NeverDieN Offline
                        NeverDie
                        Hero Member
                        wrote on last edited by NeverDie
                        #1548

                        @toyman Would this work? Buy two. Sacrifice the first so that you can image the firmware on the chip and extract the password. Use that password to unlock the OTA firmware update for the second one.

                        Or, maybe it's the universal bluetooth password: 1234. Maybe try that first. ;)

                        1 Reply Last reply
                        0
                        • scalzS Offline
                          scalzS Offline
                          scalz
                          Hardware Contributor
                          wrote on last edited by scalz
                          #1549

                          afaik mysensors nrf52 isn't working with softdevice yet (same as your 'bootloader' here). there might be some conflicts with nrf52 resources (timers etc.). so you may need to open it for reprogramming.

                          1 Reply Last reply
                          0
                          • alowhumA Offline
                            alowhumA Offline
                            alowhum
                            Plugin Developer
                            wrote on last edited by
                            #1550

                            For me losing Bluetooth would be a feature: it makes you less likely to be tracked while in stores / smart cities.

                            1 Reply Last reply
                            0
                            • alowhumA Offline
                              alowhumA Offline
                              alowhum
                              Plugin Developer
                              wrote on last edited by
                              #1551

                              I turned a ST-Link v2 into a Black Magic Probe using this guide.

                              The Black Magic Probe creates two virtual serial ports. One to program over, and another one. Can that second one be used to listen to Serial output from the NRF52? If so, how can that be set up?

                              NeverDieN nagelcN 2 Replies Last reply
                              0
                              • alowhumA alowhum

                                I turned a ST-Link v2 into a Black Magic Probe using this guide.

                                The Black Magic Probe creates two virtual serial ports. One to program over, and another one. Can that second one be used to listen to Serial output from the NRF52? If so, how can that be set up?

                                NeverDieN Offline
                                NeverDieN Offline
                                NeverDie
                                Hero Member
                                wrote on last edited by
                                #1552

                                @alowhum Doesn't answer your question, but I use just regular FTDI to listen to the serial output from the nRF5. So, there's always that for you to fall back on.

                                1 Reply Last reply
                                0
                                • alowhumA alowhum

                                  I turned a ST-Link v2 into a Black Magic Probe using this guide.

                                  The Black Magic Probe creates two virtual serial ports. One to program over, and another one. Can that second one be used to listen to Serial output from the NRF52? If so, how can that be set up?

                                  nagelcN Offline
                                  nagelcN Offline
                                  nagelc
                                  wrote on last edited by
                                  #1553

                                  @alowhum I'm using a BMP that I made from a STM32 Blue Pill. The Serial works just fine.
                                  Set a TX pin on your NRF5 in the MyBoardNFR5.h file. Connect it to the RX pin on your BMP. The default pins are TX (PA.2) and RX (PA.3). So if you connect PA.3 on your programmer to the TX pin you select on the NRF5, you should have what you need.
                                  To program, select the lower number serial port.
                                  To see serial output, select the higher number serial port for your serial monitor.

                                  1 Reply Last reply
                                  2
                                  • alowhumA Offline
                                    alowhumA Offline
                                    alowhum
                                    Plugin Developer
                                    wrote on last edited by
                                    #1554

                                    @nagelc I am using a ST-Link V2 that I turned into a BMP. So i don't have a RX pin on that. But I do have these pins left:

                                    • RST
                                    • SWIM

                                    So you suppose any of these two pins are now RX?

                                    nagelcN T 2 Replies Last reply
                                    0
                                    • T Toyman

                                      @neverdie I was thinking about that, but that's not gonna work. Why? The bootloader that accepts OTA has a private key. The key in the software should match the key.

                                      NeverDieN Offline
                                      NeverDieN Offline
                                      NeverDie
                                      Hero Member
                                      wrote on last edited by NeverDie
                                      #1555

                                      @toyman Looks like a DIY watch, using one of the very small nRF52 modules and a small OLED screen (or maybe ePaper?) would be fairly easy to design and put together.
                                      https://www.aliexpress.com/item/Free-shipping-Latest-Big-time-wearable-devices-DIY-electronic-watch-programmable-watch-FOR-ARDUINO/32309696848.html?spm=2114.search0104.3.43.6855283fBpRmHN&ws_ab_test=searchweb0_0,searchweb201602_5_10152_10065_10151_5711320_10344_10068_10130_10324_10342_10547_10325_10343_10546_10340_10341_10548_10698_10545_10697_10696_10084_5722520_10083_10618_10307_5711220_10059_5722620_5722920_308_5722720_5722820_100031_10103_441_10624_10623_10622_10621_10620-10152,searchweb201603_25,ppcSwitch_5&algo_expid=e4147df1-7362-4700-8575-4d5fa986cd9a-6&algo_pvid=e4147df1-7362-4700-8575-4d5fa986cd9a&transAbTest=ae803_1&priceBeautifyAB=0

                                      Making it aesthetically pleasing is probably much harder! Still, maybe a DIY bridge would tide you over until a more proper watch is available for conversion. Interestingly, it looks like they made their case from stacked pieces of laser cut acrylic.

                                      Unfortunately, theirs is impractically large:
                                      alt text

                                      1 Reply Last reply
                                      0
                                      • alowhumA alowhum

                                        @nagelc I am using a ST-Link V2 that I turned into a BMP. So i don't have a RX pin on that. But I do have these pins left:

                                        • RST
                                        • SWIM

                                        So you suppose any of these two pins are now RX?

                                        nagelcN Offline
                                        nagelcN Offline
                                        nagelc
                                        wrote on last edited by
                                        #1556

                                        @alowhum Reset seems unlikely. Maybe SWIM. You could try it.
                                        If you can follow the trace back to the microprocessor, then you could figure out which pin it is. Then you could change to that pin in the BMP files, recompile, reload . . .. . Not sure it's worth all that experimentation when you can just use an FTDI as @NeverDie does.

                                        1 Reply Last reply
                                        1
                                        • gohanG Offline
                                          gohanG Offline
                                          gohan
                                          Mod
                                          wrote on last edited by
                                          #1557

                                          Is this an alternative programmer or is it STM32 only? https://www.aliexpress.com/store/product/CJMCU-JLINK-Support-for-SWD-s-JLINK-Simplified-Edition-Supports-STM32-SWD-Debugging-3-Wire/1245924_32792177272.html

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


                                          13

                                          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