Got Adafruit Feather 32u4 LoRa Radio to work and here is how


(Marcusbehrens) #1

There are a few tips spread over the forum and I want to bring the end-to-end instructions together here on how to get it to work. I still would go for the M0 based Lora for memory and processing power but I like to be able to refer to a true atmel for best support for hooking up any sensor or display based on libraries. What's great about both is that the communication module and the microcontroller are on one board already. Batterypowerwise I still need to find out how low it can go (below self-discharge rate of battery). I used Arduino 1.8.2 on a Mac - your milage may vary.

  1. Get an Adafruit Feather 32u4 lora with the right frequency range for your region (866 for Europe)

  2. Follow instructions on the adafruit site to hook up antenna and power supply

  3. Connect pin 6 with IO1 (as labeled on the feather)

  4. In the following follow the tutorial at https://www.thethingsnetwork.org/labs/story/creating-a-ttn-node and skip to the "Getting thing started with the Things network" part

  5. Do not use the built-in support for finding and download the lmic library - rather follow the instructions and download the zip file from github instead, and also do the modification described in the tutorial

  6. Remove all mentions of bmp280 sensor and temperatur and pascal from the sample source code and instead send the following data as a test without sensors: byte buffer[2] = {1,2};

  7. Change the pins to match the feather 32u4 lora like this:

    const lmic_pinmap lmic_pins = {
        .nss = 8,
        .rxtx = LMIC_UNUSED_PIN,
        .rst = 4,
        .dio = {7,6,LMIC_UNUSED_PIN},
    };
  8. The next 2 steps might or might not be necessary - if anyone dares to leave them out please comment below

    • Add a delay(1000); as the first step in the setup function

    • Change the clock error like this: LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100);

  9. Now register the device and update your code as per the instructions in the tutorial mentioned above

  10. It worked at first attempt with a Gateway a friend had set-up in our account (should work with any gateway) with the Gateway close by.

  11. Do whatever you want to hook up any sensor and send its data


EV_JOIN_FAILED with Adafruit Feather 32u4 and LMIC
Adding sensors to a lora node
Adafruit Feather 32u4 Lora raw APB testing
LoRa32u4 EV_JOINING
ttn.showStatus() returns empty values
Connect LoraWan, Which library to use?
(N 7) #2

I followed every steps you mentionned but I keep on EV_JOINING, then nothing. Did you get anything like this ?


(Marcusbehrens) #3

just checking: you have a (full) gateway near enough and it is operational (shows up in the console of the owner of the gateway as online)?

i never expected the otaa onboarding to work right away given that i had only read other people's tips and plugged it together. it did work right away ("joining" is followed by something like "joined") and continues to work (joined again also after power off and on of the node).


(N 7) #4

Thanks for your reply.

The gateway and it's antenna are about 3 meters away from the boards antenna, line of sight for both.

In the logs, I can see that the gateway says that a mote tryed to join, the mote got accepted, devnonce and stuff are generated and sent to the mote.

Anyways, the mote still can't go any further than "EV_JOINING".

I know that I am the wrong one in this story, I saw about 20 guys achieving this but I still can't do it on my own !

I need to pass this !

Thanks.


(Guido Gam) #5

I had the same problem because the node and thr gateway were too close, about 3 meters.
Try standing between the antennas. so they don't see each other anymore.
That cured my problem... :wink:

Or move one of the two in another room.


(Rustie0125) #6

Hey Guys

Im so glad I found this page, ihave been looking todo the same thing for weeks now, I have a multitech gateways connected to ttn and its working. (tested with other devices) I have now bought the 32u4 feather and need to get it working, i followed all steps but when i load the code the red led on the feather flashes for 5 seconds and stops flashing, there is no activity in the serial monitor or on ttn, i have a suspicion that my implementation of the keys are not correct. can some one post there key section of the arduino code or share the entire sketch as an example ?

thank you


(Marcusbehrens) #7

I will post it ina few hours here: https://github.com/marcuscbehrens/loralife


(Rustie0125) #8

thank you !

i managed to get it working after redoing it again but the serial window is still inactive,
Must i enable debugging somewhere? seeing your example code will still be great!


(Mdroberts1243) #9

I put a "while (!Serial);" line as the first line of the "setup()"... now I can see the serial output... Starting... EV_JOINING

Stuck there, but I'm 5km from home with no line of sight to my gateway... hopefully it works once I get home!


(Mdroberts1243) #10

One step you might add... Change the radio frequency range in the lmic config.h (I'm in Canada at 915MHZ, but the default code is 868).

This got me one step closer... I see data now on the gateway but mostly EV_JOIN_FAILED in the Serial output.

On the TTN Console I see Join Request at 904.6MHz and Join Accept at 923.9MHz... but I thought my 8 gateway frequencies are centered on 904.3 and 905.0???


(Mdroberts1243) #11

The current JOIN REQUEST Rx and ACCEPT Tx look like this in the gateway log:

May 12 23:03:46 rhf2s001 pktfwd[2273]: JSON up: {"stat":{"time":"2017-05-12 23:03:16 GMT","rxnb":1,"rxok":0,"rxfw":0,"ackr":0.0,"dwnb":0,"txnb":0}}
May 12 23:03:46 rhf2s001 pktfwd[2273]: INFO: [down] PULL_ACK received in 85 ms
May 12 23:03:46 rhf2s001 pktfwd[2273]: INFO: [down] PULL_ACK received in 84 ms
May 12 23:03:46 rhf2s001 pktfwd[2273]: RX: 00 38 4C 00 F0 7E D5 B3 70 61 5C 10 FE FF B6 76 98 2C D2 21 19 D6 1D
May 12 23:03:46 rhf2s001 pktfwd[2273]: JSON up: {"rxpk":[{"tmst":2964327023,"chan":8,"rfch":0,"freq":904.600000,"stat":1,"modu":"LORA","datr":"SF8BW500","codr":"4/5","lsnr":10.8,"rssi":-66,"size":23,"data":"ADhMAPB+1bNwYVwQ/v+2dpgs0iEZ1h0="}]}
May 12 23:03:46 rhf2s001 pktfwd[2273]: INFO: [down] PULL_ACK received in 83 ms
May 12 23:03:46 rhf2s001 pktfwd[2273]: INFO: [down] PULL_RESP received :slight_smile:
May 12 23:03:46 rhf2s001 pktfwd[2273]: JSON down: {"txpk":{"imme":false,"tmst":2969327023,"freq":923.9,"rfch":0,"powe":20,"modu":"LORA","datr":"SF7BW500","codr":"4/5","ipol":true,"size":17,"data":"IAEjwsn8wvb1Xk8cviF4VYI="}}
May 12 23:03:46 rhf2s001 pktfwd[2273]: INFO: [down] a packet will be sent on timestamp value 2969327023
May 12 23:03:46 rhf2s001 pktfwd[2273]: TX: 20 01 23 C2 C9 FC C2 F6 F5 5E 4F 1C BE 21 78 55 82
May 12 23:03:46 rhf2s001 pktfwd[2273]: INFO: [down] PULL_ACK received in 82 ms
May 12 23:03:46 rhf2s001 pktfwd[2273]: INFO: [down] PULL_ACK received in 81 ms
May 12 23:03:46 rhf2s001 pktfwd[2273]: INFO: [down] PULL_ACK received in 82 ms
May 12 23:03:46 rhf2s001 pktfwd[2273]: ##### 2017-05-12 23:03:46 GMT #####
May 12 23:03:46 rhf2s001 pktfwd[2273]: ### [UPSTREAM] ###
May 12 23:03:46 rhf2s001 pktfwd[2273]: # RF packets received by concentrator: 1
May 12 23:03:46 rhf2s001 pktfwd[2273]: # CRC_OK: 100.00%, CRC_FAIL: 0.00%, NO_CRC: 0.00%
May 12 23:03:46 rhf2s001 pktfwd[2273]: # RF packets forwarded: 1 (23 bytes)
May 12 23:03:46 rhf2s001 pktfwd[2273]: # PUSH_DATA datagrams sent: 2 (318 bytes)
May 12 23:03:46 rhf2s001 pktfwd[2273]: # PUSH_DATA acknowledged: 0.00%
May 12 23:03:46 rhf2s001 pktfwd[2273]: ### [DOWNSTREAM] ###
May 12 23:03:46 rhf2s001 pktfwd[2273]: # PULL_DATA sent: 6 (100.00% acknowledged)
May 12 23:03:46 rhf2s001 pktfwd[2273]: # PULL_RESP(onse) datagrams received: 1 (178 bytes)
May 12 23:03:46 rhf2s001 pktfwd[2273]: # RF packets sent to concentrator: 1 (17 bytes)
May 12 23:03:46 rhf2s001 pktfwd[2273]: # TX errors: 0
May 12 23:03:46 rhf2s001 pktfwd[2273]: ### [GPS] ###
May 12 23:03:46 rhf2s001 pktfwd[2273]: # GPS sync is disabled
May 12 23:03:46 rhf2s001 pktfwd[2273]: ##### END #####

Does this look correct?

Is there any additional debugging that can be enabled/added to the Arduino node code to see why it is concluding EV_JOIN_FAILURE?

Thanks,
-mark.


(Rustie0125) #12

Hi Mark

What gateway are you using? I am based in south africa and the 868mhz is correct for my location.
Have you defined the semtech chip(1272 or 1276) you are using in the config file ?
Are you using a feather for the node device ?

I have managed to succesfully send data to TTN. the serial monitor as you mentioned outputs " started" and then "EV join" and nothing else. but the system is running in the background s i get a packet of data once a minutes.

Im not sure if the serial log is buggy or if its due to the sleep procedure that switched everything off when done transmitting.


(Mdroberts1243) #13

Hi Rustie,

I've made a gateway from the RisingHF board set (RHF0M301 concentrator board). It is setup for 915MHz... I got it working initially with the RisingHF RaspberryPi image and their pktfwd executable, but now I've switched over to the ic880a howto, with the necessary tweeks for the RHF board.

I finally got the Adafruit 32u4 LoRa node to work... just now! The trick turned out to be careful placement of the Clock Error adjustment...

!!! You really have to put the LMICsetClockError(MAX_CLOCK_ERROR * 1 / 100); after the LMIC_Reset(); !!!_

Didn't Join at all until I did that after every reset... I will look into exactly where it is needed but it didn't work in the original place.

I had better luck coming out of sleep after I disabled all the Serial calls... I don't think the UART recovers properly or something.

I do see long stretches of missing data sometimes, even now...

Very relieved to see something end-to-end!

-mark.


(Rustie0125) #14

Hi Mark

Glad to see you go it working, I was just as relieved when i saw the info coming through the first time, iv given up trying to understand why the serial does not work, want to get my head around the code and then rewrite it to make sure everything works correctly. the long strehces of missing data i suspect is due to the sleep routine and the LMICsetClockError(MAX_CLOCK_ERROR * 1 / 100); change. You will see if you take the sleep cycle down to 1 (every 8 seconds) you are lucky to get a transmission every 30 seconds. Good luck with that if you figure out why this happens i would like to know myself.

I am now trying to implement Arduino -> TTN -> Cayenne via the LLP protocol for custom info.


(Mdroberts1243) #15

I disabled all my Serial code and switched the LED Pin to 13 (the 32u4 Lora has dedicated SPI pins so the LED seems to work fine). I use the LED to show basic functionality (like blinking it very briefly every transmit) so I can now see the device comes out of sleep reliably after joining and transmits every 20 seconds or so (two cycles).

Problem now is that many gaps in data counter appear... the radio often uses frequencies that aren't part of a little 8-channel gateway in America (72 channels available). So I've been trying to use the LMIC_disableChannel to restrict the node to available frequencies in my gateway but it seems to often ignore it and different forks of LMIC have different behaivour w.r.t the channels that get disabled and whether or not they honour the settings!

-mark.


(Arjan) #16

As you're referring to "joining": did you try OTAA? As TTN has a frequency plan defined for US, https://www.thethingsnetwork.org/wiki/LoRaWAN/Frequencies/Frequency-Plans#lorawan-frequencies_us902-928, I'd assume that you'll get the correct settings when using OTAA. (But: I'm in Europe. I don't even know if OTAA is supported for all regions.)


(Mdroberts1243) #17

Hi,

I'm using OTAA. The gateway I've set up uses the TTN frequency plan (global_conf.json) which sets up 8+1 channels, but the LMIC Arduino library uses all the channels available by default and there seems to be multiple issues with the LMIC_disableChannel() function since it seems to ignore the settings and appears to broadcast on disabled channels... so I get lots of gaps in my Counter sequence due to missed packets.

-mark.


(Mdroberts1243) #18

O.k. counter gaps seem to be resolved... you need to disable the unused channels (or sub-bands with LMIC_disableSubBand() ) after the reset of the LMIC library.

Very happy with the results so far!


(Rustie0125) #19

Hi Mark

Interesting

Which sub bands did you disable syntax for LMIC_disableSubBand()? when I try this void I get not declared issues on compiler


(Mdroberts1243) #20

Hi Rustie,

Here's the code in my LMIC initfunc():

// initial job
static void initfunc (osjob_t* j) {
    // reset MAC state
    LMIC_reset();
    // Let LMIC compensate for +/- 1% clock error
    LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100);
    // Disable subbands not supported by TTN 915MHz plan
    for (int i=0;i<8;i++)
      if (i != 1)
        LMIC_disableSubBand(i);
    // start joining
    LMIC_startJoining();
    // init done - onEvent() callback will be invoked...
}

It is very specific to the TTN 915MHz plan... basically they only use SubBand 1.

With this in place my node joins in about 4 seconds or so and I see all eight channels being used randomly... not sure when the 500kHz channel will be used.

Also, I found each LMIC fork to be a little different. I settled on the MCCI Catena LMIC fork which seems to be the most up-to-date and oriented to 915MHz.

-mark.