I want to send a character, for example "s", to arduino from Atmega16. I use a command getchar() in code vision. But unfortunately, when we load this code on my arduino, I can see a non-meaning words in Serial Monitor. I define pin 7 and 8 as Rx and Tx, respectively in my code.
please kindly help to me to deal with this problem.
Thanks.
My Ardunino's code is:
#include <SoftwareSerial.h>
SoftwareSerial MDC20(7, 8); // RX, TX
void setup()
{
Serial.begin(9600);
while (!Serial)
{
}
MDC20.begin(9600); // set the data rate for the SoftwareSerial port
}
void loop ()
{
String str ;
while(1)
{
if ( Serial.available() )
{
str = Serial.read();
MDC20.println(str);
}
}
}
there is a smiley in your code... Please correct your post above and add code tags around your code. [code] // your code here [/code]. it should look like this:// your code here (and press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent properly)
Serial.read(); returns an int not a String object.
why do you add a while(1) as you have the loop() already looping anyway?
Thanks for your reply. I edited my code, but the non-meaning words is printed on Serial Monitor, again. I used a putchar('a') in codevision to send 'a' variable to Arduino from Atemaga 16. It should be mentioned that I recieve a none-meaning words like a sign. please help me.
Many many thanks.
// Receiving single characters
char receivedChar;
boolean newData = false;
void setup() {
Serial.begin(9600);
Serial.println("<Arduino is ready>");
}
void loop() {
recvOneChar();
showNewData();
}
void recvOneChar() {
if (Serial.available() > 0) {
receivedChar = Serial.read();
newData = true;
}
}
void showNewData() {
if (newData == true) {
Serial.print("This just in ... \n");
Serial.println(receivedChar);
newData = false;
}
}
[\code]