user81891: How can I get some constantly changing values from a separate C++ program entered and uploaded into the Arduino?
I notice when I upload code to the Arduino in the IDE it takes about a second to start moving. This is also a problem. I would like there to be no delay after instructions to the motor change.
My goal is to get a trained neural network model from the PyTorch C++ version to control the motor's spin and speed. I would assume the IDE does not allow one to import PyTorch?
I tried looking around on the Arduino website for this, but it seems like the IDE is the only option. My solution would be something that imports the Arduino library into a C++ program just like I import the PyTorch library into my C++ program.
My ficticous C++ code. Just written to illustrate what I would like to happen.
import pytorch
import arduino

// if I had an encoder on the motor giving position readings as inputs (I know this isn't how it's done in real code)
sensors = arduino_encoder_sensors

// trained model
m = pytorch.load_torch_model('model')

// model taking sensors as inputs and outputting desired speed and distance executions to the motor
speed, dist = m(sensors)

Arduino Code:
const int stepPin = 8; 
const int dirPin = 9; 
 
void setup() {
  // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT); 
  pinMode(dirPin,OUTPUT);
}
  digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
  for(int x = 0; x < dist; x++) {
    digitalWrite(stepPin,HIGH); 
    delayMicroseconds(speed); 
    digitalWrite(stepPin,LOW); 
  delay(1000); // One second delay
}


user42015: Your question seems very confused, so I will try to shine a light on some basic distinctions.

How can I get some constantly changing values from a separate C++ program entered and uploaded into the Arduino?

In your whole question you seem to confuse program and data. The program on the Arduino doesn't need to change with every changing of the values. Instead you would have a constant program, which receives changing values from the PC.
So it seems you want to send data from your python program on your PC to the Arduino. This data doesn't have anything to do with the actual program on the Arduino. The program just should use the data to act accordingly. You can use any of the communication interfaces that are usable with Arduinos and PCs, though the simplest option would be the Serial interface, which gets bridged to your PC via the USB port. The Serial interface is what you see in the Serial Monitor.
How to use a serial port in python can be googled quite easily. For the Arduino side there are many tutorials and examples about it online. You would also need to think about your communication protocol, which you want to impose on the Serial byte stream. For example you could use ASCII encoded text, each message delimited to the next by a newline character '\n', each message containing first the command and then needed parameters. Since only you know what exactly you want to send to the Arduino, you need to design this yourself.

I notice when I upload code to the Arduino in the IDE it takes about a second to start moving. This is also a problem.

This is due to the bootloader. When you upload a program this is done via the Serial interface. Normally microcontrollers can only be programmed over specialized interfaces (like ISP). But Arduinos (and other microcontrollers) can be programmed with a bootloader. That is a program sitting on the microcontroller, which runs anytime you power the microcontroller on your reset it. On Arduinos it will listen on the Serial port for a moment in the case that you want to upload a new code. If yes, then it handle the communication and write the new code to the Arduinos flash memory. If not, it will execute whatever program currently is saved in flash.
So you cannot avoid this delay without changing or deleting the bootloader. Deleting it would mean that you need a programmer board to upload new code (another Arduino can do that). Changing it would also require a programmer board, because you would need to write the new bootloader version to the Arduino with it.
I would debate if this delay is really a problem. It only appears on a reset, like when you upload new code. And why would you want to reset the Arduino or upload new codes that fast? For doing your motor movement you don't need new programs on the Arduino for every movement; you need a code that will move according to data send through the Serial interface. And that doesn't require resetting. And it works fast.
That said, with your current code (ignoring the obvious syntax problems most likely from copy and past errors) you will still have delays, even when you implement Serial communication. In general you shouldn't use long delay() calls. You use delay(1000), which makes the Arduino twiddle its thumbs for one whole second each loop iteration. Instead use the non-blocking coding style shown in the BlinkWithoutDelay example that comes with the Arduino IDE. It uses the millis() function as a clock, checking it regularily for the time to do something. There are many tutorials about that online.

My goal is to get a trained neural network model from the PyTorch C++ version to control the motor's spin and speed. I would assume the IDE does not allow one to import PyTorch?

No, it doesn't. It is based on Java, not on python. As described above you need to write your own python program and use a fitting serial port python module for the communication over the Serial interface. In that python program you can import PyTorch, do your  neural network processing and then send the resulting commands over Serial to the Arduino.

I tried looking around on the Arduino website for this, but it seems like the IDE is the only option. My solution would be something that imports the Arduino library into a C++ program just like I import the PyTorch library into my C++ program.

It is not really clear what you mean here. For communicating with an Arduino over Serial you can use any program that can interface with a serial port on your PC. There are many programs dedicated for this. Since you want to do your neural networking stuff in python, just use a fitting python module that handles serial port connections.
If you talk about writing programs for Arduinos and uploading them: This can be done in many other IDEs other than the Arduino IDE. Dave Newton mentioned some in his comment: VS Code and CLion. I also remember the Atom IDE. Or you can write your code in any text editor of your liking and then compile and upload the code with the Arduino CLI tool (that's what I do mostly).

I hope this clears up the confusion a bit so that you now can work toward a working solution.

81891: <p>How can I get some constantly changing values from a separate C++ program entered and uploaded into the Arduino?</p>
<p>I notice when I upload code to the Arduino in the IDE it takes about a second to start moving. This is also a problem. I would like there to be no delay after instructions to the motor change.<br />
My goal is to get a trained neural network model from the PyTorch C++ version to control the motor's spin and speed. I would assume the IDE does not allow one to import PyTorch?</p>
<p>I tried looking around on the Arduino website for this, but it seems like the IDE is the only option. My solution would be something that imports the Arduino library into a C++ program just like I import the PyTorch library into my C++ program.</p>
<p>My ficticous C++ code. Just written to illustrate what I would like to happen.</p>
<pre><code>import pytorch
import arduino

// if I had an encoder on the motor giving position readings as inputs (I know this isn't how it's done in real code)
sensors = arduino_encoder_sensors

// trained model
m = pytorch.load_torch_model('model')

// model taking sensors as inputs and outputting desired speed and distance executions to the motor
speed, dist = m(sensors)
</code></pre>
<p><strong>Arduino Code:</strong></p>
<pre><code>const int stepPin = 8; 
const int dirPin = 9; 
 
void setup() {
  // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT); 
  pinMode(dirPin,OUTPUT);
}
  digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
  for(int x = 0; x &lt; dist; x++) {
    digitalWrite(stepPin,HIGH); 
    delayMicroseconds(speed); 
    digitalWrite(stepPin,LOW); 
  delay(1000); // One second delay
}
</code></pre>
 42015: <p>Your question seems very confused, so I will try to shine a light on some basic distinctions.</p>
<blockquote>
<p>How can I get some constantly changing values from a separate C++ program entered and uploaded into the Arduino?</p>
</blockquote>
<p>In your whole question you seem to confuse program and data. The program on the Arduino doesn't need to change with every changing of the values. Instead you would have a constant program, which receives changing values from the PC.</p>
<p>So it seems you want to send data from your python program on your PC to the Arduino. This data doesn't have anything to do with the actual program on the Arduino. The program just should use the data to act accordingly. You can use any of the communication interfaces that are usable with Arduinos and PCs, though the simplest option would be the <code>Serial</code> interface, which gets bridged to your PC via the USB port. The <code>Serial</code> interface is what you see in the Serial Monitor.</p>
<p>How to use a serial port in python can be googled quite easily. For the Arduino side there are many tutorials and examples about it online. You would also need to think about your communication protocol, which you want to impose on the <code>Serial</code> byte stream. For example you could use ASCII encoded text, each message delimited to the next by a newline character <code>'\n'</code>, each message containing first the command and then needed parameters. Since only you know what exactly you want to send to the Arduino, you need to design this yourself.</p>
<blockquote>
<p>I notice when I upload code to the Arduino in the IDE it takes about a second to start moving. This is also a problem.</p>
</blockquote>
<p>This is due to the bootloader. When you upload a program this is done via the <code>Serial</code> interface. Normally microcontrollers can only be programmed over specialized interfaces (like ISP). But Arduinos (and other microcontrollers) can be programmed with a bootloader. That is a program sitting on the microcontroller, which runs anytime you power the microcontroller on your reset it. On Arduinos it will listen on the <code>Serial</code> port for a moment in the case that you want to upload a new code. If yes, then it handle the communication and write the new code to the Arduinos flash memory. If not, it will execute whatever program currently is saved in flash.</p>
<p>So you cannot avoid this delay without changing or deleting the bootloader. Deleting it would mean that you need a programmer board to upload new code (another Arduino can do that). Changing it would also require a programmer board, because you would need to write the new bootloader version to the Arduino with it.</p>
<p>I would debate if this delay is really a problem. It only appears on a reset, like when you upload new code. And why would you want to reset the Arduino or upload new codes that fast? For doing your motor movement you don't need new programs on the Arduino for every movement; you need a code that will move according to data send through the <code>Serial</code> interface. And that doesn't require resetting. And it works fast.</p>
<p>That said, with your current code (ignoring the obvious syntax problems most likely from copy and past errors) you will still have delays, even when you implement <code>Serial</code> communication. In general you shouldn't use long <code>delay()</code> calls. You use <code>delay(1000)</code>, which makes the Arduino twiddle its thumbs for one whole second each loop iteration. Instead use the non-blocking coding style shown in the <code>BlinkWithoutDelay</code> example that comes with the Arduino IDE. It uses the <code>millis()</code> function as a clock, checking it regularily for the time to do something. There are many tutorials about that online.</p>
<blockquote>
<p>My goal is to get a trained neural network model from the PyTorch C++ version to control the motor's spin and speed. I would assume the IDE does not allow one to import PyTorch?</p>
</blockquote>
<p>No, it doesn't. It is based on Java, not on python. As described above you need to write your own python program and use a fitting serial port python module for the communication over the <code>Serial</code> interface. In that python program you can import <code>PyTorch</code>, do your  neural network processing and then send the resulting commands over <code>Serial</code> to the Arduino.</p>
<blockquote>
<p>I tried looking around on the Arduino website for this, but it seems like the IDE is the only option. My solution would be something that imports the Arduino library into a C++ program just like I import the PyTorch library into my C++ program.</p>
</blockquote>
<p>It is not really clear what you mean here. For communicating with an Arduino over <code>Serial</code> you can use any program that can interface with a serial port on your PC. There are many programs dedicated for this. Since you want to do your neural networking stuff in python, just use a fitting python module that handles serial port connections.</p>
<p>If you talk about writing programs for Arduinos and uploading them: This can be done in many other IDEs other than the Arduino IDE. Dave Newton mentioned some in his comment: VS Code and CLion. I also remember the Atom IDE. Or you can write your code in any text editor of your liking and then compile and upload the code with the Arduino CLI tool (that's what I do mostly).</p>
<hr />
<p>I hope this clears up the confusion a bit so that you now can work toward a working solution.</p>
