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

Unlock the true power of automation and robotics by becoming a proud subscriber of Synthiam ARC Pro.

PRO
USA
#9  

Yes, your firmware Version 3 (2/5/2021).

PRO
Synthiam
#10  

Can you share your modified esp32 firmware code?

Also I can’t quite understand the ezscript code you posted. I’m going to switch you to JavaScript or Python because ezscript is broken and being deprecated.

PRO
USA
#11   — Edited

Here's a zip file of the ESP32 code:

EZ_ESP32_Head.zip

and here's the EZ-script:

UARTWrite($HeadPort, 0, $ReadEncoder)       #Roboclaw read encoder value

sleep(500) $x = UartAvailable($HeadPort, 0)

print("Bytes in buffer: " + $x)

PRO
USA
#12  

And, by the way, I hate the editor on this forum.

PRO
USA
#13  

I switched to JavaScript, and it worked.  So the problem was on the ARC side with EZB-script.  Guess I'm changing ALL of my code to JavaScript.  One step forward, 100 backwards:)

#15   — Edited

Congrats @JSale!. I know that's a good feeling.

I've been spending the past month or so learning Javascript and rewriting all my scripts for my Lost in Space B9 robot. It was painful at first but with some help from DJ and Athena along with a lot of research and reading, trial and error I'm managing to do it. I can't believe how many scripts I had to do but I'm getting close to finishing. I'm really happy I did it and love the performance boost. It also gave me a reason to clean out old scripts and refine most of the others. I'm sure they aren't up to professional script writing standards but they look and run a lot better then my EZ Scripts did.

How's your B9 build coming along? I haven't heard from you in a while.

Happy building!

PRO
USA
#16  

Well I spoke too soon. Yes, I finally got data back on the ARC side, but now the ESP32 side for some reason is looping trying to read data that I don't thing is there. Don't know why it is even attempting to read data. So, more work to do.