Hello,
I am trying to write a code that should control a steppermotor.
I want feed the information about the speed, ease in, ease out, and direction
in a string of information into the arduino once.
Then in the void loop I want Arduino to work with that info.
So I am trying to put a If(Serial.available()) in the void setup().
For some reason that doesn't work and I can't figure out why.
Here is the code that I wrote. Any suggestions are very welcome.
Regards
Ruud

String inString;
float easeIn;
float eaN;
int dash1;
int dash2;
int dash3;
int dash4;

Yes it does work. There is nothing to read the one and only time you look at the serial port, so you read nothing, exactly like you told the code to do.

You’re calling available right directly after you call begin. I wouldn’t expect a whole bunch of anything to show up in the few microseconds between the two. Throw a millisecond of delay in there between the two and see if that doesn’t help.

Are you sure that the sender is sending the information right at that millisecond? If you need the data before you do anything else, maybe you should wait around on it with a while loop.

I put that in a loop
x= 90/EaseIn;
for(y=0;y<90; y = y +x){
and then I tried
float z = Speed/sin(y);

Some real code, please. Not what you think you remember the code looking like.

You might also be interested in reading the documentation for the sin() function. Of particular interest would be the part that says that the input is in radians, not degrees.

PaulS:
You might also be interested in reading the documentation for the sin() function. Of particular interest would be the part that says that the input is in radians, not degrees.

That little tidbit has bitten more than a few Arduino newbies.

That little tidbit has bitten more than a few Arduino newbies.

And a few oldies, too. Beats me why sin(), cos(), etc. take an unusual measurement like radians as input, when no one knows what the hell a radian is. Everyone knows what a degree is. 90 degrees is a measurement everyone can visualize. 1.57 radians? What the hell is that?

Thing is that the algorithms for working out sin & cos are in radians, it is a circulat measurement with two Pi of them being in a circle. If you can stick to radians it is a lot more effecent.

Thing is that the algorithms for working out sin & cos are in radians, it is a circulat measurement with two Pi of them being in a circle. If you can stick to radians it is a lot more effecent.

I have no problem with sin(), cos(), etc. converting a value, like 90 degrees, into a value like PI/2 radians, if it makes sense. I object to having to convert from a unit of measure that makes sense to one that doesn't. I can understand how those functions could be more efficient dealing with radians. But, the mathematicians should be designing software - they should have been restricted to implementing the algorithm. Engineers should have been in charge of the interface. Then, the functions would have taken values in degrees.

Other versions, like sinForNerds(), could have taken an input in radians.

Thing is that the algorithms for working out sin & cos are in radians, it is a circulat measurement with two Pi of them being in a circle. If you can stick to radians it is a lot more effecent.

I have no problem with sin(), cos(), etc. converting a value, like 90 degrees, into a value like PI/2 radians, if it makes sense. I object to having to convert from a unit of measure that makes sense to one that doesn’t. I can understand how those functions could be more efficient dealing with radians. But, the mathematicians should be designing software - they should have been restricted to implementing the algorithm. Engineers should have been in charge of the interface. Then, the functions would have taken values in degrees.

Other versions, like sinForNerds(), could have taken an input in radians.

Radians are what trig functions have always been in (by default) since the dawn of time. Change it and people who are used to the “normal” way of doing it get confused. No one who uses trig seriously works in degrees. You might as well argue for arc-seconds (1/1296000 of a circle), or gradians (1/400 of a circle). The ratio between a circle’s circumference and its diameter is Pi - it makes sense to work in angles based on that same ratio.

Some programming languages provide the facility to change “mode”, but by default they will always be in radians.

Radians are what trig functions have always been in (by default) since the dawn of time.

And Arduinos have had odd pin spacing on one side since the beginning. Doesn't mean it's right, though. A dumb decision is a dumb decision, no matter how long ago it was made.

PaulS:
And a few oldies, too. Beats me why sin(), cos(), etc. take an unusual measurement like radians as input, when no one knows what the hell a radian is. Everyone knows what a degree is. 90 degrees is a measurement everyone can visualize. 1.57 radians? What the hell is that?

Probably because the iterative function that does the calculation works in radians. To convert from degrees to radians is simple, but if the sine function did that for you (and you happened to want to use radians) then you have two extra calculations (converting to degrees, and then have the function convert back to radians) when you don’t need any. Especially when those calculations involve a division.

Personally though I think C++ should have gone further with strongly typed variables, and have the variable definition define the content, not just the storage format.

So you could have

Degrees myAngle = 45;
Radians myOtherAngle = 180/PI;
float result;
result = sin(myAngle);
result = sin(myOtherAngle);

and it’d use the right calculations for you.

Yes, I know you can manually do it with classes and overloading the sin() etc functions, but it’d be nice if that kind of thing was standard. Trouble is, the math functions are pretty much all the original C functions, not C++ specific ones, so that kind of thing never happened.

Maybe an “advanced math library” would be good, with classes for the different things, so you could do such things as:

Degrees are mostly used for navigation. Its better to say "heading 280deg" as "heading 4.37rad".. At least you know where is the North then. Otherwise we use "angular mil" when we home at EU commissioners..

pito:
Degrees are mostly used for navigation. Its better to say "heading 280deg" as "heading 4.37rad".. At least you know where is the North then. Otherwise we use "angular mil" when we home at EU commissioners..