The character_variable is something that is "A", "B", "9", etc.
I have confirmed good code that sends and receives data just fine from my Arduino. The only difference that I can think of is that my good code is not a function, but a simple Python3 script.
I THINK my Python3 function is writing to my Arduino since I placed a print line under the arduino.write(bytes(character_variable, 'utf-8')) line and it printed out data, but it did not print out data under the returned_data = arduino.readline() line.
will likely reboot your arduino if you have a UNO or MEGA or similar... so it's possible it's not ready when you send the character as the setup takes a bit of time to run and Serial be ready
I figured out a solution! I created a class and function. Within the class I defined a variable that sets the "arduino = serial.Serial('/dev/ttyACM0', 115200)" and then I created a function that sends and receives data. Here is my sample code for Python3:
import serial
class arduino_communication:
# Class variable
arduino = serial.Serial('/dev/ttyACM0', 115200)
def simple_demo(self, character_variable):
arduino = self.arduino
arduino.write(bytes(character_variable, 'utf-8'))
returned_data = arduino.readline()
returned_data = returned_data.decode('utf-8')
return returned_data