Results 1 to 7 of 7

Thread: Need Some Help Guys

  1. #1
    Join Date
    Jan 2018
    Location
    North Wales, United Kingdom
    Posts
    44
    Post Thanks / Like

    Default Need Some Help Guys

    Hi Guys

    back on my setup again, just received my dirkcheap817's made up! and built. now comes the weird part i have to alter my code to be output high and you guessed im struggling.

    I'll post my code below, i have a few questions. Firstly i dont need the softpwm in anymore do i as the 817's will do the fade for me or am i wrong?
    plus how do i alter the outputs from low to high, keep in mind it only has to be altered on channel 2 to 11 and not c11-15

    code as follows
    Code:
    #include <SoftPWM.h>
    #include <SoftPWM_timer.h>
    #include <Wire.h>
    #include <Adafruit_PWMServoDriver.h>
    Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
    
    
    int C11 = 00;
    int C12 = 01;
    int C13 = 02;
    int C14 = 03;
    int C15 = 04;
    
    #define M_NUMBER_OF_DATA_BYTES 15
    static const char Header[4] = "Andy";
    
    // index into the Header indicating the next expected byte
    int HeaderIndex = 0;
    
    // Allocate space to hold received data for easy access
    int incomingByte[M_NUMBER_OF_DATA_BYTES + 1];
    
    #define SERVOMIN  150 
    #define SERVOMAX  600 
    
    void setup()
    {
      Serial.begin(57600);
      Wire.beginTransmission(0x40);
      Wire.begin();
      
      pwm.begin();
      pwm.setPWMFreq(490);
      
      uint8_t twbrbackup = TWBR;
      
      TWBR = 12;
      SoftPWMBegin();
      SoftPWMSet(2, 255);
      SoftPWMSet(3, 255);
      SoftPWMSet(4, 255);
      SoftPWMSet(5, 255);
      SoftPWMSet(6, 255);
      SoftPWMSet(7, 255);
      SoftPWMSet(8, 255);
      SoftPWMSet(9, 255);
      SoftPWMSet(10, 255);
      SoftPWMSet(11, 255);
      pwm.setPWM(C11, 0, 0);
      pwm.setPWM(C12, 0, 0);
      pwm.setPWM(C13, 0, 0);
      pwm.setPWM(C14, 0, 0);
      pwm.setPWM(C15, 0, 0);
    } // setup
    
    
    void loop()
    {
      // check to see if we have the minimum number of expected data in the input buffer
      if (Serial.available() >= M_NUMBER_OF_DATA_BYTES ) 
      {
        // has the entire header been processed?
        if( sizeof(Header) <= HeaderIndex )
        {
          // header is complete. That means the rest of the bytes are channel data
    
          // read in the data into a holding buffer
          for (int i=0; i <= M_NUMBER_OF_DATA_BYTES ; i++)
          {
            // read in a single channel and stroe it in a local buffer
            incomingByte[i] = Serial.read();
          }
        
          // output the data to the PWM generator
          SoftPWMSet(2, incomingByte[0]);
          SoftPWMSet(3, incomingByte[1]);
          SoftPWMSet(4, incomingByte[2]);
          SoftPWMSet(5, incomingByte[3]);
          SoftPWMSet(6, incomingByte[4]);
          SoftPWMSet(7, incomingByte[5]);
          SoftPWMSet(8, incomingByte[6]);
          SoftPWMSet(9, incomingByte[7]);
          SoftPWMSet(10, incomingByte[8]);
          SoftPWMSet(11, incomingByte[9]);
          pwm.setPWM(C11, 0, incomingByte[10]*16.05882352941176);
          pwm.setPWM(C12, 0, incomingByte[11]*16.05882352941176);
          pwm.setPWM(C13, 0, incomingByte[12]*16.05882352941176);
          pwm.setPWM(C14, 0, incomingByte[13]*16.05882352941176);
          pwm.setPWM(C15, 0, incomingByte[14]*16.05882352941176);
    
          // start looking for the next header
          HeaderIndex = 0;
    
        } // end process data after header was reveived
    
        // else lets see if the data has the correct header
        else if( Header[HeaderIndex] == Serial.read())
        {
            // This IS the expected header byte. Move to the next header byte
            HeaderIndex++;
    
        } // end header match
        else // opps, there is a problem
        {
            // This is NOT the expected header byte. Start waiting for the begining of the header
            HeaderIndex = 0;
    
        } // end header miss-match
      } // End there was enough data in the buffer to process
    } // loop

  2. #2
    Join Date
    Jan 2018
    Location
    North Wales, United Kingdom
    Posts
    44
    Post Thanks / Like

    Default Re: Need Some Help Guys

    a change to my code keeping the softpwm in works but doesnt completely shut off the lights do i need to add a section to state i have a zero cross circuit
    modded code as follows


    [CODE]#include <SoftPWM.h>
    #include <SoftPWM_timer.h>
    #include <Wire.h>
    #include <Adafruit_PWMServoDriver.h>
    Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();


    int C11 = 00;
    int C12 = 01;
    int C13 = 02;
    int C14 = 03;
    int C15 = 04;

    #define M_NUMBER_OF_DATA_BYTES 15
    static const char Header[4] = "Andy";

    // index into the Header indicating the next expected byte
    int HeaderIndex = 0;

    // Allocate space to hold received data for easy access
    int incomingByte[M_NUMBER_OF_DATA_BYTES + 1];

    #define SERVOMIN 150
    #define SERVOMAX 600

    void setup()
    {
    Serial.begin(57600);
    Wire.beginTransmission(0x40);
    Wire.begin();

    pwm.begin();
    pwm.setPWMFreq(490);

    uint8_t twbrbackup = TWBR;

    TWBR = 12;
    SoftPWMBegin();
    SoftPWMSet(2, 0);
    SoftPWMSet(3, 0);
    SoftPWMSet(4, 0);
    SoftPWMSet(5, 0);
    SoftPWMSet(6, 0);
    SoftPWMSet(7, 0);
    SoftPWMSet(8, 0);
    SoftPWMSet(9, 0);
    SoftPWMSet(10, 0);
    SoftPWMSet(11, 0);
    pwm.setPWM(C11, 0, 0);
    pwm.setPWM(C12, 0, 0);
    pwm.setPWM(C13, 0, 0);
    pwm.setPWM(C14, 0, 0);
    pwm.setPWM(C15, 0, 0);
    } // setup


    void loop()
    {
    // check to see if we have the minimum number of expected data in the input buffer
    if (Serial.available() >= M_NUMBER_OF_DATA_BYTES )
    {
    // has the entire header been processed?
    if( sizeof(Header) <= HeaderIndex )
    {
    // header is complete. That means the rest of the bytes are channel data

    // read in the data into a holding buffer
    for (int i=0; i <= M_NUMBER_OF_DATA_BYTES ; i++)
    {
    // read in a single channel and stroe it in a local buffer
    incomingByte[i] = Serial.read();
    }

    // output the data to the PWM generator
    SoftPWMSet(2,( 255 - incomingByte[0]));
    SoftPWMSet(3, ( 255 - incomingByte[1]));
    SoftPWMSet(4, ( 255 - incomingByte[2]));
    SoftPWMSet(5, ( 255 - incomingByte[3]));
    SoftPWMSet(6, ( 255 - incomingByte[4]));
    SoftPWMSet(7, ( 255 - incomingByte[5]));
    SoftPWMSet(8, ( 255 - incomingByte[6]));
    SoftPWMSet(9, ( 255 - incomingByte[7]));
    SoftPWMSet(10, ( 255 - incomingByte[8]));
    SoftPWMSet(11, ( 255 - incomingByte[9]));
    pwm.setPWM(C11, 0, incomingByte[10]*16.05882352941176);
    pwm.setPWM(C12, 0, incomingByte[11]*16.05882352941176);
    pwm.setPWM(C13, 0, incomingByte[12]*16.05882352941176);
    pwm.setPWM(C14, 0, incomingByte[13]*16.05882352941176);
    pwm.setPWM(C15, 0, incomingByte[14]*16.05882352941176);

    // start looking for the next header
    HeaderIndex = 0;

    } // end process data after header was reveived

    // else lets see if the data has the correct header
    else if( Header[HeaderIndex] == Serial.read())
    {
    // This IS the expected header byte. Move to the next header byte
    HeaderIndex++;

    } // end header match
    else // opps, there is a problem
    {
    // This is NOT the expected header byte. Start waiting for the begining of the header
    HeaderIndex = 0;

    } // end header miss-match
    } // End there was enough data in the buffer to process
    } // loop[CODE]

  3. #3
    Join Date
    Dec 2012
    Location
    Hudson MA
    Posts
    2,764
    Post Thanks / Like

    Default Re: Need Some Help Guys

    What is 16..... And why are you using it as a multiplier?


    2018 - Moving and going to visit my Daughter in New Zealand. Most likely I will be dark or nearly dark, Some static stuff that is simple to put up.

  4. #4
    Join Date
    Jan 2018
    Location
    North Wales, United Kingdom
    Posts
    44
    Post Thanks / Like

    Default Re: Need Some Help Guys

    The 16 is conversion factor as those 5 channels C11 to C15 are for my servos

  5. #5
    Join Date
    Dec 2012
    Location
    Hudson MA
    Posts
    2,764
    Post Thanks / Like

    Default Re: Need Some Help Guys

    ok. One issue is that when you multiply an integer times a floating point number, the result is left in floating point format. You should explicitly convert it back to an integer (which is what the call to PWM is expecting). I am surprised the compiler did not give a warning about an implicit conversion.


    2018 - Moving and going to visit my Daughter in New Zealand. Most likely I will be dark or nearly dark, Some static stuff that is simple to put up.

  6. #6
    Join Date
    Jan 2018
    Location
    North Wales, United Kingdom
    Posts
    44
    Post Thanks / Like

    Default Re: Need Some Help Guys

    found out its the softpwm thats giving me the voltage leak any ideas anyone on how to stop it?

  7. #7
    Join Date
    Jan 2018
    Location
    North Wales, United Kingdom
    Posts
    44
    Post Thanks / Like

    Default Re: Need Some Help Guys

    just as a heads up guys, i changed from an uno to a mega as it gave me more pwm ports, everything now works a treat. if anyone would like the code or direction give me a shoud and im happy to pass on my solutions

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •