* This function outputs the message, msg, preceded by a start-text char and followed by an end-text char While( message_string.length() <= max_size ) //end the while loop if the "end of text" char is read or buffer maximum is reached Int max_size = 64 //size of serial buffer on UNOĭelay(5) //Not sure why I need this, but it needs to be at least 5ms, as per experimentation * The function breaks out of reading into the string if the "end of text" char is read or the maximum buffer size is reached * This function checks for the "start of text" ascii char and then reads in each char to a string. If( message != "" ) //only report meaningful strings Serial.println("Connection established at 9600 baud from SLAVE to COMPUTER.") SoftwareSerial RS485(RS485RX, RS485TX) // RX, TX #define TxControl 4 //RS485 Direction control Why do I need that small delay in receive_message()? #include If this is somehow a poor example of code, please correct it for the benefit of everyone else. I've learned so much about programming from this forum that I hope to be able to give back. Please ignore this part of the example.Īn aside: Although I'm no software developer, I hope this example helps others in their Arduino serial communication. The shorter the delay, the more frequent the errors occur.īelow is my test program which I will eventually implement on an RS485 network, so the send_message() function also sends a signal to the MAX485 chip to transmit on the network. Can anyone explain to me why this happens? If I make the delay any shorter than 5 milliseconds the errors occur. In the function I've had to include a short delay or the incoming string shows random ascii characters at seemingly random times. Hello, I've made a function to receive a string via SoftwareSerial.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |