Arduino serial data communication to Robotis CM-530 controller

Issue:

I pulled my BIOLOID PREMIUM off the shelf after an extended time away from it and planning on a new phase of voice-control for it (see my prior posts) - this time around it will be controlled by Amazon Alexa Voice Services via Arduino Cloud…

Anyway, at present just trying to refamiliarize myself with basic operation and looking to re-establish means of sending serial data into the CM-530 via the USB port as I did previously using a Raspberry Pi…

Only this time, I plan on using an Arduino NANO 2040, so I will be moving from Python to Arduino [C++] code and so not sure yet on exact serial protocol/syntax changes I will need to make…

My first attempt failed, but I will follow up on that later in another post…for now, I just wanted to verify that the CM-530 was receiving serial data, so I connected PC to USB port and started the old RoboPlus original software - it connected…

I downloaded a simple “blink” Task and it worked OK, but, I then later also tried to use the Virtual Remote Controller applet portion of the RoboPlus Task software in order to see the serial data come across, but, I got no robot action or any data shown on the Monitor screen…

The actual Wireless Remote Controller works fine…

I assume I am supposed to be in the PLAY MODE to use the Virtual Remote Controller?

Do not know what else to do?? I think I remember it working before some years ago…

Frank


UPDATE


I re-installed the default Task and Motion files; I also was careful to only click on the Controller icon and I also hit the “R” button on the CM-530…

In any event, I was able to get the Virtual Controller to work a couple to times, so I do know that sending serial data packets into the USB port will still indeed allow robot control…

Now I just need to figure out why my C++ serial.Write syntax is not working…

In the RPi, using Python and pySerial, I initialized the port with:

# open serial port
ser = serial.Serial(port='/dev/ttyUSB0', baudrate=57600, timeout=1)

and sent:

    # send command to bot
    ser.write(b'\xFF\x55\x01\xFE\x00\xFF')
    # terminates action at one step
    ser.write(b'\xFF\x55\x00\xFF\x00\xFF')

For the Arduino NANO, I am initializing with:

Serial.begin(57600); 

and sending:

// send example to bot
      Serial.write(0xFF);
      Serial.write(0x55);
      Serial.write(0x21);
      Serial.write(0xDE);
      Serial.write((byte) 0x00);  // required by Arduino
      Serial.write(0xFF);

When I run a serial monitor on the output, I see characters out the USB port of the NANO, but there is no response from the robot.

Both the Physical and Virtual Remote Controller use the RC-100 protocol, see this link

As you are switching to Arduino, there is quite a bit to do. You can see the free Kindle sample for my Arduino book where I showed considerable details about applying the RC-100 protocol on an OpenRB-150. Perhaps you can adapt that material for your NANO 2040.

https://www.amazon.com/Using-ARDUINO-ROBOTIS-Systems-Ngoc/dp/0999391895/

What kind of language do you plan to use on the CM-530?

My plan is to only use the basic built-in commands provided by the default program…I will associate the required hex codes with voice commands to Alexa, and have her pass them into the CM-530 as I did in my earlier project

I saw your book and checked it out…I may look there if I can’t solve my communication issue - see revised initial topic above…

Thanks for checking in!

Frank

Also, the CM-530 is “weird” in the sense that it can communicate to the outside EITHER via wired OR wireless connections - not BOTH options at the same time.

So, I assume my formatting for the hex code is improper and the CM-530 is not recognizing it…

Not real familiar with serial data transmission coding and would appreciate if someone could look and point out what I am doing wrong in new approach from old one in Python that did work…

Frank

When I initially tried it, I did not have the Bluetooth modules connected…

ROBOTIS has the source code for ZIGBEE SDK C Library that describe the RC-100 protocol in details.

ZIGBEE SDk

That was how I learned the RC-100 protocol.

Whether in Python or in C++, it is about sending and receiving the same 6 bytes. In Python “bytearray” is used, in C/C++ you should use unsigned char

Thanks - I’ll look into creating that in Arduino!

Hi - finally have a chance to get back to this after some other wild excursions trying some different “serial” routes…

So, I looked over the ZIGBEE SDK and it looks pretty straight-forward to use to send commands and would like to try in an Arduino board, but, a little confused non implementation…

Guessing it is/can be imbedded in the CM-530 and I would need a corresponding C library installed in the Arduino IDE to implement for sending codes?

I see ZIGBEE-like libraries available, but I doubt they are what I need…I have searched Robotis but do not find…

So, you are saying that the port that connects to the USB port on my computer is looking for a serial Remocon packet…I got your book and am studying it now…I see that there is an RC-100 library somewhere that maybe I can incorporate into my Arduino code…I will study more…thanks…

First, let’s clarify a few things:

  1. From your previous posts, I got the gist that you want to stay with the CM-530 and TASK coding because you want to keep on using MOTION to move your humanoid right? And on the other end you want to use Arduino NANO 2040? As CM-530 + TASK can only understand the RC-100 protocol, you’ll need somehow to implement that Zigbee SDK into the Arduino NANO 2040.

  2. If you got my Arduino book, it shows how to use Arduino boards that are compatible with the Arduino2Dynamixel (D2A) library, for example the OpenRB-150. Then the RC-100 protocol is already incorporated into the D2A library. And the OpenRB-150 can control the DXLs directly too and do Motion Programming too, but only on new DXLs such as XL-430s which can do Time-based Position Control mode. Your PREMIUM Humanoid uses older AX-12s which cannot do this Mode. But the OpenRB-150 can be programmed to send just RC-100 packets to a CM-530 also. Assuming you can make Alexa work with OpenRB-150. I have not used Alexa before, so what is Alexa’s function relative to an Arduino board? Just talk to each other via Bluetooth/ Which version BT 4 or 5?

Or may be my book for the ENGINEER systems would be better suited for you.

Projects Guide for ROBOTIS ENGINEER: Combined Edition, Thai, Chi, eBook - Amazon.com

This book deals with how to use RPi4b and Jetson Nano to work either directly with DXLs or with CM-550 (using the regular MOTION tool that you may be familiar already). In that book an Hexapod and an Humanoid robot are used this way. So you can adapt this book to your project too, but this book covers the new DXLs XL430s and the CM-550 only.

You need to tell me more details about what you want to do, so that I can “steer” you in the right direction better.

Hi Chi,

My goal is very simple…

I am trying to create a simple plaything for my very young grandson - I want him to be able to ask the Humanoid to do the simple things that are already preprogrammed into the CM-530, a subset of the ones that you can command using the RC-100, such as forward, back, right, left, cheer, poundchest, pushup, handstand, etc.

I want him to be able to use Alexa’s voice service for commanding those actions, in a similar fashion to the way I used SNIPS to create Jarvis which you can see on the YouTube link I set…

So, I simply want to associate a Remocon packet transmission into the Humanoid CM-530 with the action that results from activating a call to Alexa over the Arduino IoT Cloud…I have that basic piece complete…

I do not want to do any new Task or Motion work, I simply want to send packets to the CM-530…

So, as I said, I have been successful using the Raspberry Pi and PySerial, but not successful using Arduino and its hardware serial…

As best as I can tell, the serial port I created in PySerial and the one created in Arduino are the same and should present the same to the CM-530 (57600, 8, N, 1):

//Python:
ser = serial.Serial(port='/dev/ttyUSB0', baudrate=57600, timeout=1)
// vs
//Arduino:
Serial.begin(57600);

The packet should be the same:
Python:

ser.write(b'\xFF\x55\x21\xDE\x00\xFF')

Arduino (I took your suggestion re byte vs unsigned char - still did not work):

unsigned char action_poundChest[6] = {0xFF, 0x55, 0x21, 0xDE, 0x00, 0xFF};
Serial.write(action_poundChest, 6);

So, I will study your book…I glanced at the first and second chapters and there may be enough clues there to help…I did notice some library references to RC-100, so maybe I can try to incorporate them somehow…

I just wish I could see how the two scenarios differ - it must be very subtle, don’t you think?

I also then want him to be able to use Alexa as Alexa, but that is beside the point here…

Frank

BTW, I sent an email to get the demonstration code for the book, but have not seen anything yet…

First, I need you to clarify a few things:

  1. Which ARDUINO board are you using.
  2. How does your Arduino communicate with the CM-530? Some kind of UART Port on the Arduino? and via the 4-Pin Comm Port on the CM-530? Or via the CM-530 USB Port?
  3. If you are using Bluetooth, what is the hardware used on the Arduino board and what is the hardware used on the CM-530?

I have looked at your example RC-100 packet and these are my findings:

LOWBYTE is 0x21

image

So, you were sending the equivalent of Button UP and Button 2 in your RC-100 packet, which is fine.

1-complement of 00100001 (i.e. ~00100001) is 11011110 which is DE. So your packet is correct so the familiar TASK command on the CM-530 side such as the one below should have worked for you.

image

VRC_Button should have the value 00100001: i.e. Button UP and Button 2 were pressed.

So I don’t think that you have a software programming issue.

As I mentioned before, the CM-530 is weird in the way that if you have the USB cable still plugged in the CM-530 USB Port, it will disable its 4-pins COMM Port, i.e. no BT functionality at run time. Please check your operating conditions.

Also in Section 2.11 of the Arduino book where I used 2 OpenRB-150s, one is sending RC-100 packets to the other. So please look at the example INO sketch named DC_PT_HLS_ColorTracker.ino whereas Serial3 was used to SEND RC-100 packets.

image

image

So it looks like that I used uint8_t type of array for Arduino coding.
See figures 2.116 and 2.118. Also don’t send your RC-100 packets too fast, it will overwhelm the CM-530.

When I was using a Windows PC with Visual Studio C++ and the ZigBee SDK, I used unsigned char array

image

and

image

Probably differences between C++2003 (the ZigBee SDK is very old and written for the CM-5) and C++2011 (on Arduino boards) probably.

Hi Chi,

I have used an Arduino NANO 33 IoT, a NANO 2040 and a UNO R4 WiFi, all with same result…I am sending the packet to the hardware serial port with the following simple test code, so it’s just one packet, slow…I can see the six chars flow if I open the Serial Monitor, so I know they go…

My physical connection is to the CM-530 USB port (with no BT module plugged in), same connection used when I connect using the PC and the Virtual RC-100, which works, or the RPi/Python, which works…

// Simple test for sending Remocon packet to Humanoid

const int buttonPin = 2;
const int ledPin = 13;
int buttonState = 0;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
  Serial.begin(57600);
  delay(1500); 
}

void loop() {
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {
	  
    unsigned char action_poundChest[6] = {0xFF, 0x55, 0x21, 0xDE, 0x00, 0xFF};
    Serial.write(action_poundChest, 6);
	
    digitalWrite(ledPin, HIGH);
    delay(1000);
  } else {
    digitalWrite(ledPin, LOW);
  }
}
// A similar button sketch used for the RPI/PySerial approach with this setup:
import serial
ser = serial.Serial(port='/dev/ttyUSB0', baudrate=57600, timeout=1)

ser.write(b'\xFF\x55\x21\xDE\x00\xFF')

So, again, I would think that the RPi setup, which works, is the same as the Arduino, which does not, but apparently not, so again, either the serial ports are dissimilar in someway (the “timeout=1” is for the read function so should make no difference), or, the packet construction is different…

I think I will try to use the other serial port (Serial1) on an Arduino today with soft-serial and see if that might make any difference? Something to try anyway, right?

Baffled…

Thanks for your attention…there has to be an answer as to why this is, and hopefully a corresponding solution…

My path to all this narrowed a while back because both Amazon and Google decided to withdraw from providing the API keys to their voice services and the only path I can find now is through the Arduino IoT Cloud…I originally used SNIPS and then ported to Google when SNIPS was acquired by SONOS…

Frank

Some more thoughts to share…

The PC and RPi solutions both use USB ports that are converted to serial, whereas the Arduino starts as serial, so maybe there is something there to consider?

Along those lines is the reason I tried an Arduino UNO R4 WiFi…I determined that you could equip it with a USB Host Shield which can use the USB Host Shield 2.0 library…

I figured I could then use that port, convert it back to serial like the PC/RPi situation, and see if that would work…unfortunately, after getting it set up, I looked at all the Examples and searched the internet but could not find how to write out any “data”…maybe you could take a look Chi, and see if you can make some sense of it - I just do not have the C background to tackle that…I think it is just a limited USB HID-type port…

Another thought would be to look at the source code for the Robotis Task app, specifically the Terminal/Virtual Remote Controller stuff and see if any clues there (but again, it is piping through the USB port)…I will see if I can find that code and take a look…

Frank

I have never used the Arduino USB port to send out RC-100 packet so I do not know why it does not work for you. I have only used the “regular” Serial1, Serial2, etc … which are UART PORTS. And I am no USB Driver expert, so I am not even going to try.

You can try to use the 4-Pins Port on the CM-530 which is a UART Port and hook it up to Serial1, etc… on your Arduino board. Then all my example codes should work.

If you buy then modify this BT Cable from ROBOTIS

image

The big end will fit to the 4-pin connector COMM Port on the CM-530 fine. You’ll need to cut off the smaller connector out and fit those 4 wires with Dupont Pins so that you can insert them to the GPIO pins on the Arduino board (for the proper UART Pins of your chosen SerialN port). And then you’ll have a “wired” connection between your Arduino and the CM-530.
Just remember to swap the TX and RX wires between the Arduino end and the CM-530 end - basically cross them over. Also remember that UART on the CM-530 is using 3.3 V, so you’ll need a Logic Shifter chip if your Arduino is a 5V board.

Understand re UART port…I may have a compatible cable around here I can use…okay too re 3.3V…I assume from what you say that the port is just sitting there waiting for packets too…

I still think it might be worth it if you can spare the time to look at the Example .ino files for the USB Host Shield 2.0 library as there may be a clue in there re data transfer over that port if it it is capable - that would be convenient…

Thanks again for your time…

Frank

Chi,

I think I figured out the problem - here is the result of a “conversation” I had with ChatGPT regarding the data flow in and out of the Arduino USB port:


##### You said:
what does /dev/ttyUSB0 refer to when configuring a serial port on a RPi USB port

###### ChatGPT said:

ChatGPT

On a Raspberry Pi, /dev/ttyUSB0 is a device file that represents a USB-to-serial adapter connected to a USB port on the Pi. When configuring a serial port through USB on a Linux system, these device files (/dev/ttyUSB0, /dev/ttyUSB1, etc.) are automatically created by the OS each time a USB-to-serial adapter is connected.

Here’s a breakdown of what each part means:

** /dev/: This is the directory where device files are stored on Linux systems.*
** ttyUSB0: This specific file name is for a USB-based serial interface. The number (0) indicates it’s the first USB serial device detected. Additional adapters would show up as ttyUSB1, ttyUSB2, and so on.*

When configuring a serial port to communicate with an external device (e.g., a microcontroller or sensor) over USB, you’ll typically use this device file to establish communication. It allows you to set parameters like baud rate and transfer data to and from the external device over the serial connection.

##### You said:

so /dev/ttyUSB0 makes a USB port emulate a UART?

###### ChatGPT said:

Yes, exactly! The /dev/ttyUSB0 file allows the USB port to emulate a UART (Universal Asynchronous Receiver-Transmitter) serial interface. This setup uses a USB-to-serial adapter (typically a chip like the FTDI, CP2102, or CH340) to convert USB signals into standard UART serial communication.

Here’s how it works:

1. USB-to-Serial Adapter: The adapter (or chip) bridges the USB and UART protocols. It handles the conversion of data between USB signals and the TX/RX (transmit/receive) lines used in UART communication.
2. Device File /dev/ttyUSB0: When you plug in a USB-to-serial adapter, the Linux kernel detects the device and creates a device file like /dev/ttyUSB0. Programs can then open and use this file to send and receive serial data just as they would with a native UART port.
3. Communication: With this setup, you can use standard serial communication parameters (like baud rate, data bits, stop bits, and parity) over the USB port, allowing you to interact with UART devices such as microcontrollers, GPS modules, or sensors that communicate over a UART interface.

In short, the USB-to-serial adapter and /dev/ttyUSB0 together make it possible to connect and communicate with traditional UART-based devices through a USB port.

##### You said:

is the USB connector on an Arduino NANO a USB port or a UART

###### ChatGPT said:

The USB connector on an Arduino Nano is technically a USB port, but it is used to emulate a UART (serial) interface. This is achieved through a USB-to-serial converter chip on the Nano.

Here’s how it works in more detail:

1. USB Port on the Nano: The Nano’s USB connector (usually a mini-USB or micro-USB) physically connects the board to a computer over USB.
2. USB-to-Serial Converter Chip: Older Arduino Nano models typically have an FTDI FT232 chip, while newer versions might use a CH340 or CP2102 chip. This chip acts as a USB-to-UART bridge, converting USB data from your computer to UART signals that the Arduino’s microcontroller (e.g., ATmega328) can understand.
3. Emulated UART Communication: The computer communicates with the Arduino Nano over a virtual serial port (such as /dev/ttyUSB0 on Linux or COM3 on Windows), which mimics a traditional UART interface. Data sent through this virtual serial port is converted by the USB-to-serial chip and received as UART data by the microcontroller.
4. Serial Monitor & Programming: This emulated UART connection allows you to both program the Arduino (upload code) and communicate with it through the Serial Monitor in the Arduino IDE, as if it had a native UART port.

So, while the physical connection is USB, the interface emulates a UART through the use of the USB-to-serial converter, making it appear as a standard serial port for most purposes.

##### You said:

so when I send data out of an Arduino USB port, it is actually a UART communication

###### ChatGPT said:

Yes, when you send data from the Arduino Nano’s USB port, it is actually UART communication being transmitted over USB. Here’s what happens:

1. USB-to-UART Conversion: Data you send over Serial (like Serial.print() in Arduino code) is handled by the USB-to-serial converter chip on the Nano (like the FTDI or CH340). This chip converts the UART data into USB protocol packets so that it can travel over the USB cable.
2. Virtual Serial Port on the Computer: On the computer side, these USB packets are received by the operating system, which translates them into data accessible through a virtual serial port (e.g., /dev/ttyUSB0 or COM3). This virtual serial port lets your computer interact with the Arduino as if it were connected via a traditional UART interface.
3. Emulated UART Communication: From your code’s perspective, the data is being sent and received over a UART serial interface, but it is encapsulated in USB packets for transport over the USB cable.

So, while the physical connection is USB, the communication itself emulates UART. This is why you can use typical serial communication functions and settings (like baud rate) despite using a USB cable.

In summary:

** On the Arduino side: UART data is generated by the microcontroller.*
** In transit: The USB-to-serial chip converts UART data to USB packets for transport.*
** On the computer side: The USB packets are reinterpreted as UART data by the OS, making it accessible as a standard serial port.*

So, conceptually, yes—the data you send from the Arduino Nano’s USB port is UART communication at its core, sent over USB. [Frank: key point]


So, Chi, I think as per your suggestion, the answer is to use the other serial UART on the Arduino, TX1/RX1, rather than trying to use the USB port…

I guess a good clue there is that I can always still connect the Arduino to the PC via the Arduino USB port when I am programming, but cannot do the same with the RPi’s USB port that I use to connect to the CM-530 unless I force it into “device” mode…

So, I have a bit of work to do here but I think I have a plan - I’ll keep you posted!

Frank

Thanks for sharing. That is a good use of ChatGPT. I should use it more often. :grinning:

Another thought came to me also, regarding the CM-530. Normally the 4-Pin connection already has the BT-210/410 connected to it so that users can use the RC-100 Physical Controller (or the Virtual Controller from the PC) with it. So you had been using your Premium Humanoid without the BT-210/410?

Correct…just dumping the output of the RPi into the Humanoid’s USB port…I have only used the wireless BT-410 for testing…

Now that I understand things a bit better, I will try two things:

  1. Use a USB to UART converter to try inputting the Arduino USB output into the CM-530 mini-USB connector (not going to call it a USB port anymore - I do not think that’s what it is - it’s a UART using a mini-USB connector, I think)…
  2. Ordered a couple of the cables you suggested and will use to take output from the second Arduino UART, TX1/RX1, into the 4-pin CM-530 [BT] UART connector…

I think one-way-or-another, I should be able to get packets to register into the CM-530! Fingers crossed…

Thanks for the clues!

Frank