Asked
Resolved Resolved by DJ Sures!

How To Connect Arduino To Ezb With Uart

@DJSures it has been awhile since we discussed my attempt to use Roboclaw library with ESP32 and ARC. But I have made some progress (not real clean, but it does what I need). But now I'm trying to send data from the Roboclaw back to ARC, and can't seem to get the serial comms to work from the ESP32 to ARC. On the ARC side, I have the following EZ-Script code:

$Getbuf = " " #parms: EZB boardindex, UART, RoboClaw CMD UARTWrite(0, 0, $ReadEncoder) #Roboclaw read encoder value

sleep(3000) $x = UartAvailable(0, 0) print("bytes available: " + $x)

This sends a command (ReadEncoder) to the ESP32, sleeps, and then attempts to read data from the ESP32. The ESP32 which correctly recognizes the command it recieved, and then executes the following code on the ESP32:

   char roboCmd       = ' ';
   uint32_t position  = 0;
   roboCmd = ReadByte();
   switch (roboCmd)
   {
   case ReadEncoder:
      position = roboclaw.ReadEncM2(0x80);
      Serial.print("Reading encoder value:");
      Serial.println(position);
      Write32(position);
      break;    

On the Arduino IDE, I can see that the correct value of the encoder is returned, so I know that worked (17:29:19.481 -> Reading encoder value:1125). But on the ARC side, the UartAvailable turns 0 number of bytes in the buffer.
Is there some other function besides Write32() I should be using on the ESP32 side to send data back to the ARC?



ARC Pro

Upgrade to ARC Pro

Harnessing the power of ARC Pro, your robot can be more than just a simple automated machine.

PRO
USA
#1  

@DJSures it has been awhile since we discussed my attempt to use Roboclaw library with ESP32 and ARC. But I have made some progress (not real clean, but it does what I need). But now I'm trying to send data from the Roboclaw back to ARC, and can't seem to get the serial comms to work from the ESP32 to ARC. On the ARC side, I have the following EZ-Script code:

$Getbuf = " " #parms: EZB boardindex, UART, RoboClaw CMD UARTWrite(0, 0, $ReadEncoder) #Roboclaw read encoder value

sleep(3000) $x = UartAvailable(0, 0) print("bytes available: " + $x)

This sends a command (ReadEncoder) to the ESP32, sleeps, and then attempts to read data from the ESP32. The ESP32 which correctly recognizes the command it recieved, and then executes the following code on the ESP32:

   char roboCmd       = ' ';
   uint32_t position  = 0;
   roboCmd = ReadByte();
   switch (roboCmd)
   {
   case ReadEncoder:
      position = roboclaw.ReadEncM2(0x80);
      Serial.print("Reading encoder value:");
      Serial.println(position);
      Write32(position);
      break;    

On the Arduino IDE, I can see that the correct value of the encoder is returned, so I know that worked (17:29:19.481 -> Reading encoder value:1125). But on the ARC side, the UartAvailable turns 0 number of bytes in the buffer.
Is there some other function besides Write32() I should be using on the ESP32 side to send data back to the ARC?

#2  

Are you initializing the uart in your script? There does not seem to be an Initialization command in the script you provided. However, one is needed to configure the uart for correct parameters and baudrate.

PRO
USA
#3  

Yes I initialized the UART.  I do not have all the code shown, it is way too much to post.  As I mentioned, sending data from ARC to ESP32 via the UART is working.  I am having trouble sending from ESP32 to ARC.

PRO
USA
#5  

I have not yet figured out what my problem is. Does the ESP32 WiFi use UART0, or does it have it's own buffers/functions to do communications with ARC? If it has its own, what do I need to do on ARC to read the data coming from the ESP32 WiFi?

PRO
Synthiam
#6  

Wifi? Hmm I'm missing something in what you're proposing. Can you describe how you have this setup? Like, how the wire are, or wifi, or what ever. Because UART is not wifi, so I'm missing something. Or even a diagram I guess is useful:)

PRO
USA
#7  

@DJSures So ARC communicates with ESP32 (EZB) via WiFi. In ARC, I send a command via UARTWrite() using Uart0. This is sent via wifi to the ESP32, which reads the command (one byte code sent via the UARTWrite), the command is ReadEncoder. On the ESP32 firmware I've added reading that one byte command (ReadEncoder) and it then executes the RoboClaw C++ library command roboclaw.ReadEncM2 (which returns the encoder reading for Motor 2) and then I execute COMMUNICATION_PORT.Write (encoder reading) to send the value back to ARC. On the ARC side, I then execute:

$x = UartAvailable($HeadPort, 0) print("Bytes in buffer: " + $x)

and that returns either 0, or some large (invalid) number, like 4000. Mostly it returns 0.

So the "from ARC to ESP32" wifi works, but it does not seem like the "from ESP32 to ARC" works. I assume it works on the initial log-in, as I think the ARC software is expecting the ESP32 (EBZ) to send back the "Capability Controler" (222 for ESP32) and the firmware ID, and since it connects with no problems, I assume ESP32 is doing that.

So I don't understand why I can't send data back to ARC.

User-inserted image

PRO
Synthiam
#8  

Ah i see, so the ESP32 has EZB firmware on it?