Modifications

Sauter à la navigation Sauter à la recherche
612 octets ajoutés ,  30 octobre 2018 à 20:57
Ligne 240 : Ligne 240 :     
Then press the "upload" button.
 
Then press the "upload" button.
 +
 +
== Capturing data to file ==
 +
Having data available in the Arduino Serial Monitor is great... but capturing the content to a file is even better.
 +
 +
 +
=== With Python ===
 +
<syntaxhighlight lang="python">
 +
import serial
 +
 +
serial_port = '/dev/ttyACM0';
 +
baud_rate = 9600; #In arduino, Serial.begin(baud_rate)
 +
write_to_file_path = "output.txt";
 +
 +
output_file = open(write_to_file_path, "w+");
 +
ser = serial.Serial(serial_port, baud_rate)
 +
while True:
 +
    line = ser.readline();
 +
    line = line.decode("utf-8") #ser.readline returns a binary, convert to string
 +
    print(line);
 +
    output_file.write(line);
 +
</syntaxhighlight>
    
{{ENG-CANSAT-TRAILER}}
 
{{ENG-CANSAT-TRAILER}}
29 836

modifications

Menu de navigation