So right now im using the arduino to generate random 8 bit numbers which are being output through serial port via Serial.print(). If the board can output to serial can that serial be written to a text file? I want the binary to be put to a text file so that i may read the file into a java or c program to convert the binary to decimal values for further processing. Ive seen file output with c but can it be done through serial? #include <stdio.h>
fp = fopen(filename, "w"); /* open file for reading */
if(fp == NULL) /* ALWAYS CHECK RETURN VALUE !!! /
{
printf("Failed to open file for writing\n");
return -1;
}
fputs("Hello world\n", fp); / write a string to file /
fputc('A', fp); / write a character to file /
fclose(fp); / close file /
fp = fopen(filename, "a"); / open file for appending !!! /
if(fp == NULL)
{
printf("Failed to open file for appending\n");
return -2;
}
fprintf(fp, "\nMy age is %d\n", 99); / write a formatted string to file */
fclose(fp);
fp = fopen(filename, "r"); /* open file for reading */
if(fp == NULL)
{
printf("Failed to open file for reading\n");
return -3;
}
while(fgets(buffer, BUFSIZ, fp) != NULL)
printf(buffer);
fclose(fp);
return 0;
}
this is what i know to use for c output but this all doesnt work for the arduino ide so this is where i need help.
I know you can write to an sd card but i do not have the appropriate device to connect the sd card to the board. Unless anyone can link me to how to connect the sd without a second interface board i would like to write the file to my laptop hard drive
I like the idea of having a program reads the serial output and in java i know how to read and write files but how does one read from the serial box? I can see making a java program that reads the serial box until the box closes that read wouldnt be hard but how do you actually read from the serial box?
I don't think you have to read from the serial monitor window, if that's what you're envisioning. I believe that if you don't open the serial monitor window, your host PC won't have the COM port open, so you can open it from another program written in C or Java or , then read from the port and you will receive whatever you present to Serial.print() on the Arduino side.