Flip MWC 1.5 Multiwii Serial to Arduino Nano

Post Reply
AdrianLand
Posts: 2
Joined: Sat Aug 29, 2015 1:23 am

Flip MWC 1.5 Multiwii Serial to Arduino Nano

Post by AdrianLand »

I’m trying to implement the “Multiwii SD Card Logger” setup posted by renes, but am not receiving any response from my Flip MWC

Here's my bench set up:
Flight controller: Flip MWC 1.5
Code: MWC 2.3 MultiWii_Flip_Tri
Arduino Nano V3.1

I’ve changed renes’ code to use SoftwareSerial on the Nano and checked out this connection using a standalone Adafruit GPS board
Hookups: Nano (TX (D8), RX(D7), Gnd) to Flip (RX, TX, Gnd)
(This lets me use the ‘hardware’ serial connection for the Arduino IDE Serial Monitor for debugging)

Datalogger code attached below
The serial connections seems to initialize (line 35)
The Arduino sends the data request out ( line 51 Note, Protocol.h has been modified for mySerial() )
but I don’t get any response from readData(); (line 64)

What am I missing?
Is there something specific to the Flip MWC serial connection?
Do I need to configure something in the Multiwii code itself?

Any advice would be very much appreciated!

Regards
Adrian Land

Code: Select all

#include <SD.h>
#include <SPI.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(8, 7);

#include "protocol.h"

#ifndef serialstate_h
#define serialstate_h
#include "serialstate.h"
#endif

#ifndef cardlogger_h
#define cardlogger_h
#include "cardlogger.h"
#endif

#define INBUF_SIZE 64

static uint8_t inBuf[INBUF_SIZE];
static uint8_t checksum;
static uint8_t commandMW;
static uint8_t offset;
static uint8_t dataSize;

static Protocol p;
static CardLogger logger;
int8_t c,n; 

void setup() 
{
  Serial.begin(115200);
  delay(2000);
  mySerial.begin(115200);
  while (!mySerial) {
    ;
  } // wait for Flip to be ready
  Serial.println("Setup loop okay");
  logger.init();
}

void loop() // run over and over
{

  uint8_t  datad = 0;
  uint8_t  *data = & datad;

  // If you dont need a certain log just comment out the two lines for sending and reading
  // p.send_msp( MSP_ATTITUDE  ,data, 0);
  // readData();
  p.send_msp( MSP_RAW_IMU  ,data, 0); //Protocol will send opcode to terminal
  readData();
    Serial.println("Read data?");
  // p.send_msp( MSP_RC  ,data, 0);
  // readData();
  // p.send_msp( MSP_RAW_GPS ,data, 0);
  // readData();
}

void readData() {

  delay(60);

  while (mySerial.available()) {

    byte c = mySerial.read();
 Serial.println("myserial.read okay");
    if (c_state == IDLE) {
      c_state = (c=='$') ? HEADER_START : IDLE;
    }
    else if (c_state == HEADER_START) {
      c_state = (c=='M') ? HEADER_M : IDLE;
    }
    else if (c_state == HEADER_M) {
      c_state = (c=='>') ? HEADER_ARROW : IDLE;
    }
    else if (c_state == HEADER_ARROW) {

      if (c > INBUF_SIZE) {  // now we are expecting the payload size
        c_state = IDLE;

      }
      else {
        dataSize = c;
        offset = 0;
        checksum = 0;
        checksum ^= c;
        c_state = HEADER_SIZE; 
      }
    }
    else if (c_state == HEADER_SIZE) {
      commandMW = c;
      checksum ^= c;
      c_state = HEADER_CMD;
    }
    else if (c_state == HEADER_CMD && offset < dataSize) {
      checksum ^= c;
      inBuf[offset++] = c;
    }
    else if (c_state == HEADER_CMD && offset >= dataSize) {

      if (checksum == c) {
        if (commandMW == MSP_ATTITUDE) {
          XYAngle result = p.evalAtt(inBuf);
          logger.logXYAngle(result);
        }
        if (commandMW == MSP_RAW_IMU) {
          IMUValues result = p.evalIMU(inBuf);
          logger.logIMU(result);
        }
        if (commandMW == MSP_RC) {
          RCInput result = p.evalRC(inBuf);
          logger.logRC(result);
        }
        if (commandMW == MSP_RAW_GPS) {
          GPSValues result = p.evalGPS(inBuf);
          logger.logGPS(result);
        }

      }

      c_state = IDLE;
    }

  }
}

Post Reply