old comms bad (low retention) -> this works as PoC

This commit is contained in:
FluffyCube9343 2022-12-02 23:11:57 -05:00
parent 9ac6887f98
commit cc467b9cf3
2 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,27 @@
/*
Program: Receive Strings From Raspberry Pi
File: receive_string_from_raspberrypi.ino
Description: Receive strings from a Raspberry Pi
Author: Addison Sears-Collins
Website: https://automaticaddison.com
Date: July 5, 2020
*/
int i=0;
void setup(){
// Set the baud rate
Serial.begin(9600);
}
void loop(){
if(Serial.available() > 0) {
String data = Serial.readStringUntil('\n');
if(data=="Data"){
Serial.print("Hi Raspberry Pi! You sent me: ");
Serial.println(String(i));
i+=1;}
}
}

45
Comms-Rewrite/toA.py Normal file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env python3
###############################################################################
# Program: Send Strings to an Arduino From a Raspberry Pi
# File: send_strings_to_arduino.py
# Description: This program runs on a Raspberry Pi. It sends strings
# to Arduino. It also receives the string it sent
# and prints it to the screen. This provides bi-directional (2-way) communication
# between Arduino and Raspberry Pi.
# Author: Addison Sears-Collins
# Website: https://automaticaddison.com
# Date: July 5, 2020
###############################################################################
import serial # Module needed for serial communication
import time # Module needed to add delays in the code
# Set the port name and the baud rate. This baud rate should match the
# baud rate set on the Arduino.
# Timeout parameter makes sure that program doesn't get stuck if data isn't
# being received. After 1 second, the function will return with whatever data
# it has. The readline() function will only wait 1 second for a complete line
# of input.
ser = serial.Serial('/dev/ttyACM1', 9600, timeout=1)
# Get rid of garbage/incomplete data
ser.flush()
# Infinite loop
i = 0
while (1):
i+=1
send_string = ("Data\n")
# Send the string. Make sure you encode it before you send it to the Arduino.
ser.write(send_string.encode('utf-8'))
# Do nothing for 500 milliseconds (0.5 seconds)
time.sleep(0.02)
# Receive data from the Arduino
receive_string = ser.readline().decode('utf-8').rstrip()
# Print the data received from Arduino to the terminal
print(receive_string)