RCKit
RCRxESP8266.ino

Receives RCOIP commmands from the built-in WiFi device on an ESP8266 and uses them to set servo and digital outputs. This simple example handles 5 RCOIP receiver channels. Its configured like this: 4 Servos (receiver channels 0, 1, 2, 3) 1 Digital output (horn) (receiver channel 4)

// RCRxESP8266
//
// Sample RCRx RCOIP receiver
// Receives RCOIP commmands on an ESP8266 device and uses them to set servo
// and digital outputs.
//
// This simple example handles 5 RCOIP receiver channels. Its configured like this:
// 4 Servos (receiver channels 0, 1, 2, 3)
// 1 Digital output (horn) (receiver channel 4)
// which is consistent with the default setup of the RCTx iPhone app.
//
// However, almost any combination of up to a large number of channels can be used as you see fit.
// Output devices supported are:
// analog output pins
// digital output pins
// Servo
// AccelStepper speed
// AccelStepper position
// HBridge to drive 2 other outputs
//
// Also you can string varies objects together top modify channel values as
// they make their way from the receiver to an output:
// Limiter
// Inverter
// This can be used off the shelf with the RCTx transmitter app for iPhone
// dont forget to set the destination IP address in the RCTx transmitter app profile
//
// Copyright (C) 2018 Mike McCauley
#include <ESP8266Transceiver.h>
#include <RCRx.h>
#include <Servo.h>
#include <ServoSetter.h>
#include <AnalogSetter.h>
#include <DigitalSetter.h>
#include <AccelStepper.h>
// Declare the receiver object. It will handle messages received from the
// transceiver and turn them into channel outputs.
// The receiver and transceiver obects are connected together during setup()
RCRx rcrx;
// Declare the transceiver object, in this case the built-in ESP8266 WiFi
// transceiver.
// Note: other type of transceiver are supported by RCRx
// It will create a WiFi Access Point with SSID of "RCArduino", that you can connect to with the
// password "xyzzyxyzzy"
// on channel 1
// The default IP address of this transceiver is 192.168.4.1/24 port 9048
// These defaults can be changed by editing ESP8266Transceiver.cpp
// The reported RSSI is in dBm above -60dBm
// If you are using the RCTx transmitter app for iPhone
// dont forget to set the destination IP address in the RCTx transmitter app profile
// (the defaults of 192.168.4.1 and port 9048 will work with the defaults in this sketch)
ESP8266Transceiver transceiver;
// Definitions for the ESP8266 output pins we want to use to control our devices
// The battery voltage is measured on the ESP8266 ADC pin
#define HORN_PIN 12
#define NUM_OUTPUTS 5
#define SERVO_0_PIN 13
#define SERVO_1_PIN 14
#define SERVO_2_PIN 15
#define SERVO_3_PIN 16
// There are 5 outputs for 5 channels:
// 4 Servos (receiver channels 0, 1, 2, 3)
// 1 Digital output (horn) (receiver channel 4)
// These are the low level Servo drivers
#define NUM_SERVOS 4
Servo servos[NUM_SERVOS];
// These Setter set the output value onto a Servo
ServoSetter servoSetter0(&servos[0]);
ServoSetter servoSetter1(&servos[1]);
ServoSetter servoSetter2(&servos[2]);
ServoSetter servoSetter3(&servos[3]);
// This setter sets a digital output
DigitalSetter horn(HORN_PIN);
// This array of all the outputs is in channel-number-order so RCRx knows which
// Setter to call for each channel received. We define an array of 5 Setters for receiver channels 0 through 4
Setter* outputs[NUM_OUTPUTS] = {&servoSetter0, &servoSetter1, &servoSetter2, &servoSetter3, &horn};
void setup()
{
Serial.begin(9600);
while (!Serial)
;
// Ensure we can output on the horn digital pin
pinMode(HORN_PIN, OUTPUT);
// Attach the Servo drivers to the servo output pins
servos[0].attach(SERVO_0_PIN);
servos[1].attach(SERVO_1_PIN);
servos[2].attach(SERVO_2_PIN);
servos[3].attach(SERVO_3_PIN);
// Tell the receiver where to send the 5 channels
rcrx.setOutputs((Setter**)&outputs, NUM_OUTPUTS);
// Join the transceiver and the RCRx receiver object together
rcrx.setTransceiver(&transceiver);
// Initialise the receiver and transceiver
rcrx.init();
}
void loop()
{
// And do it
rcrx.run();
}