0

For a long time I use Arduino Uno controller and Adafruit 16-Channel 12-bit PWM/Servo Shield with 6.3V 1000 uF capacitor, powered with 6V 8Amp adapter to control 6 High-Speed Digital Micro Servo DSM44 and 2 FEETECH Mini Servo FT1117M, in total 8 digital servo motors from C# desktop application.

First of all here is a serial port initialization, which is COM3 with my Arduino Uno:

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (comPort == null)
        {
            comPort = comboBox1.Text;
            var portExists = SerialPort.GetPortNames().Any(x => x == comPort);
            if (portExists == true)
            {
                try
                {
                 myport.PortName = comPort; 
                 myport.BaudRate = 9600;
                 myport.Open();
                 myport.DtrEnable = true;          
            }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }             
        }       
    }

With click on button from my C# desktop application code, I sending x angle value, which is different degree 360, 300, 200 etc:

private void button1_Click(object sender, EventArgs e)  
{  
   if (myport.IsOpen) 
   { 
    myport.WriteLine("0"); 
    myport.WriteLine(x.ToString());
   }    
}

to controller with servo shield. Here is minimal example for 2 motors, from 0-1 pin (in project I use 0 to 7 pins):

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN  160
#define SERVOMAX  500
int val;

void setup() {
  Serial.begin(9600);
  pwm.begin();
  pwm.setPWMFreq(60);
  delay(10);
}

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

This code was successfully working for a long time of using my project device, but today I've plugged controller, and something goes wrong way, when I've not damaged of changed anything in my project, as in code, also in device assembly. I found two different and absolutely not clear problems, which newer was before with completely same code, devices, computer and Windows 10 pro OS:

  1. When I'm loading Adafruit control #include <Wire.h> #include <Adafruit_PWMServoDriver.h> sketch, I see TX, RX and L led indicates upload as usually, but motors does not moves with command from desktop via serial port, just does some short random movements with load of controller and then stops, at the same time RX led indicates receiving of message from C# desktop command with button or trackbar successfully.

  2. When I'm trying to load another sketch, which uses <Servo.h>:

    #include <Servo.h>
    Servo servo1;
    int val;
    void setup() {
        Serial.begin(9600);
        servo1.attach(9);
    }       
    void loop() { 
      val = Serial.parseInt();
      if(val == 9){
        servo1.write(Serial.parseInt());
      }
    }
    

which should receive serial command from my C# desktop, with same shown initialization, to check if I am able to move motor from desktop this way, but C# application hangs and freezes with selecting of same "COM3" in combobox. Then after number of attempts, it was somehow loaded and selected without freezing with port selection, but did nothing with servo, just indication of message with RX, and same unexpected random movements.

Both of this problems was never appeared before.

To be sure, I've checked all motors separately only with Arduino (without shield) from basic servo control with direct connection minus to GND, 5V to V+, Signal to PWM by this example, which also uses <Servo.h>, and works fine, turns all motors from sketch successfully.

Also I've checked absolutely new Arduino Due, which uses COM4 and it is same behavior. So, seems like controller and motors are fine, it looks like my USB serial port works incorrectly, or it is something wrong with shield, what is more likely, even if serial port selection freezing looks really doubtful and does not shows any error if I run application from VS debug, I almost sure that the problem comes from shield, because kind of proof is that I've checked same C# application from 2 different computers with Windows OS and with 2 different controllers Uno and Due, single or number of servos on board, and 3 different USB cables serial command received but motor does not moves by command, just does rare unexpected random movements.

Power to shield correct is a 6V, board and port selected in Arduino IDE tools by requirement.

It looks like something wrong with shield, even if freezing of serial port sounds like separate problem, but I don't have another shield to check, so I've to find out somehow with particular device

I'm not sure where to go next and what to check else.

Any advice, guide or example would be helpful

  • two Arduinos doing the same thing ... that does not sound like a problem with the Arduino ... run simple LED blink sketch ... do not use any shields – jsotola Nov 22 '19 at 3:23
  • 1
    you posted in multiple places ... please keep one and delete the rest ... robotics.stackexchange.com/questions/19771/… – jsotola Nov 22 '19 at 3:36
  • You should try to check the servos with the Sweep example, without any Serial, so that you are really only testing the Servos. Your Serial testcode is really strange with all that parseInt. Also we don't know what you are exactly sending in that case. Also please verify, that you get the same problem, when using a simple serial terminal program (Arduino Monitor is sufficient for this). As we are on Arduino stackexchange, we cannot debug your C# application and this would show, if the board is really the problem, or the C# application – chrisl Nov 22 '19 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.