
jsale

@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?
@Dave Schulpius, have not move forward much on the B9, as I have been stuck trying to get the coding for the ESP32s working. I am using two ESP32s in the B9 to control the waist and head rotations. The setup I had before worked more like a servo, which did not allow me to spin the head/waist around without limitations. With the ESP32 and a magnetic sensor to home on, I am getting close to achieving full, continuous rotation. I am also using RoboClaw motor controllers so I can get exact position readings, which is what I am having the issue with right now. And like you, I'm going to be switching all my code from EZB-script to javascript. I might have to hit you up for help!
You're trying to put code in the
But to do that, you'll have to understand how that is working...
For example, the roboCmd in this snipet of code is actually the "length of bytes" according to the protocol document.
Here's the protocol details: synthiam.com/Support/EZB-Firmware/communication-protocol
And here's how you can optionally extend it - but your way "will work" if you're not doing anything else with the uart and saves u from having to create a robot skill I guess: synthiam.com/Support/EZB-Firmware/extend-ezb-protocol
That's what I was missing. I think I need to go with extending the EZB protocol on my ESP32 firmware. I'll start looking at that. Thanks.
@Jsale,
You seem so much more advanced in coding then me. I'm not sure how much help I can be but i'm very happy to share what I have.Good luck and have fun!!
Okay, if you're going to do that - let me know if you want any hints or tips. Here's pretty much what you'll do... (I don't want to take the fun away hehe)
In the event functions, you can send the appropriate data to the ESP32 with the command info for the specified servo
In the ESP32 firmware, extend protocol command 0x00 as the link here says (synthiam.com/Support/EZB-Firmware/extend-ezb-protocol). There's an example of it in the Arduino firmware; a few others are listed on that page. So if ARC sends 0x00, 0x01, the 0x00 means "custom command" and 0x01 means "move servo" perhaps. and then the following bytes are the parameters for the move servo. It is up to you to decide how to implement the protocol and what commands it uses. There's no worry about conflict because your firmware and robot skill work together.
Here's a little cheater for you to get you up and running. This is the code for LewanSoul that does the exact thing u wanna do, except it's using the UART and not custom commands. This is already on GitHub anyway but this will save you from searching for it: LewanSoul_Servos.zip
I finally found out what the real issue is with my code. But I did not find it until after I built a skill for a JavaScript extension and creating function calls to send requests to the ESP32.
In my variable initialization for the custom ESP32 firmware I had, for some very dump reason, initialized a variable with a call to Read16(). Not sure why I had that, and the code using that variable was not even being called. Reading that byte messed everything else up.
Can't believe I was doing something so stupid. You would never know I've been programing for 40 years
!
Well, at least I finally built a skill and got it working. That is something I had been trying to do for a couple of years, but just never got it fully done.
Congratulations James! Don't beat yourself up over this. You found it, that's the important thing.
@DJ Sures, now that I got the RoboClaw library and related Javascript interface to work, now I need to know what to add to the ESP32 firmware to make it work with EZB ControlCommand("EZB Connect By Name", "Connect", port, "devicename").