Problem image received with lora

hi I have 2 esp32, 2 lora ra02 and cameraa ov7670 I program a code but problem image received very blurry and detach help me to solve this problem

Seeing the code might help

2 Likes

I would agree, it could be an error in your code.

Code for Slave:

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

const int SIOD = 21; // SDA
const int SIOC = 22; // SCL

const int VSYNC = 34;
const int HREF = 35;

const int XCLK = 32;
const int PCLK = 33;

const int D0 = 27;
const int D1 = 17;
const int D2 = 16;
const int D3 = 15;
const int D4 = 25;
const int D5 = 13;
const int D6 = 12;
const int D7 = 26;

const int NSS = 18; // LoRa SS pin
const int RST = 14; // LoRa reset pin
const int DIO0 = 26; // LoRa IRQ pin

OV7670 *camera;

void setup()
{
Serial.begin(115200);

// Initialize Camera
camera = new OV7670(OV7670::Mode::QQVGA_RGB565, SIOD, SIOC, VSYNC, HREF, XCLK, PCLK, D0, D1, D2, D3, D4, D5, D6, D7);

// Initialize LoRa
SPI.begin(5, 19, 27, 18); // SCK, MISO, MOSI, SS
LoRa.setPins(NSS, RST, DIO0);
if (!LoRa.begin(433E6)) { // Set frequency to 433MHz
Serial.println("Starting LoRa failed!");
while (1);
}
Serial.println("LoRa initialized");
}

void loop()
{
camera->oneFrame();

// Send image frame data via LoRa
int frameSize = camera->xres * camera->yres * 2;
int packetSize = 200; // Adjust the packet size if needed
for (int i = 0; i < frameSize; i += packetSize) {
LoRa.beginPacket();
LoRa.write(camera->frame + i, min(packetSize, frameSize - i));
LoRa.endPacket();
delay(10); // Small delay between packets
}

delay(1000); // Adjust delay as needed
}
Code for master:

#include <SPI.h>
#include <LoRa.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include "BMP.h"

const int NSS = 18; // LoRa SS pin
const int RST = 14; // LoRa reset pin
const int DIO0 = 26; // LoRa IRQ pin

#define ssid1 "amine"
#define password1 "0123456789"

WiFiServer server(80);

unsigned char bmpHeader[BMP::headerSize];
unsigned char frame[160 * 120 * 2]; // Buffer for QQVGA RGB565 image
int frameIndex = 0;

void serve()
{
WiFiClient client = server.available();
if (client)
{
String currentLine = "";
while (client.connected())
{
if (client.available())
{
char c = client.read();
if (c == '\n')
{
if (currentLine.length() == 0)
{
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
client.print(
"body{margin: 0}\nimg{height: 40%; width: auto}"
""
"");
client.println();
break;
}
else
{
currentLine = "";
}
}
else if (c != '\r')
{
currentLine += c;
}

    if(currentLine.endsWith("GET /camera"))
    {
      client.println("HTTP/1.1 200 OK");
      client.println("Content-type:image/bmp");
      client.println();
       
      client.write(bmpHeader, BMP::headerSize);
      client.write(frame, sizeof(frame));
    }
  }
}
 
client.stop();

}
}

void setup()
{
Serial.begin(115200);

// Initialize WiFi
WiFi.begin(ssid1, password1);
Serial.println("Connecting Wifi...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("Stream Link: http://");
Serial.print(WiFi.localIP());
Serial.println("/camera");

BMP::construct16BitHeader(bmpHeader, 160, 120); // QQVGA resolution

server.begin();

// Initialize LoRa
SPI.begin(5, 19, 27, 18); // SCK, MISO, MOSI, SS
LoRa.setPins(NSS, RST, DIO0);
if (!LoRa.begin(433E6)) { // Set frequency to 433MHz
Serial.println("Starting LoRa failed!");
while (1);
}
Serial.println("LoRa initialized");
}

void loop()
{
int packetSize = LoRa.parsePacket();
if (packetSize) {
while (LoRa.available()) {
frame[frameIndex++] = LoRa.read();
if (frameIndex >= sizeof(frame)) {
frameIndex = 0; // Reset index after receiving full frame
}
}
}
serve();
}

please read

and post your code accordingly.

Furthermore I suspect you should not transmit an image via LoRa as you might exceed limits for data transmission in this band.

A few comments;

First, if the image being received via LoRa is not correct, you need to be sure that the original image taked by the camera is good.

Second, there appears to be no error checking, you seem to be assuming that all packets that are part of the image (and there is quite a few) are all received completly error free. Appreciate that LoRa in itself cannot alter the image so that its 'blurry'.

Third, take with the duty cycle restrictions in your part of the World, you could be restricted to 10% or even 1%, which severly restricts the number of images per hour you can send.

Finally, 2.4Ghz LoRa is a far better choice for sending images, its a Worldwide band with no or few duty cycle issues.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.