MRF24J40 with arduino (teensyduino)

Earlier, I’d been working in pure C land, but I know not everyone uses pure C, and sometimes, the arduino environment is a nice easy way to get something prototyped.

So, I turned my mrf24j40 library into an arduino library! It supports all the basic stuff for sending and receiving 802.15.4 frames in a non-beacon network. It’s been tested so far with teensyduino, but it doesn’t use any teensy specific features, so it should work just fine on any arduino style board that has SPI and three spare pins for the reset, interrupt and chip select pins.

You can get the library from github, and like any arduino library, just extract it into your arduino/libraries directory. There are examples for tx only, rx only, and two way data.

Get the MRF24J40 arduino library

The examples are about the extent of the documentation so far, but just email me with questions!

Leave a comment ?


  1. Hello Karl,

    Greetings. I am trying to interface MRF24J40 with Arduino.
    Thanks for making your MRF24J40 Arduino library public.
    I installed your mrf-arduino library in the arduino libraries folder.

    I have connected MRF pins to Arduino as follows:
    MRF – Arduino Pin
    INTR – 5
    RESET – 6
    CS – 7
    MISO – 11
    MOSI – 12
    SCK – 13

    When I compile the sketch, TxOnly ,
    nothing happens. Looks like while MRF object
    initialization the arduino hangs or doesnt respond.

    I commented all the Tx functionality, I am only doing

    Mrf24j mrf(pin_reset, pin_cs, pin_interrupt);

    void setup() {


    void loop(){
    Serial.print(” MRF Tx “);

    I have tested the arduino with Blinky and other examples,
    all are working fine.

    Am I missing anything?


  2. hi im having the same problem too , im using the arduino nano and when i tried the object initialization in functions it works but gives output as 0 if i try to read the pan , if u have solved the problem please let me know

  3. This is almost certainly wiring problems. A few people have private emailed me with problems, all of which so far have been resolved to wiring.

  4. First of all, thanks for the library! I’ve got my two boards communicating, but I’m having trouble with the data part. I can see where to put in the data for the transmitting side, but the receiving end spits out hex data, rather than the ascii that is sent. Any ideas on how to convert it? Also, in the examples, they all have the same address(0x6001), but the transmit code sends to a different address (0x4202). Is this intentional, or should the RX board have the 0x4202 address?

  5. The examples are for one node. You would need to change these for the “other” node. ie, the examples are all programmed to Node A (address 0x6001) and are expected to be communicating with Node B (address 0x4202)

    As for the hex vs ascii, that’s all up to you. Line 81 in Basic_TwoWay just loops through all the received data, and prints it as hex. If you want that be interpreted as some other format, that’s all up to you. Those sorts of places are where I really expect you to put your own code in.

  6. I am having the same problem as jn. I haven’t really dug into it yet so I will keep troubleshooting and let you know what I find.

  7. Hey karl , thanks for the code . i have encountered 2 problems and btw im using arduino uno.

    1: i see that both the TX_only and Rx_only only listen to 6001 and there is no send16() there in tx_only so what exactly is being written ? and do i need to change 6001 to 4202 in rx_only ?

    2. and i am using the tx and rx and i keep getting ‘txxxing’ and when i try to read PANIDH within the loop() i keep getting 0 and both the modules keeps saying txxxing but no ack received or failed

    thanks mate

  8. Your absolutely right.

    I merged some code in that for some inexplicable reason removed the code that actually _sent_ This was when I was still learning git, so I probably just screwed up. I’ll try and fix that later today, but I don’t have any arduinos set up any more, so it won’t be tested.

    The same probably applies to 2, there’s some code that was merged that look at now, I don’t know why I ever accepted it. I can only plead ignorance that I missed it. The last commit from me, where it would have been tested, was

  9. So mate , do i need to change 6001 to 4202 in rx_only and add send 16 to the tx_only ?

  10. Hello KarIp
    – I have a question. Why you don’t connect wake pin ?
    Or mrf24j40 always active (wake) don’t sleep.
    – And you can write sleep mode ?

  11. hello Karlp,
    thanks for this library,
    I’m using this library for my MRF24J40MA with arduino.I ‘ve seen your library source code but I ‘ve not found which function can be used to transfer data (such as: int, float…) between them.

    What can i do now?

  12. How you format your messages is up to you. You need to decide that for yourself. the examples send a string, but it’s really just a character buffer.

  13. Thanks, Karlp

    Now I want to set up a sensor network between 5 modules. 1 is coordinator, 1 is router and 3 are end device with Security.
    But I found it’s difficulty to do that. May you continue to develope your library in the future (such as: Beacon, Encryption, communication between up to 2 modules…)? That will helps me many things. Because I’m not good at writting an Library and Zigbee is quite complicated …

    Help me please! :D

  14. Zigbee is an entire layer on top of 802.15.4. My library has no inkling of zigbee, nor will it ever. (In my fork of it at least)

  15. Sr, I mean may you continue to develope your library? Or may you give me some advices for my project?

    I wanna set up between 5 MRF24J40MA modules. (as I said above). But I got trouble when I tried to let 4 modules send data to another one.(my modules I wanna receive data has address: 0x6001, and 4 modules I told you send data to this address) I don’t know how to config for this one to receive data in an order. For example:

    When I send char from 4 modules to this one. I wanna see in its Serial monitor in an order:

    “Received from module 1
    Received from module 2
    Received from module 3…”

    But all I got in the serial monitor are not in an order and sometimes I got some error characters, even I’ve try to add delay function for each module after send data code (module 1: delay(500), module 2: delay(1000),module 3: delay(1500)…) :

    “Received from module 1
    Received from modu@#$@
    Received from module 2…”

    What can I do now? Please give me some instruction… Thanks alot

  16. Let me be clear. a) comments on a ~4 year old post are _not_ the way to have a discussion, let alone get help. b) I’m not planning _any_ further work on this library, but if people send a pull request, I’ll consider merging it if it comes with clear explanations and test methods. c) I’m not interested in developing your mesh network application. d) using delay(hundreds of milliseconds) is going to _trash_ network reception. If you expect to be able to program in blocking delays with any sort of network interface you are sorely mistaken, and will continue to have pain and suffering until you stop that.

    I’m locking comments on this post, the library does what it claims. If you want more, consider looking at: for how the linux kernel handles this device.

  17. Hi Karl, am trying to run the new MRF24J40MD RF with arduino Due. Can you tell me what modifications i have to do to my code if i want it to run?

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Trackbacks and Pingbacks: