Controlling RC Servos Wirelessly Over UDP

Introduction: Controlling RC Servos Wirelessly Over UDP

About: Hi there, my name is Váradi, György [ˈɟørɟ], but you can call me Bodri. I like electronics, technology and building stuff.

In this project I want to use my iPhone to control RC servos. I'll use the accelerometer to control two servos over UDP connection. This is a Proof Of Concept project to verify that a connection between an iPhone and a peripheral can achieve high update rates (higher then BLE) using UDP.

Step 1: Parts List

Hardware

Software

Step 2: Hardware

The hardware setup is very simple. I use the D1 (pitch) and D2 (roll) output on the ESP8266 to control the RC servos respectively. The board is powered from a USB power bank. The RC servos are powered from the 5v and GND pin of the board.

Step 3: Software

The control app for the iPhone is written in Swift which connects to the ESP8266 controller board wirelessly and controls pitch and roll servos based on the iPhone motion data. The controller board creates a Wifi Access Point and listens for upcomming UDP packets which contains the servo position information as a stream of bytes with the following general format:

Servo index | Position MSB | Position LSB

The servo index is either 1 for pitch or 2 for roll. The servo position is calculated from the phone x, y tilt degrees and converted to microseconds between 1000 and 2000. The refresh rate is 20 milliseconds.

The app is using the new Network.framework to establish the UDP connection, so it is only running on iOS 12 and above.

This is a POC app to demostrate how easy to use UDP connection in iOS 12.To keep it simple the UDP packets are sent separately for pitch and roll.

Be the First to Share

    Recommendations

    • Battery Powered Contest

      Battery Powered Contest
    • Plywood Challenge

      Plywood Challenge
    • Plastic Contest

      Plastic Contest

    4 Discussions

    0
    TheGrandPoohbah
    TheGrandPoohbah

    Question 4 months ago on Introduction

    In your sample sketch, you write to the Servo using degrees in the setup and using microseconds in the loop. I can see that it works, but why are you passing microseconds from the iPhone app instead of degrees?

    0
    bodri72
    bodri72

    Reply 4 months ago

    There's no any particular reason for that. You need microseconds for the PWM to control the servos, but indeed you can also make the translation on the other side.

    0
    TheGrandPoohbah
    TheGrandPoohbah

    Reply 4 months ago

    That was a very clever use of constraints to control the "float" of the joystick view. I learned something from that too. Thanks. Please share any other iOS Xcode projects that interface with Arduino/esp8266 devices. You write nice, clean, easy to read code.

    0
    DIY Hacks and How Tos

    Great Arduino tutorial. Thanks for sharing with the community.