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 631.3k 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.
  • M magkudjee

    Hi every one. I'm very new in mysensors (I use bad English)
    in my sketch how to setup sleep,interrupt for 3 button (์NRF51822)
    thank you

    #define MY_DEBUG 
    #define MY_NODE_ID 4
    
    //#define MY_RADIO_NRF24
    #define MY_RADIO_NRF5_ESB
    
    #include <SPI.h>
    #include <MySensors.h>
    
    #define CHILD_ID_SW1 1
    #define CHILD_ID_SW2 2
    #define CHILD_ID_SW3 3
    
    #define BUTTON1_PIN 3
    #define BUTTON2_PIN 4
    #define BUTTON3_PIN 5
    
    boolean sw1State;
    boolean lastState1;
    boolean tripped1 = HIGH;
    
    boolean sw2State;
    boolean lastState2;
    boolean tripped2 = HIGH;
    
    boolean sw3State;
    boolean lastState3;
    boolean tripped3 = HIGH;
    
    MyMessage msg1(CHILD_ID_SW1, V_TRIPPED);
    MyMessage msg2(CHILD_ID_SW2, V_TRIPPED);
    MyMessage msg3(CHILD_ID_SW3, V_TRIPPED);
    
    void presentation() 
    {
      sendSketchInfo("Push Button 1", "1.0");
      
      present(CHILD_ID_SW1, S_DOOR); 
      present(CHILD_ID_SW2, S_DOOR);
      present(CHILD_ID_SW3, S_DOOR); 
    }
    
    void setup() 
    {
      pinMode (BUTTON1_PIN,INPUT_PULLUP);
      pinMode (BUTTON2_PIN,INPUT_PULLUP);
      pinMode (BUTTON3_PIN,INPUT_PULLUP);
    
    }
     
    void loop() 
    { 
      sw1State = digitalRead(BUTTON1_PIN);
      if ( ( sw1State == LOW) && (lastState1 == HIGH) ) tripped1 = !tripped1;
      send(msg1.set(tripped1==HIGH ? "1" : "0"));
         lastState1 = sw1State;
    
      sw2State = digitalRead(BUTTON2_PIN);
      if ( ( sw2State == LOW) && (lastState2 == HIGH) ) tripped2 = !tripped2;
      send(msg2.set(tripped2==HIGH ? "1" : "0"));
         lastState2 = sw2State;
    
      sw3State = digitalRead(BUTTON3_PIN);
      if ( ( sw3State == LOW) && (lastState3 == HIGH) ) tripped3 = !tripped3;
      send(msg3.set(tripped3==HIGH ? "1" : "0"));
         lastState3 = sw3State;
    
      //sleep(digitalPinToInterrupt(BUTTON1_PIN), CHANGE, 0);    
      //sleep(INTERRUPT, CHANGE, 0);
    }
    
    nagelcN Offline
    nagelcN Offline
    nagelc
    wrote on last edited by
    #1757

    @magkudjee
    MySensors will support 2 interrupts using sleep. I do not think it will support 3.
    Use this format for the sleep call:
    sleep(interrupt1, mode1, interrupt2, mode2, ms=0);
    In your case: sleep(BUTTON1_PIN, CHANGE, BUTTON2_PIN, CHANGE, 0);

    I don't know how to handle the 3rd interrupt.

    Check the MySensors API document here: https://www.mysensors.org/download/sensor_api_20#sleeping

    M 1 Reply Last reply
    1
    • O Omemanti

      @smilvert do you have some more information? like some serial output?

      I had some issues with statements that uses millis(), in about 1,5 up to 2 days (much shorter the normaly I suppose) it did its rollover back to 0. This messed some waiting times for me.

      S Offline
      S Offline
      smilvert
      wrote on last edited by
      #1758

      @omemanti Well it seems to start working now... Hopefully it works :) Havn't restart the gateway in 2 weeks now

      1 Reply Last reply
      0
      • T Toyman

        @omemanti actually, all you need is to issue the following command:
        nrfjprog.exe --recover

        mr_redM Offline
        mr_redM Offline
        mr_red
        wrote on last edited by
        #1759

        @toyman @Omemanti

        For Documentations sake:
        I was having the same problems of the Ebyte E73 Module of being locked.
        The ST_LinkV2 Clone Firmware are not able to recover the modules as the swd implementation is missing some direct register write capabilities.
        The nfrjprog and nor openocd are working with the ST_LinkV2.

        As suggested in this thread somewhere, I was able to get the modules unlocked with the Jlink clone and nrfjprog.
        see also :
        https://github.com/micooke/arduino-nRF5-smartwatches/blob/master/nrf52_disable_read_protection.txt

        That (pirated) Firmware is working with swd and is able to recover the modules. Had to solve some dll-issues before, but got it working.
        After the recovery with nrfjprog the stlink and the jlink are working as expected with openocd.

        To find out if your wiring etc. is fine and it is really the locked devices you get this when starting your openocd interface.
        The voltage is fine but the breakpoints are recognized.

        Info : STLINK v2 JTAG v17 API v2 SWIM v4 VID 0x0483 PID 0x3748
        Info : using stlink api v2
        Info : Target voltage: 3.241270
        Info : nrf52.cpu: hardware has 0 breakpoints, 2 watchpoints
        Error: timed out while waiting for target halted
        TARGET: nrf52.cpu - Not halted
        

        It should be

        Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints
        
        ileneken3I 1 Reply Last reply
        0
        • mr_redM mr_red

          @toyman @Omemanti

          For Documentations sake:
          I was having the same problems of the Ebyte E73 Module of being locked.
          The ST_LinkV2 Clone Firmware are not able to recover the modules as the swd implementation is missing some direct register write capabilities.
          The nfrjprog and nor openocd are working with the ST_LinkV2.

          As suggested in this thread somewhere, I was able to get the modules unlocked with the Jlink clone and nrfjprog.
          see also :
          https://github.com/micooke/arduino-nRF5-smartwatches/blob/master/nrf52_disable_read_protection.txt

          That (pirated) Firmware is working with swd and is able to recover the modules. Had to solve some dll-issues before, but got it working.
          After the recovery with nrfjprog the stlink and the jlink are working as expected with openocd.

          To find out if your wiring etc. is fine and it is really the locked devices you get this when starting your openocd interface.
          The voltage is fine but the breakpoints are recognized.

          Info : STLINK v2 JTAG v17 API v2 SWIM v4 VID 0x0483 PID 0x3748
          Info : using stlink api v2
          Info : Target voltage: 3.241270
          Info : nrf52.cpu: hardware has 0 breakpoints, 2 watchpoints
          Error: timed out while waiting for target halted
          TARGET: nrf52.cpu - Not halted
          

          It should be

          Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints
          
          ileneken3I Offline
          ileneken3I Offline
          ileneken3
          wrote on last edited by
          #1760

          @mr_red
          I can add some of my own "documentation" on this issue. I only recently was able to program an Ebyte E73 module, and it was a long struggle. I used the NRF DK, and had help from a Nordic engineer.

          • The recommended way to connect to the external device is:

          Using the P20 and P1 headers, connect:
          P20 VDD -> 3.3v on EBYTE 2G4M04S1B module
          P20 SWDIO -> SWDIO on EBYTE 2G4M04S1B module
          P20 SWDCLK -> SWDCLK on EBYTE 2G4M04S1B module
          P20 VTG -> P1 VDD
          P1 GND -> GND on EBYTE 2G4M04S1B module

          To unlock the chip, execute:

          nrfjprog -f nrf52 --recover

          They also recommend using nrfjprog to program the device, because nRFgo Studio is deprecated. But I used the Studio and it worked fine. I gave Studio the .hex produced by the Arduino IDE using "Sketch" -> "Export compiled Binary".

          As mentioned in the previous post, it is unlikely to unlock the board with anything but the NRF DK or a genuine J-Link. (Maybe a good fake J-Link).

          Mistakes others may be able to learn from:

          • Soldering the module onto a custom board can be hard. If you miss a little solder on SWDCLK or SWDIO, there is no hope. Check continuity on every pin you need!
          • Make sure you don't order a NRF52810 module - only NRF52832 . You can program them, but Mysensors is not compatible. It's easy to hit the wrong link on AliExpress as they look identical.
          • The NRF DK seems to deliver only 2.8V to the device. I first thought there was a problem, and tried to connect external power sources. But it seems to work powered from the DK.
          mr_redM 1 Reply Last reply
          0
          • nagelcN nagelc

            @magkudjee
            MySensors will support 2 interrupts using sleep. I do not think it will support 3.
            Use this format for the sleep call:
            sleep(interrupt1, mode1, interrupt2, mode2, ms=0);
            In your case: sleep(BUTTON1_PIN, CHANGE, BUTTON2_PIN, CHANGE, 0);

            I don't know how to handle the 3rd interrupt.

            Check the MySensors API document here: https://www.mysensors.org/download/sensor_api_20#sleeping

            M Offline
            M Offline
            magkudjee
            wrote on last edited by
            #1761

            @nagelc

            thank you

            1 Reply Last reply
            0
            • ileneken3I ileneken3

              @mr_red
              I can add some of my own "documentation" on this issue. I only recently was able to program an Ebyte E73 module, and it was a long struggle. I used the NRF DK, and had help from a Nordic engineer.

              • The recommended way to connect to the external device is:

              Using the P20 and P1 headers, connect:
              P20 VDD -> 3.3v on EBYTE 2G4M04S1B module
              P20 SWDIO -> SWDIO on EBYTE 2G4M04S1B module
              P20 SWDCLK -> SWDCLK on EBYTE 2G4M04S1B module
              P20 VTG -> P1 VDD
              P1 GND -> GND on EBYTE 2G4M04S1B module

              To unlock the chip, execute:

              nrfjprog -f nrf52 --recover

              They also recommend using nrfjprog to program the device, because nRFgo Studio is deprecated. But I used the Studio and it worked fine. I gave Studio the .hex produced by the Arduino IDE using "Sketch" -> "Export compiled Binary".

              As mentioned in the previous post, it is unlikely to unlock the board with anything but the NRF DK or a genuine J-Link. (Maybe a good fake J-Link).

              Mistakes others may be able to learn from:

              • Soldering the module onto a custom board can be hard. If you miss a little solder on SWDCLK or SWDIO, there is no hope. Check continuity on every pin you need!
              • Make sure you don't order a NRF52810 module - only NRF52832 . You can program them, but Mysensors is not compatible. It's easy to hit the wrong link on AliExpress as they look identical.
              • The NRF DK seems to deliver only 2.8V to the device. I first thought there was a problem, and tried to connect external power sources. But it seems to work powered from the DK.
              mr_redM Offline
              mr_redM Offline
              mr_red
              wrote on last edited by
              #1762

              @ileneken3
              It is a struggle indeed. I wanted to stay "low cost" with clone stlink and clone jlink.
              As this is in preparation for a local hackspace workshop the entry level should be as low as possible.
              And I suceeded to get this running for under 10€. (only one Jlink needed to unlock the modules once)

              I am using platform.io and arduino, which use openocd internally. No need for nrfgo or an second programm and take the hex somewhere else.
              Highly recommend platform.io for this! Flashing & Serial output are superfast, nice IDE and my dev-cycle speed up by an order of magnitude.

              Question:
              I am using an second device for USB-Serial convertion to get some print-msg out of the nrf52832.
              Is there any way to do this over the programmer?

              You can define the RX/TX pins in the nrf52832 to the pins you want.
              Hardware Workaround by Neverdie: Connector Board -openhardware.io

              T 1 Reply Last reply
              0
              • mr_redM mr_red

                @ileneken3
                It is a struggle indeed. I wanted to stay "low cost" with clone stlink and clone jlink.
                As this is in preparation for a local hackspace workshop the entry level should be as low as possible.
                And I suceeded to get this running for under 10€. (only one Jlink needed to unlock the modules once)

                I am using platform.io and arduino, which use openocd internally. No need for nrfgo or an second programm and take the hex somewhere else.
                Highly recommend platform.io for this! Flashing & Serial output are superfast, nice IDE and my dev-cycle speed up by an order of magnitude.

                Question:
                I am using an second device for USB-Serial convertion to get some print-msg out of the nrf52832.
                Is there any way to do this over the programmer?

                You can define the RX/TX pins in the nrf52832 to the pins you want.
                Hardware Workaround by Neverdie: Connector Board -openhardware.io

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

                @mr_red said in nRF5 action!:

                Is there any way to do this over the programmer?

                Not in Arduino. In KEIL you can use RTT (pretty cool stuff, debug via SWD)
                But if you just want to decrease a number of programmers, you can use Black Magic Probe, made from BluePill ($2 at Ali). It is 2-in-1 SWD and USB-UART converter on one PCB

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

                  @ileneken3 @mr_red Thanks for this! Glad to hear I wasn't going crazy, but that others have had the same issue.

                  1 Reply Last reply
                  0
                  • O Offline
                    O Offline
                    Omemanti
                    wrote on last edited by
                    #1765

                    A quick Google pointed me to https://github.com/AndruPol/nrf52832-recover/blob/master/README.md

                    I do have a STM32F103C8T6 laying around. But ATM no time to play with it.

                    Maybe that's the €3 solution for unlocking.

                    T 1 Reply Last reply
                    0
                    • O Omemanti

                      A quick Google pointed me to https://github.com/AndruPol/nrf52832-recover/blob/master/README.md

                      I do have a STM32F103C8T6 laying around. But ATM no time to play with it.

                      Maybe that's the €3 solution for unlocking.

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

                      @omemanti said in [nRF5 action!]Maybe that's the €3 solution for unlocking.

                      BMP is enough to unlock. BluePill costs ca. €2 and it's easily convertable to BMP

                      1 Reply Last reply
                      0
                      • mr_redM Offline
                        mr_redM Offline
                        mr_red
                        wrote on last edited by
                        #1767

                        @Omemanti Good find about the BMP to recover the Ebyte module. Can you point me to an aliexpress link? "stm32" "bluepill" are not the magic chinese keywords..

                        mfalkviddM 1 Reply Last reply
                        1
                        • mr_redM mr_red

                          @Omemanti Good find about the BMP to recover the Ebyte module. Can you point me to an aliexpress link? "stm32" "bluepill" are not the magic chinese keywords..

                          mfalkviddM Offline
                          mfalkviddM Offline
                          mfalkvidd
                          Mod
                          wrote on last edited by
                          #1768

                          @mr_red https://medium.com/@paramaggarwal/converting-an-stm32f103-board-to-a-black-magic-probe-c013cf2cc38c has keywords and a direct link to Ali

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

                            I created a BMP, both from a cheap ST-Link and an STM32, and it didn't help me break open those eByte NRF52 units.

                            mr_redM 1 Reply Last reply
                            0
                            • alowhumA alowhum

                              I created a BMP, both from a cheap ST-Link and an STM32, and it didn't help me break open those eByte NRF52 units.

                              mr_redM Offline
                              mr_redM Offline
                              mr_red
                              wrote on last edited by
                              #1770

                              @alowhum where did you get stuck? Whats your process?

                              ileneken3I 1 Reply Last reply
                              0
                              • monteM monte

                                @smilvert I think I solved issues I mentioned. But I don't have final code yet as I am waiting for parts to arrive for my board. But I think there is no problem using WT51822 board except that you'll have to manually set PORT interrupt and also set pin SENSE register which is cannot be done with arduino function pinMode().
                                So I guess you can order PCBs if you want, I'm going to post final sketch with explanations at the end of the month.

                                W Offline
                                W Offline
                                waspie
                                wrote on last edited by
                                #1771

                                @monte do you have final code now ? :)

                                1 Reply Last reply
                                0
                                • mr_redM mr_red

                                  @alowhum where did you get stuck? Whats your process?

                                  ileneken3I Offline
                                  ileneken3I Offline
                                  ileneken3
                                  wrote on last edited by
                                  #1772

                                  @mr_red

                                  I got to the point where the stm32loader.py runs and outputs:

                                  Bootloader version 22
                                  Chip id: 0x410 (STM32 Medium-density)
                                  Write 256 bytes at 0x8000000
                                  Write 256 bytes at 0x8000100
                                  [..snip..]
                                  Write 256 bytes at 0x8001900
                                  Write 256 bytes at 0x8001A00
                                  Read 256 bytes at 0x8000000
                                  Read 256 bytes at 0x8000100
                                  [..snip..]
                                  Read 256 bytes at 0x8001900
                                  Read 256 bytes at 0x8001A00
                                  Verification OK

                                  After that, you're supposed to plug in to the USB directly. I get " USB device not recognized". Zadig doesn't help. It lists it as:

                                  "Unknown USB Device (Device Descriptor Request Failed)"

                                  Any ideas?

                                  Thanks.

                                  T 1 Reply Last reply
                                  0
                                  • ileneken3I ileneken3

                                    @mr_red

                                    I got to the point where the stm32loader.py runs and outputs:

                                    Bootloader version 22
                                    Chip id: 0x410 (STM32 Medium-density)
                                    Write 256 bytes at 0x8000000
                                    Write 256 bytes at 0x8000100
                                    [..snip..]
                                    Write 256 bytes at 0x8001900
                                    Write 256 bytes at 0x8001A00
                                    Read 256 bytes at 0x8000000
                                    Read 256 bytes at 0x8000100
                                    [..snip..]
                                    Read 256 bytes at 0x8001900
                                    Read 256 bytes at 0x8001A00
                                    Verification OK

                                    After that, you're supposed to plug in to the USB directly. I get " USB device not recognized". Zadig doesn't help. It lists it as:

                                    "Unknown USB Device (Device Descriptor Request Failed)"

                                    Any ideas?

                                    Thanks.

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

                                    @ileneken3 have you returned the jumpers back?

                                    ileneken3I 1 Reply Last reply
                                    0
                                    • T Toyman

                                      @ileneken3 have you returned the jumpers back?

                                      ileneken3I Offline
                                      ileneken3I Offline
                                      ileneken3
                                      wrote on last edited by
                                      #1774

                                      @toyman
                                      Unfortunately, yes, I have returned the jumpers to their original settings, and have even tried all 4 combinations.
                                      I also changed computers, changed OS's, changed cables.

                                      The board LOOKS like it was well manufactured, but I suppose a bad board is a possibility. Other than that, I can't figure out what could be wrong.

                                      1 Reply Last reply
                                      0
                                      • d00616D d00616

                                        @Nca78 said in nRF5 Bluetooth action!:

                                        Does that mean I have to go the long hard way with a bluepill as programmer and openocd ? Anyone has other ideas to unlock and erase the device ?

                                        Select in to Tools menu "None" Softdevice and then "Burn Bootloader". This raises an error but the device is erased completely.

                                        sebiS Offline
                                        sebiS Offline
                                        sebi
                                        wrote on last edited by
                                        #1775

                                        @d00616 said in nRF5 action!:

                                        @Nca78 said in nRF5 Bluetooth action!:

                                        Does that mean I have to go the long hard way with a bluepill as programmer and openocd ? Anyone has other ideas to unlock and erase the device ?

                                        Select in to Tools menu "None" Softdevice and then "Burn Bootloader". This raises an error but the device is erased completely.

                                        I am having the same issue trying to write on a E73 module with read/write protections. I don't have a JLink, but a ST Link-V2 and OpenOCD.
                                        Do you know how to remove the protections on the E73 with such tools? Thanks.

                                        1 Reply Last reply
                                        0
                                        • N Offline
                                          N Offline
                                          novicit
                                          wrote on last edited by
                                          #1776

                                          @sebi,
                                          A couple weeks ago I began exploring deploying E73 modules and had to remove protections. I was successful and now have a working E73 ethernet gateway. Only had ST Link-V2, so I used a "blue pill" I had in inventory to load it with Black Magic Probe. This cleared the protections.

                                          The instructions I followed to load the BMP are step-by-step at https://github.com/TamojitSaha/STM32f103_Black-Magic-Probe

                                          The instructions followed to clear protections with BMP also are step-by-step and worked perfect. They are at https://github.com/AndruPol/nrf52832-recover

                                          In item #4, the program arm-none-eabi-gdb.exe seems to be part of the Arduino tool chain as I found it just by doing a search in file explorer and it was already on my win10 machine. Also, in item #4, (gdb) is the prompt that the program arm-none-eabi-gdb.exe gives. In the first line, change the '/dev/ttyACM0' to your com port. Use 'quit' to exit the program. Also, use 'mon help' to see options.

                                          There are apparently a number of ways to 'recover' the E73, but this worked easily for me, and was step-by-step.

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


                                          6

                                          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