title: C# serial command to move Arduino servo X degrees?
body: <p>I have an Arduino wired up with a servo (Pin 9, 5.5v and Ground), it will run with any ol' testing on the Arduino; however, when I send a serial command to move it, well nothing happens. The rx light flashes so I know the Arduino is getting the info. I think the issue is in my byte conversion.</p>
  
  <p>Code Time:</p>
  
  <p>Arduino Code:</p>
  
  <pre><code>#include &lt;Servo.h&gt; 
  
  Servo myservo;  // create servo object to control a servo 
                  // a maximum of eight servo objects can be created 
  void setup() 
  { 
      myservo.attach(9); 
      // attaches the servo on pin 9 to the servo object and sets the rotation to 0
      myservo.write(0); 
  } 
  
  int pos1= 0;
  int pos2= 0;
  int pos3= 0;
  int totalMove = 0;
  
  void loop() 
  { 
      if (Serial.available() &gt; 0 &amp;&amp; totalMove &gt; 0)
      {
          pos1 = Serial.read() - '0'; 
          // pos2 = Serial.read() - '0'; 
          // pos3 = Serial.read() - '0'; 
          // totalMove = ((pos3) + (pos2*10) + pos1*100);
  
          myservo.write(pos1);
       }
  } 
  </code></pre>
  
  <p>You see the other pos holders because evenutally I would like to be able to send values larger than 9, however for now I just need to get it to respond :)</p>
  
  <p>C# code:</p>
  
  <pre><code>public void moveServo()
  {
      if (!serialPort1.IsOpen)
      {
          Console.WriteLine("Oops");
          serialPort1.Open();
          return;
      }
  
      serialPort1.DtrEnable = true;
  
      serialPort1.DataReceived += 
          new System.IO.Ports.SerialDataReceivedEventHandler(
              serialPort1_DataReceived);
  
      serialPort1.Write(new byte[] {57}, 0, 1);
  }
  </code></pre>
  
  <p>Any ideas?</p>