Skip to content

Commit

Permalink
improved p2p IDF-JPG samples and some minor doc fixes
Browse files Browse the repository at this point in the history
hpsaturn committed May 14, 2024
1 parent 1d29f2d commit f341fd3
Showing 4 changed files with 150 additions and 64 deletions.
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -134,6 +134,22 @@ Camera.config.frame_size = FRAMESIZE_QQVGA;

For now, it includes drivers for FreenoveS3, XIAOS3, M5UnitCamS3, ESP32Cam AI-Thinker and the TTGO T-Journal cameras, but you are able to define your custom camera like is shown in the [custom-camera-sender](examples/custom-camera-sender/) example. If you can run it in a different camera, please notify me :D

### PSRAM or DRAM?

Well, in my last tests with different cameras and using QVGA frame size, sounds that is better using the DRAM and the internal JPG. DRAM is more faster, and the internal compressor
has a better quality but it uses more bandwidth. The result is so good on P2P mode.

For change to DRAM and the internal JPG, you are able to pre-configure it like this:

```cpp
Camera.config.pixel_format = PIXFORMAT_JPEG;
Camera.config.frame_size = FRAMESIZE_QVGA;
Camera.config.fb_count = 2;
Camera.config.fb_location = CAMERA_FB_IN_DRAM;
```

more details in the sample [xiao-internal-jpg-sender](examples/xiao-internal-jpg-sender/).

## Examples

[![Tank Example - Video demo](https://raw.githubusercontent.com/hpsaturn/ESPNowCam/master/pictures/tank_example.jpg)](https://youtu.be/nhLr7XEUdfU) [![ESPNowCam Broadcasting - Video demo](https://raw.githubusercontent.com/hpsaturn/ESPNowCam/master/pictures/broadcasting_example.jpg)](https://youtu.be/zXIzP1TGlpA) [![Multi camera - Video demo](https://raw.githubusercontent.com/hpsaturn/ESPNowCam/master/pictures/multi-camera.jpg)](https://youtu.be/ip6RohVEg2s)
@@ -142,16 +158,14 @@ For now, it includes drivers for FreenoveS3, XIAOS3, M5UnitCamS3, ESP32Cam AI-Th

| ENV Name | Details | Frame| Status |
|:-----------------|:--------------:|:----------:|:----------:|
| freenove-basic-sender | PSRAM, 2FB, JPG | QVGA | STABLE |
| freenove-p2p-sender | PSRAM, 2FB, JPG | QVGA | STABLE |
| freenove-hvga-sender | PSRAM, 2FB, JPG | HVGA | <6 FPS |
| freenove-nojpg-sender | PSRAM, 2FB, NOJPG | QVGA | <2FPS |
| xiao-espnow-sender | PSRAM, 2FB, JPG | QVGA | STABLE |
| xiao-fpv-sender | POWER ON/OFF, PSRAM, 2FB, JPG | QVGA | STABLE |
| unitcams3 | PSRAM, 2FB, JPG | QVGA | TESTING |
| unitcams3-basic-sender | PSRAM, 2FB, JPG | QVGA | TESTING |
| custom-camera-sender | Custom settings - optional PSRAM | QVGA | STABLE |
| tjournal-espnow-sender | NOPSRAM, 1FB, internal JPG | QVGA | STABLE |
| m5cores3-espnow-sender | PSRAM, 2FB, JPG built-in camera | QVGA | STABLE |
| | | | |

### Receivers samples

@@ -163,7 +177,6 @@ For now, it includes drivers for FreenoveS3, XIAOS3, M5UnitCamS3, ESP32Cam AI-Th
| makerfabs-basic-receiver | Video receiver [1] [2] | STABLE |
| makerfabs-nojpg-receiver | Video receiver [1] [2] | <2FPS |
| tft-3.5-basic-receiver | Any TFT display with LGFX [1] | STABLE |
| | | |

[1] Use with any sender sample
[2] Use with freenove HVGA sender sample for example.
@@ -173,13 +186,13 @@ For now, it includes drivers for FreenoveS3, XIAOS3, M5UnitCamS3, ESP32Cam AI-Th
| ENV Name | Details | Frame| Status |
|:-----------------|:--------------:|:----------:|:----------:|
| xiao-fpv-sender | POWER ON/OFF, PSRAM, 2FB, JPG | QVGA | STABLE |
| xiao-internal-jpg-sender | POWER ON/OFF, NOPSRAM, 2FB, IDF-JPG | QVGA | STABLE |
| freenove-tank | sender and custom payload receiver | QVGA | TESTING |
| m5stickCplus-joystick-tank | custom payload - Telemetry | -- | TESTING |
| makerfabs-multi-receiver | N:1 mode, muti camera one receiver | -- | TESTING |
| m5cores3-camera1 | One target only for multi-receiver sample | QVGA | TESTING |
| tjournal-camera2 | One target only for multi-receiver sample | QQVGA | TESTING |
| xiao-camera3 | One target only for multi-receiver sample | QQVGA | TESTING |
| | | | |

## Running samples

59 changes: 59 additions & 0 deletions examples/freenove-p2p-sender/freenove-p2p-sender.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**************************************************
* ESP32Cam Freenove ESPNow Transmitter
* by @hpsaturn Copyright (C) 2024
* This file is part ESP32S3 camera tests project:
* https://github.com/hpsaturn/esp32s3-cam
**************************************************/

// N O T E:
// -------
// Don't forget first install NanoPb library!
// and also review the README.md file.

#include <Arduino.h>
#include <ESPNowCam.h>
#include <drivers/CamFreenove.h>

CamFreenove Camera;
ESPNowCam radio;

void processFrame() {
if (Camera.get()) {
uint8_t *out_jpg = NULL;
size_t out_jpg_len = 0;
frame2jpg(Camera.fb, 12, &out_jpg, &out_jpg_len);
radio.sendData(out_jpg, out_jpg_len);
free(out_jpg);
Camera.free();
}
}

void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
Serial.println();
delay(1000);

if(psramFound()){
size_t psram_size = esp_spiram_get_size() / 1048576;
Serial.printf("PSRAM size: %dMb\r\n", psram_size);
}

// M5Core2 receiver
uint8_t macRecv[6] = {0xB8,0xF0,0x09,0xC6,0x0E,0xCC};
radio.setTarget(macRecv);
radio.init();

// You are able to change the Camera config E.g:
// Camera.config.fb_count = 2;
// Camera.config.frame_size = FRAMESIZE_QQVGA;

if (!Camera.begin()) {
Serial.println("Camera Init Fail");
}
delay(500);
}

void loop() {
processFrame();
}
46 changes: 22 additions & 24 deletions examples/xiao-internal-jpg-sender/xiao-internal-jpg-sender.cpp
Original file line number Diff line number Diff line change
@@ -1,66 +1,64 @@
/**************************************************
* ESPNowCam video Transmitter.
* ----------------------------
*
*
* XIAO FPV ESPNow transmitter uses some extra features of
* this board to have some power consumption improvements
* this board to have some power consumption improvements.
*
* Also in this sample we are using DRAM, not PSRAM. It is
* more faster than PSRAM, and also we are using the internal
* compressor, that consume more bandwidht but the quality
* is so good with the same JPG compression. I don't know why ??
* The only consideration is that the reciever needs allocate
* more memory.
*
* by @hpsaturn Copyright (C) 2024
* This file is part ESP32S3 camera tests project:
* https://github.com/hpsaturn/esp32s3-cam
**************************************************/
* This file is part ESPNowCam project:
* https://github.com/hpsaturn/ESPNowCam
**************************************************/

#include <Arduino.h>
#include <OneButton.h>
#include <ESPNowCam.h>
#include <drivers/CamXiao.h>
#include <OneButton.h>
#include <Utils.h>
#include <drivers/CamXiao.h>

CamXiao Camera;
CamXiao Camera;
ESPNowCam radio;
OneButton btnB(GPIO_NUM_0, true);

void processFrame() {
if (Camera.get()) {
radio.sendData(Camera.fb->buf, Camera.fb->len);
delay(40); // ==> weird delay for NOPSRAM camera.
delay(40); // ==> weird delay when you are using only DRAM.
printFPS("CAM:");
Camera.free();
}
// if (Camera.get()) {
// uint8_t *out_jpg = NULL;
// size_t out_jpg_len = 0;
// frame2jpg(Camera.fb, 12, &out_jpg, &out_jpg_len);
// radio.sendData(out_jpg, out_jpg_len);
// printFPS("CAM:");
// free(out_jpg);
// Camera.free();
// }
}

void shutdown() {
Serial.println("shutdown..");
esp_sleep_enable_ext0_wakeup(GPIO_NUM_0,0);
esp_sleep_enable_ext0_wakeup(GPIO_NUM_0, 0);
delay(1000);
esp_deep_sleep_start();
}

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

delay(1000); // only for debugging
delay(1000); // only for debugging

if(psramFound()){
if (psramFound()) {
size_t psram_size = esp_spiram_get_size() / 1048576;
Serial.printf("PSRAM size: %dMb\r\n", psram_size);
}

// Makerfabs receiver 7C:DF:A1:F3:73:3C
uint8_t macRecv[6] = {0x7C,0xDF,0xA1,0xF3,0x73,0x3C};
uint8_t macRecv[6] = {0x7C, 0xDF, 0xA1, 0xF3, 0x73, 0x3C};
radio.setTarget(macRecv);
radio.init();

// You are able to change the Camera config E.g:
// Configuration without using the PSRAM, only DRAM. (more faster)
Camera.config.pixel_format = PIXFORMAT_JPEG;
Camera.config.frame_size = FRAMESIZE_QVGA;
Camera.config.fb_count = 2;
84 changes: 50 additions & 34 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ build_flags =
; -Wall
; -Wextra
; -Werror
-D CORE_DEBUG_LEVEL=3
-D CORE_DEBUG_LEVEL=0
-D BOARD_HAS_PSRAM=1
lib_deps =
nanopb/Nanopb@0.4.8
@@ -38,6 +38,27 @@ build_flags =
-DARDUINO_USB_CDC_ON_BOOT=1
-DARDUINO_USB_MODE=1

[m5cores3_common]
extends = esp32common
lib_deps =
${esp32common.lib_deps}
https://github.com/m5stack/M5CoreS3.git
m5stack/M5Unified@^0.1.6
build_flags =
${env.build_flags}
-DESP32S3
-DARDUINO_USB_CDC_ON_BOOT=1
-DARDUINO_USB_MODE=1

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Camera Senders
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

[env:freenove-p2p-sender]
extends = esp32common
board_build.arduino.memory_type = dio_opi ;
build_src_filter = -<*> +<common/> +<freenove-p2p-sender/>

[env:xiao-espnow-sender]
extends = xiao-common
build_src_filter = -<*> -<*common*> +<xiao-espnow-sender/>
@@ -56,17 +77,7 @@ lib_deps =
${esp32common.lib_deps}
mathertel/OneButton@^2.0.3

[env:freenove-tank]
extends = esp32common
board_build.arduino.memory_type = dio_opi ;
build_src_filter = -<*> +<common/> +<freenove-tank/>
lib_deps =
${esp32common.lib_deps}
madhephaestus/ESP32Servo@1.1.2
https://github.com/hpsaturn/SerialTerminal.git
hpsaturn/ESP32 Wifi CLI @^0.2.1

[env:unitcams3]
[env:unitcams3-basic-sender]
extends = esp32common
board = esp32s3box
board_build.f_cpu = 240000000L
@@ -91,22 +102,14 @@ extends = env
board = esp32dev
build_src_filter = -<*> -<*common*> +<custom-camera-sender/>

[m5cores3_common]
extends = esp32common
lib_deps =
${esp32common.lib_deps}
https://github.com/m5stack/M5CoreS3.git
m5stack/M5Unified@^0.1.6
build_flags =
${env.build_flags}
-DESP32S3
-DARDUINO_USB_CDC_ON_BOOT=1
-DARDUINO_USB_MODE=1

[env:m5cores3-espnow-sender]
extends = m5cores3_common
build_src_filter = -<*> +<m5cores3-espnow-sender/>

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; TFT Receivers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

[env:m5cores3-espnow-receiver]
extends = m5cores3_common
build_src_filter = -<*> +<m5cores3-espnow-receiver/>
@@ -126,18 +129,9 @@ lib_deps =
${esp32common.lib_deps}
lovyan03/LovyanGFX@^1.1.5

[env:m5stickCplus-joystick-tank]
extends = esp32common
board = esp32dev
upload_speed = 1500001
build_src_filter = -<*> +<common/> +<m5stickCplus-joystick-tank/>
lib_deps =
${esp32common.lib_deps}
m5stack/M5Unified@^0.1.6

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; N:1 EXAMPLES
; Mmulti camera to one receiver examples.
; Multi camera to one receiver examples.
; example directory: multi-camera-one-receiver
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

@@ -173,3 +167,25 @@ lib_deps =
${esp32common.lib_deps}
mathertel/OneButton@^2.0.3

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Tank advanced example
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

[env:freenove-tank]
extends = esp32common
board_build.arduino.memory_type = dio_opi ;
build_src_filter = -<*> +<common/> +<freenove-tank/>
lib_deps =
${esp32common.lib_deps}
madhephaestus/ESP32Servo@1.1.2
https://github.com/hpsaturn/SerialTerminal.git
hpsaturn/ESP32 Wifi CLI @^0.2.1

[env:m5stickCplus-joystick-tank]
extends = esp32common
board = esp32dev
upload_speed = 1500001
build_src_filter = -<*> +<common/> +<m5stickCplus-joystick-tank/>
lib_deps =
${esp32common.lib_deps}
m5stack/M5Unified@^0.1.6

0 comments on commit f341fd3

Please sign in to comment.