Author Topic: Remote Servo Control  (Read 14036 times)

bstott

  • Newbie
  • *
  • Posts: 37
Re: Remote Servo Control
« Reply #15 on: September 12, 2013, 09:57:05 PM »
OK IT IS Real because - Here is the obligatory Youtube video link as proof that the wireless Moteino servo project works - http://youtu.be/-AFmAWcR1cc

Below is the code for a single servo. Just edit to double, triple or ??? the instances for the devices.

Thanks again Alex for the great inexpensive product, involved code examples, good information on the web site, and the access to imagination. I am now an old but, burgeoning new 'C' Programmer of wireless embedded systems.

Transmitter Code
Code: [Select]
 /* Wirelessly transmit Potentiometer signals via an RFM69HW enabled Moteino connection.
 
Referenced & using example code, logic, format from:
 * https://github.com/LowPowerLab/RFM69/tree/master/Examples
   Lowpowerlab.com RFM69 examples: Node & Struct_send by Felix Rusu
 * http://www.instructables.com/id/Arduino-2-Servos-Thumbstick-joystick/step4/The-Code/
   by Biomech75 2012
 * http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
   code by David A. Mellis 2005; modified by Paul Stoffregen 8 Feb 2010
 * http://www.jeremyblum.com/2011/02/27/arduino-tutorial-9-wireless-communication/
   code by Jeremy Blum
 * http://forum.arduino.cc/index.php?PHPSESSID=jts7bh8gq4mos865mb4kbsi4l0&topic=151699.15
   code examples within forum string by 'ashh'
 * Credit for RFM12B code from Glyn Hudson openenergymonitor.org GNU GPL V3 12/4/12
 * Credit to JCW from Jeelabs.org for RFM12 by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
 * http://forum.arduino.cc/index.php/topic,154463.0.html

 This example code is in the public domain.

 B.Stott 2013
 */

#include <RFM69.h>
#include <RFM69registers.h>
#include <SPI.h>
#include <SPIFlash.h>

#define NODEID      99
#define NETWORKID   100
#define GATEWAYID   1
#define FREQUENCY   RF69_915MHZ //Match this with the version of your Moteino! (others: RF69_433MHZ, RF69_868MHZ)
#define KEY         "thisIsEncryptKey" //has to be same 16 characters/bytes on all nodes, not more not less!
#define LED         9
#define SERIAL_BAUD 9600
//#define ACK_TIME    30  // # of ms to wait for an ack ---- Not Currently Used.

// Ack will not be used. This is a streaming application. If a packet is lost the next servo position data
// will be accurate enough to update and move the servo.

SPIFlash flash(8, 0xEF30);                           //EF40 for 16mbit windbond chip
RFM69 radio;                                         // initiate radio object
   
 int potpin0 = 0;                                    // analog pin used to connect the potentiometer
 int val0 = 0;                                       // variable initialized for storing potpin0 value

 typedef struct
 {
   int           Pot_0;                              //create transmit variable & store data potentiometer 0 data
 } Payload;
 Payload theData;                                    // create transmission package 'theData'.

void setup()
{
  Serial.begin(SERIAL_BAUD);
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
  radio.setHighPower();                              //uncomment only for RFM69HW!
  radio.encrypt(KEY);
  char buff[50];
  sprintf(buff, "\nTransmitting at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
  Serial.println(buff);                             // Output to serial operating frequency of transceiver       
 
  if (flash.initialize())
    Serial.println("SPI Flash Init OK!");          // Output to serial regarding status if Flash memory exists.
  else
    Serial.println("SPI Flash Init FAIL! (is chip present?)");
}

void loop()
{
 // Output to serial some communications information - Data length, RSSI
    for (byte i = 0; i < radio.DATALEN; i++)
    Serial.print((char)radio.DATA[i]);
    Serial.print("   [RX_RSSI:");Serial.print(radio.readRSSI());Serial.print("]");
    Serial.println();

 // translate Pot rotation to Servo position.   
    theData.Pot_0 = map(analogRead(potpin0), 0, 1023, 0, 179);                                              // assign servo position to transmit packet variable.
 
 // Transmit payload - theData
    radio.send(GATEWAYID, (const void*)(&theData), sizeof(theData));   // transmit data to other end
       
 // Output to serial information of # bytes sent.
    Serial.print("Sending struct (");
    Serial.print(sizeof(theData));
    Serial.println(" bytes) ");
    Serial.println();

    Blink(LED,3);                                                     
    // Board indicator of radio transmitting/receiving.
}

void Blink(byte PIN, int DELAY_MS)
{
  pinMode(PIN, OUTPUT);
  digitalWrite(PIN,HIGH);
  delay(DELAY_MS);
  digitalWrite(PIN,LOW);
}

Receiver Code
Code: [Select]
 /* Wirelessly receive potentiometer signals to actuate a servo motor using an
    RFM69HW enabled Moteino connection
 
 Referenced & using example code, logic, format from:
 * https://github.com/LowPowerLab/RFM69/tree/master/Examples
   Lowpowerlab.com RFM69 examples: Node & Struct_send by Felix Rusu
 * http://www.instructables.com/id/Arduino-2-Servos-Thumbstick-joystick/step4/The-Code/
   by Biomech75 2012
 * http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
   code by David A. Mellis 2005; modified by Paul Stoffregen 8 Feb 2010
 * http://www.jeremyblum.com/2011/02/27/arduino-tutorial-9-wireless-communication/
   code by Jeremy Blum
 * http://forum.arduino.cc/index.php?PHPSESSID=jts7bh8gq4mos865mb4kbsi4l0&topic=151699.15
   code examples within forum string by 'ashh'
 * Credit for RFM12B code from Glyn Hudson openenergymonitor.org GNU GPL V3 12/4/12
 * Credit to JCW from Jeelabs.org for RFM12 by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
 * http://forum.arduino.cc/index.php/topic,154463.0.html

 This example code is in the public domain.

 B.Stott 2013
 */

 #include <RFM69.h>
 #include <SPI.h>
 #include <SPIFlash.h>
 #include <Servo.h>

 #define NODEID      1
 #define NETWORKID   100
 #define FREQUENCY   RF69_915MHZ                      //Match this with the version of your Moteino! (others: RF69_433MHZ, RF69_868MHZ)
 #define KEY         "thisIsEncryptKey"               //has to be same 16 characters/bytes on all nodes, not more not less!
 #define LED         9
 #define SERIAL_BAUD 9600
 #define ACK_TIME    30                               // # of ms to wait for an ack --- Not currently used.

// Ack will not be used. This is a streaming application. If a packet is lost the next servo position data
// will be accurate enough to update and move the servo.

 RFM69 radio;                                         // initiate radio object
 SPIFlash flash(8, 0xEF30);                           //EF40 for 16mbit windbond chip
 bool promiscuousMode = false;                        //set to 'true' to sniff all packets on the same network

     //  Setup Servo Objects
 Servo Servo0;

 typedef struct
 {
  int           Pot_0;                                 //designate transmitted data for this potentiometer 0 value
 } Payload;
 Payload theData;

 void setup()
 {

 // Attach Servo Objects to respective PWM pins
  Servo0.attach(5);

 // Radio initialization
  Serial.begin(SERIAL_BAUD);
  delay(100);
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
  radio.setHighPower(); //uncomment only for RFM69HW!
  radio.encrypt(KEY);
  radio.promiscuous(promiscuousMode);
  char buff[50];
  sprintf(buff, "\nListening at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
  Serial.println(buff);                                // Output operting frequency of transceiver
 
  if (flash.initialize())
    Serial.println("SPI Flash Init OK!");              // Print status of Flash memory
  else
    Serial.println("SPI Flash Init FAIL! (is chip present?)");
 }

 byte ackCount=0;

 void loop()
 {
  //process any serial input
  if (Serial.available() > 0) {
    char input = Serial.read();
    }

  if (radio.receiveDone())
  { 
  //Output to serial information of: NodeID & RSSI 
    Serial.print('[');Serial.print(radio.SENDERID, DEC);Serial.print("] ");
    Serial.print(" [RX_RSSI:");Serial.print(radio.readRSSI());Serial.println("]");
    if (promiscuousMode)
    {
      Serial.print("to [");Serial.print(radio.TARGETID, DEC);Serial.print("] ");
    }

    if (radio.DATALEN != sizeof(Payload))
      Serial.print("Invalid payload received, not matching Payload struct!");
    else
    {
      theData = *(Payload*)radio.DATA;                       //assume radio.DATA actually contains our struct and not something else

   // Adjust RF data for Servo Output
      theData.Pot_0 = constrain(theData.Pot_0, 0, 180);

   // Print to Serial Terminal to verify RF data and Servo degree conversions.
      Serial.print(" Data_Servo0 ");
      Serial.println(theData.Pot_0);
      Serial.println();

      Servo0.write(theData.Pot_0);                           // Write position to servo0
    }
    }
   
  Blink(LED,3);                                             // Blink indicates transceiver operation.
  }

 void Blink(byte PIN, int DELAY_MS)
  {
  pinMode(PIN, OUTPUT);
  digitalWrite(PIN,HIGH);
  delay(DELAY_MS);
  digitalWrite(PIN,LOW);
  }

bstott

  • Newbie
  • *
  • Posts: 37
Re: Remote Servo Control
« Reply #16 on: September 13, 2013, 12:11:58 AM »
I've been playing with two servos using the Moteinos for a few hours. Well, actually I've left them on and just sitting. In the past, most of my limited playing with servos always leaves them buzzing or jittery. Even on my quad. This new Moteino RC system just sits quietly waiting for commands from the pots. It is really neat to reach over every once in a while and turn the pots. The motors quickly, easily and smoothly (Well, for servos.) move to their next position and then go quiet. Even turning both pots simultaneously like playing with an etcha-sketch works well.

2 axes at the same time: http://youtu.be/IEjgRM-omJ0   ;D


Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5841
  • Country: us
    • LowPowerLab
Re: Remote Servo Control
« Reply #17 on: September 13, 2013, 08:04:34 AM »
Nice!
Another question - have you considered using some king of joystick? Or are the pots enough for what you need?
When you said "gimbal" I instantly thought "joystick". I've seen some camera gimbals using brushless motors, pretty neat stuff, but that was automatic adjustment movement based on gyroscopes and accelerometers, so maybe your application is different...

Hey maybe you could add "Moteino" and "RFM69W" in the description/titles of the videos so people can find them when searching the web...  ;D

bstott

  • Newbie
  • *
  • Posts: 37
Re: Remote Servo Control
« Reply #18 on: September 13, 2013, 12:15:35 PM »
Nice!
Another question - have you considered using some king of joystick?

Yes, but two Pots are a joy stick.  ;)  I've 3D printers to make it happen yet, No that is not the plan.

Quote
I've seen some camera gimbals using brushless motors, pretty neat stuff, but that was automatic adjustment movement based on gyroscopes and accelerometers, so maybe your application is different...

Yes again. Very cool seeing BLDC motors but, I do not know how they position them and I can not get into this new tech too. I did see the videos of accel.  & gyro for stabilization but, they use the bldc for position also I believe.

Felix,
I'm already lost in UAV, FPV, 3D printers, electronic design, manufacture, prototype and robot. I did not want to 'C' program too and here it is done. I really do need a new life, an income, work, a career not more features to what I'm drowning in.  --- A condition you know very well - am only One Man.  :)

Quote
Hey maybe you could add "Moteino" and "RFM69W" in the description/titles of the videos so people can find them when searching the web...  ;D

You BET! On Good Luck Friday too!!! I updated my four (4) video titles and descriptions bragging about the cool product I've used. Even two bonuses - I added keywords in tags and just uploaded a better video. Kinda overkill. I'm newb!

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5841
  • Country: us
    • LowPowerLab
Re: Remote Servo Control
« Reply #19 on: September 13, 2013, 08:43:34 PM »
Nice, great last video. Thanks for updating :)

bstott

  • Newbie
  • *
  • Posts: 37
Re: Remote Servo Control
« Reply #20 on: September 18, 2013, 06:32:46 AM »
Felix,

You asked about a Joystick. --- See the project: Wireless Joystick & Camera Gimbal. :D

http://lowpowerlab.com/forum/index.php/topic,130.0.html

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5841
  • Country: us
    • LowPowerLab
Re: Remote Servo Control
« Reply #21 on: September 20, 2013, 08:37:55 AM »
Hey check this raspberry pi camera tilter/panner:


Although when you start adding the cost of something like that ... $40 Pi, $30 camera, $30-50? gimball, it's not worth it any more, just buy a commercial pan/tilt wireless or cat5 wired camera...
« Last Edit: September 20, 2013, 08:39:52 AM by Felix »

bstott

  • Newbie
  • *
  • Posts: 37
Re: Remote Servo Control
« Reply #22 on: September 26, 2013, 08:06:35 AM »
Ha, ha... buy commercial product made in china ripped from cool project in USA or other part of the world. Forgo development, learning, exploring, innovating, invention and just wait and go to Walmart. Say, there are so many home automation products I'll just get the catalog and get them. In the long run easier, less time, and overall likely cheaper.  :o

 :o   ::)   :-\