Hello everyone,
I am relatively new to the world of Arduino programming and am currently facing a problem: I cannot read data from my Arduino Micro in Excel. The code seems to be correct, as the values displayed in the Serial Monitor are exactly what I want. However, reading the data into Excel via the Datastreamer does not work. I have closed all tabs in the Arduino IDE, but nothing happens. Both the port and the baud rate have been set correctly.
Another strange thing is that I don't get any timestamps in the first table in Excel; this remains empty even after the execution has started, just like all the other data. Does anyone have any idea what could be causing this? Or could it even be directly due to the Arduino Micro?
Here is my example code:
// Pin-28BYJ-48
const int motorPin1 = 8;
const int motorPin2 = 9;
const int motorPin3 = 10;
const int motorPin4 = 11;
const int potPin1 = A0; // Potentiometer 1, Angle determination for engine
const int potPin2 = A3; // Potentiometer 2, Rotation angle for determining the step of the motor
// 28BYJ-48 Motor
const int stepsPerRevolution = 4096; // Total steps for 28BYJ-48
int stepNumber = 0; //
struct Event {
float voltage1;
float voltage2;
int stepNumber;
};
void setup() {
Serial.begin(9600);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
}
void loop() {
Event event;
int potValue1 = analogRead(potPin1);
int potValue2 = analogRead(potPin2);
event.voltage2 = potValue2 * (5.0 / 1023.0);
event.voltage1 = potValue1 * (5.0 / 1023.0);
event.stepNumber = stepNumber;
Serial.println(event.voltage1);
delay(150);
// Output Sensor1 for stepper
int angle = map(potValue1, 0, 1023, 0, 270);
int invertedAngle = 270 - angle;
int targetStep = map(invertedAngle, 0, 270, 0, stepsPerRevolution / 2);
int stepsToMove = targetStep - stepNumber;
if (stepsToMove != 0) {
int direction = stepsToMove > 0 ? 1 : -1;
stepMotor(direction);
stepNumber += direction;
}
delay(2); // speed Stepper
}
void stepMotor(int step) {
switch (stepNumber % 4) {
case 0:
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
break;
case 1:
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
break;
case 2:
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
break;
case 3:
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
break;
}
}
Many thanks in advance and best regards!