Skip to content

Issue with LoRa.read() #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
keithr0 opened this issue Jan 25, 2019 · 1 comment
Open

Issue with LoRa.read() #222

keithr0 opened this issue Jan 25, 2019 · 1 comment

Comments

@keithr0
Copy link

keithr0 commented Jan 25, 2019

I wrote a small app in order to test the range of the TTGO ESP32/SX1278/SSD1306 boards. The transmit side is straightforward and sends packets with the string "Block" followed by a number that increments from 0 to 999. the receiver is interrupt driven (code below). The problem was that after startup, the correct block number was displayed but all subsequent packets were displayed with the same block number. To fix it I had to comment out the following line from handleDio0Rise() in LoRa.cpp at line 484

writeRegister(REG_FIFO_ADDR_PTR, 0);

After that the correct packet was displayed.

Code:

#include <SPI.h>
#include <LoRa.h>
#include "SSD1306.h"

//****** SX1278 pins to ESP32 GPIOs ******//
#define SCK   5
#define MISO  19
#define MOSI  27
#define CS    18
#define RESET 14
#define IRQ   26 //(Interrupt Request)

#define BAND  915E6 // Set LORA band to 915MHz

//****** OLED pins to ESP32 GPIOs ******//
#define OLED_SDA 4  // GPIO4
#define OLED_SCL 15 // GPIO15
#define OLED_RST 16 // GPIO16

SSD1306  display(0x3c, OLED_SDA, OLED_SCL);

volatile int MessageLength = 0;

void PrintMessage(String Message)
{
  display.clear();
  display.println(Message);
  display.drawLogBuffer(0, 0); // Draw it to the internal screen buffer
  display.display();           // Display it on the screen
}

void setup() 
{
//****** Set up OLED display ******//
  pinMode(OLED_RST,OUTPUT);
  digitalWrite(OLED_RST, LOW);    // set GPIO16 low to reset OLED
  delay(50); 
  digitalWrite(OLED_RST, HIGH);   // while OLED is running, must set GPIO16 in high
  display.init();
  display.setContrast(255);
  display.setLogBuffer(8, 30);    // Initialise OLED buffer to 30x8 char
  PrintMessage("LoRa Range Test starting");

//****** Set up LORA chip ******//
  SPI.begin(SCK, MISO, MOSI, CS);
  LoRa.setPins(CS, RESET, IRQ);
  if (!LoRa.begin(BAND)) 
  {
    PrintMessage(" ");
    PrintMessage(" ");
    PrintMessage("LoRa failed to start!");
    while (1);
  }
  LoRa.onReceive(onReceive); // register the receive callback
  LoRa.receive();            // put the radio into receive mode
}

void loop() 
{
  if(MessageLength > 0)
  {
    HandleInterrupt(MessageLength);
    MessageLength = 0;
  }
}

void onReceive(int packetSize) // received a packet
{   
  MessageLength = packetSize;
}

void HandleInterrupt(int packetSize)
{
  String Message = "Rcved: ";
  for (int i = 0; i < packetSize; i++) Message = Message + (char)LoRa.read();
  Message = Message + " RSSI: " + LoRa.packetRssi(); // print RSSI of packet
  PrintMessage(Message);
}

@keithr0
Copy link
Author

keithr0 commented Jan 26, 2019

This more or less a dupe of #218. Sorry about that.

mchacher pushed a commit to mchacher/LoRaNodeGY271 that referenced this issue May 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant