BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Issue with code (or Blynk) for RC Car

esp32

#1

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


#2

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


#3

Because I am using a slider to change the value of V3, which is meant for the servo. The ESC also works when I move the slider for V3.


#4

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());
}

#5

Hmm, when I try to compile your code, it gives me this error:

Arduino: 1.8.7 (Windows 10), Board: "ESP32 Dev Module, Disabled, Default, QIO, 80MHz, 4MB (32Mb), 921600, None"

C:\Users\NeefoPlays\Documents\Arduino\wifi_dual_servos\wifi_dual_servos.ino: In function 'void BlynkWidgetWrite3(BlynkReq&, const BlynkParam&)':

wifi_dual_servos:21:38: error: 'BlynkvirtualWrite' was not declared in this scope

   BlynkvirtualWrite(V5, param.asInt());

                                      ^

C:\Users\NeefoPlays\Documents\Arduino\wifi_dual_servos\wifi_dual_servos.ino: In function 'void BlynkWidgetWrite4(BlynkReq&, const BlynkParam&)':

wifi_dual_servos:27:38: error: 'BlynkvirtualWrite' was not declared in this scope

   BlynkvirtualWrite(V6, param.asInt());

                                      ^

Multiple libraries were found for "WiFi.h"
 Used: C:\Users\NeefoPlays\Documents\Arduino\hardware\espressif\esp32\libraries\WiFi
 Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
Multiple libraries were found for "Servo.h"
 Used: C:\Users\NeefoPlays\Documents\Arduino\libraries\ESP32_Arduino_Servo_Library
 Not used: C:\Program Files (x86)\Arduino\libraries\Servo
exit status 1
'BlynkvirtualWrite' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

#6

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


#8

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


#9

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


#10

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


#11

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).