Arduino Result to text file

Hiii i need to know how to save my Arduino Uno distance Results into a Text File in order to display the result in an android application, that the Arduino board is connected to the pc via USB?? Any help?

There are many ways to do that:

  1. save the data on SD card (text file);
  2. send data through Bluetooth directly to your Android app;
  3. send data through USB (serial port) to PC.

Thanks a lot but i don't have SD Card nor Bluetooth connected to the Arduino Board , So Am using USB , but the problem is i am not understanding how , I found this code
Wise time with Arduino: Arduino writes to file , but I can't understand it or determine if it is useful or not can you explain it or sth ? . thanks again ...

What operating system does the PC run? If it's Microsoft Windows, you can use Gobetwino to write data supplied by the Arduino to a file on the PC. I'm not clear how you would get it from there to the Android, but since you don't seem to have provided any other way to get the data off the Arduino, getting it onto a file the PC would seem to be a useful first step.

GoBetwino can run on your PC and ave data coming from Arduino to a txt file on the PC.

The code you linked to is a VB script (running on Windows) that reads characters on a COM (serial) port and saves them to the specified file.
Did you try running it? What part of the code you don't understand?

I have downloaded GobetWino but I didn't understand how it functions well ..
and Florinc I understand the code but i keep getting "An unhandled exception of type 'System.IO.FileNotFoundException' occurred in DataReader.exe" while running !! and I can't figure out how to solve it ... can you help?

What version of Windows are you running on?
What COM port are you using?
Can you post your code?

If you check the sample code that comes with GoBetwino you can find an example of how to log data to a txt file on the PC.

I am running on Windows 7, using Com Port 25 and here is my code
Imports Scripting
Imports System.Threading.Thread
Imports System.Windows.Forms.SendKeys

Public Class Form1

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Try
Const ForReading = 1
Const ForWriting = 2
Dim fso

Dim com
Dim objFSO
Dim objFile
Dim s

Dim WShell

WShell = CreateObject("WScript.Shell")
fso = CreateObject("Scripting.FileSystemObject")

com = fso.OpenTextFile("COM25:9600,N,8,0", ForReading)

objFSO = CreateObject("Scripting.FileSystemObject")
objFile = objFSO.OpenTextFile("D:\Data.txt", ForWriting, True)

MsgBox("Start to read data from COM")

Do While com.AtEndOfStream <> True
s = com.ReadLine
objFile.WriteLine(s)
System.Threading.Thread.Sleep(100)
Loop

objFile.Close()
com.Close()

Catch
MessageBox.Show("Unable to read file ")
End Try

End Sub
End Class

Iactually used it from this site : Wise time with Arduino: Arduino writes to file
I keep getting file not found, the error is on line :com = fso.OpenTextFile("COM25:9600,N,8,0", ForReading)
thanks a lot

And for the Gobetwino I found out that it doesn't work on Windows 7 that's why it couldn't run on my pc ... thanks !!1 :slight_smile:

GSim:
And for the Gobetwino I found out that it doesn't work on Windows 7 that's why it couldn't run on my pc ... thanks !!1 :slight_smile:

I am running it on Windows 7.

Thats Greaaat!! then could you help me understand how to use it??? it didn't work for me,I guess I was using it wrong then !

I dont' think there' any problem running GoBetwino on Window 7.

What have you done so far?

According to this microsoft article
http://support.microsoft.com/kb/115831
COM ports higher than 9 are named like this: \.\COM10

I don't have windows 7 to test it, but I think it will work if you change the line to:

  com = fso.OpenTextFile("\\\\.\\COM25:9600,N,8,0", ForReading)

florinc:
According to this microsoft article
HOWTO: Specify Serial Ports Larger than COM9 - Microsoft Support
COM ports higher than 9 are named like this: \.\COM10

I don't have windows 7 to test it, but I think it will work if you change the line to:

  com = fso.OpenTextFile("\\\\.\\COM25:9600,N,8,0", ForReading)

I changed the code line it also didn't work !! I still get the same problem !! could there be something wtrong with the Arduino Code itself ???

PeterH:
What have you done so far?

I have this Arduino Code
int configPin = 13; //Set the sonar Calibration Pin

int value = 877;
char buffer[5];

void setup() { //begin of program
Serial.begin(9600); //serial baud rate 9600

pinMode(configPin,OUTPUT); //make Calibration pin output
}
void loop(){ //looping of program
digitalWrite(configPin,HIGH); //raise the reset pin high
delay(120); //start of calibration ring
float sensorvalue = analogRead(0); //get analog sensor value from pin 0
float inchvalue = (254.0/1024.0) 2.0 sensorvalue ; //convert to inches
//float cm=inchvalue*2.54;
//Serial.print("Sensed a-d value:"); //print a-d text
//Serial.println(sensorvalue); //print a-d value
Serial.print("Inch value="); //print inch text
Serial.println(inchvalue);
//Serial.print("cm=");
//Serial.println(cm);
delay(500); //optional delay 1 second
digitalWrite(configPin,LOW); //turn off Calibration ring and sensor
delay(500); //delay 1 second
Serial.print("#S|LOGTEST|[");
Serial.print(itoa((value), buffer, 10)); //function. Itoa() is a function that will take an integer and return it
//converted to it’s string representation.
Serial.println("]#");
}

I can't understand how to display the results on Gobetwino :slight_smile:

thanks a lot again :slight_smile:

I changed the code line it also didn't work !!

What error do you get?
Can you see COM25 in the device manager?

GSim:
I can't understand how to display the results on Gobetwino :slight_smile:

The Arduino code looks reasonable, and should print out lines like "#S|LOGTEST|[xxx]#" every second or so. Do you see those lines appear correctly in the serial monitor in the Arduino IDE?

You need to install Gobetwino on your PC and then launch it by running Gobetwino.exe. In Windows 7, in order for Gobetwino to be able to save configuration changes you need to run it with administrator privileges. Your Arduino should be connected to the USB port and running your sketch before you launch Gobetwino. You must not have any other applications running which use the Arduino's serial port, such as the Arduino IDE. People have also reported problems with management software for mobile devices which connect by USB such as phones - some of this software probes serial ports and interfere with other applications trying to use them. If you have this type of software installed and have trouble getting Gobetwino to recognise your Arduino, try stopping them.

Gobetwino opens a window which has a menu bar with three menus: File, Settings, Commands. Click on Settings to display the Gobetwino configuration window and then click on the Serial Port tab. Here you need to select the serial port corresponding to your Arduino. You should also have the baud rate set to 9600, data bits set to 8, parity set to none, stop bits set to one, handshake set to none. Click the Update button to save your changes. Display the Status and Log tab and select (tick) Show Status Messages and Log Status Messages, and set the status message level to 1. Click the Update button to save your changes. Then click Exit to close the configuration window.

You only need to do the actions above once. After making these changes, I seem to remember it was necessary to exit Gobetwino and restart it in order for these changes to take effect - but I did this a long time ago and may have mis-remembered.

After you restart Gobetwino you should see a message like "Serial port : COMx opened at 9600 baud" followed by the output from your sketch. At this stage you won't have configured Gobetwino to recognise the commands so it should log them but not do anything about them. I suggest you confirm you've got this far before you try configuring the commands.

Serial.print("Inch value=");      //print inch text
Serial.println(inchvalue);
//Serial.print("cm=");
//Serial.println(cm);
delay(500);                      //optional delay 1 second
digitalWrite(configPin,LOW);      //turn off Calibration ring and sensor
delay(500);                      //delay 1 second
Serial.print("#S|LOGTEST|[");
Serial.print(itoa((value), buffer, 10));  //function. Itoa() is a function that will take an integer and return it
//converted to it’s string representation.
Serial.println("]#");

This look to me like you are sendeing something to GoBetwino AND something that is not meant to go to GoBetwino. That will not work. When you use GoBetwino you can ONLY send well formed GoBetwino commands, otherwise GoBewtino will try to interpret it a commands and fail miserably.

I bet you get all kinds of errormessage in he GoBetwino window - right ?

florinc:

I changed the code line it also didn't work !!

What error do you get?
Can you see COM25 in the device manager?

Well Yes I Can Find it in the Device manager ! :slight_smile:

MikMo:
This look to me like you are sendeing something to GoBetwino AND something that is not meant to go to GoBetwino. That will not work. When you use GoBetwino you can ONLY send well formed GoBetwino commands, otherwise GoBewtino will try to interpret it a commands and fail miserably.

I bet you get all kinds of errormessage in he GoBetwino window - right ?

PeterH:

GSim:
I can't understand how to display the results on Gobetwino :slight_smile:

. Your Arduino should be connected to the USB port and running your sketch before you launch Gobetwino. You must not have any other applications running which use the Arduino's serial port, such as the Arduino IDE.

well Thanks a looooooot guys !! cause when I removed the code lines
//Serial.print("Inch value="); //print inch text
//Serial.println(inchvalue);
and when I closed the Arduino IDE It Worked perfectly !!!!!!
thanks a looot and all my respect ! :slight_smile:

you helped a lot !