Hi,
I have some trouble getting two-way communication working between an Arduino UNO and a Win10 PC through USB. Trying to use the PySerialTransfer library by Power_Broker.
Code:
#include "SerialTransfer.h"
SerialTransfer myTransfer;
bool mustanswer = false;
void setup()
{
Serial.begin(115200);
myTransfer.begin(Serial);
}
void loop()
{
if(myTransfer.available())
{
mustanswer = true;
}
else if(myTransfer.status < 0)
{
Serial.print("ERROR: ");
Serial.println(myTransfer.status);
}
if(mustanswer == true)
{
myTransfer.txBuff[0] = 'h';
myTransfer.txBuff[1] = 'e';
myTransfer.txBuff[2] = 'y';
myTransfer.sendData(3);
delay(100);
}
}
The code here is just to debug. I started out with the standard example that I couldn't get working either. The python part is still the standard example (changed port).
I can receive data on the PC from the Arduino (when sending data is not conditional), but it seems something goes wrong with the PC sending to Arduino. Specifically I find that "myTransfer.available()" never becomes true - resulting in nothing being returned to the PC. I can see the TX LED blinking "once" when I try to send a few bytes from the PC, either from python or the IDE serial monitor. I don't receive any answer either in python or serial monitor (2 separate tests, as they can't both have the port).
As expected, if I manually set "mustanswer = true" out in the main loop I receive "hey" in python - and if looking in the IDE serial monitor it keeps repeating "~⸮hey⸮".
I also found that if I change the code from:
...
if(myTransfer.available())
...
Into:
...
if(Serial.available() > 0)
...
And send a few characters from the IDE serial monitor then I also get a result back, constantly repeating "~⸮hey⸮". I don't get any response in python if trying the same with the script though, it just hangs.
I also have a Mega that I tested with, no difference.
The basic plan is that a piece of software on the PC must interface with an Arduino controlled turntable through this python script/driver - when the driver has send the command the Arduino executes and a few seconds later responds with a result to the driver - if all went well the driver will let the PC software continue. Using PySerialTransfer might not be necessary, but it seemed like a nice way of getting there.
I hope someone can assist. Thanks.