I have run simple programs such as the following and had success using Tera Term and Python:
#include <SoftwareSerial.h>
SoftwareSerial Bluetooth(2, 3); // RX, TX
int LED = 13; // the on-board LED
int Data; // the data received
void setup() {
Bluetooth.begin(9600);
Serial.begin(9600);
Serial.println("Waiting for command...");
Bluetooth.println("Send 1 to turn on the LED. Send 0 to turn Off");
pinMode(LED,OUTPUT);
}
void loop() {
if (Bluetooth.available()){ //wait for data received
Data=Bluetooth.read();
if(Data=='1'){
digitalWrite(LED,1);
Serial.println("LED On!");
Bluetooth.println("LED On!");
Bluetooth.println("Here's a string that is really long. We won't know if the arduino is able to send this string to me, especially because it is quite a bit of data. Python can certainly handle it, but we won't know for sure");
}
else if(Data=='0'){
digitalWrite(LED,0);
Serial.println("LED Off!");
Bluetooth.println("LED On D13 Off ! ");
}
else{;}
}
delay(100);
}
However, I have written a much larger file to log data for a self-watering garden setup. My eventual goal is to have Python request data from my SD card when it has been offline for a while, but I can’t even get the current software serial println commands to show up. I have tested this using both Tera Term and Python, and the data just doesn’t come through.
There's a lot of other cool nuances and tricks you can use with these libs to get guaranteed file transmission without corruption, but I won't get into it right now.
2.) You can create a simple Bash-styled serial interface with SdTerminal.h. SdTerminal allows Python to query SD file data from the Arduino via USB. Here are a list of commands:
For more information on a specific command, type help command-name
Create file if it doesn't already exist
ap - Append a line to an existing file
cd - Change present working directory
cp - Copy a file to another location
echo - Turn on or off echoing user commands
help - Provide info on commands. Can specify a specific command for help ls - List the contents of the card. Can specify a specific dir for listing
mkdir - Make a new directory at a specific location
mv - Move or rename a file print - Print the contents of the given file
pwd - Print the present working directory
rm - Remove a file or dir
1.) You can use a defined and robust serial packet structure to transfer the file using SerialTransfer.h and the compatible, pip-installable Python package pySerialTransfer. There are also several examples that come with the libraries, including a sketch that transmits an entire 2kbyte text file.
I am already using pySerial, so I will look into pySerialTransfer. However, transferring entire files wasn't necessarily in the scope of my original idea.
2.) You can create a simple Bash-styled serial interface with SdTerminal.h. SdTerminal allows Python to query SD file data from the Arduino via USB.
I'll also do some research into this to see if it's what I'm looking for.
To be a little clearer, under normal operation, I want my program to send data via bluetooth and have my Python program write it to a .csv file. I have gotten this to work with my simple program, but not my actual program.
Then, if the Python program stops operation, when it restarts, I want to send a string or key to the Arduino and check there if it is the current loop of data. If not, I want the Arduino to find where my last imported serialized data transfer occurred, and send all the data from that point. Then, continue to normal operation. The reason I want the live data is to make a live graphical representation of the data on a web page. Although the GitHub file has a data collection every 10 seconds at the moment, I will eventually increase that to 1 collection every 6 minutes.
Let me know if you think there is a better way to do this, or if my idea is too intensive for the Arduino. I've also considered doing what you mentioned, sending the whole file, and then letting my Python program do the data checking (which is probably faster?).
Sorry for the misunderstanding - sending small datapackets one at a time instead of trying to send an entire file is better. In this case, pySerialTransfer will be more applicable than SdTerminal.