RadioHead lib for RFM95, worked pro mini but also for 8266...finally


After trying several lorawan on 8266, I decided to firsst try out lora...
Most of these libs are for arduino and mostly tested on arduino.

http://www.airspayce.com/mikem/arduino/RadioHead/
seems to have a very good document, and the state clearly on platforms:

ESP8266 on Arduino IDE and Boards Manager per https://github.com/esp8266/Arduino Tested using Arduino 1.6.8 with esp8266 by ESP8266 Community version 2.1.0 Examples serial_reliable_datagram_* and ask_* are shown to work.
as to esp32
ESP32 built using Arduino IDE 1.8.1 or later using the ESP32 toolchain installed per https://diyprojects.io/programming-esp32-board-arduino-ide-macos-windows-linux-arm-raspberrypi-orangepi/ 
i down loaded the latest one which is 1.82, and follow the example from here:

https://learn.adafruit.com/adafruit-rfm69hcw-and-rfm96-rfm95-rfm98-lora-packet-padio-breakouts/rfm9x-test


without modification, (of course I followed the pin define on CS, RST,INT) it works good

// LoRa 9x_TX
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messaging client (transmitter)
// 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 LoRa9x_RX

#include <SPI.h>
#include <RH_RF95.h>

#define RFM95_CS 10
#define RFM95_RST 9
#define RFM95_INT 2

// Change to 434.0 or other frequency, must match RX's freq!
#define RF95_FREQ 915.0

// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);

void setup() 
{
  pinMode(RFM95_RST, OUTPUT);
  digitalWrite(RFM95_RST, HIGH);

  while (!Serial);
  Serial.begin(9600);
  delay(100);

  Serial.println("Arduino LoRa TX Test!");

  // manual reset
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);

  while (!rf95.init()) {
    Serial.println("LoRa radio init failed");
    while (1);
  }
  Serial.println("LoRa radio init OK!");

  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
  if (!rf95.setFrequency(RF95_FREQ)) {
    Serial.println("setFrequency failed");
    while (1);
  }
  Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
  
  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on

  // The default transmitter power is 13dBm, using PA_BOOST.
  // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then 
  // you can set transmitter powers from 5 to 23 dBm:
  rf95.setTxPower(23, false);
}

int16_t packetnum = 0;  // packet counter, we increment per xmission

void loop()
{
  Serial.println("Sending to rf95_server");
  // Send a message to rf95_server
  
  char radiopacket[20] = "Hello World #      ";
  itoa(packetnum++, radiopacket+13, 10);
  Serial.print("Sending "); Serial.println(radiopacket);
  radiopacket[19] = 0;
  
  Serial.println("Sending..."); delay(10);
  rf95.send((uint8_t *)radiopacket, 20);

  Serial.println("Waiting for packet to complete..."); delay(10);
  rf95.waitPacketSent();
  // Now wait for a reply
  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  uint8_t len = sizeof(buf);

  Serial.println("Waiting for reply..."); delay(10);
  if (rf95.waitAvailableTimeout(1000))
  { 
    // Should be a reply message for us now   
    if (rf95.recv(buf, &len))
   {
      Serial.print("Got reply: ");
      Serial.println((char*)buf);
      Serial.print("RSSI: ");
      Serial.println(rf95.lastRssi(), DEC);    
    }
    else
    {
      Serial.println("Receive failed");
    }
  }
  else
  {
    Serial.println("No reply, is there a listener around?");
  }
  delay(1000);
}
 Then I try to make it work with myesp8266 by changing the pins
#define RFM95_CS 16 //
#define RFM95_RST 5 
#define RFM95_INT 15

it works only few step and hang on 

  Serial.println("Waiting for packet to complete..."); delay(10);
  rf95.waitPacketSent();


and most of time hang on "LoRa radio init failed"...

I tryed to work arround on grounding , 3.3V, and reset pin(use it or not)...still not working.
I think it could be a spi issue, better to check out the json file for 8266

I checked the version I have on ny arduino 1.8.5, my is 2.4.0...

I removed it and load the ver.2.1.0 as descripted in radiohead...

still the same,....

Then I suspect the bread board, then I connect directly with wires...

it finally worked....














i used 8266 as TX and promin as Rx,
1.8266 send a hello world,
2. promini received, and send a hello back
3. 8266 got reply

but when I use promin as tx, 8266 as rx, promini did not received the hello back....

留言

這個網誌中的熱門文章

Heltec ESP32+OLED+Lora, hardware testing

micro SD card for ESP32, on lolin32 with OLED and heltec 32 lora oled

Install Network Time Protocol(NTP) on BeagleBone with Angstrom linux and set local time zone