Results 1 to 2 of 2

Thread: Wemos d1 mini servo controller

  1. #1
    Join Date
    Oct 2014
    Location
    Cleethorpes, England
    Posts
    62
    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:
    #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[] = "12345678";  // replace with your SSID.
    const char passphrase[] = "abcdefghij"; // 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(4); // D2
      ch_1_green_Servo_2.attach(5); // D1
      ch_1_blue_Servo_3.attach(12); // D6
      ch_2_red_Servo_4.attach(13); // D7
      ch_2_green_Servo_5.attach(14); // D5
      ch_2_blue_Servo_6.attach(15); // D8
    
    
       // 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
        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) 
        ch_1_red_Servo_1.write(val1);        //(Change the 90 to 0 and the 45 to 180 will use full motion of servo) .        
                                    
        //Servo2
        val2 = e131.data[ch_1_green];
        val2 = map(val2, 0, 255, 90, 45);    
        ch_1_green_Servo_2.write(val2);
        
        //Servo3
        val3 = e131.data[ch_1_blue];
        val3 = map(val3, 0, 255, 90, 45);     
        ch_1_blue_Servo_3.write(val3);
        
        //Servo4
        val4 = e131.data[ch_2_red];                  
        val4 = map(val4, 0, 255, 90, 45);    
        ch_2_red_Servo_4.write(val4);                   
                                    
        //Servo5
        val5 = e131.data[ch_2_green];
        val5 = map(val5, 0, 255, 90, 45);    
        ch_2_green_Servo_5.write(val5);
        
        //Servo6
        val6 = e131.data[ch_2_blue];
        val6 = map(val6, 0, 255, 90, 45);     
        ch_2_blue_Servo_6.write(val6);
        
       
        
       }
    }

  2. #2
    Join Date
    Feb 2009
    Location
    Plymouth, MN
    Posts
    9,339
    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.

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
  •