Pages: [1]   Go Down
Author Topic: Arduino + Spektrum serial  (Read 2170 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 3
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For my current project I wanted to use Spektrum serial. That is the signal that comes out of the little satellite receiver. DIY drones Mbed Desert RC and others had some great info on the subject. But clearly Spektrum has gotten wise to this and changed up the protocol. Reference pages:

http://diydrones.com/profiles/blogs/24ghz-how-to-read-7-channels?id=705844%3ABlogPost%3A64228&page=3#comments

http://www.desertrc.com/spektrum_protocol.htm

http://mbed.org/users/offroad/notebook/spektrum-satellite-rx-driver/

DIY and mbed both have a preamble of 0x0301. Desert RC found 0x039b. The preamble I found was 0x00A2. Unless I power cycled the transmitter. Than the first byte of the preamble changes. This was causing me to lose a large number of the data frames. So in the first state for parsing the values I have included all the preambles. Once I get my hands on a 7 channel reciever I am going to update the code. The 7 channel supposedly puts the channels in a different order. I also am going to try a JR satasatellite lite as well as one of the cheap hobby king knock offs. So I will update this post after all the hardware arrives and I have time to test it. So here is updated Spektrum serial handling for arduino. Be warned if you are going to use the code do a reality check and make sure your preamble is the same. And if you have a different preamble please post on this thread to let me know. Hope this helps:

Code:
//this code is for the 6 channel transmitter
#include <Streaming.h>

#include <SerialPort.h>


SerialPort<1,128,128> port1;
SerialPort<2,128,128> port2;

const byte hexZero = 0x00;
uint8_t endianArray[14] = {1,0,3,2,5,4,7,6,9,8,11,10,13,12};

typedef union{
  struct{
    uint16_t aileron;
    uint16_t flap;
    uint16_t elevator;
    uint16_t gear;
    uint16_t rudder;
    uint16_t unused;
    uint16_t throttle;
  }
  variables;
  byte buffer[14];
}
Spektrum_t;


Spektrum_t spektrum;

byte inByte;

int bufferIndex=0;
int readState = 0;
boolean dataReady = false;


void setup(){
  port1.begin(115200);
  port2.begin(115200);
}


void loop(){
  while(port2.available() > 0){

    inByte = port2.read();
    switch (readState){
    case 0:
      if (inByte == hexZero || inByte == 0x2D || inByte == 0x5A || inByte == 0x87 || inByte == 0xB4 || inByte == 0xE1 || inByte == 0xFF){
        readState = 1;
       }
      break;
    case 1:
      if (inByte == 0xA2){
        readState = 2;
        bufferIndex = 0;
      }
      break;
    case 2:
      if (bufferIndex % 2 == 0){
        
        spektrum.buffer[endianArray[bufferIndex]] = inByte & 0x07;
      }else{
        spektrum.buffer[endianArray[bufferIndex]] = inByte;
      }
      bufferIndex++;
      if(bufferIndex == 14){
        readState = 0;
        dataReady = true;
      }
      break;
    default:
      break;

    }
  }
  if (dataReady == true){
    dataReady = false;
    port1 << "Time: " << millis() << "\r\n";
    port1 << "Aileron: "<<  spektrum.variables.aileron << "\r\n";
    port1 <<"Flap: "<<spektrum.variables.flap<<"\r\n";
    port1 << "Elevator: "<<spektrum.variables.elevator<<"\r\n";
    port1 << "Gear: " <<spektrum.variables.gear<<"\r\n";
    port1 << "Rudder: " <<spektrum.variables.rudder<<"\r\n";
    port1 << "Empty channel: "<<spektrum.variables.unused<<"\r\n";
    port1 << "Throttle: " <<spektrum.variables.throttle << "\r\n";
  }

}
« Last Edit: July 09, 2012, 12:37:14 pm by mikesbaker » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I try to get the same thing working.
My AR7000 is bound with the Spektrum DX7 (steady red led) but I am not receiving any data.
Is there anything else to set up to get data?
I used 3.3V, GND and RX1 (19) on my Mega, but also other pins do not work.
On the receiver I used the leftmost sockets (-,+,signal).

Any advice for me?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Mike,

I've been trying to read serial data from my Spektrum Satellite receiver for the last few days and haven't been able to get it working. I'm keen to know if you managed to get this working correctly?

Thanks
Logged

Pages: [1]   Go Up
Jump to: