Skip to content

Commit 20b4a28

Browse files
authored
Merge pull request #24 from hpsaturn/devel
Devel
2 parents ad229f5 + c5bcd54 commit 20b4a28

File tree

12 files changed

+416
-37
lines changed

12 files changed

+416
-37
lines changed

README.md

Lines changed: 81 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# ESPNowCam - Camera streamer via ESPNow
1+
# ESPNowCam - Data streamer
22

33
[![PlatformIO](https://github.com/hpsaturn/esp32s3-cam/workflows/PlatformIO/badge.svg)](https://github.com/hpsaturn/esp32s3-cam/actions/) ![ViewCount](https://views.whatilearened.today/views/github/hpsaturn/esp32s3-cam.svg)
44

5-
The ESPNowCam library is a simple and direct video streamer designed for popular ESP32Cam models, utilizing the ESPNow protocol. No need for IPs, routers, or credentials—keeping it straightforward and hassle-free! :D
5+
The ESPNowCam library is a simple and direct video or data streamer designed for popular ESP32 devices, utilizing the ESPNow protocol. No need for IPs, routers, or credentials—keeping it straightforward and hassle-free! :D
66

77
**This library is for general purpose**, as it accepts pointers to various types of data, including buffers, strings, images, or any byte-formatted content. This flexibility enables transmission of larger packages across different scenarios, not limited to cameras alone. For instance, a buffer of 4000 bytes takes approximately 1/9 of a second to transmit, resulting in a frame rate of around 9FPS.
88

@@ -16,14 +16,15 @@ The ESPNowCam library is a simple and direct video streamer designed for popular
1616

1717
## Performance
1818

19-
The current version tested with:
19+
The current version tested with the next cameras:
2020

21-
| Sender | Receiver | Frame size | JPG Quality | FPS | Status |
22-
|:-----------------|:-----------:|:-------:|:-----:|:------:|:------:|
23-
| Freenove S3 Camera | M5Core2 / M5CoreS3 | QVGA | 12 | ~10 FPS | STABLE |
24-
| M5CoreS3 builtin Camera | M5Core2 | QVGA | 12 | ~11 FPS | STABLE |
25-
| Freenove S3 Camera | Makerfabs | HVGA | 12 | ~6 FPS | STABLE |
26-
| XIAO ESP32S3 Camera | M5Core2 / M5CoreS3 | QVGA | 12 | ~9 FPS | STABLE |
21+
| Sender | Frame | JPGQ | FPS | Status |
22+
|:-----------------|:-------:|:-----:|:------:|:------:|
23+
| TTGO TJournal | QVGA | 12 | ~11 FPS | TESTING |
24+
| Freenove S3 | QVGA | 12 | ~10 FPS | STABLE |
25+
| Freenove S3 | HVGA | 12 | ~6 FPS | STABLE |
26+
| M5CoreS3 | QVGA | 12 | ~11 FPS | STABLE |
27+
| XIAO ESP32S3 | QVGA | 12 | ~9 FPS | STABLE |
2728

2829
## Library installation
2930

@@ -50,7 +51,53 @@ For `Arduino IDE` is a little bit more complicated because the Arduino IDE depen
5051

5152
Note: Nanobp is not included as a dependency because, despite being 25 years after the invention of symbolic links, Arduino IDE does not support these types of files. Consider exploring PlatformIO for your future developments, as it offers a more versatile and modern development environment.
5253

53-
## Examples and Tests
54+
## Usage
55+
56+
**To send** any kind of data, you only need a buffer and the size to send:
57+
58+
```cpp
59+
ESPNowCam radio;
60+
61+
radio.init();
62+
radio.sendData(out_jpg, out_jpg_len);
63+
```
64+
65+
**To receive** the data, you only need to define a buffer and callback:
66+
67+
```cpp
68+
radio.setRecvBuffer(fb);
69+
radio.setRecvCallback(onDataReady);
70+
radio.init();
71+
```
72+
73+
```cpp
74+
void onDataReady(uint32_t lenght) {
75+
tft.drawJpg(fb, lenght , 0, 0, dw, dh);
76+
}
77+
```
78+
79+
It is also possible to define a specific target:
80+
81+
```cpp
82+
uint8_t macRecv[6] = {0xB8,0xF0,0x09,0xC6,0x0E,0xCC};
83+
radio.setTarget(macRecv);
84+
radio.init();
85+
```
86+
87+
**Predefined drivers:**
88+
89+
The library includes some pre-defined camera configs to have an easy implementation, for example:
90+
91+
```cpp
92+
#include <ESPNowCam.h>
93+
#include <drivers/CamFreenove.h>
94+
95+
CamFreenove Camera;
96+
```
97+
98+
for now, it includes drivers for FreenoveS3, XIAOS3, 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
99+
100+
## Examples
54101

55102
[![video demo](https://raw.githubusercontent.com/hpsaturn/esp32s3-cam/master/pictures/youtube.jpg)](https://youtu.be/nhLr7XEUdfU)
56103
[[video]](https://youtu.be/nhLr7XEUdfU)
@@ -60,8 +107,10 @@ Note: Nanobp is not included as a dependency because, despite being 25 years aft
60107
| freenove-basic-sender | ESPNow camera transmitter (QVGA) | STABLE |
61108
| freenove-hvga-sender | ESPNow camera transmitter (HVGA) | <6 FPS |
62109
| freenove-nojpg-sender | ESPNow camera transmitter (NOJPG) | DEMO ONLY (<2FPS) |
63-
| freenove-tank | Advanced sample. Sender/Receiver | TESTING |
64110
| xiao-espnow-sender | ESPNow camera transmitter (QVGA) | STABLE |
111+
| xiao-fpv-sender | Power ON/OFF improvement (QVGA) | STABLE |
112+
| tjournal-espnow-sender | Camera without PSRAM (QVGA) | TESTING |
113+
| freenove-tank | Advanced sample. Sender/Receiver | TESTING |
65114
| m5core2-basic-receiver | Video receiver via ESPNow [1] | STABLE |
66115
| m5core2-espnow-receiver | Video receiver via ESPNow [1] | STABLE |
67116
| m5cores3-espnow-receiver | Video receiver via ESPNow [1] | STABLE|
@@ -85,12 +134,30 @@ pio run -e m5cores3-espnow-receiver --target upload
85134

86135
Some examples, only needs run `pio run --target upload` into each directory
87136

137+
## ESPNow Transmitter and Receiver
138+
139+
The last version has many improvements, and right now is very stable. For now, it supports one transmitter and multiple receivers in real time using broadcast, and also P2P connections using MAC address. It is possible, using IDs, uses of multiple sources to one receiver.
140+
141+
[![ESPNow Camera Video](https://raw.githubusercontent.com/hpsaturn/esp32s3-cam/master/pictures/espnow_video.gif)](https://youtu.be/zXIzP1TGlpA)
142+
[[video]](https://youtu.be/zXIzP1TGlpA)
143+
144+
## Troubleshooting
145+
146+
The **Freenove camera** sometimes needs good power cable and also takes some seconds to stabilization, that means, that not worries for initial video glitches.
147+
148+
The **XIAO camera** experiences thermal issues; after a few minutes, it may stop transmission and won't restart it until it's cooled down.
149+
150+
For **Arduino IDE users**, if you have a compiling error, maybe you forget install NanoPb library. Please see above.
151+
152+
This project was developed and thoroughly tested on PlatformIO. While I did compile and execute it successfully on Arduino IDE using Espressif 2.0.11 and Arduino IDE 2.2.1, with PSRAM enabled, I generally avoid using Arduino IDE due to its tendency to mix everything and its buggy nature. Therefore, **I highly recommend using PlatformIO** for a smoother and more reliable development experience.
153+
88154
## Tested devices
89155

90156
**Cameras:**
91157

92-
- [x] ESP32S3 Cam Freenove
93-
- [x] M5CoreS3 builtin Camera
158+
- [x] ESP32 TTGO T-Journal (without PSRAM)
159+
- [x] ESP32S3 Freenove Camera
160+
- [x] M5CoreS3 (builtin Camera)
94161
- [x] XIAO ESP32S3 Sense Camera
95162

96163
**Receivers:**
@@ -108,24 +175,10 @@ Some examples, only needs run `pio run --target upload` into each directory
108175
- [x] Isolate the ESPNow Receiver and Transmitter in a seperated library
109176
- [x] Unified and migrated to only one header `ESPNowCam.h`
110177
- [x] Add sender callback to improve speed
178+
- [ ] Add callback to Radio send action. issue #20
111179
- [ ] Migration to esp_wifi_80211_tx() to improve Payload and Quality
112180

113-
## ESPNow Transmitter and Receiver
114-
115-
The last version has many improvements, and right now is very stable. It needs some tiny changes but now it supports ~9FPS with JPG Quality 18.
116181

117-
[![ESPNow Camera Video](https://raw.githubusercontent.com/hpsaturn/esp32s3-cam/master/pictures/espnow_video.gif)](https://youtu.be/zXIzP1TGlpA)
118-
[[video]](https://youtu.be/zXIzP1TGlpA)
119-
120-
## Troubleshooting
121-
122-
The **Freenove camera** sometimes needs good power cable and also takes some seconds to stabilization, that means, that not worries for initial video glitches.
123-
124-
The **XIAO camera** experiences thermal issues; after a few minutes, it may stop transmission and won't restart it until it's cooled down.
125-
126-
For **Arduino IDE users**, if you have a compiling error, maybe you forget install NanoPb library. Please see above.
127-
128-
This project was developed and thoroughly tested on PlatformIO. While I did compile and execute it successfully on Arduino IDE using Espressif 2.0.11 and Arduino IDE 2.2.1, with PSRAM enabled, I generally avoid using Arduino IDE due to its tendency to mix everything and its buggy nature. Therefore, **I highly recommend using PlatformIO** for a smoother and more reliable development experience.
129182

130183
## Credits
131184

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/**************************************************
2+
* ESPNowCam video Transmitter
3+
* by @hpsaturn Copyright (C) 2024
4+
* This file is part ESP32S3 camera tests project:
5+
* https://github.com/hpsaturn/esp32s3-cam
6+
**************************************************/
7+
8+
#include <Arduino.h>
9+
#include <esp_camera.h>
10+
#include <ESPNowCam.h>
11+
#include <Utils.h>
12+
13+
ESPNowCam radio;
14+
camera_fb_t* fb;
15+
16+
bool has_psram = false;
17+
18+
camera_config_t camera_config = {
19+
.pin_pwdn = -1,
20+
.pin_reset = 15,
21+
.pin_xclk = 27,
22+
.pin_sscb_sda = 25,
23+
.pin_sscb_scl = 23,
24+
.pin_d7 = 19,
25+
.pin_d6 = 36,
26+
.pin_d5 = 18,
27+
.pin_d4 = 39,
28+
.pin_d3 = 5,
29+
.pin_d2 = 34,
30+
.pin_d1 = 35,
31+
.pin_d0 = 17,
32+
.pin_vsync = 22,
33+
.pin_href = 26,
34+
.pin_pclk = 21,
35+
36+
.xclk_freq_hz = 20000000,
37+
.ledc_timer = LEDC_TIMER_0,
38+
.ledc_channel = LEDC_CHANNEL_0,
39+
40+
.pixel_format = PIXFORMAT_JPEG,
41+
.frame_size = FRAMESIZE_QVGA,
42+
.jpeg_quality = 12,
43+
.fb_count = 1,
44+
.fb_location = CAMERA_FB_IN_DRAM,
45+
.grab_mode = CAMERA_GRAB_WHEN_EMPTY,
46+
};
47+
48+
bool CameraBegin() {
49+
esp_err_t err = esp_camera_init(&camera_config);
50+
if (err != ESP_OK) {
51+
return false;
52+
}
53+
return true;
54+
}
55+
56+
bool CameraGet() {
57+
fb = esp_camera_fb_get();
58+
if (!fb) {
59+
return false;
60+
}
61+
return true;
62+
}
63+
64+
bool CameraFree() {
65+
if (fb) {
66+
esp_camera_fb_return(fb);
67+
return true;
68+
}
69+
return false;
70+
}
71+
72+
void processFrame() {
73+
if (CameraGet()) {
74+
if (has_psram) {
75+
uint8_t *out_jpg = NULL;
76+
size_t out_jpg_len = 0;
77+
frame2jpg(fb, 12, &out_jpg, &out_jpg_len);
78+
radio.sendData(out_jpg, out_jpg_len);
79+
free(out_jpg);
80+
}
81+
else{
82+
radio.sendData(fb->buf, fb->len);
83+
delay(30); // ==> weird delay for cameras without PSRAM
84+
}
85+
printFPS("CAM:");
86+
CameraFree();
87+
}
88+
}
89+
90+
void setup() {
91+
Serial.begin(115200);
92+
93+
delay(5000); // only for debugging
94+
95+
if(psramFound()){
96+
has_psram = true;
97+
size_t psram_size = esp_spiram_get_size() / 1048576;
98+
Serial.printf("PSRAM size: %dMb\r\n", psram_size);
99+
// suggested config with PSRAM
100+
camera_config.pixel_format = PIXFORMAT_RGB565;
101+
camera_config.fb_location = CAMERA_FB_IN_PSRAM;
102+
camera_config.fb_count = 2;
103+
}
104+
else{
105+
Serial.println("PSRAM not found! Basic framebuffer setup.");
106+
}
107+
108+
radio.init();
109+
110+
if (!CameraBegin()) {
111+
Serial.println("Camera Init Fail");
112+
delay(1000);
113+
ESP.restart();
114+
}
115+
delay(500);
116+
}
117+
118+
void loop() {
119+
processFrame();
120+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**************************************************
2+
* ESPNowCam video Transmitter
3+
* by @hpsaturn Copyright (C) 2024
4+
* This file is part ESP32S3 camera tests project:
5+
* https://github.com/hpsaturn/esp32s3-cam
6+
**************************************************/
7+
8+
#include <Arduino.h>
9+
#include <ESPNowCam.h>
10+
#include <drivers/CamTJournal.h>
11+
#include <Utils.h>
12+
13+
CamTJournal Camera;
14+
ESPNowCam radio;
15+
16+
void processFrame() {
17+
if (Camera.get()) {
18+
radio.sendData(Camera.fb->buf, Camera.fb->len);
19+
delay(25); // ==> weird delay for this camera.
20+
printFPS("CAM:");
21+
Camera.free();
22+
}
23+
}
24+
25+
void setup() {
26+
Serial.begin(115200);
27+
28+
delay(5000); // only for debugging
29+
30+
if(psramFound()){
31+
size_t psram_size = esp_spiram_get_size() / 1048576;
32+
Serial.printf("PSRAM size: %dMb\r\n", psram_size);
33+
}
34+
35+
radio.init();
36+
if (!Camera.begin()) {
37+
Serial.println("Camera Init Fail");
38+
delay(1000);
39+
ESP.restart();
40+
}
41+
delay(500);
42+
}
43+
44+
void loop() {
45+
processFrame();
46+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**************************************************
2+
* ESPNowCam video Transmitter.
3+
* ----------------------------
4+
*
5+
* XIAO FPV ESPNow transmitter uses some extra features of
6+
* this board to have some power consumption improvements
7+
*
8+
* by @hpsaturn Copyright (C) 2024
9+
* This file is part ESP32S3 camera tests project:
10+
* https://github.com/hpsaturn/esp32s3-cam
11+
**************************************************/
12+
13+
#include <Arduino.h>
14+
#include <OneButton.h>
15+
#include <ESPNowCam.h>
16+
#include <drivers/CamXiao.h>
17+
#include <Utils.h>
18+
19+
CamXiao Camera;
20+
ESPNowCam radio;
21+
OneButton btnB(GPIO_NUM_0, true);
22+
23+
void processFrame() {
24+
if (Camera.get()) {
25+
uint8_t *out_jpg = NULL;
26+
size_t out_jpg_len = 0;
27+
frame2jpg(Camera.fb, 12, &out_jpg, &out_jpg_len);
28+
radio.sendData(out_jpg, out_jpg_len);
29+
printFPS("CAM:");
30+
free(out_jpg);
31+
Camera.free();
32+
}
33+
}
34+
35+
void shutdown() {
36+
Serial.println("shutdown..");
37+
esp_sleep_enable_ext0_wakeup(GPIO_NUM_0,0);
38+
delay(1000);
39+
esp_deep_sleep_start();
40+
}
41+
42+
void setup() {
43+
Serial.begin(115200);
44+
45+
delay(1000); // only for debugging
46+
47+
if(psramFound()){
48+
size_t psram_size = esp_spiram_get_size() / 1048576;
49+
Serial.printf("PSRAM size: %dMb\r\n", psram_size);
50+
}
51+
52+
radio.init();
53+
if (!Camera.begin()) {
54+
Serial.println("Camera Init Fail");
55+
delay(1000);
56+
}
57+
58+
btnB.attachClick([]() { shutdown(); });
59+
delay(100);
60+
}
61+
62+
void loop() {
63+
processFrame();
64+
btnB.tick();
65+
}

0 commit comments

Comments
 (0)