Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
import serial import time import multiprocessing def send_command(ser, command): ser.write(command.encode()) print(f"Sent command: {command}") def receive_response(ser): while True: response = ser.readline().decode().strip() if response: print(f"Received response: {response}") def main(port='/dev/ttyACM0', baudrate=9600, timeout=1): try: # Open the serial port ser = serial.Serial(port, baudrate, timeout=timeout) # Wait for the Arduino to initialize (optional) time.sleep(2) # Define commands to send commands = ["command1", "command2", "command3"] # Create a separate process to continuously listen for responses response_process = multiprocessing.Process(target=receive_response, args=(ser,)) response_process.daemon = True response_process.start() # Send commands for command in commands: send_command(ser, command) # Close the serial port ser.close() print("Communication finished.") except Exception as e: print("Error:", str(e)) if __name__ == "__main__": main()
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)