Skip to content

Commit

Permalink
Merge pull request #38 from hpsaturn/esp32cam-ai-thinker
Browse files Browse the repository at this point in the history
Esp32cam AI-Thinker
  • Loading branch information
hpsaturn authored May 14, 2024
2 parents ce261e9 + 7be3dbf commit 0d34c27
Show file tree
Hide file tree
Showing 24 changed files with 398 additions and 105 deletions.
45 changes: 34 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ The current version was tested with the next cameras:
Add the following line to the lib_deps option of your [env:] section:

```python
hpsaturn/EspNowCam@^0.1.11
hpsaturn/EspNowCam@^0.1.12
```

Or via command line:

```python
pio pkg install --library "hpsaturn/ESPNowCam@^0.1.11"
pio pkg install --library "hpsaturn/ESPNowCam@^0.1.12"
```

**Arduino IDE**:
Expand Down Expand Up @@ -86,15 +86,21 @@ void onDataReady(uint32_t lenght) {
}
```
It is also possible to define a specific target:
Note: if you don't define any specific target, the radio will work in broadcasting mode, that means **1:N mode**, for instance one camera sending video to multiple screen receivers.
### P2P mode (1:1)
It's also possible to define a specific target:
```cpp
uint8_t macRecv[6] = {0xB8,0xF0,0x09,0xC6,0x0E,0xCC};
radio.setTarget(macRecv);
radio.init();
```

### Multi camera mode
Note: this mode is very recommended to increase the performance, and also it reduces the noise and possible glitches.

### Multi camera mode (N:1)

Is possible too configure multiple cameras or senders to only one receiver, N:1 mode, configuring filters by MAC in the receiver:

Expand Down Expand Up @@ -124,7 +130,23 @@ Camera.config.fb_count = 2;
Camera.config.frame_size = FRAMESIZE_QQVGA;
```

For now, it includes drivers for FreenoveS3, XIAOS3, M5UnitCamS3, 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
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

Expand All @@ -134,16 +156,15 @@ For now, it includes drivers for FreenoveS3, XIAOS3, M5UnitCamS3, and the TTGO T

| 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 |
| | | | |
| esp32cam-p2p-sender | PSRAM, 1FB, IDF-JPG | QVGA | UNTESTED |

### Receivers samples

Expand All @@ -155,7 +176,6 @@ For now, it includes drivers for FreenoveS3, XIAOS3, M5UnitCamS3, and the TTGO T
| 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.
Expand All @@ -165,13 +185,13 @@ For now, it includes drivers for FreenoveS3, XIAOS3, M5UnitCamS3, and the TTGO T
| 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

Expand All @@ -187,6 +207,8 @@ Some examples, *.ino samples, only needs run `pio run --target upload` into each

## Troubleshooting

To increase the performance, **the recommended use is the 1:1 mode**, and also is a good practice to configure the other radio senders around of this device in this mode, because if you have other senders in broadcasting mode together, them could be generating interference.

The **Freenove camera** sometimes needs good power cable and also takes some seconds to stabilization, that means, that not worries for initial video glitches.

For **Arduino IDE users**, if you have a compiling error, maybe you forget install NanoPb library. Please see above.
Expand All @@ -204,6 +226,7 @@ The library was tested on the next devices:
- [x] M5CoreS3 (builtin Camera)
- [x] XIAO ESP32S3 Sense Camera
- [x] M5UnitCamS3
- [ ] ESP32Cam AI-Thinker (untested. Help wanted)

**Receivers:**

Expand Down
4 changes: 2 additions & 2 deletions examples/custom-camera-sender/custom-camera-sender.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**************************************************
* ESPNowCam video Transmitter
* 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>
Expand Down
60 changes: 60 additions & 0 deletions examples/esp32cam-basic-sender/esp32cam-basic-sender.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**************************************************
* ESP32Cam AI-Thinker Transmitter
* by @hpsaturn Copyright (C) 2024
* This file is part ESPNowCam project:
* https://github.com/hpsaturn/ESPNowCam
**************************************************/

// 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/CamAIThinker.h>

CamAIThinker 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); // only for debugging.

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

// M5Core2 receiver target (P2P or 1:1 mode)
// 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();
}
26 changes: 26 additions & 0 deletions examples/esp32cam-basic-sender/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
; ESPNowCam Freenove ESP32S3CAM
; https://github.com/hpsaturn/esp32s3-cam
; @Hpsaturn 2024

[platformio]
src_dir = ./

[env]
platform = espressif32
framework = arduino
monitor_speed = 115200
monitor_filters =
esp32_exception_decoder
time
build_flags =
-D CORE_DEBUG_LEVEL=3
-D BOARD_HAS_PSRAM=1

[esp32common]
extends = env
board = esp32dev

[env:freenove-basic-sender]
extends = esp32common
lib_deps =
hpsaturn/EspNowCam@^0.1.12
60 changes: 60 additions & 0 deletions examples/esp32cam-p2p-sender/esp32cam-p2p-sender.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**************************************************
* ESP32Cam AI-Thinker Transmitter
* by @hpsaturn Copyright (C) 2024
* This file is part ESPNowCam project:
* https://github.com/hpsaturn/ESPNowCam
**************************************************/

// 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/CamAIThinker.h>

CamAIThinker 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); // only for debugging.

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

// M5Core2 receiver target (P2P or 1:1 mode)
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();
}
14 changes: 6 additions & 8 deletions examples/freenove-basic-sender/freenove-basic-sender.ino
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**************************************************
* ESP32Cam Freenove ESPNow Transmitter
* 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
**************************************************/

// N O T E:
Expand All @@ -13,7 +13,6 @@
#include <Arduino.h>
#include <ESPNowCam.h>
#include <drivers/CamFreenove.h>
// #include <Utils.h>

CamFreenove Camera;
ESPNowCam radio;
Expand All @@ -26,25 +25,24 @@ void processFrame() {
radio.sendData(out_jpg, out_jpg_len);
free(out_jpg);
Camera.free();
// printFPS("CAM:");
}
}

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

delay(1000); // only for debugging.

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

// M5Core2 receiver
// M5Core2 receiver target (P2P or 1:1 mode)
// uint8_t macRecv[6] = {0xB8,0xF0,0x09,0xC6,0x0E,0xCC};
uint8_t macRecv[6] = {0xF4,0x12,0xFA,0x85,0xF4,0x9C};
radio.setTarget(macRecv);
// radio.setTarget(macRecv);
radio.init();

// You are able to change the Camera config E.g:
Expand Down
4 changes: 2 additions & 2 deletions examples/freenove-hvga-sender/freenove-hvga-sender.ino
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**************************************************
* ESPNowCam Freenove Transmitter
* 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>
Expand Down
6 changes: 2 additions & 4 deletions examples/freenove-nojpg-sender/freenove-nojpg-sender.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/**************************************************
* ESPNowCam Transmitter without JPG compression (very slow)
*
* Use with: makerfabs-nojpg-receiver example
*
* by @hpsaturn Copyright (C) 2024
* This file is part ESPNowCam examples:
* https://github.com/hpsaturn/esp32s3-cam
* This file is part ESPNowCam project:
* https://github.com/hpsaturn/ESPNowCam
**************************************************/

#include <Arduino.h>
Expand Down
Loading

0 comments on commit 0d34c27

Please sign in to comment.