<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: Problem with Serial read with XBee from PC</title>
		<link>http://forums.leaflabs.com/topic.php?id=1379</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:24:53 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=1379" rel="self" type="application/rss+xml" />

		<item>
			<title>ModMob on "Problem with Serial read with XBee from PC"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1379#post-8328</link>
			<pubDate>Thu, 23 Feb 2012 16:26:25 +0000</pubDate>
			<dc:creator>ModMob</dc:creator>
			<guid isPermaLink="false">8328@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Okay, I found my problem...I just need a small delay each time I clear the command:&#60;/p&#62;
&#60;p&#62;clearCommand(InputCommand);&#60;br /&#62;
delay(5);&#60;/p&#62;
&#60;p&#62;Sorry I didn't wait to post, but I've been at this for days.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ModMob on "Problem with Serial read with XBee from PC"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1379#post-8326</link>
			<pubDate>Thu, 23 Feb 2012 15:37:44 +0000</pubDate>
			<dc:creator>ModMob</dc:creator>
			<guid isPermaLink="false">8326@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I’m pretty new to this stuff, so I assume I’ve made a mistake somewhere. Using Processing I’m sending game controller inputs to the Maple via XBee S1 transceivers. I have a simple protocol that uses ‘$’ as begin of command and ‘Z’ as end of command.&#60;/p&#62;
&#60;p&#62;For testing I’m mapping the received input to a PWM output for an LED.  The LED brightness changes erratically to input changes, making me think I’m not reading all the bytes in the command.&#60;/p&#62;
&#60;p&#62;Here’s what I send from the PC in Processing:&#60;br /&#62;
XBeePort.write(&#34;$&#34;+(int)lUpDown+&#34;Z&#34;);&#60;br /&#62;
Where, lUpDown ranges from 0 to 510.&#60;/p&#62;
&#60;p&#62;Here’s the Maple code:&#60;br /&#62;
'#include &#38;lt;stdlib.h&#38;gt;&#60;br /&#62;
char commandBegin = '$';&#60;br /&#62;
char commandEnd = 'Z';&#60;br /&#62;
char InputCommand[100];&#60;br /&#62;
int maxIn = 510;&#60;br /&#62;
int minIn = 0;&#60;br /&#62;
char currentChar = ' ';&#60;/p&#62;
&#60;p&#62;void setup() {&#60;br /&#62;
    Serial1.begin(9600);&#60;br /&#62;
    delay(500);&#60;br /&#62;
    Serial1.flush();&#60;br /&#62;
    pinMode(0, PWM);&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;void loop() {&#60;br /&#62;
  while (Serial1.available()&#38;gt;0){&#60;br /&#62;
    currentChar = Serial1.read();&#60;br /&#62;
    if(currentChar == commandBegin){&#60;br /&#62;
      clearCommand(InputCommand); &#60;/p&#62;
&#60;p&#62;      int i = 0;&#60;br /&#62;
      while(currentChar != commandEnd){&#60;br /&#62;
       currentChar = Serial1.read();&#60;br /&#62;
       delay(50);&#60;br /&#62;
       InputCommand[i] = currentChar;&#60;br /&#62;
       i++;&#60;br /&#62;
      }&#60;br /&#62;
    }&#60;br /&#62;
   if (currentChar == commandEnd){&#60;br /&#62;
      handleCommand(InputCommand);&#60;br /&#62;
      clearCommand(InputCommand);&#60;br /&#62;
  }&#60;br /&#62;
  }&#60;br /&#62;
}&#60;br /&#62;
void handleCommand(char InputCommand[]){&#60;br /&#62;
      int pwmValue=map(atoi(InputCommand),minIn,maxIn,0,65535);&#60;br /&#62;
      pwmWrite(0,pwmValue);&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;void clearCommand(char InputCommand[]){&#60;br /&#62;
    int commandSize = sizeof(InputCommand);&#60;br /&#62;
    for (int i = 0; i &#38;lt; commandSize - 1; i++) {&#60;br /&#62;
      InputCommand[i]=' ';&#60;br /&#62;
    }&#60;br /&#62;
}  '&#60;/p&#62;
&#60;p&#62;Can anyone suggest why I might not be reading all of the command bytes?&#60;br /&#62;
Thanks
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
