Send Json to Arduino (ESP32) serial via Bluetooth (need a little help here please)

my problem is create a json and send to serial monitor and then deserealise
blocks below:

You are overthinking the JSON building part.

Just use a 3 way text JOIN sandwich, with your thumb position in the middle:

  • {"motorforward":
  • Slider1.ThumbPosition
  • }

Feed the JOIN directly into the BlueTooth.SendText block.
You might need to add a '\n' afterwards to signal end of message.

To get extra JOIN sockets, use the blue mutator button.

i hope i did right this time now i want to receive this json i mean the entire string a deserealise but inside the serial i receive one at time the arduino code below ,can you help me me that

/*
  Project: ESP32 Bluetooth Mobile Robot
 
 */

#include "BluetoothSerial.h"
#include "ArduinoJson.h"

BluetoothSerial SerialBT;

char receivedChar;// received value will be stored as CHAR in this variable

      String DATA;
      String myFloat;
      
float motorlaterall;
float motorforwardd;


      

const int pinEnA = 2;
const int pinIn1 = 0;
const int pinIn2 = 4;

const int pinEnB = 18;
const int pinIn3 = 22;
const int pinIn4 = 23;

#define PWM_FREQUENCY   1000
#define PWM_RESOLUTION  8 // Setting the resolution to 8Bits, gives you a duty cycle range [0 – 255].
#define PWM_CHANNEL 0



void setup() {
  
Serial.begin(9600);
   SerialBT.begin("ESP32_Technical_Alexandre"); //You can change your Bluetooth device name

   
   pinMode(pinEnA,OUTPUT);
  pinMode(pinEnB,OUTPUT);
  pinMode(pinIn1,OUTPUT);
  pinMode(pinIn2,OUTPUT);
  pinMode(pinIn3,OUTPUT);
  pinMode(pinIn4,OUTPUT);
  
  

  //Decide on the PWM channel that you’re going to use
  //configure this PWM Channel with the selected frequency & resolution using this function.
  ledcSetup(PWM_CHANNEL, PWM_FREQUENCY, PWM_RESOLUTION);
 
  //Decide on the GPIO pin to route this PWM Ch signal to.
  //Assign that PWM Ch to the selected GPIO pin 

  
  ledcAttachPin(pinEnA,PWM_CHANNEL);
  ledcAttachPin(pinEnB,PWM_CHANNEL);

 //now you can control this PWM pin by changing the duty cycle
//ledcAttachPin(pin,duty cycle)











}


//////////////////////////////////////////////////
       //            WHEELING FUNCTION
//////////////////////////////////////////////////



   void forward(){
 
  Serial.println("Moving forward");
  digitalWrite(pinIn1, HIGH);
  digitalWrite(pinIn2, LOW);
  digitalWrite(pinIn3, HIGH);
  digitalWrite(pinIn4, LOW); 

   }

  
      void right(){

  Serial.println("Moving right");
  digitalWrite(pinIn1, LOW);
  digitalWrite(pinIn2, HIGH);
  digitalWrite(pinIn3, HIGH);
  digitalWrite(pinIn4, LOW); 

    }
    
      void left(){
 
  Serial.println("Moving left");
  digitalWrite(pinIn1, HIGH);
  digitalWrite(pinIn2, LOW);
  digitalWrite(pinIn3, LOW);
  digitalWrite(pinIn4, HIGH); 
  
      }
      
      void backwards(){

  Serial.println("Moving backwards");
  digitalWrite(pinIn1, LOW);
  digitalWrite(pinIn2, HIGH);
  digitalWrite(pinIn3, LOW);
  digitalWrite(pinIn4, HIGH); 

      }
 
  
      void STOP(){

  Serial.println("STOP");
  digitalWrite(pinIn1, LOW);
  digitalWrite(pinIn2, LOW);
  digitalWrite(pinIn3, LOW);
  digitalWrite(pinIn4, LOW); 

      }
      




void control(float forward,float lateral){
 
  float  wheelL, wheelR, l = 0.13, r = 0.03;
  

  wheelR = ((forward / r) + (lateral * l) / (2 * r)) * 60;
  wheelL = ((forward / r) - (lateral * l) / (2 * r)) * 60;

  Serial.print("Roda Direita:");
  Serial.println(wheelR);
  Serial.print("Roda Esquerda:");
  Serial.println(wheelL);
  
  if (wheelR >= 0) {
    
    ledcWrite(PWM_CHANNEL, wheelR);
  }
  else {
    
    ledcWrite(PWM_CHANNEL, abs(wheelR));


    
  }
  if (wheelL >= 0) {
    ledcWrite(PWM_CHANNEL, wheelL);
    
  }
  else {
    
    ledcWrite(PWM_CHANNEL, abs(wheelL));
  }
}








void loop() {



 float motorforward ;
  float motorlateral;
  String ch="";

  if (Serial.available()) {
    
    SerialBT.write(Serial.read());

  
  }
  
  if (SerialBT.available()) {



   DATA =(String)SerialBT.read()

   

 // receivedChar =  (char)SerialBT.read();

/*
while(  (ch = (char)SerialBT.read()) != '\0'){
 receivedChar +=ch;
 
  

}
  */
  ch.concat(DATA);
    Serial.print ("Received:");//print on serial monitor
    Serial.println(ch);//print on serial monitor
    
//Serial.print ("Received:");//print on serial monitor
  //  Serial.println(receivedChar);//print on serial monitor

    
    
   //////////////////////////////////////////////////
//                  json document
////////////////////////////////////////////////


/*
  
StaticJsonDocument <800> doc;

const char * json = DATA.c_str();


DeserializationError error = deserializeJson(doc, json);

 if (error) {
      Serial.print(F("deserializeJson() failed: "));
      Serial.println(error.f_str());
      return;
   }


 long motorforwardd = doc["motorforwardd"];
 long motorlaterall = doc["motorlaterall"];

 
Serial.println(motorforwardd);
Serial.println(motorlaterall);


*/




  

if(receivedChar == 'F')
    {


      
    forward() ;

  
  motorforward=motorforward;
  motorlateral=0 ;

control( motorforward,motorlateral);
  
  }



 if(receivedChar == 'R')
    {

     right();
      motorforward=0;
  motorlateral=-motorlateral;
  
 control(motorforward, motorlateral);
    }
    


if(receivedChar == 'L')
    {

      left() ;
    motorforward=0;
  motorlateral=motorlaterall;

  control( motorforward,motorlateral);
  
      }
      
     
 
 if(receivedChar == 'B')
    {

       backwards();
  motorforward= -motorforwardd;
  motorlateral=0;
  
 control( motorforward, motorlateral);

      }
  
  

if(receivedChar == 'S')
    {

      

  motorforward=0;
  motorlateral=0;
  
  control(motorforward,motorlateral);
      }
      
   
  
 
  }

 delay(20);

}
 

The quotes around your \n characters in your slider events are counterproductive.
Remove them.

Regarding how to parse incoming JSON on an IOT device, I defer to those with more experience than me.

Create a small app to send a simple text to the ESP32, and study the information obtained in the Serial Monitor.

About the Slider, I think this extension is better, since the Slider component continuously sends information by BT while sliding and that can cause an error.

thanks ill wait i did what you,ve said

i obtain one at a time { then " and so on

I commented in my previous message that it is best to make a small program to study its operation, I also commented that Slider is not a good option to send information, unless you use it with a Clock.
Here is a small example for you to study how to send information by BT.

#include "BluetoothSerial.h"
BluetoothSerial SerialBT;

char caracter;
String palabra;

void setup(){
  Serial.begin(9600);
  SerialBT.begin("ESP32test");
}

void loop(){
  if(SerialBT.available()) {
  caracter = SerialBT.read();
  palabra = palabra + caracter;

  if(caracter == '*') {    
     palabra = palabra.substring(0, palabra.length() - 1); // Quita último caracter * 
     Serial.println(palabra);
     palabra = "";
  }
    delay(100); 
   } // =>Fin del available
}

thanks it works fine i can now get my json is a litlle bit slow though but yes ,thank you so much

now ill try to adapt to my esp32 car to change speed

@Alex22

Try the Slider extension, as I mentioned in the previous message, the information is sent when you TouchUp Slider.

borr_bt_json.aia (12.4 KB)

thanks for helping ill now try to finish the project and send my results later

hello again i hav this new blocks i want to combine de joystick angle with lateral and foreward ,i mwan whenever the angle is negative lateral or forward follow the same parameter

the blocks below

I don't quite understand what you are looking for.
You may want to Send Text the x,y values ​​of the joystick, so in the joystcik.TouchUp block, let
forward = x
lateral = y
SendText

yes i do want to do that the result must be according to the angle of the joystick if i drag towards negative axis i should get the result to my json forward x and lateral y but i dont see how can i do it by using the joystick

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.