Adafruit 16 channel pwm servo shield control servo with Arduino

I’ve followed this guide to use Adafruit 16 channel pwm servo shield with Arduino Uno controller.

I’ve uploaded this servo example code from Adafruit PWM Servo Driver Library. I’m not quite understand code yet, but it successfully performs example movement, I guess, it is single movement from one side to another for each servo sequentially in time interval loop. It means that everything soldered and connected correctly I guess.

So I found minimal and maximal value for my digital servos 160-500, I have 2 motors attached to 0, 1 of Adafruit 16 channel pwm servo shield, works fine:

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN  160 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  500 // this is the 'maximum' pulse length count (out of 4096)
uint8_t servonum = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("8 channel Servo test!");
  pwm.begin();  
  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates
  delay(10);
}

void loop() {
    pwm.setPWM(0, 0, 160);
    pwm.setPWM(1, 0, 160);
  delay(500);
    pwm.setPWM(0, 0, 500);
    pwm.setPWM(1, 0, 500);    
  delay(500);
}

What I’m trying to do, is to control amount of digital or regular servos with C# control application. But I can’t figure out, how to receive condition and angle value. My load in C# WinForm desktop application, in case of Uno it is COM3, with Due COM4:

myport.PortName = comPort;  
myport.BaudRate = 9600;  
myport.Open();

This works successfully with breadboard connection, I send pin number and angel for example with trackBar or button to servos with condition to choose servos and different angle degree values at the same time, here is attempt to send and receive values, to make same movement control:

    private void button2_Click(object sender, EventArgs e)
        {
            if (myport.IsOpen)
            {
                myport.WriteLine("0");       // Pin number as name for servo condition
                myport.WriteLine("160");    // Angle degree position 
                myport.WriteLine("1");         // Pin number as name for servo condition
                myport.WriteLine("160");     // Angle degree position 
            }
        }

and back:

            if (myport.IsOpen)
            {
                myport.WriteLine("0");        // Pin number as name for servo condition
                myport.WriteLine("500");    // Angle degree position 
                myport.WriteLine("1");          // Pin number as name for servo condition
                myport.WriteLine("500");     // Angle degree position 
            }

To this code:

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN  150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  600 // this is the 'maximum' pulse length count (out of 4096)
int val;
void setup() {
  Serial.begin(9600);
  Serial.println("8 channel Servo test!");
  pwm.begin();
  pwm.setPWMFreq(333);  // Analog servos run at ~60 Hz updates
  delay(10);
}

void loop() {
  val = Serial.parseInt(); //get servo selection
  if(val == 0){
    pwm.setPWM(0, 0, Serial.parseInt());
  }
  else if(val == 1){
     pwm.setPWM(1, 0, Serial.parseInt());
  }  
}

Seems like it is wrong way, servo does not moves. I don’t think so that the C# code must be different, it is condition value and angle. But I can’t even move one single servo on the shield, because in all appearances, in this case, It seems like, I just have no connection between C# and Adafruit code, and library requires completely different way to do what I want.

But how? I can’t find any appropriate example in internet. I think, it is connection problem with sending and receiving of condition and angel values from C# to Adafruit code and using of shield, but I have no idea, what to do to connect C# with Adafruit

I’m not sure how to use it, need your support

Any advice, guide or example would be helpful

Start by making sure you receive the communication correctly. Read the following Serial Input Basics tutorial and implement something for your case printing reliably PIN number and angle.

Once your code gets the serial input correctly, then add your servos

J-M-L:
Start by making sure you receive the communication correctly. Read the following Serial Input Basics tutorial and implement something for your case printing reliably PIN number and angle.

Once your code gets the serial input correctly, then add your servos

Hello,

Well, my breadboard code receives serial input correctly I guess, with angle value and servo number by pin for both:

 val = Serial.parseInt();
      if(val == 9){
        servo1.write(Serial.parseInt());
      }

Problem with Adafruit library example. I've checked all by your link, but the result is same. With val = Serial.println(); and Serial.println(), serial port becomes busy for uploaded code or control application with debug of one or another, but anyway without checking of serial monitor, myport.WriteLine("0"); myport.WriteLine(trackBar1.Value.ToString()); does not moves motor