{"id":42,"date":"2013-10-24T15:41:34","date_gmt":"2013-10-24T15:41:34","guid":{"rendered":"https:\/\/arduino-developer.com\/arduino\/?p=42"},"modified":"2019-09-10T10:14:39","modified_gmt":"2019-09-10T10:14:39","slug":"serial-port-uart","status":"publish","type":"post","link":"https:\/\/arduino-developer.com\/arduino\/programming\/uart\/serial-port-uart","title":{"rendered":"Serial Port (UART)"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Arduino Serial Ports<\/h4>\n\n\n\n<p>UART0 is the default serial port which is used for serial programming.<\/p>\n\n\n\n<p>Some arduino&#8217;s have more than one serial port and these are called Serial1, Serial2, etc<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Setup Serial Port<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  \/\/----- SETUP SERIAL PORT -----\n  Serial.begin(9600);\n  while(!Serial)\n    ;           \/\/Leonardo\/Micro should wait for serial init\n\n  \/\/or\n\n  Serial2.begin(9600);\n\n  \/\/or\n\n  Serial.begin(9600, SERIAL_8N2);    \/\/SERIAL_8E1, SERIAL_8O1, etc<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Sending ASCII Text <\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  Serial.print(\"Hello\");        \/\/Write string no new line\n  Serial.println(my_variable);  \/\/Write a value with line break at end<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Sending Variables As ASCII <\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>    Serial.print(MyVariable, DEC);     \/\/int value\n    Serial.print(MyVariable, HEX);    \/\/hex value\n    Serial.println(1.23456, 2)       \/\/Limit decimal places (gives \"1.23\")<\/code><\/pre>\n\n\n\n<p>Others see <a href=\"http:\/\/arduino.cc\/en\/Serial\/Print\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Write Binary Data <\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  Serial.write(0x01);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Receive Binary Data <\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  int DataRx;\n  if (Serial.available() > 0)    \/\/Gets the number of bytes available for reading from the serial port (buffer holds up to 64 bytes)\n  {\n    DataRx = Serial.read();      \/\/Read next byte (returns -1 if no data available)\n  }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Arduino Serial Ports UART0 is the default serial port which is used for serial programming. Some arduino&#8217;s have more than one serial port and these are called Serial1, Serial2, etc Setup Serial Port Sending ASCII Text Sending Variables As ASCII Others see here. Write Binary Data Receive Binary Data<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-42","post","type-post","status-publish","format-standard","hentry","category-uart"],"_links":{"self":[{"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/posts\/42","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/comments?post=42"}],"version-history":[{"count":9,"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/posts\/42\/revisions"}],"predecessor-version":[{"id":512,"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/posts\/42\/revisions\/512"}],"wp:attachment":[{"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/media?parent=42"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/categories?post=42"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/tags?post=42"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}