Arduino Serial monitor and programming

Hello,

I am using Arduino UNO R3.

The operating system used is a picture of Windows. Currently, a model experiment for seismic waves is being conducted using a linear actuator. I would like to do coding that changes the speed over time, but I am wondering what coding term should be used. I’ll attach a picture for the input of the serial monitor I asked before.

Currently, it is coded as shown in the figure below, and it is under study to give time changes and speed changes accordingly. Forward and reverse rotations were performed by repeatedly entering the angles 360 and -360 on the serial monitor. However, if you enter that value more than 10 times, the linear actuator works 10 times and after that, the input value cannot be read and does not work. I am wondering if this is the capacity issue of Arduino.



Posting an image of your code is the least useful method. Please read the sticky post at the top of the forum and learn how to properly post your code using code tags. It will help people help you.

You have your STEPS constant declared as a float, yet give it an int value you have your val variable declared as an int, but give it the results of parseFloat().

There is a difference between floating point variables and int variables.

A better way of reading and parsing input from Serial monitor is Robin2's tutorial Serial Input Basics or use the SerialTransfer library.

parkshun: Forward and reverse rotations were performed by repeatedly entering the angles 360 and -360 on the serial monitor. However, if you enter that value more than 10 times, the linear actuator works 10 times and after that, the input value cannot be read and does not work. I am wondering if this is the capacity issue of Arduino.

certainly not a limitation of the Arduino or the serial monitor.

how do you know the input value is not read? you can flash an LED to show the arduino it continueing to run or indicate where it is in the program

results from serial monitor for code below

    360   2048
   -360  -2048
    360   2048
   -360  -2048
    360   2048
   -360  -2048
    360   2048
   -360  -2048
    360   2048
   -360  -2048
    360   2048
   -360  -2048
    360   2048
   -360  -2048
    360   2048
   -360  -2048
#define LedPin  13
const float Steps = 2048;
char  s [40];

void setup (void)
{
    Serial.begin (9600);
    pinMode (LedPin, OUTPUT);
}

void loop (void) {
    if (Serial.available ()) {
        float val   = Serial.parseFloat();
        float step  = map(val, 0, 360, 0, 2048);

        sprintf (s, " %6d %6d", int(val), int(step));
        Serial.println (s);
    }

    static unsigned long msecLst = 0;
           unsigned long msec    = millis();

    if (msec - msecLst > 500)  {
        msecLst = msec;
        digitalWrite (LedPin, ! digitalRead (LedPin));
    }
}

The question about the Arduino code.
We are making two matrices.
I want to help the coding speed and displacement.
For example, if you have a matrix of val and vel [j ], you want vel[1] to work when val [1] and vel[2] to work when val [2 ].
Please advise me a favor.
*

*

Please read the sticky post at the top of the forum about how to properly post your code using code tags. Posting a picture of your code is not very useful.

The question about the Arduino code.
We are making two matrices.
I want to help the coding speed and displacement.
For example, if you have a matrix of val and vel [j ], you want vel[1] to work when val [1] and vel[2] to work when val [2 ].
Please advise me a favor.

#include <Stepper.h>

const int STEPS = 2048;
Stepper stepper(STEPS, 8,9,10,11);

void setup()
{
 
 Serial.begin(9600);
   
pinMode(8,OUTPUT);  
   pinMode(9,OUTPUT);
   pinMode(10,OUTPUT); 
   pinMode(11,OUTPUT);  

  digitalWrite(8,HIGH);
  digitalWrite(9,LOW);
  digitalWrite(10,HIGH);
  digitalWrite(11,LOW);
  
 

   
 
}

void loop()
{

  int vel[5] = {0, 200, 150, 100, 50};
  int val[12] = {3600, -3600, 1800, -2000, 3600, -3000, 1500, -3000, 1200, -1200, 1500, -1500}; 
   
   val[12]=map(val,0,360,0,2048); 
   
   vel[5]=Serial.parseInt();
   val[12]=Serial.parseInt();
    
    for (int j=1; j<5; j++){
     for(int i=0; i<12; i++) {
     
   Serial.available() ;
   stepper.step(val[i]);
   Serial.print("val[");
    Serial.print(i);
    Serial.print("] =");
   Serial.println(val[i]);   
  
   }
      Serial.available() ;
      stepper.setSpeed(vel[j]);
      Serial.print("vel[");
       Serial.print(j);
       Serial.print("] =");
      Serial.println(vel[j]);  
   }     
   
   }

Why start a new thread? Why did you not read the forum guidelines to see how to post code properly?

Cross posted https://forum.arduino.cc/index.php?topic=689438.0

Threads merged.

parkshun: The question about the Arduino code. We are making two matrices.

Do you mean "arrays"? In C++ an array is something like

int vel[5] = {0, 200, 150, 100, 50};

Matrices are a complicated mathematical concept that I don't know how to use

I want to help the coding speed and displacement. For example, if you have a matrix of val and vel [j ], you want vel[1] to work when val [1] and vel[2] to work when val [2 ]. Please advise me a favor.

Do you mean that you want to use a value in one array to provide an index to a position in the other array?

If not, please try to provide a better explanation of what you want to achieve. A few examples would help.

...R