How to send HEX via serial monitor

Good day. I've purchased mp3 shield of elechouse. I have one question, can I control it manually via sending the commands through arduino serial monitor by typping by myself? How can I send for example this command: 0x7E 0x04 0xA2 0x00 0x01 0x7E - to start the music playing. I know, that I can use the library, but I'm interested if I can do it manually, what should I type?

Waiting for your answer.

Best regards, Oleg

You are asking if you can use an ASCII terminal to send binary data. The answer should be obvious. A hint, in case you need it. The answer is not yes.

You could send the text representation, and have the Arduino read the string, and convert the value to an int, and send the int to the device. The device, I'm sure, does not expect a string representation of the value. It also doesn't know whether you send binary, octal, decimal, or hexadecimal values to the Arduino. The Arduino is going to send binary values to the device.

You could use "Processing" to send the Hex code rather than use the Serial monitor. Serial monitor will send characters - and as PaulS suggested - you would have to convert these characters on the Arduino side.

Processing is a very useful programming language. You can create buttons on your screen and get the program to send specific Hex values / sequence based on the buttons you press.

I have a tutorial on my blog if you are interested ??

If there an equivalent control code, you might be able so send some bytes: https://en.wikipedia.org/wiki/ASCII

For example, CTRL-G would send 0x7, which would ring the bell on the terminal.

PaulS:
You could send the text representation, and have the Arduino read the string, and convert the value to an int

How?
Can this be done to a strtok() token?
If you have char* textIn = “0xFF”;
How do you convert it to int?

I spent half the day yesterday trying to do it.
Finally decided sending decimal values instead hexadecimal was much easier to work with.
But still wonder how to convert the hexadecimal input in case I ever run across something I want to read data from that only outputs in a hex format.

@Frostline: Use strtol or sscanf

Frostline:

If you are using the Processing language : you can use the unhex() function.

Here is a link to the blog post that I was talking about that shows you how to convert a String representation of a hex value eg ("FF" or "00") and send it to the Arduino. In the blog post example, the Arduino uses the Hex values to adjust the brightness of a LED (using PWM).

It is a simple tutorial - but it may help you with your endeavors.

@Guix: Thank you. I had seen these in my searching. I discounted strtol() because it just seemed like atoi() but for long integers at first glance. And it had pointers in it, which makes my brain go all fuzzy. But actually it works and seems more useful than sscanf(). I managed to get both functions to work in a limited fashion. It seems like if I only used whitespace as a delimiter in my strings I could skip using strtok() entirely and just use strtol().

@ScottC: Very impressive blog. If the rest of the projects are as well drawn out as the one you linked I can see me spending a lot of time reading through them. Good stuff. I have a question though about what you are saying unhex() does. It seems like you are saying if you have hex value FF and use unhex() you get 0xFF. But don't you really get 255? It looks a lot like the int h1i = Convert.ToInt16(h1x, 16); I am using in my C# to send to Arduino.

@Frostline - yes unhex("FF") = 0xFF = 255

It's all zeros and ones anyway :)

As for my projects - yes - they are all pretty much set out in the same way. I decided to learn how to blog at the same time I decided to learn how to use the Arduino. So you will probably find that the quality deteriorates the further back you go :)

Click on the "Arduino Basics project page" on the top menu of the blog for a quick list. And feel free to leave any comments while you are wondering around -as it is always good to get some constructive criticism/feedback.

@Frostline hello Frostline

i am trying to send Hex commands to my hexadecimal bluetooth device which is connected to the arduino can you please share me your code just to know how you used the function strtok .

thanks for you help in advance .