Author Topic: Arduino (NodeMCU/Wemos) Servo Setup  (Read 693 times)

Offline theblacksheep

  • Newbie
  • *
  • Posts: 6
    • View Profile
Arduino (NodeMCU/Wemos) Servo Setup
« on: May 08, 2020, 01:36:57 AM »
First of all apologies for my ignorance...

I'm trying to work out how to setup a simple ESP8266/ESP32 based servo prop in xLights and effectively test it.

I have built a simple test rig for a single servo connected directly to a GPIO port (i.e. not through a PWM device - although I am planning to expand this up later) and included the E1.31 library but couldn't work out the equivalent xLights setup and the corresponding decoding on the E1.31 side to receive the data which I can then use to set the servo angle using the standard Arduino servo library.

I'm receiving E1.31 data through but the terminology is a bit alien and I really don't know how to set the relevant configuration values in xLights. 

I've currently ditched the servo and I'm just using the standard test .ino from the github forkineye e1.31 site but really confused about how to setup the device/layout for a servo/custom device. What do I need to set and if I added a PCA9685 to go to 16 servo's what would that also look like in xLights? 

Any help would be most appreciated.

The Black Sheep
 
 

   
« Last Edit: May 08, 2020, 02:49:49 AM by theblacksheep »

Offline Gilrock

  • Supporting Member
  • Hero Member
  • *
  • Posts: 6946
    • View Profile
Re: Arduino (NodeMCU/Wemos) Servo Setup
« Reply #1 on: May 11, 2020, 01:56:05 PM »
As soon as you say "servo" its not "simple".  Start with the DMXServo model if you haven't seen it.

Offline dkulp

  • Supporting Member
  • Hero Member
  • *
  • Posts: 812
    • View Profile
Re: Arduino (NodeMCU/Wemos) Servo Setup
« Reply #2 on: May 11, 2020, 04:58:59 PM »
If you want to use the PCA9685, you may want to grab a RaspberryPi and install FPP on it and use that as a starting point.   The PCA9685 can be hooked up to the Pi via the I2C pins and FPP has a output driver for it built in.   
Daniel Kulp
Framingham, MA

Offline theblacksheep

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Arduino (NodeMCU/Wemos) Servo Setup
« Reply #3 on: May 24, 2020, 09:52:33 AM »
ok after a bit of experimentation I've got something working - thought it might be worth documenting here in case anyone else finds this useful.

this is the code for the NodeMCU/Wemos - I'm using VSCode/PlatformIO but should work just as well as an INO file in the Arduino IDE.

Code: [Select]
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

#include <ESP8266WiFi.h>
#include <E131.h>

const char ssid[] = "xxxxxx";         /* Replace with your SSID */
const char passphrase[] = "xxxxxxxxxx";   /* Replace with your WPA2 passphrase */

E131 e131;

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

// Depending on your servo make, the pulse width min and max may vary, you
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you
// have!
#define SERVOMIN  125 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  575 // this is the 'maximum' pulse length count (out of 4096)

uint8_t max_servos = 16;

void setup() {
    Serial.begin(115200);
    delay(10);
    Serial.println("16 channel Servo test!");

    e131.begin(ssid, passphrase);               

    pwm.begin();
 
    pwm.setPWMFreq(60); 
}

void loop() {

    uint16_t num_channels = e131.parsePacket();
   
    /* Process channel data if we have it */
    if (num_channels) {

        //Serial.printf("P:%u - ", e131.stats.num_packets);
        for (size_t servonum = 0; servonum < max_servos; servonum++) {
            int value = e131.data[servonum];
            int pulse = map(value, 1, 255, SERVOMIN, SERVOMAX);
            Serial.printf("%hd->%hd ", servonum, value );
            //Serial.printf("%hd->%hd:%u ", servonum, value, pulse );
            if (value > 0) {
                pwm.setPWM(servonum, 0, pulse );
            }
        }

        Serial.printf("\n");
        yield();

    }
 
}


There are 16 servo's connected to a PCA9685 with separate PSU and the NodeMCU supplies the servo position from the value in the E1.31 packet.

Chris

Offline theblacksheep

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Arduino (NodeMCU/Wemos) Servo Setup
« Reply #4 on: May 24, 2020, 09:55:29 AM »
In xLights this is my servo setup on the controller tab;

Offline theblacksheep

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Arduino (NodeMCU/Wemos) Servo Setup
« Reply #5 on: May 24, 2020, 09:59:04 AM »
This is the Layout tab with servo 2 opened;

Offline theblacksheep

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Arduino (NodeMCU/Wemos) Servo Setup
« Reply #6 on: May 24, 2020, 10:29:44 AM »
This is a basic show test for servo's 1,2 and 5 - servo 2 has a decaying sine wave on one of the steps.

Everything looks to be working as far as I can gather but just wanted to check that I have things setup correctly in xLights...

A couple of questions;

1. I'm running the Debian/Ubuntu version of xLights (it works well) but cant seem to get it to re-render (recreate) all the devices in a sequence if I add them after creating  - once I've created a sequence based on an audio but then go back and add add another device on the layout tab (say going back and adding servo 4) it doesn't show as available (I've clicked the "Render All" button) on the Sequence timeline is there something I'm missing i.e. I have to re-create the whole sequence again, does this work fine on Windows?

2. On the sequencer, I've added the devices as "Servos" in Layout as DMX -> Servo - these are 8 bit so I've adjusted the settings accordingly.  If you look at the Arduino code I'm doing a simple map of the value (1..255 with 0 being off) to the relevant pulse width range.  On the Sequencer when you add the servo adjustment frame to the timeline - i.e. where you set the value/position - the editable "Value" is a percentage (0..100) rather than a DMX value (0..255) - and the value that is sent is actually 0..255.

If you add as a native DMX device it does show as 0..255 - I've attached a couple of screenshots and highlighted the relevant editable options to show what I mean - the servo option looks neater but they both work. 

Chris

Offline keithsw1111

  • Administrator
  • Hero Member
  • *****
  • Posts: 2733
    • View Profile
    • Kellyville Christmas Lights
Re: Arduino (NodeMCU/Wemos) Servo Setup
« Reply #7 on: May 24, 2020, 12:06:48 PM »
New props don?t add automatically to existing sequences. You need to add them via the display elements panel which you access by right clicking on the row heading in the sequencer tab.

Offline theblacksheep

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Arduino (NodeMCU/Wemos) Servo Setup
« Reply #8 on: May 24, 2020, 12:33:38 PM »
Thanks Keith - I can see how to add it now.