Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Wemos d1 mini servo controller

  1. #1
    Join Date
    Oct 2014
    Location
    Cleethorpes, England
    Posts
    75
    Post Thanks / Like

    Default Wemos d1 mini servo controller

    Hi everyone ive been a member for a few years now and most of my knowlegde came from the people here
    I found a piece code a few years ago to control servos with a arduino uno via generic serial and it worked a treat

    https://www.instructables.com/Talking-Pumpkins/

    but eventually i wanted to make it wireless, initially i used a pi running fpp and asked a lot of questions in the forum
    read a few thousand post and picked a lot of brains

    Then i came across this post

    http://doityourselfchristmas.com/for...rvo-Controller

    and "Zero9r" posted the code he had been working on for the Wemos d1 mini
    the code worked well but didnt give me the control i had before so i tried to understand how his code worked
    i started by removing the bits i didnt understand, ok i was left with a blank page but eventually i put my code
    on 1 side of my screen and his on the other and started swapping from one to the other, after a bit of trial and a lot
    of error it worked yeah! so i thought its about time i paid something back for all that i have taken from this forum

    If it helps some thats great i can relax for another couple of years

    Thanks qubie


    Code:
    // Wemos D1 Mini E1.31 - 6 channel Servo Controller - modded by Qubie
    // Thanks to Doityourselfchristmas.com
    #include <ESP8266WiFi.h>
    #include <E131.h> // Copyright (c) 2015 Shelby Merrick http://www.forkineye.com
    #include <Servo.h> 
    
    Servo ch_1_red_Servo_1;
    Servo ch_1_green_Servo_2;
    Servo ch_1_blue_Servo_3;
    Servo ch_2_red_Servo_4;
    Servo ch_2_green_Servo_5;
    Servo ch_2_blue_Servo_6;
    
    
    // ***** USER SETUP STUFF *****
    const char ssid[] = "aaaaaaaaa";  // replace with your SSID.
    const char passphrase[] = "111111111111"; // replace with your PASSWORD.
    const int universe = 1; // this sets the universe number you are using.
    
    // this sets the Universe channel number used by the output.
    const int ch_1_red = 0; // the channel number to link to output 1 red.
    const int ch_1_green = 1; // the channel number to link to output 1 green.
    const int ch_1_blue = 2; // the channel number to link to output 1 blue.
    const int ch_2_red = 3; // the channel number to link to output 2 red.
    const int ch_2_green = 4; // the channel number to link to output 2 green.
    const int ch_2_blue = 5; // the channel number to link to output 2 blue.
    
    
    int val1;
    int val2;
    int val3;
    int val4;
    int val5;
    int val6;
    
    E131 e131;
    
    void setup(){
      Serial.begin(115200);
      ch_1_red_Servo_1.attach(14); // D5
      ch_1_green_Servo_2.attach(12); // D6
      ch_1_blue_Servo_3.attach(13); // D7
      ch_2_red_Servo_4.attach(15); // D8
      ch_2_green_Servo_5.attach(5); // D1
      ch_2_blue_Servo_6.attach(4); // D2
     
    
       // set the servos to Mid point 
      ch_1_red_Servo_1.write(90);
      ch_1_green_Servo_2.write(90);
      ch_1_blue_Servo_3.write(90);
      ch_2_red_Servo_4.write(90);
      ch_2_green_Servo_5.write(90);
      ch_2_blue_Servo_6.write(90);
    
    
        /* Choose one to begin listening for E1.31 data */
       e131.begin(ssid, passphrase);               /* via Unicast on the default port */
       //e131.beginMulticast(ssid, passphrase, universe); /* via Multicast for Universe 1 */
    
    }
    
    void loop() {
      /* Parse a packet */
      uint16_t num_channels = e131.parsePacket();
    
      /* Process channel data if we have it */
      if (num_channels) {
      Serial.println("we have data");
    
        Serial.println(e131.data[ch_1_red]);
        Serial.println(e131.data[ch_1_green]);
        Serial.println(e131.data[ch_1_blue]);
        Serial.println(e131.data[ch_2_red]);    
        Serial.println(e131.data[ch_2_green]);
        Serial.println(e131.data[ch_2_blue]);
    
        
        
        
        //Servo1 Jaw1
        val1 = e131.data[ch_1_red];                  
        val1 = map(val1, 0, 255, 90, 45);    //(maps incoming data 0-255 to servo, start at 90 move to 45, swap these 2 numbers around will change direction of servo) 
        if (e131.data[ch_1_red] == 0){ch_1_red_Servo_1.write(90);}
        else {ch_1_red_Servo_1.write(val1);  }      //(Change the 90 to 0 and the 45 to 180 will use full motion of servo) .        
                                    
        //Servo2 Pan1
        val2 = e131.data[ch_1_green];
        val2 = map(val2, 0, 255, 20, 160);    //Change the last number according to how far you want the servo to open.
        if (e131.data[ch_1_green] == 0){ch_1_green_Servo_2.write(90);}
        else {ch_1_green_Servo_2.write(val2);}
        
        //Servo3 Jaw2
        val3 = e131.data[ch_1_blue];
        val3 = map(val3, 0, 255, 90, 45);     //Change the last number according to how far you want the servo to open.
        if (e131.data[ch_1_blue] == 0){ch_1_blue_Servo_3.write(90);}
        else {ch_1_blue_Servo_3.write(val3);}
        
        //Servo4 Pan2
        val4 = e131.data[ch_2_red];                  
        val4 = map(val4, 0, 255, 20, 160);    //Change the last number according to how far you want the servo to open.
        if (e131.data[ch_2_red] == 0){ch_2_red_Servo_4.write(90);}
        else {ch_2_red_Servo_4.write(val4);}                   
                                    
        //Servo5 Jaw3
        val5 = e131.data[ch_2_green];
        val5 = map(val5, 0, 255, 90, 45);    //Change the last number according to how far you want the servo to open.
        if (e131.data[ch_2_green] == 0){ch_2_green_Servo_5.write(90);}
        else {ch_2_green_Servo_5.write(val5);}
        
        //Servo6 Pan3
        val6 = e131.data[ch_2_blue];
        val6 = map(val6, 0, 255, 20, 160);     //Change the last number according to how far you want the servo to open.
        if (e131.data[ch_2_blue] == 0){ch_2_blue_Servo_6.write(90);}
        else {ch_2_blue_Servo_6.write(val6);}
        
       
        
       }
    }]
    Last edited by qubie; 06-25-2021 at 04:11 AM.

  2. #2
    Join Date
    Feb 2009
    Location
    Plymouth, MN
    Posts
    9,362
    Post Thanks / Like

    Default Re: Wemos d1 mini servo controller

    Nice job, thanks!

    http://digwdf.org/store/
    Even though the DIGWDF Store has been closed for two years, it's still awesome!
    User guides, documentation and other files are still free and available for downloading.

  3. #3
    Join Date
    Oct 2014
    Location
    Cleethorpes, England
    Posts
    75
    Post Thanks / Like

    Default Re: Wemos d1 mini servo controller

    Hi everyone thought i would post a little update
    1st thanks Dirknerkle for your nice comments

    ok so i built myself a little test rig using a Wemos D1 mini, 6 servos and a cardboard box, ok so the box was not a good idea as it amplified the sound of the servos but one thing i realized from being a part of this community is we make do with what we have.

    The software for the D1 is part mine part taken from the internet and part from Zero9r with a lot of tweeking and head scratching
    ive done a few songs (8) so far, some for halloween and some just for fun.
    only thing i need to do now is learn how to make puppets rather than just using skulls and skeletons

    i would like some CC so i will put a couple of youtube links just see what you think

    many thanks

    Twilight Zone intro
    https://youtu.be/E4RtBFHGGvg

    Haunted Rave by Gary and the ghouls
    https://youtu.be/Q0LHCmjlHlc

    Run araound Sue by Human Nature
    https://youtu.be/4I0BLGxcUV0

    Christmas by Human Nature
    https://youtu.be/hCyaLq-x0R8
    Last edited by qubie; 06-20-2021 at 01:34 PM.

  4. #4
    Join Date
    Dec 2020
    Posts
    9
    Post Thanks / Like

    Default Re: Wemos d1 mini servo controller

    Way cool. Great job....

  5. #5
    Join Date
    Mar 2012
    Location
    Lebanon, Illinois, USA
    Posts
    3,076
    Post Thanks / Like

    Default Re: Wemos d1 mini servo controller

    OK now, you have my attention! Nice.
    Live, Laugh, Love.

  6. #6
    Join Date
    Dec 2007
    Location
    Jacksonville, FL
    Posts
    513
    Post Thanks / Like

    Default Re: Wemos d1 mini servo controller

    Great job! I have a few old serial controllers from Pololu that I haven't used in years. Bought the Pixel2Things server controller this year. This wireless solution also looks good.

  7. #7
    Join Date
    Oct 2009
    Location
    Vancouver BC
    Posts
    61
    Post Thanks / Like

    Default Re: Wemos d1 mini servo controller

    That looks wonderful..
    I'd love to see how you have used xLights to program the servo movement..
    I have used Visual Show Animation (VSA) for some animatronics but have never found an easy way to create servo sequences in xLights..
    Two things in VSA that help considerably with programming sequences are:
    1) Wave Motion Analysis - Lets you setup a servo channel to follow the audio track (with various adjustments)to create jaw movement
    2) Capture Events - Lets you record servo movement from a joystick while the track plays

    I haven't found an easy way to do the above with xLights

  8. #8
    Join Date
    Oct 2014
    Location
    Cleethorpes, England
    Posts
    75
    Post Thanks / Like

    Default Re: Wemos d1 mini servo controller

    Hi packetbob
    you are correct there is no easy way to do this in xLights but that is probably due to the way my D1 works, its set to react to red green and blue channel so conventional servo functions dont work as well. its not perfect but i have been using it for about 4 years now and yes it is very time consuming because every servo movement is put in manually.
    "sorry to disappoint you" but that allows me to be more accurate with the timings of each movement, i have tried other controllers but i dont seem to get the level of control that i like.
    Models in xLights are setup as 1 string with 1 node in 1 coulour ie R G or B
    Sequencing i use the ON effect and change the start and end intensity 100 start - 0 end opens the jaw quickly and closes slowly then adjust the length for how long you want it to take before it is fully closed.
    The Pan channel is a bit different because the servo starts at 90% ie skull facing forward the effect start at 50 and if you end at 70 ste skull turns 20% left, if you went to 30 it would turn 20% to the right then you need the effect to be start 20 end 20 and the skull will remain looking that direction until the next effect start 20 end 50
    It is very laborious but thats the way i like it, its got to be as perfect as i can get it.
    Models.jpgSequence1.jpgSequence2.jpg

  9. #9
    Join Date
    Oct 2014
    Location
    Cleethorpes, England
    Posts
    75
    Post Thanks / Like

    Default Re: Wemos d1 mini servo controller

    Updated D1 Code in 1st post

  10. #10
    Join Date
    Dec 2011
    Posts
    7,092
    Post Thanks / Like

    Default Re: Wemos d1 mini servo controller

    This looks like a fun thread just wish there was some free time to play with servos .

    Is Xlights capable of discrete pixel level sequencing ?

Page 1 of 2 12 LastLast

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
  •