11 Replies Latest reply on Mar 8, 2016 1:21 PM by CMata_Intel

    AlexMos sketch works fine on Arduino Uno but not so with Galileo Gen2

    RoboBill

      I'm trying to control an AlexMos gimbal controller through a serial port at terminal 3. I've altered the original SoftwareSerial of the sketch to use the SoftwareSerial_Class per discussions I've found here but I still can't get my sketch below to work.

       

      Is there something else in this sketch I need to change?


      BTW successfully tested the SoftwareSerial_Class example provided by Diego.

       

      Thanks

       

      RoboBill

       

       

       

      #include <SoftwareSerial_Class.h>

      SoftwareSerial AlexMosSerial(2, 3);

       

       

      // BASECAM default is 115200 but may be changed in the Advanced tab of the SimpleBGC GUI

      #define SERIAL_SPEED 115200

      // delay between commands, ms

      #define SBGC_CMD_DELAY 20

      // Some definitions required to send commands

      #define SBGC_CMD_CONTROL 'C'

      #define SBGC_CMD_TRIGGER 'T'

      #define SBGC_CONTROL_MODE_SPEED 1

       

       

      // Conversion from degree/sec to units that command understand

      #define SBGC_SPEED_SCALE (1.0f/0.1220740379f)

       

       

      #define TERMINAL_MONITOR_BAUDRATE  115200

       

       

      //-- Variables --

       

       

      int gimbal_motor_init = 0;

      float motor_speed = 180.0; //motor speed in degrees per second

       

       

       

       

      // Holder for command parameters

      typedef struct {

        uint8_t mode;

        int16_t speedROLL;

        int16_t angleROLL;

        int16_t speedPITCH;

        int16_t anglePITCH;

        int16_t speedYAW;

        int16_t angleYAW;

      } SBGC_cmd_control_data;

       

       

      typedef struct {

        uint8_t pin;

        int8_t state;

      } SBGC_cmd_trigger_data;

       

       

      // This helper function formats and sends a command to SimpleBGC Serial API

      void SBGC_sendCommand(uint8_t cmd, void *data, uint8_t size) {

        uint8_t i, checksum = 0;

        // Header

        AlexMosSerial.write('>');

        AlexMosSerial.write(cmd);

        AlexMosSerial.write(size);

        AlexMosSerial.write(cmd + size);

        // Body

        for (i = 0; i<size; i++) {

        checksum += ((uint8_t*)data)[i];

        AlexMosSerial.write(((uint8_t*)data)[i]);

        }

        AlexMosSerial.write(checksum);

      }

      void setup() {

        // initialize serial communication:

        AlexMosSerial.begin(SERIAL_SPEED);

        pinMode(13, OUTPUT);

      }

       

       

       

       

      void loop() {

        if (gimbal_motor_init == 0)

        {

        digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)

      SBGC_cmd_control_data c = { 0, 0, 0, 0, 0, 0, 0 };

        SBGC_cmd_trigger_data t = { 0, 0 };

        delay(3000);

        // start AlexMos speed control

        c.mode = SBGC_CONTROL_MODE_SPEED;

        c.speedYAW = motor_speed * SBGC_SPEED_SCALE;

        SBGC_sendCommand(SBGC_CMD_CONTROL, &c, sizeof(c));

        gimbal_motor_init = 1;

        }

      }

        • 1. Re: AlexMos sketch works fine on Arduino Uno but not so with Galileo Gen2
          CMata_Intel

          Hi RoboBill,

           

          Which is the error you are getting?

          I download the folder SoftwareSerial with SoftwareSerial.cpp and SoftwareSerial_Class.h files from Galileo/Arduino-Examples/SoftwareSerial at master · MakersTeam/Galileo · GitHub

          Then, I placed the folder on C:\Users\MyUser\AppData\Local\Arduino15\packages\Intel\hardware\i586\1.6.2+1.0\libraries

          I’m using the Arduino IDE 1.6.6 and your code and I hadn’t problems compiling the code.

           

          Could you post the errors you are getting?

          If you are having problems while writing and reading data, I suggest you first to wire you Rx to Tx in order to debug your code.

           

          Regards,

          Charlie

          1 of 1 people found this helpful
          • 2. Re: AlexMos sketch works fine on Arduino Uno but not so with Galileo Gen2
            RoboBill

            Hi Charlie,

             

            Oops... I forgot to mention that I don't get any output. And yes it does compile OK.

             

            So I went ahead and

            1) removed any reference to SoftwareSerial

            2) switched my output from terminal 3 to 1

            3) changed all the AlexMosSerial to Serial1.

             

            Still nothing... Darn!

             

            Then I changed all Serial1's to just Serial... still nothing... Darn Darn

             

            My question is, did you see anything in the existing code above that might give you concern as to it's compatibility with my Galileo 2? If not then it's something wrong here and I'll get out my old Tek-scope and dive in.

             

            Thanks

             

            RoboBill

            • 3. Re: AlexMos sketch works fine on Arduino Uno but not so with Galileo Gen2
              RoboBill

              Hi Everyone,

               

              I put my old 2 channel Tek-465M 200 mhz scope on my Galileo 2 and Uno to compare SoftwareSerial and SoftwareSerial_Class signals side by side running the same AlexMos sketch. Unfortunately I couldn't get them to trigger at the same time (go figure) plus this old scope is OLD. So I'm not real sure about whether both serial outputs are the same. They do look slightly different but that could be just bad alignment of my scope.

               

              So does anyone have any thoughts as to why there might be a difference between an Uno SoftwareSerial output and a Galileo SoftwareSerial_Class output?

               

              Thanks

               

              RoboBill

              • 4. Re: AlexMos sketch works fine on Arduino Uno but not so with Galileo Gen2
                RoboBill

                Hello again,

                 

                I modified the AlexMos sketch above to direct all serial output to the IDE monitor. COM16 is a readout of the Galileo and COM17 is a readout of an Arduino Uno R3.

                Galileo Uno Serial Output Comparison.GIF

                 

                Shouldn't these readouts be the same?

                 

                Thanks

                 

                RoboBill

                • 5. Re: AlexMos sketch works fine on Arduino Uno but not so with Galileo Gen2
                  RoboBill

                  BTW here  is the sketch I uploaded to both the Galileo and the Uno....

                   

                  //#include <SoftwareSerial.h>

                  //#include <SoftwareSerial_Class.h>

                  //SoftwareSerial AlexMosSerial(2, 3);

                   

                   

                  // BASECAM default is 115200 but may be changed in the Advanced tab of the SimpleBGC GUI

                  #define SERIAL_SPEED 115200

                  // delay between commands, ms

                  #define SBGC_CMD_DELAY 20

                  // Some definitions required to send commands

                  #define SBGC_CMD_CONTROL 'C'

                  #define SBGC_CMD_TRIGGER 'T'

                  #define SBGC_CONTROL_MODE_SPEED 1

                   

                   

                  // Conversion from degree/sec to units that command understand

                  #define SBGC_SPEED_SCALE (1.0f/0.1220740379f)

                   

                   

                  #define TERMINAL_MONITOR_BAUDRATE  115200

                   

                   

                  //-- Variables --

                   

                   

                  int gimbal_motor_init = 0;

                  float motor_speed = 45.0; //motor speed in degrees per second

                   

                   

                   

                   

                     // Holder for command parameters

                  typedef struct {

                    uint8_t mode;

                    int16_t speedROLL;

                    int16_t angleROLL;

                    int16_t speedPITCH;

                    int16_t anglePITCH;

                    int16_t speedYAW;

                    int16_t angleYAW;

                  } SBGC_cmd_control_data;

                   

                   

                  typedef struct {

                    uint8_t pin;

                    int8_t state;

                  } SBGC_cmd_trigger_data;

                   

                   

                  // This helper function formats and sends a command to SimpleBGC Serial API

                  void SBGC_sendCommand(uint8_t cmd, void *data, uint8_t size) {

                    uint8_t i, checksum = 0;

                    // Header

                    Serial.write('>');

                    Serial.write(cmd);

                    Serial.write(size);

                    Serial.write(cmd + size);

                    // Body

                    for (i = 0; i<size; i++) {

                    checksum += ((uint8_t*)data)[i];

                    Serial.write(((uint8_t*)data)[i]);

                    }

                    //Serial.write(checksum);

                    Serial.println(checksum);

                   

                   

                  }

                  void setup() {

                    // initialize serial communication:

                    Serial.begin(SERIAL_SPEED);

                    pinMode(13, OUTPUT);

                  }

                   

                   

                   

                   

                  void loop() {

                    //if (gimbal_motor_init == 0)

                    //{

                    digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)

                    SBGC_cmd_control_data c = { 0, 0, 0, 0, 0, 0, 0 };

                    SBGC_cmd_trigger_data t = { 0, 0 };

                    //delay(3000);

                    // start AlexMos speed control

                    c.mode = SBGC_CONTROL_MODE_SPEED;

                    c.speedYAW = motor_speed * SBGC_SPEED_SCALE;

                    SBGC_sendCommand(SBGC_CMD_CONTROL, &c, sizeof(c));

                    gimbal_motor_init = 1;

                    //}

                    delay(1000);

                    digitalWrite(13, LOW);   // turn the LED on (HIGH is the voltage level)

                    delay(1000);              // wait for a second

                     //digitalWrite(13, HIGH);    // turn the LED off by making the voltage LOW

                     //delay(1000);              // wait for a second

                   

                   

                  }

                  • 6. Re: AlexMos sketch works fine on Arduino Uno but not so with Galileo Gen2
                    RoboBill

                    I may have found a problem... I put the scope on an Uno and watched the outgoing serial port voltage drop from 5 to 0 with no load and 4.8 to .5 volts with the AlexMos controller attached.

                     

                    With the Galileo... without any load; same as Uno... but the voltage drop with controller attached went from 4.8 to only 1 volt.

                     

                    Is this a problem?

                     

                    RoboBill

                    • 7. Re: AlexMos sketch works fine on Arduino Uno but not so with Galileo Gen2
                      CMata_Intel

                      Hi RoboBill,

                       

                      I used the following code while having the 0 and 1 pins wired.

                      //#include <SoftwareSerial.h>
                      //#include <SoftwareSerial_Class.h>
                      //SoftwareSerial AlexMosSerial(2, 3);
                      
                      // BASECAM default is 115200 but may be changed in the Advanced tab of the SimpleBGC GUI
                      #define SERIAL_SPEED 115200
                      // delay between commands, ms
                      #define SBGC_CMD_DELAY 20
                      // Some definitions required to send commands
                      #define SBGC_CMD_CONTROL 'C'
                      #define SBGC_CMD_TRIGGER 'T'
                      #define SBGC_CONTROL_MODE_SPEED 1
                      
                      // Conversion from degree/sec to units that command understand
                      #define SBGC_SPEED_SCALE (1.0f/0.1220740379f)
                      
                      #define TERMINAL_MONITOR_BAUDRATE  115200
                      
                      //-- Variables --
                      
                      int gimbal_motor_init = 0;
                      float motor_speed = 45.0; //motor speed in degrees per second
                      
                        // Holder for command parameters
                      typedef struct {
                        uint8_t mode;
                        int16_t speedROLL;
                        int16_t angleROLL;
                        int16_t speedPITCH;
                        int16_t anglePITCH;
                        int16_t speedYAW;
                        int16_t angleYAW;
                      } SBGC_cmd_control_data;
                      
                      typedef struct {
                        uint8_t pin;
                        int8_t state;
                      } SBGC_cmd_trigger_data;
                      
                      // This helper function formats and sends a command to SimpleBGC Serial API
                      void SBGC_sendCommand(uint8_t cmd, void *data, uint8_t size) {
                        uint8_t i, checksum = 0;
                        // Header
                        Serial.write('>');
                        Serial.write(cmd);
                        Serial.write(size);
                        Serial.write(cmd + size);
                        // Body
                        for (i = 0; i<size; i++) {
                        checksum += ((uint8_t*)data)[i];
                        Serial.write(((uint8_t*)data)[i]);
                        }
                        //Serial.write(checksum);
                        Serial.println(checksum);
                      
                      
                      }
                      void setup() {
                        // initialize serial communication:
                        Serial1.begin(SERIAL_SPEED);
                        Serial.begin(SERIAL_SPEED);
                        pinMode(13, OUTPUT);
                      }
                      
                      void loop() {
                        //if (gimbal_motor_init == 0)
                        //{
                        digitalWrite(13, HIGH);  // turn the LED on (HIGH is the voltage level)
                        SBGC_cmd_control_data c = { 0, 0, 0, 0, 0, 0, 0 };
                        SBGC_cmd_trigger_data t = { 0, 0 };
                        //delay(3000);
                        // start AlexMos speed control
                        c.mode = SBGC_CONTROL_MODE_SPEED;
                        c.speedYAW = motor_speed * SBGC_SPEED_SCALE;
                        SBGC_sendCommand(SBGC_CMD_CONTROL, &c, sizeof(c));
                        gimbal_motor_init = 1;
                        //}
                        delay(1000);
                        digitalWrite(13, LOW);  // turn the LED on (HIGH is the voltage level)
                        delay(1000);              // wait for a second
                        //digitalWrite(13, HIGH);    // turn the LED off by making the voltage LOW
                        //delay(1000);              // wait for a second
                      }
                      
                      
                      
                      

                       

                      I’m using the Arduino IDE 1.6.6, image (from uname -a) Linux galileo 3.8.7-yocto-standard #1 Tue Sep 29 22:16:33 GMT 2015 i586 GNU/Linux. Also, be sure that on the Serial Monitor of the IDE you have selected the correct baud rate. Under these conditions I’m having the following as result.

                      serialAlexMOS.JPG

                      I haven’t been able to reproduce the issue you posted on Reply 4. Try with my conditions and run the code so we could see if there are improvements. Then we can start checking if it works if we use the SoftwareSerial library for the pins 2 and 3.

                      I don’t have the AlexMos controller to test the behavior you mentioned with the voltage, could you check if the voltage also drops while using the code above and the conditions mentioned.

                       

                      Regards,

                      Charlie

                      • 8. Re: AlexMos sketch works fine on Arduino Uno but not so with Galileo Gen2
                        RoboBill

                        Hi Charles,

                         

                        So that we're both on the same page, I downloaded the 1.6.6 and uname -a gives me;  Linux clanton 3.8.7-yocto-standard #1 Thu Oct 16 16:06:45 PDT 2014 i586 GNU/Linux.

                         

                        So yes I got the same Serial monitor data as you did on both the Uno and Galileo2.

                         

                        I then changed your sketch and directed the Serial output to Serial1 pin 0 & 1 on the Galileo and observed the scope pattern. With no power applied to the AlexMos board, the scope pattern looked "normal" like with the Uno. But when I powered up the AlexMos board, the pattern was as before 5 volts down to only 1.5 volts instead of down to 1/2 volt with the Uno.

                         

                        I think its an AlexMos problem so I put the same question on the AlexMos Basecam forum.

                         

                        Thanks

                         

                        RoboBill

                        • 9. Re: AlexMos sketch works fine on Arduino Uno but not so with Galileo Gen2
                          CMata_Intel

                          Hi RoboBill,

                           

                          I checked your thread in there and noticed that there isn’t a response yet. Try with their email support too: Support : BaseCam Electronics

                           

                          Regards,

                          Charlie

                          • 10. Re: AlexMos sketch works fine on Arduino Uno but not so with Galileo Gen2
                            RoboBill

                            Hi Charlie,

                             

                            Yes there hasn't been any response.   In addition to the AlexMos board, I also have another shield attached via I2C. Its from POZYX.IO. It too is unable to connect.

                             

                            Because I don't have the expertise to resolves these connectivity issues, I have switched over to a UNO/YUN and set aside the Galileo for now until my next project which will be way more IoT-ish and will not depend on any new shields or uncommon boards.

                             

                            Many thanks to you sir,

                             

                            RoboBill

                            • 11. Re: AlexMos sketch works fine on Arduino Uno but not so with Galileo Gen2
                              CMata_Intel

                              Hi RoboBill,

                               

                              It’s a shame that it didn’t work for you, I suggest you to also check the power input of the AlexMos board, when it is connected to the power supply there could be a drop in the current that may be causing the drops you have reported.

                              If you have a question or problem when you come back to Galileo, don’t hesitate to ask us and to open a new thread, we will be glad to help you.

                               

                              Regards,

                              Charlie