Issue with code (or Blynk) for RC Car

Hello! I am using an ESP32 (Dev Module) on WiFi to control an ESC and a servo of a RC car. The ESC requires a PWM signal thus why I have substituted analogWrite for ledcWrite. My problem is that the integer val is taking the value from V3 instead of V4 Because of this, when I change the value of V3, the ESC works when the servo is the only thing that should be working. I have limited experience and knowledge with ESP32’s and Blynk, hence why I have come here for help. I am currently using the Blynk Andriod app version 2.27.1 and I use Blynk’s servers and am using Blynk library version 0.5.4.

//Libraries 
#include <Wire.h>
#include <Servo.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

//Blynk & Network Settings
char auth[] = "Nice";  
char ssid[] = "Try";
char pass[] = "Lmao";

//Code Goes Here
int val = 0;

Servo steering;

BLYNK_WRITE(V3) 
{  
  steering.write(param.asInt()); 
}

BLYNK_WRITE(V4) 
{
  val = param.asInt(); 
}

#define LEDC_CHANNEL_0     0
#define LEDC_TIMER_13_BIT  13
#define LEDC_BASE_FREQ     5000
#define LED_PIN            22

void ledcAnalogWrite(uint8_t channel, uint32_t value, uint32_t valueMax = 255) 
{
  ledcWrite(channel, val); 
}

void setup()
{
  Serial.begin(9600); 
  ledcSetup(LEDC_CHANNEL_0, LEDC_BASE_FREQ, LEDC_TIMER_13_BIT);
  ledcAttachPin(LED_PIN, LEDC_CHANNEL_0);
  Blynk.begin(auth, ssid, pass);
  steering.attach(23);
}

void loop()
{
  Blynk.run(); 
}

Thanks in Advance,

Janith Hettiarachchi

How do you know that for sure? Your code says differently.

Well your different functions for V3 and V4 are different :stuck_out_tongue: so whatever crossover is happening has something to do with the servo library and your alternative for PWM ledcWrite as they may be unintentionally sharing some communication

This is an esp32 thing and not really Blynk specific as Blynk is probably working perfectly normal… Something you can confirm with simple feedback to display widgets, like V5 & V6

BLYNK_WRITE(V3) 
{  
  steering.write(param.asInt()); 
  BlynkvirtualWrite(V5, param.asInt());
}

BLYNK_WRITE(V4) 
{
  val = param.asInt(); 
  BlynkvirtualWrite(V6, param.asInt());
}

I would love to say I did that on purpose to see if you are simply doing the copy/paste scriptkiddy thing, or actually reading, examining and learning the commands… But alas that was just a simple syntax error on my part :blush:

Just fix the command syntax as I missed a period

http://docs.blynk.cc/#blynk-firmware-virtual-pins-control-blynkvirtualwritevpin-value

Hmmm yeah you seem to be right, now the issue is fixing this issue :frowning:

Blynk.virtualWrite(V6, param.asInt()); not BlynkvirtualWrite(V6, param.asInt()); etc…

no not that issue lol, getting my esc to take the value of val.

Try using the ledcWrite method for the servo as well… at least long enough to see if there is a conflict or not (AKA remove the servo library).