I can get softwareSerial to send data between two Arduino’s but only one character at a time. Then I use myDate +=rc (where rc is the serial read). I can print rc but not myData. All I get is a black triangle with a ? in it.
Welcome to the forums. Take a moment to read this: How to get the best out of this forum - Using Arduino / Installation & Troubleshooting - Arduino Forum
It will help others help you.
We can't see your code if you don't post it.
What data type is 'myDate' (or 'myData') ?
It would indeed be helpful to see the code. If you can print rc, then evidently the character is being transmitted and received, but myDate/myData is not being handled correctly in some respect.
When you do post the code, please use the Edit -> Copy for Forum feature in the IDE to copy and then paste it into your post.
Sorry, myDate should have been myData I have tried setting myData as String, char, and uint8_t but none work This is the code I am using
// Buffer to store incoming commands from serial port
String inData;
void setup() {
Serial.begin(9600);
softSerial.begin(9600);
Serial.println("Serial conection started, waiting for instructions...");
}
void loop() {
while (Serial.available() > 0){
char rc = softSerial.read();
myData += rc;
if (rc == '\\n'){
Serial.print("Arduino Received: ");
Serial.print(myData);
}
}
myData = ""; // Clear recieved buffer
}
Only need one backslash for newline:
if (rc == '\n'){
Not sure what happened to the formatting?
There should be 3 backticks before and after your code. None in-between.
Looks like your code got fragmented somehow. It would be appreciated if you could adjust your post accordingly.
So many problems it is hard to know where to start.
Take the advice in post 3 and format your code properly and show all of it.
Why is the while loop based on Serial.available() when is is never read?
The softSerial.read() will return -1 if there is no data. This is probably where your strange results are coming from.
I assume myData is a String - there is no definition shown. This is a very bad way to get a dynamic character string in small AVR processors like the UNO R3. They have poor heap management and limited memory, which leads to crashes.
// receiving string thru Serial
void process (
char *s )
{
Serial.println (s);
}
void loop ()
{
if (Serial.available()) {
char buf [90];
int n = Serial.readBytesUntil ('\n', buf, sizeof(buf)-1);
buf [n] = '\0'; // terminate with nul
process (buf);
}
}
void setup ()
{
Serial.begin (9600);
Serial.println ("ready");
}
Please correct your post and add code tags around your code.
There is a small pencil
below your existing posts.
- click on this pencil ➜ that will let you edit your post.
- Select the part of the text that corresponds to the code
- Click on the
<code/>icon in the toolbar to indicate that it is code - click
Save Edit
(Also make sure to properly indent the code in the IDE before copying and pasting it here. This can be done by pressing ctrlT on a PC or cmdT on a Mac)
———
softSerial is not defined in your code, so zero chance it works
your loop checks Serial not softSerial...
I would suggest to study Serial Input Basics to handle this
You check the Serial port and then read from the software serial.