Basic Arduino Serial Communication -


i'm trying basics of serial communication started; i'm trying use example found, understand should working. want type serial monitor output back, can see how works. tried removing while serial.available in case serial monitor doesn't trigger condition. here code:

// buffer store incoming commands serial port string indata;  void setup() { serial.begin(9600); serial.println("initialized\n");  }     void loop() {      while (serial.available() > 0)  {     char recieved = serial.read();     indata += recieved;       // process message when new line character recieved     if (recieved == '\n')     {         serial.println("arduino received: ");         serial.println(indata);          indata = ""; // clear recieved buffer         }     } } 

it uploads fine, , prints "initialized" doesn't work if try "send" data.

serial.read() returns , int. need cast (char) in order store char.

char recieved = (char)serial.read(); 

btw: variable name should received :)

edit:

maybe never receiving data reason. let's try super simple, use serialevent() suggested @sohnryang , print text serial.available() triggers:

    while (serial.available() > 0) {         serial.println("something has been received");     } 

you should see message every time send arduino.


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -