Monday, April 8, 2013

Wireless/Zigbee for PIC Micros

Back in 2009, my professional work involved leading the firmware project of a low power wireless network of sensors collecting temperature and humidity data. Wireless gateways accumulated the information and sent to a data center over the internet. During that project, I fancied my own Zigbee network for my robots and setting up a network of home monitoring sensors. I eventually bought some Microchip MRF24J40MA modules (which is a completely different platform than my professional work). Unfortunately, the modules had been siting idle for more than 3 years and until very recently, I didn't get a chance to play with them.

Microchip has a great library called Miwi which provides out of the box Zigbee like infrastructure based and P2P protocols. There are plenty of demo boards available as well. However, to fit wireless into projects where space is a luxury, you need to get your hands dirty.

I prefer building my own platforms from the scratch rather than using ready solutions like the microchip demo boards or even the Arduino and Zigbee shields. While Arduino and its sheilds are excellent kits for beginners, I feel I have a different taste. Arduino + Zigbee shields are insanely expensive as well. For example, a set Arduino + Zigbee shields will cost £40 or more while PIC + its radio modules are less than £7. So you can easily have a whole network of PICs with the price of one bulky Arduino Zigbee :). I'm happy with any low level programming challenge the PIC solution will through at me (In fact, that's what I really enjoy doing).

I'm using the PIC18F26K20 for the network. With 64KB ROM, 4K RAM, 16 mips/64 MHz and XLP, it has been adequate for my hobbits works for some years. Here's how my prototypes look like:

Sending data to the Zena network analyzer.

Sending and receiving tests with two sets of modules.

So my Zigbee network is ready to be plugged in (to my next projects). The assembled version of these prototype boards will look very different. I'll introduce the PCB version soon.

Later this week, I'll present how to talk to a micro wirelessly from C#, how to add wireless internet to a PIC and how to add Zigbee support to a Raspberry Pi. Sounds interesting?

10 comments:

  1. where do we find your other posts on how to program these guys and such ?

    ReplyDelete
  2. For the hardware part, you can use PICKIT3 which supports programming and debugging most PIC controllers. Or for a professional solution, ICD3 is the one. Microchip C18 compiler has free unrestricted version and the MPLAB IDE is always free as well. Each PIC is very well documented (which is the best part of PICs) and there are plenty of programming guides online (microchip.com).

    ReplyDelete
  3. Hi,

    fiorst of all, great set of articles/blogs you have here.

    I am starting a project much like the one you described for
    remote sensing the temperature, and the central device
    would be Pi.

    The intention was to use Atmel's ZigBit modules, having
    integrated antennae + usable MCU + Zigbe HA profile. All
    this at a cost of around £20 + my custom sensor board.

    Seeing this your set of blogs, i am having second thougts.

    Would you present some insight info about the range for these
    devices (or the one you used in commercial project, like,
    is it possible to use it in a house. Like for example, 4 sensors
    on each floor, and the center device (Pi) to be on whatever
    floor ? So the longest distance from sensor to Pi would be
    roughly about 20m trough walls ? Speed of transfer is irrelevent here.
    And secondly, do you feel that the Microchip's MiWi protocol
    stack is appropriate for this configuration ?
    I suppose, that you would propose the host pic MCU to use in this
    configuration (like PIC18) ?

    I am open to any suggestions/ideas,
    Miroslav

    ReplyDelete
    Replies
    1. That sounds like a proper sensor network!

      The MRF24J40MA's PCB antenna has a poor range. With some quick indoor testing in between two modules, signals faded out at 4-5 meters even with line of sight. With no line of sight, signals didn't survive indoor walls + 2-3 meters. As I haven't done proper thorough testing, I could be wrong with the ranges (but google can answer). Please note both of those modules in test have PCB antennas which are very weak by their nature.

      To achieve 20m with no LoS, you'll probably need modules with external antennas. Ideal sensor network will have external antenna in the gateway/center devices and PCB on the sensor nodes. That works well with power too, as in most of the cases, the gateway is mains powered and sensor boards are battery powered. You can also have some repeaters to extend the range.

      I found this module with a quick search:
      http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en553922

      Miwi (and Zigbee) supports these common network topologies and it simply classifies devices as full function (FFD) or reduced function (RFD). Gateway and repeater as FFDs and sensor nodes are RFD here.

      Miwi is written for Microchip MCU + its Radio in mind, I guess the main challenge in porting it for Atmel is the compiler specific C codes in Miwi. Unless you find a working port to Atmel, you probably don't want to put much time in it. So, if you're using Miwi, yes I suggest using a microchip MCU for both sensor nodes and in the gateway for Pi.

      Hope that helps!

      Delete
    2. Sure it helps, thank you.

      As I had my doubts about the range, it seems my selection is as follows:

      PIC variant, needs external PIC MCU, so +4e more
      http://uk.farnell.com/microchip/mrf24j40mc-i-rm/trx-2-4ghz-ieee-802-15-4-12module/dp/1971845
      (cost around 25e total)

      ATMEL, has usable MCU integrated
      http://uk.farnell.com/atmel/atzb-a24-uflr/zigbee-module-2-4ghz-u-fl-conn/dp/1773404
      (costs around 38e total)

      We would then need
      - U.FL to SMA cable for antenna
      http://uk.farnell.com/multicomp/r-134g7210200ca/cable-u-fl-sma-rp-200mm/dp/1699248
      (costs around 8e)

      - SMA whip antenna
      http://uk.farnell.com/multicomp/r-134g7210200ca/cable-u-fl-sma-rp-200mm/dp/1699248
      (costs around 4e, can go as high as 12e)


      So from low-budget (as you pointed out) project, like sub 15e, to a whopping
      38e to 50e - WOW !!!
      And this is only for RF part, so, none sensor installed, barebox PCB !
      Again, wow ! It seems like a bit too expensive for a DIY project,which may
      (or may not) become a commercial project. I mean, who is going to pay for
      a temperature/humidity sensor for a price range of at least 80e to 100e ?
      It seems a lot to me, am I doing something wrong here?

      I would really like to try Atmel's dual ceramic chip antenna module, as stated,
      there is +3dBm output power, so if this signal is going through walls (concrete
      and brick) then we might have a bit lower cost (around -15e)?

      Your thoughts on this, please?

      Delete
    3. Just to add,
      the tech specs for both solutions seem really close,
      both having around +20dbM output power
      only:

      - ATMEL claims +50mA in TX mode VS PIC for +120mA
      - ATMEL claims <6uA sleep VS PIC for <12uA

      So, the cost difference may (or may not) be worth the
      tech spec gain...

      Delete
    4. But then again,

      how do they manage to present a sub-50e price like
      http://simplehomenet.com/proddetail.asp?prod=Wireless_ZigBee_Humidity_Temperature_Sensor_LCD

      Delete
    5. May I suggest this nice one that I'm using:
      https://www.olimex.com/Products/Modules/RF/MOD-ZIGBEE/

      It has slightly bigger antenna, a good MCU and a temperature sensor! It's the complete product you want to make and it's at 17e! It comes with open source firmware as well, based on Miwi... I'm using this for one of my robots, I was planning post about it soon.

      For the range, have you thought about using a mesh network topology? Using mesh, you can avoid using external antennas by using few more FFD nodes. Miwi again does support it out of the box.

      Delete
    6. Nice ready made solution, no need for
      first prototype, then revision 1 and 2 :)
      But still, 0dBm does not satisfy range specs.

      "have you thought about using a mesh network topology"
      I've been thinking about that too, but, even using
      more FFD-s, it is still a question weather the signal
      will penetrate the concrete between the floors ?
      Not to mention that you need to explain to the customer
      that the mesh structure of sensor network (more batteries, more worries) is needed. Like: you don't need
      to measure the temperature in 10 points per floor, but
      it will give you better results :)

      Tnx again, still no solution for real life examples,
      like a simple home automation (for HVAC or something)...



      Delete
  4. This comment has been removed by the author.

    ReplyDelete