Go Down

Topic: Arduino + Spektrum serial (Read 2553 times) previous topic - next topic


Jul 09, 2012, 07:10 pm Last Edit: Jul 09, 2012, 07:37 pm by mikesbaker Reason: 1
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:




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: [Select]

//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{
   uint16_t aileron;
   uint16_t flap;
   uint16_t elevator;
   uint16_t gear;
   uint16_t rudder;
   uint16_t unused;
   uint16_t throttle;
 byte buffer[14];

Spektrum_t spektrum;

byte inByte;

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

void setup(){

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;
   case 1:
     if (inByte == 0xA2){
       readState = 2;
       bufferIndex = 0;
   case 2:
     if (bufferIndex % 2 == 0){
       spektrum.buffer[endianArray[bufferIndex]] = inByte & 0x07;
       spektrum.buffer[endianArray[bufferIndex]] = inByte;
     if(bufferIndex == 14){
       readState = 0;
       dataReady = true;

 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";



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?


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?


Go Up