▲ 0 r/NightVision
I'm using this for my homemade nvg but cant seem to get the program to work.
here's the program:
#include <Arduino.h>
#include <esp_camera.h>
#include <Arduino_GFX_Library.h>
// =========================
// NOISE / SHARPNESS CONTROL
// =========================
float TEMPORAL_SMOOTHING = 0.20;
// =========================
// DISPLAY SETUP (40 MHz SPI)
// =========================
Arduino_DataBus *bus = new Arduino_ESP32SPI(
2, 1, 6, 4, GFX_NOT_DEFINED, 40000000 // CHANGED 8→6 and 9→4
);
Arduino_GFX *gfx = new Arduino_ST7735(
bus, 3, 0, true, 80, 160, 26, 1
);
// =========================
// CAMERA PINS (MINI ESP-CAM DEV BOARD)
// =========================
#define PWDN_GPIO_NUM -1
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 10
#define SIOD_GPIO_NUM 11
#define SIOC_GPIO_NUM 12
#define Y9_GPIO_NUM 48
#define Y8_GPIO_NUM 47
#define Y7_GPIO_NUM 21
#define Y6_GPIO_NUM 18
#define Y5_GPIO_NUM 17
#define Y4_GPIO_NUM 16
#define Y3_GPIO_NUM 15
#define Y2_GPIO_NUM 14
#define VSYNC_GPIO_NUM 8
#define HREF_GPIO_NUM 7
#define PCLK_GPIO_NUM 9
bool showCrosshair = true;
bool showGridBox = false;
// =========================
// GRAYSCALE + WHITE PHOSPHOR
// =========================
inline uint16_t whiteFromGray(uint8_t g) {
uint8_t v = min<uint16_t>(g * 1.6, 255);
return ((v >> 3) << 11) | ((v >> 2) << 5) | (v >> 3);
}
int offsetX = -10;
int offsetY = -5;
// =========================
// SETUP
// =========================
void setup() {
Serial.begin(115200);
delay(300);
gfx->begin();
gfx->fillScreen(0x0000);
camera_config_t config;
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;
config.pin_d0 = Y2_GPIO_NUM;
config.pin_d1 = Y3_GPIO_NUM;
config.pin_d2 = Y4_GPIO_NUM;
config.pin_d3 = Y5_GPIO_NUM;
config.pin_d4 = Y6_GPIO_NUM;
config.pin_d5 = Y7_GPIO_NUM;
config.pin_d6 = Y8_GPIO_NUM;
config.pin_d7 = Y9_GPIO_NUM;
config.pin_xclk = XCLK_GPIO_NUM;
config.pin_pclk = PCLK_GPIO_NUM;
config.pin_vsync = VSYNC_GPIO_NUM;
config.pin_href = HREF_GPIO_NUM;
config.pin_sscb_sda = SIOD_GPIO_NUM;
config.pin_sscb_scl = SIOC_GPIO_NUM;
config.pin_pwdn = PWDN_GPIO_NUM;
config.pin_reset = RESET_GPIO_NUM;
config.xclk_freq_hz = 20000000;
// ⭐ FIXED: GRAYSCALE MODE (WORKS ON YOUR CAMERA)
config.pixel_format = PIXFORMAT_GRAYSCALE;
config.frame_size = FRAMESIZE_QQVGA;
config.fb_count = 1;
esp_camera_init(&config);
gfx->setCursor(0, 20);
gfx->setTextColor(0xFFFF);
gfx->println("WP NVG + TNR");
}
// =========================
// LOOP
// =========================
void loop() {
camera_fb_t *fb = esp_camera_fb_get();
if (!fb) return;
uint8_t *pix = fb->buf; // ⭐ GRAYSCALE BUFFER (8-bit)
static uint16_t lineBuf[80];
static uint8_t grayRow[160];
static uint8_t grayPrev[160];
for (int x = 0; x < 160; x++)
grayPrev[x] = pix[x];
for (int dy = 0; dy < 160; dy++) {
for (int x = 0; x < 160; x++) {
int ox = 159 - (dy + offsetY);
int oy = x + 20 + offsetX;
if (ox < 0) ox = 0;
if (ox > 159) ox = 159;
if (oy < 0) oy = 0;
if (oy > 119) oy = 119;
grayRow[x] = pix[oy * 160 + ox];
}
for (int dx = 0; dx < 80; dx++) {
int rx = dx + 20 + offsetX;
if (rx < 0) rx = 0;
if (rx > 159) rx = 159;
uint8_t g = (grayRow[rx] * (1.0 - TEMPORAL_SMOOTHING)) +
(grayPrev[rx] * TEMPORAL_SMOOTHING);
uint16_t pixel = whiteFromGray(g);
int cx = 40, cy = 80, radius = 48;
int dx2 = dx - cx;
int dy2 = dy - cy;
if ((dx2 * dx2 + dy2 * dy2) > (radius * radius))
pixel = 0x0000;
lineBuf[dx] = pixel;
}
gfx->draw16bitRGBBitmap(0, dy, lineBuf, 80, 1);
memcpy(grayPrev, grayRow, 160);
}
esp_camera_fb_return(fb);
}
Snvi TFT IPS LCD Display Module 0.96 80x160
Seeed Studio XIAO ESP32S3 Sense Seeeduino ESP32-S3 2.4G WiFi BLE Mesh 5.0 OV2640 Camera Development Board
u/Head-logger — 7 days ago