Hello,
I am working on a project that would have an ESP32 sit between an Arduino, using the Pololu Maestro library, and a Mini Maestro 18. The purpose of this project is to wirelessly trigger animations on multiple Maestros wirelessly. I am using ESP NOW as my transmission protocol between multiple ESP32s. I have the ESP32 communicating perfectly, so not worried about that part.
I don’t control the code on the Arduino so I’m trying to receive the serial stream that it outputs, and send the device ID and sequence number wirelessly an another ESP32 so it can then trigger animations to the connected Maestro. I’ve been told that it uses the Maestro library to send its commands to the Maestro.
I have no problem getting the Maestro to trigger the sequences from the ESP32 directly connected to the Maestro. That works all day long. The problem I am struggling is ingesting the serial stream that the Arduino/Maestro library outputs and processing that to extract the device ID and sequence number. I don’t want to do any RC passthrough or anything else at the moment. I’m just trying to understand how to read the serial stream from the Arduino so I process it.
Does anyone think this is possible? Any advice would be greatly appreciated.
Thank you!!
Hello.
Can you elaborate on your setup and why you can’t control the code on the Arduino? Also, is there a reason you need to do extra processing to parse the device number and subroutine number instead of just echoing all of the data from the serial stream to your other ESP32 devices?
Do you know if that Arduino code is intended to send commands to multiple Maestros with different device numbers? If not, it might be using the compact protocol (which all Maestros will respond to independent of their device number). You can find more information about the different protocols in the “Command Protocols” section of the Maestro user’s guide.
To start with, if you really need to parse the data and can’t reprogram the Arduino directly, I suggest loading a simple program on your ESP32 that just prints data coming in from the serial port so you can get a better understanding of what the Arduino is sending. If you post an example of that output, I would be happy to take a look.
Brandon
Hi Brandon,
Thanks for the feedback and the link to the control protocols. It was immensely helpful. I don’t control the code on the Arduino because it is a product sold by someone else. I just want to be the middle man in the equation between them and the Maestro. In the below image, my ESP32’s are the blue WCBs (Wireless Communication Boards). The Arduino in question is the Kyber (outlined in Red) and is sold by someone else. You can see that I have multiple Maestros(Outlined in dark purple) that are connected to the same WCB as the Kyber, and other WCBs that are not connected locally to the Kyber.
What you posted triggered something in my head and I am now able to see the serial stream coming in from the Arduino that uses the Maestro Library. I can see the hex values of “0xAA 0x01 0x27 0x01” when I issue the restartScript that is destined for a Maestro with the ID set to 1 and triggering sequence 1. If I try to send a restartScript to a Maestro with the ID of 2 and trigger a sequence of 0, I see “0xAA 0x02 0x27 0x00”. I can receive that stream and send it over to the other WCB and send that out to the other Maestro and trigger it. I’m thrilled to have that working. There’s no need to process that data any longer since I’m just repeating what came in. Thank you very much for that suggestion.
The problem that I’m dealing with now is that I don’t see an end of line character in the communication protocol. I’m struggling to determine when the command is completed sending from the Arduino. In normal serial commands that I’m used to working with, i normally see the “/r” or “/n” as the end of line delimiter. Is there anything similar to that in the Pololu Maestro library communication protocols?
I tried to have a timeout to say when the stream stops, but I am sending commands one after another from the Arduino in order to try and trigger both maestro boards and the second command isn’t being picked up because of the timeout.
Thanks again so much for your help.
The Maestro does not use end line characters like that (although it does have the option of enabling a cyclic redundancy check as a checksum). It essentially waits for a “command byte”, which is characterized by having the most significant bit (MSB) enabled, then it knows how many bytes to expect as part of that command. As described in the “Command Protocols” section of the guide I linked to in my previous reply, when using the Pololu protocol, the actual byte specifying the command must have its MSB cleared. This leaves 0xAA
as the only byte with the MSB enabled, so when it receives 0xAA
, it knows to expect a device number next followed by a command byte with the MSB cleared (which tells it how many more bytes to expect).
If your Arduino is constantly streaming commands, splitting the packets when your ESP32 receives a byte with the MSB enabled might be good enough. Otherwise, you could have it look at the specific command being sent and use that to know how many more bytes should be associated with it. You can reference the “Serial Servo Commands” and “Serial Script Commands” sections of the guide to see the format of each command.
Brandon