You have posted code without using code tags. The code tags make the code look
like this
when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The "Code: [Select]" feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.
If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button. Code tags can also be inserted manually in the forum text using the code and /code metatags.
Unless the sketch is too large, it's better if you post your code, rather than attach it. When it's attached, we have to download it, create a folder then open your code in our IDE. And afterwards, the folder remains unless we navigate to the "Temp" folder and manually remove it. It's much easier to just view the code in your post.
One thing I noticed, is that you have total control over what order you read the bytes in msg.buf[]. Why not just store them in the endian-ness that you desire? You lost track when you stored them as 16 bit ints. They are probably bytes. You can use a union to create a long word that you can store bytes in.
If you read the code that is what I did. All stored in an unsigned int array in big endian. Some solutions for int, hex, string, char conversions that I have found can be easily changed for either so i didn't want to rule out a conversion from the read in little endian. simpler code is better code.
kvasir:
If you read the code that is what I did. All stored in an unsigned int array in big endian. Some solutions for int, hex, string, char conversions that I have found can be easily changed for either so i didn't want to rule out a conversion from the read in little endian. simpler code is better code.
You are lecturing me on simplicity? I gave you the simple solution. Also, you have not yet followed the forum guidelines on posting code which makes it hard to read, so many people are likely to ignore it.
Reading bytes into an array of 16 bit ints is hardly conducive to any kind of simplicity.
kvasir:
Didn't mean to offend. I'll give your suggestion a shot. I'm use to C#, Java, and Python than C. Time to go hunt down the union command.
It's the standard approach in AVR C++. You can also use bit shifting if you want more platform independence but it is rarely important with Arduino sketches.
Basically, I am saying that if you assign the bytes in the right order, there is no need to convert endian-ness later.
Serial.println("Press -> t <- Test 1");
Serial.println("Press -> r <- Test 2");
}
void loop() {
if (Serial.available() > 0) {
dataIN = Serial.readStringUntil(CR);
Why on earth do you need to piss away resources on the String class to read ONE letter?
I'll clean up my code later. This was primarily a trivial example and apparently a some snarky people hang around arduino forums. It's about as bad as an Arch Linux forum. Anyways here is the solution to anyone else who looks
I have no idea what you mean. Honestly. Not snarky. I really didn't guess anything. I just showed you an error. If it worked as you showed, my example sketch would print, "1010101", not "101".
Yeah an overflow will likely never happen. At most these values get up 2^14. The indexing of the motion of the motor is fairly small and only four hex bytes are used to hold the position value.