My problem is that every way I've tried does not transmit the data, or it's hit and miss garbled or bytes go missing out of the middle. I'm using software serial on the Wemos side. While searching for some answers to this problem I came accross one post that said software serial won't work on the Wemos because of the web stuff using interupts preventing software serial from working.
So then I got the SerialTransfer library. Same story on the uart portion of the library. Then I tried the I2C examples that come with the library but same result being that the send from Wemos triggers the recieve on the Arduino but without any of the actual data.
Did more research and then downloaded the EspSoftwareSerial library. Ran the "onewire" example that only uses D6,D5. No data in either direction.
To start off I'm just going to ask if it is possible to get communication to actually work between a directly connected Wemos D1 and Arduino Mega 2560 without using the Wemos hardware TX/RX pins?
I want to be able to have both the Wemos D1 Mini and Arduino Mega 2560 on separate usb connections so I can print debug information about the data being sent between them.
wire the Wemos and Mega for serial or whatever works. They will sit an inch apart from each other.
if you use a software serial solution, don't expect it to work well under heavy load at high baud rate. so depending on how you read the data (hint) you might also loose stuff there
I don't know, but I use SoftwareSerial on a WeMos D1 (also on an R1!!), provided you don't set high speeds, at 9600 baud it works fine. Don't trust Arduino Documentation saying "up to 115200 bps": real life tests show you shouldn't exceed 38400, the lower the better for reliability if you don't need high data volumes.
If for any reason you need higher speeds, you better switch to a physical UART (like the integrated one, if you don't need serial debugging).
9600 baud is fine for what I'm doing. The amount of data being transferred at one time is less than 80 bytes and transfers will be infrequent.
Do you know which SoftwareSerial library you are using? When I compile the compiler verbose output shows multiple libraries and the compiler selects:
I'm using the Arduino IDE 2.0 stable release. For those who asked, I am using a voltage level shifter and all grounds are common. I've tested this on two different Wemos D1 mini boards.
I have also tried the EspSoftwareSerial library and was able to force the compiler to select it by making a file named EspSoftwareSerial.h in the library src folder with #include "SoftwareSerial.h". The "onewire" example uses D6, D5 and uses only the Wemos itself. The code prints D5=14, D6=12. Same issue, no data.
#include "EspSoftwareSerial.h"
#ifndef D5
#if defined(ESP8266)
#define D5 (14)
#define D6 (12)
#elif defined(ESP32)
#define D5 (18)
#define D6 (19)
#endif
#endif
SoftwareSerial swSer1;
SoftwareSerial swSer2;
void setup() {
delay(2000);
Serial.begin(9600);
Serial.println(PSTR("\nOne Wire Half Duplex Serial Tester"));
swSer1.begin(9600, SWSERIAL_8N1, D6, D6, false, 256);
// high speed half duplex, turn off interrupts during tx
swSer1.enableIntTx(false);
swSer2.begin(9600, SWSERIAL_8N1, D5, D5, false, 256);
// high speed half duplex, turn off interrupts during tx
swSer2.enableIntTx(false);
Serial.print("D5 = ");
Serial.println(D5);
Serial.print("D6 = ");
Serial.println(D6);
}
void loop() {
Serial.println(PSTR("\n\nTesting on swSer1"));
Serial.print(PSTR("Enter something to send using swSer1."));
checkSwSerial(&swSer1);
Serial.println(PSTR("\n\nTesting on swSer2"));
Serial.print(PSTR("Enter something to send using swSer2."));
checkSwSerial(&swSer2);
}
void checkSwSerial(SoftwareSerial* ss) {
byte ch;
while (!Serial.available());
ss->enableTx(true);
while (Serial.available()) {
ch = Serial.read();
ss->write(ch);
}
ss->enableTx(false);
// wait 1 second for the reply from SOftwareSerial if any
delay(1000);
if (ss->available()) {
Serial.print(PSTR("\nResult:"));
while (ss->available()) {
ch = (byte)ss->read();
Serial.print(ch < 0x10 ? PSTR(" 0") : PSTR(" "));
Serial.print(ch, HEX);
}
Serial.println();
}
}
I still use the 1.8.19 (I won't use the 2.0 unless a 2.1 will be released, my policy is to avoid any software with *.0 version, if possible, due to potential new bugs..), and the portable one (e.g. the zip file) on Windows OS. I don't know, but if you installed from Microsoft store uninstall it and try the portable version: just copy the zip content to a "C:\Arduino" folder, add any library you need and try again.
Why? I never had to do anything like that.
By the way, if you just need to send data, why don't you use Serial1 (WeMos D1 built-in secondary UART, pin GPIO2 or D4) instead of SoftwareSerial?
I need bidirectional data transfer. From what I have gleaned from brief research on the usefulness of the secondary UART is a hinky workaround. It requires an additional piece of hardware (USB to TTL converter) and then in setup() after Serial.begin(), a Serial.swap() is performed so that main serial pins are swapped from TX0,RX0 to D8,D7. Then, you have to send any normal information needed for debugging out Serial1 so that is more coding.
On the page that you linked to, one of the download options is "Windows ZIP file". You can download this file and unzip it into a directory of your choice.
I appreciate the information. I'm guessing that this means its possible to have more than one "installation" of the IDE at the same time by installing them in different directories?
I am now seeing data that was sent by the Wemos D1 mini on the Mega 2560.
I pulled all the wires and rewired the project but it still was not working. I changed from Serial1 to Serial3 on the Mega - no change. Swapped out the voltage level converter - no change. Tried swapping the TX/RX pins just in case - no change.
I noticed that the SoftwareSerial s(D6,D5); function allowed a third parameter. It defaults to false so I set it to true - no change but then decided to power off the USB to the Mega. When it came back, nothing on the IDE Monitor. So I decided to try TeraTerm on the Mega COM port. I got data coming out but it was not readable characters. I set the SoftwareSerial s(D6,D5,false); back to false and normal characters began appearing. So now it's working. The first 4 or 5 resets I could only get data while using TeraTerm but now it seems to work on the IDE monitor as well.
I am now getting data when just printing or writing but it still fails when using the SerialTransfer library. Bummer. I would prefer buffered transmits.
This works:
Sending from the Wemos D1 Mini
#include <SoftwareSerial.h>
SoftwareSerial s(D6,D5,false);
void setup()
{
Serial.begin(9600);
s.begin(9600);
}
void loop()
{
Serial.print("Sending...\n");
s.print("\nHello.\n");
delay(2000);
}
Recieving on Mega 2560
void setup()
{
Serial.begin(9600);
Serial3.begin(9600);
}
void loop()
{
char ch;
if (Serial3.available()){
ch = Serial3.read() ;
Serial.println(ch);
delay(500);
}
}
This doesn't work:
Sending from the Wemos D1 mini:
#include <SoftwareSerial.h>
#include "SerialTransfer.h"
SoftwareSerial s(D6,D5,false);
SerialTransfer myTransfer;
struct STRUCT {
char z;
float y;
} testStruct;
char arr[] = "hello";
void setup()
{
Serial.begin(9600);
s.begin(9600);
myTransfer.begin(s);
testStruct.z = '$';
testStruct.y = 4.5;
}
void loop()
{
testStruct.z = '$';
testStruct.y = 4.5;
// use this variable to keep track of how many
// bytes we're stuffing in the transmit buffer
uint16_t sendSize = 0;
///////////////////////////////////////// Stuff buffer with struct
sendSize = myTransfer.txObj(testStruct, sendSize);
///////////////////////////////////////// Stuff buffer with array
sendSize = myTransfer.txObj(arr, sendSize);
///////////////////////////////////////// Send buffer
Serial.print("Sending.\n");
myTransfer.sendData(sendSize);
delay(5000);
}
Recieving on Mega 2560:
#include "SerialTransfer.h"
SerialTransfer myTransfer;
struct STRUCT {
char z;
float y;
} testStruct;
char arr[6];
void setup()
{
Serial.begin(9600);
Serial3.begin(9600);
myTransfer.begin(Serial3);
}
void loop()
{
if(myTransfer.available())
{
// use this variable to keep track of how many
// bytes we've processed from the receive buffer
uint16_t recSize = 0;
recSize = myTransfer.rxObj(testStruct, recSize);
Serial.print(testStruct.z);
Serial.print(testStruct.y);
Serial.print(" | ");
recSize = myTransfer.rxObj(arr, recSize);
Serial.println(arr);
}
}
I have been using the 2.0 IDE. Started with beta 1.6 but now using the stable release. I never used the older IDE and since I'm really new to these devices I didn't want to start development with the older one just to change later.
There were issues with 1.6 but working around just meant using TeraTerm.
Good thing it's working, but I can't figure out why the operations you did changed/restored the serial behaviour. I always try to understand when something appears to be out of any logical reason (computers are logical, noting happens without any reason), so if you or someone else could explain me, I'll be happy.
Anyway, I'm sorry I can't help you on SerialTransfer as I never used it. Just following the thread now.
PS: I forgot to say SoftwareSerial constructor third parameter if true means "inverse logic" (haven't you checked the docs out when saw it as this optiona param?). Default value is "false" so when you put it to "true" it can't work (provided the sender doesn't have inverse logic) and with "false" it can't be the reason for current behaviour.