moh43
May 25, 2024, 7:08pm
1
Hi all,I'm using the ESP32-CAM to recognize QR codes, and everything was working perfectly until I started using SoftSerial to transmit the SBUS signal. I can receive the SBUS signal via RX2, but for my project, I need to send the SBUS signal to the flight controller.
However, I received an error message:
E (2304) gpio: gpio_install_isr_service(449): GPIO isr service already installed
Here is the code :
#include "esp_camera.h"
#include "SBUS.h"
#include <SoftwareSerial.h>
#define RX_PIN 13 // RX
#define TX_PIN 15 // TX
SoftwareSerial mySerial(RX_PIN, TX_PIN);
SBUS x8r(Serial2);
uint16_t mohamed[16];
bool failSafe;
bool lostFrame;
#define PWDN_GPIO_NUM 32
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 0
#define SIOD_GPIO_NUM 26
#define SIOC_GPIO_NUM 27
#define Y9_GPIO_NUM 35
#define Y8_GPIO_NUM 34
#define Y7_GPIO_NUM 39
#define Y6_GPIO_NUM 36
#define Y5_GPIO_NUM 21
#define Y4_GPIO_NUM 19
#define Y3_GPIO_NUM 18
#define Y2_GPIO_NUM 5
#define VSYNC_GPIO_NUM 25
#define HREF_GPIO_NUM 23
#define PCLK_GPIO_NUM 22
// Function to configure and initialize the camera
static void configCamera() {
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;
config.pixel_format = PIXFORMAT_JPEG;
config.frame_size = FRAMESIZE_VGA;
config.jpeg_quality = 12;
config.fb_count = 1;
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf("Camera init failed with error 0x%x", err);
return;
}
}
void setup() {
Serial.begin(115200);
mySerial.begin(100000, SWSERIAL_8E2);
x8r.begin(16, 17, true, 100000);
configCamera();
}
void loop()
}
srnet
May 25, 2024, 8:11pm
2
Why are you using software serial on an ESP32CAM when you can use hardware serial ?
moh43
May 25, 2024, 8:25pm
3
I only have the RX pin (RGPIO16) available on my ESP32-CAM.
I know hardly anything about ESP32 devices and I only know a little bit about the SBUS. But below strikes me as odd.
moh43:
mySerial.begin(100000, SWSERIAL_8E2);
x8r.begin(16, 17, true, 100000);
x8r is an SBUS device. Do you have a second SBUS device that requires the use of SoftwareSerial?
Note:
I doubt that your presented code will compile
srnet
May 26, 2024, 6:18am
5
Pin 16 is the select pin for the PSRAM, 17 is the PSRAM CLK.
Plus, software serial does allow you to allocate a serial interface to any free pins, but on an ESP32 you can do that with hardware serial too.
moh43
May 26, 2024, 7:26am
6
I'm not using PSRAM, so I'm able to use Pin 16. I still need another serial, and based on your experience, I'll create a hardware serial. Could you please tell me which pins you have used before? I want to make sure, as I chose GPIO12 and GPIO13 for the ESP32-CAM.
srnet
May 26, 2024, 7:47am
7
You can use Serial2 like this;
Serial2.begin(9600, SERIAL_8N1, TXpin, RXpin);
I have used pin 33 for outputting debug info via Serial2.
moh43
May 26, 2024, 9:49am
8
Thank you, it worked perfectly. However, when I used WiFi, it started rebooting
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x4008e5fc PS : 0x00060d30 A0 : 0x800d71c9 A1 : 0x3ffcb5d0
A2 : 0xffffffff A3 : 0xffffffff A4 : 0xffffffff A5 : 0x00060d23
A6 : 0x00060d23 A7 : 0x00000001 A8 : 0x00000001 A9 : 0x00000004
A10 : 0x00060d23 A11 : 0x3ffc4d88 A12 : 0x3ffc4a38 A13 : 0x00004e20
A14 : 0x007bf528 A15 : 0x003fffff SAR : 0x00000017 EXCCAUSE: 0x0000001c
EXCVADDR: 0x0000003f LBEG : 0x4008b699 LEND : 0x4008b6a9 LCOUNT : 0xfffffffc
here is the code:
#include <WiFi.h>
#include "esp_camera.h"
#include "SBUS.h"
#include <HardwareSerial.h>
HardwareSerial UART1(2);
#define TX_PIN 12
#define RX_PIN 16
#define num_channels 16
SBUS x8r(Serial2);
uint16_t mohamed[num_channels];
bool failSafe;
bool lostFrame;
const char* ssid = "Redmi Note 10S";
const char* password = "1234567899";
#define PWDN_GPIO_NUM 32
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 0
#define SIOD_GPIO_NUM 26
#define SIOC_GPIO_NUM 27
#define Y9_GPIO_NUM 35
#define Y8_GPIO_NUM 34
#define Y7_GPIO_NUM 39
#define Y6_GPIO_NUM 36
#define Y5_GPIO_NUM 21
#define Y4_GPIO_NUM 19
#define Y3_GPIO_NUM 18
#define Y2_GPIO_NUM 5
#define VSYNC_GPIO_NUM 25
#define HREF_GPIO_NUM 23
#define PCLK_GPIO_NUM 22
static void configCamera() {
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;
config.pixel_format = PIXFORMAT_JPEG;
config.frame_size = FRAMESIZE_VGA;
config.jpeg_quality = 12;
config.fb_count = 1;
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf("Camera init failed with error 0x%x", err);
return;
}
}
#define SBUS_MIN_OFFSET 173
#define SBUS_MID_OFFSET 992
#define SBUS_MAX_OFFSET 1811
#define SBUS_CHANNEL_NUMBER 16
#define SBUS_PACKET_LENGTH 25
#define SBUS_FRAME_HEADER 0x0f
#define SBUS_FRAME_FOOTER 0x00
#define SBUS_FRAME_FOOTER_V2 0x04
#define SBUS_STATE_FAILSAFE 0x08
#define SBUS_STATE_SIGNALLOSS 0x04
#define SBUS_UPDATE_RATE 15 //ms
void sbusPreparePacket(uint8_t packet[], int channels[], bool isSignalLoss, bool isFailsafe){
static int output[SBUS_CHANNEL_NUMBER] = {0};
for (uint8_t i = 0; i < SBUS_CHANNEL_NUMBER; i++) {
output[i] = channels[i];
}
uint8_t stateByte = 0x00;
if (isSignalLoss) {
stateByte |= SBUS_STATE_SIGNALLOSS;
}
if (isFailsafe) {
stateByte |= SBUS_STATE_FAILSAFE;
}
packet[0] = SBUS_FRAME_HEADER; //Header
packet[1] = (uint8_t) (output[0] & 0x07FF);
packet[2] = (uint8_t) ((output[0] & 0x07FF)>>8 | (output[1] & 0x07FF)<<3);
packet[3] = (uint8_t) ((output[1] & 0x07FF)>>5 | (output[2] & 0x07FF)<<6);
packet[4] = (uint8_t) ((output[2] & 0x07FF)>>2);
packet[5] = (uint8_t) ((output[2] & 0x07FF)>>10 | (output[3] & 0x07FF)<<1);
packet[6] = (uint8_t) ((output[3] & 0x07FF)>>7 | (output[4] & 0x07FF)<<4);
packet[7] = (uint8_t) ((output[4] & 0x07FF)>>4 | (output[5] & 0x07FF)<<7);
packet[8] = (uint8_t) ((output[5] & 0x07FF)>>1);
packet[9] = (uint8_t) ((output[5] & 0x07FF)>>9 | (output[6] & 0x07FF)<<2);
packet[10] = (uint8_t) ((output[6] & 0x07FF)>>6 | (output[7] & 0x07FF)<<5);
packet[11] = (uint8_t) ((output[7] & 0x07FF)>>3);
packet[12] = (uint8_t) ((output[8] & 0x07FF));
packet[13] = (uint8_t) ((output[8] & 0x07FF)>>8 | (output[9] & 0x07FF)<<3);
packet[14] = (uint8_t) ((output[9] & 0x07FF)>>5 | (output[10] & 0x07FF)<<6);
packet[15] = (uint8_t) ((output[10] & 0x07FF)>>2);
packet[16] = (uint8_t) ((output[10] & 0x07FF)>>10 | (output[11] & 0x07FF)<<1);
packet[17] = (uint8_t) ((output[11] & 0x07FF)>>7 | (output[12] & 0x07FF)<<4);
packet[18] = (uint8_t) ((output[12] & 0x07FF)>>4 | (output[13] & 0x07FF)<<7);
packet[19] = (uint8_t) ((output[13] & 0x07FF)>>1);
packet[20] = (uint8_t) ((output[13] & 0x07FF)>>9 | (output[14] & 0x07FF)<<2);
packet[21] = (uint8_t) ((output[14] & 0x07FF)>>6 | (output[15] & 0x07FF)<<5);
packet[22] = (uint8_t) ((output[15] & 0x07FF)>>3);
packet[23] = stateByte; //Flags byte
packet[24] = SBUS_FRAME_FOOTER; //Footer
}
uint8_t sbusPacket[SBUS_PACKET_LENGTH];
int rcChannels[SBUS_CHANNEL_NUMBER];
uint32_t sbusTime = 0;
void setup(){
Serial.begin(115200);
UART1.begin(100000, SERIAL_8N2, RX_PIN, TX_PIN);
x8r.begin(16, 17, true, 100000);
WiFi.begin(ssid, password);
Serial.print("Connecting...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("IP address: " + WiFi.localIP().toString());
configCamera();
}
void loop(){
if(x8r.read(&mohamed[0], &failSafe, &lostFrame)){
for (uint8_t i = 0; i < SBUS_CHANNEL_NUMBER; i++) {
rcChannels[i] = mohamed[i];
}
}
uint32_t currentMillis = millis();
if (currentMillis > sbusTime) {
sbusPreparePacket(sbusPacket, rcChannels, false, false);
UART1.write(sbusPacket,SBUS_PACKET_LENGTH);
sbusTime = currentMillis + SBUS_UPDATE_RATE;
}
}
system
Closed
November 22, 2024, 9:50am
9
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.