Tagged: , , ,

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #4850
    tasm-devil
    Participant

    Hi there,

    i recently got my brand new Mini Ultra Pro with the 868MHz RM95 Lora Module. I tested the module by reading some teperature values from a DS18B20 sensor and after i figured out that i have to include the line#define Serial SerialUSB everything word like a charm.

    Than i wanted to try the wireless modules by running a simple test sketch from the Radiohead library. It is not working and I am really frustrated because i cannot see what went wrong. Here are the two Sketches for the transmitter and the receiver.

    rf95_client

    // rf95_client.pde
    // -*- mode: C++ -*-
    // Example sketch showing how to create a simple messageing client
    // with the RH_RF95 class. RH_RF95 class does not provide for addressing or
    // reliability, so you should only use RH_RF95 if you do not need the higher
    // level messaging abilities.
    // It is designed to work with the other example rf95_server
    // Tested with Anarduino MiniWirelessLoRa, Rocket Scream Mini Ultra Pro with
    // the RFM95W, Adafruit Feather M0 with RFM95
    
    #include <SPI.h>
    #include <RH_RF95.h>
    
    #define RF95_FREQ 868.0
    //#define RF95_FREQ 915.0
    
    // Singleton instance of the radio driver
    //RH_RF95 rf95;
    RH_RF95 driver(5, 2); // Rocket Scream Mini Ultra Pro with the RFM95W
    //RH_RF95 rf95(8, 3); // Adafruit Feather M0 with RFM95 
    
    // Need this on Arduino Zero with SerialUSB port (eg RocketScream Mini Ultra Pro)
    #define Serial SerialUSB
    
    void setup() 
    {
      // Rocket Scream Mini Ultra Pro with the RFM95W only:
      // Ensure serial flash is not interfering with radio communication on SPI bus
      pinMode(4, OUTPUT);
      digitalWrite(4, HIGH);
    
      Serial.begin(9600);
      while (!Serial) ; // Wait for serial port to be available
      if (!driver.init())
        Serial.println("init failed");
      // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
      if (!driver.setFrequency(RF95_FREQ)) {
        Serial.println("setFrequency failed");
        while (1);
      }
      Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
      driver.setTxPower(15, false);
    }
    
    void loop()
    {
      Serial.println("Sending to rf95_server");
      // Send a message to rf95_server
      uint8_t data[] = "Hello World!";
      driver.send(data, sizeof(data));
      
      driver.waitPacketSent();
      // Now wait for a reply
      uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
      uint8_t len = sizeof(buf);
    
      if (driver.waitAvailableTimeout(3000))
      { 
        // Should be a reply message for us now   
        if (driver.recv(buf, &len))
       {
          Serial.print("got reply: ");
          Serial.println((char*)buf);
    //      Serial.print("RSSI: ");
    //      Serial.println(rf95.lastRssi(), DEC);    
        }
        else
        {
          Serial.println("recv failed");
        }
      }
      else
      {
        Serial.println("No reply, is rf95_server running?");
      }
      delay(400);
    }
    

    rf95_server:

    // rf95_server.pde
    // -*- mode: C++ -*-
    // Example sketch showing how to create a simple messageing server
    // with the RH_RF95 class. RH_RF95 class does not provide for addressing or
    // reliability, so you should only use RH_RF95  if you do not need the higher
    // level messaging abilities.
    // It is designed to work with the other example rf95_client
    // Tested with Anarduino MiniWirelessLoRa, Rocket Scream Mini Ultra Pro with
    // the RFM95W, Adafruit Feather M0 with RFM95
    
    #include <SPI.h>
    #include <RH_RF95.h>
    
    #define RF95_FREQ 868.0
    //#define RF95_FREQ 915.0
    
    // Singleton instance of the radio driver
    //RH_RF95 rf95;
    RH_RF95 driver(5, 2); // Rocket Scream Mini Ultra Pro with the RFM95W
    //RH_RF95 rf95(8, 3); // Adafruit Feather M0 with RFM95 
    
    // Need this on Arduino Zero with SerialUSB port (eg RocketScream Mini Ultra Pro)
    #define Serial SerialUSB
    
    int led = 13;
    
    void setup() 
    {
      // Rocket Scream Mini Ultra Pro with the RFM95W only:
      // Ensure serial flash is not interfering with radio communication on SPI bus
      pinMode(4, OUTPUT);
      digitalWrite(4, HIGH);
    
      pinMode(led, OUTPUT);     
      Serial.begin(9600);
      while (!Serial) ; // Wait for serial port to be available
      if (!driver.init())
        Serial.println("init failed");  
      // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
      if (!driver.setFrequency(RF95_FREQ)) {
        Serial.println("setFrequency failed");
        while (1);
      }
      Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
      driver.setTxPower(15, false);
    }
    
    void loop()
    {
      if (driver.available())
      {
        // Should be a message for us now   
        uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
        uint8_t len = sizeof(buf);
        if (driver.recv(buf, &len))
        {
          digitalWrite(led, HIGH);
    //      RH_RF95::printBuffer("request: ", buf, len);
          Serial.print("got request: ");
          Serial.println((char*)buf);
    //      Serial.print("RSSI: ");
    //      Serial.println(rf95.lastRssi(), DEC);
          
          // Send a reply
          uint8_t data[] = "And hello back to you";
          driver.send(data, sizeof(data));
          driver.waitPacketSent();
          Serial.println("Sent a reply");
           digitalWrite(led, LOW);
        }
        else
        {
          Serial.println("recv failed");
        }
      }
    }
    
    

    The server is not responding to the Serial console and the client is sending the String No reply, is rf95_server running?

    Thanks for any help.

    #4854
    LIM PHANG MOH
    Keymaster

    Hi,

    First check, are both USB connected to a PC with a terminal open?

    while (!Serial) ; // Wait for serial port to be available

    This will wait for the serial port (in this case USB) to open before running the remaining of the codes. With the default radio configuration, it will even run without antenna for few meters.

    #4861
    tasm-devil
    Participant

    OK Cool. Thanks a lot. Its working fine. I totally missed that bug.
    rf96_reliable_datagram is working quite good with tree nodes.
    Do you have a good example sketch for a small Wireless sensor network?
    What settings for setModemConfig would you prefer?

    #4866
    LIM PHANG MOH
    Keymaster

    Do you have a good example sketch for a small Wireless sensor network?

    I have plans to do this but I need to finish a companion product that can add as a gateway, so we can relay data to the cloud. So, currently it is not written yet. As a start, you get use the examples of the server and client to begin with. The server can act as a central/gateway node, while the rest uses the client code as end node.

    What settings for setModemConfig would you prefer?

    That depends on the range and data rate you want to achieve. When you increase the range (through higher SF setting and smaller bandwidth), the data will become slower and vice versa. With slower but longer range, you would then recommended to send small data package.

    What are your application scenario looks like?

    #4871
    tasm-devil
    Participant

    For the moment, I like to take it to the limit in range. As far as possible. 10-100 byte/sec would be more than enough.
    Thank you for your fast answer and good luck with the gateway project. Did the same thin during my masters-thesis. I used so called micaz-nodes and an arduino as LAN-Gateway. Programming in TinyOS was a horror. Currently I do some experiments with the ESP8266. Great little thing!

    Best regards!

    #4872
    LIM PHANG MOH
    Keymaster

    You could use something like SF=11 & BW=125 kHz (few hundred byte per second, have to calculate to get exact number based on few parameters, at SF=12, CR=4/5 & BW=125 kHz, it is 293 bps). With the RFM95W module, it will not work when your data is longer at high SF and small bandwidth range. The crystal on the module is only rated at 10 ppm. At high SF setting and small bandwidth, these tolerance is not enough especially when the data is longer (more than few bytes will easily fail) as the accumulated error due to the tolerance of the crystal.
    A TXCO version of the module is very recently released with tolerance of 2 ppm. This is said to resolve the problem at high SF and small bandwidth setting although I don’t think it would work on extreme case like 32.5 kHz at SF=12 still. We are still waiting for the TXCO module to come as it has lead time of 4 weeks.

    Did the same thin during my masters-thesis. I used so called micaz-nodes and an arduino as LAN-Gateway. Programming in TinyOS was a horror.

    Was working on TinyOS back in 2006. Micaz, T-mote Sky, Crossbow and all those jazz. And yes, I have to admit it was horrible to work on it (but if you are from C++ background and understand about thread on Linux it should be okay). Supported radio chip was limited. We were using our custom board based on Micaz (ATmega128+CC2420). Range was very limited at 2.4 GHz and even with power amplifier, it is not even close to a FSK RFM69HCW today. 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.