Hello,
I want to input Strings into a Programm running on my Arduino.
The String is entered on a Website, saved on the Webserver.
A Python Programm is reading the String and sending it to the Arduino. (the Arduino uses it to morse/blinnk it)
This works quite well, wenn the Arduino is connected to my laptop.
It sometimes works, when I'm doing the same thing with a raspberry pi (Arduino connected same way, with an USB cable to the Raspberry). Sometimes only the first letter of the string arrives, sometimes nothing happens.
Im posting parts of the arduino and my Python script. Am I doing something wrong? How to make the behavior a little bit more predictable?
Best regards
Adriana
This is, how the Arduino gets the String
void setup()
{
Serial.begin(9600);
while (!Serial) {
; }
void loop()
{
if (Serial.available() > 0) {
instring = Serial.readString();
}
Serial.println(instring);
...
And this, how the python script is sending the data to the arduino (it looks up the text on a webserver and writes something back...this part has not much to do with the serial problem, I suppose, but to be sure, I left the code as it is)
import serial
import urllib
import requests
import time
while 1:
print("hello");
time.sleep(4);
link_ready = 'http://www.mikolaskova.cz/r57/ready.txt'
f_ready = urllib.urlopen(link_ready)
myfile_ready = f_ready.readline()
if myfile_ready=="no":
link = 'http://www.mikolaskova.cz/r57/text.txt'
f = urllib.urlopen(link)
myfile = f.readline()
print myfile
ser= serial.Serial('/dev/ttyACM0',9600)
if ser.isOpen():
ser.write(myfile)
response = ser.read(ser.inWaiting())
response = urllib.urlopen("http://www.mikolaskova.cz/r57/done.php")
data = response.read()
print data
else:
print "nothing to do-ready: no"