How to print on the same row in excel

Hi everyone,
I was doing a project with an Arduino UNO that involves receiving and printing clients names and phone numbers and the time that they have registered. I choose to use data streamer on an excel. The problem is that I can't print all of them on the same row. Here is my code

#include <RTClib.h>
#include <Wire.h>
RTC_DS1307 rtc;
char t[32];
String regular[5][4];
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
delay(1000);
Wire.begin();
rtc.begin();
rtc.adjust(DateTime(F(__DATE__),F(__TIME__)));
}

void loop() {
  // put your main code here, to run repeatedly:
  Case();
}
void Case(){
  if (Serial.available()>0)
   switch(Serial.read())
  {
    case 'r':
      Regular();
      break;
    
  }
}
  void Regular(){
  Serial.print("case R"); 
  while (Serial.available()==0){
  } 
  regular[0][1]=Serial.readString();
  Serial.print(regular[0][1]);
  Serial.print(",");  
  while (Serial.available()==0){
  } 
  regular[0][2]=Serial.readString();
  Serial.print(regular[0][2]);
  Serial.print(","); 
  DateTime now = rtc.now();
  sprintf(t, "%02d:%02d:%02d %02d/%02d/%02d", now.hour(), now.minute(), now.second(), now.day(), now.month(), now.year());  
  delay(500); 
  Serial.print("Date/Time: ");
  Serial.println(t);
}

And I am getting this

I would start by using serial monitor instead of datastreamer; that will tell you if your Arduino code behaves as expected. If it behaves as expected you know that the issue is with datastreamer.

It works fine with the serial monitor, but it goes into another row in the excel

I don't know anything about datastreamer; but it sounds like the problem is there.

What happens if you just send some fixed data from the Arduino? So not waiting for user input.

E.g.

Serial.print("hello");
Serial.print(",");
Serial.print("world");
Serial.print(",");
Serial.println(t);
delay(5000);

The delay is there so you don't flood the PC side of things.

1 Like

Gosh thats untidy.
Could you please:

1: put all your functions below the setup() and main()

so like this:

declarations
including function prototypes (with comments ie what the function does)
setup();
main();
fuction1();
function 2();

2: dont use the same name for different things - eg dont call a function "case".
or both a variable and a function "regular".

3: Show us what you get on the serial monitor and
what you get for the same input in Excel

Can you show us what the printout in serial monitor is like?

I can only see the following line twice:

  Serial.print(","); 

You need a comma delimiter between each different field.

It works on that case, but I need to receive the information from the users

This is the output from the serial mointor

case RJohn,0911111111,Date/Time: 00:00:00 00/00/2005

OK, I understand that :wink:

It's just a guess but maybe datastreamer has a timeout in some way.

You can collect the data first and next send it in one go to the PC.

Using a simple sketch like sterretje suggested in post #4, it is possible to get the correct format in Excel.

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.print("case R");
  Serial.print(",");
  Serial.print("John");
  Serial.print(",");
  Serial.print("0911111111");
  Serial.print(",");
  Serial.print("Date/Time: ");
  Serial.print(",");
  Serial.print("12/05/2023");
  Serial.print(",");
  Serial.print("09:52:43");
  Serial.print(",");
  Serial.print("Insert");
  Serial.print(",");
  Serial.print("Additional");
  Serial.print(",");
  Serial.println("Commas");
  delay(5000);
}

Serial monitor output:

Excel output:

1 Like

Thank you John, but I wanted to receive the data( name and phone number) from the users

#include <RTClib.h>
#include <Wire.h>
RTC_DS1307 rtc;
char t[32];
String regular[5][4];
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  delay(1000);
  Wire.begin();
  rtc.begin();
  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}

void loop() {
  if (Serial.available() > 0)
    switch (Serial.read()) {
      case 'r':
        Regular();
        break;
    }
}

void Regular() {
  Serial.print("case R");
  while (Serial.available() == 0);
  regular[0][1] = Serial.readString();
  Serial.print(regular[0][1]);
  while (Serial.available() == 0) ;
  regular[0][2] = Serial.readString();
  Serial.print(regular[0][2]);

  DateTime now = rtc.now();
  sprintf(t, "%02d:%02d:%02d %02d/%02d/%02d", now.hour(), now.minute(), now.second(), now.day(), now.month(), now.year());
  delay(500);
  Serial.print("Date/Time: ");
  Serial.print(",");
}

I'm beginning to see the problem now, but I have a question:

Is the user entering data into the serial monitor or into Excel?

I'm asking this because you can't connect the serial port to Excel if it is in use by the serial monitor, and vice versa.

I'm wondering if you need to be using two serial ports, one to enter the data using serial monitor, and a second to send the data to Excel.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.