MultiWii Serial Protocol help...

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
User avatar
city_kid
Posts: 64
Joined: Wed Apr 03, 2013 8:09 pm
Location: Birmingham UK

MultiWii Serial Protocol help...

Post by city_kid »

Great project!

MultiWii in ANGLE mode is so much easier than KK etc...

Some questions:

1) I'm trying to use MW with serial data link. I want to use the Multiwii Serial Protocol but can't get past the basics. The MultiWiiGUI by EOSBandi has a CLI tab, but I can't get anything to work. MultiWii 2.2 compiled and loaded with RCSERIAL enabled. Trying things like "$M<MSP_IDENT" or "$M<100" as input to the CLI but not seeing any data coming back. Anyone got any ideas...?

2) Does the RCSERIAL enabled stop the normal "servo" style RX working or can the two be run in parallel?

Many thanks in advance!

city_kid

itain
Posts: 75
Joined: Tue Aug 23, 2011 10:32 pm

Re: MultiWii Serial Protocol help...

Post by itain »

1. It's a binary protocol, and you need to send the checksum as well. From your question it looks like you are sending ASCII without checksum.

2. The two can run together... You can use the serial protocol while flying (eg, for an OSD).

User avatar
city_kid
Posts: 64
Joined: Wed Apr 03, 2013 8:09 pm
Location: Birmingham UK

Re: MultiWii Serial Protocol help...

Post by city_kid »

@itain

OK, I've now reverse engineered some PHP code to talk MSP.

To get a MSP_IDENT you open the serial port and then execute fwrite($serial_port_handle,'$M<'.chr(0).chr(100).chr(100));

You get back a load of bytes that represent the MultiWii software version, protocol version etc etc

I'll now be creating a PHP Class library that will ask MultiWii FC for various data like MSP_ATTITUDE and then convert the data bytes coming out into real world values.

Thanks for the help on this!

PS: I will try to PM EOSbandi for a MSP reference or guide....

city_kid

User avatar
EOSBandi
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary
Contact:

Re: MultiWii Serial Protocol help...

Post by EOSBandi »

city_kid wrote:@itain

OK, I've now reverse engineered some PHP code to talk MSP.

To get a MSP_IDENT you open the serial port and then execute fwrite($serial_port_handle,'$M<'.chr(0).chr(100).chr(100));

You get back a load of bytes that represent the MultiWii software version, protocol version etc etc

I'll now be creating a PHP Class library that will ask MultiWii FC for various data like MSP_ATTITUDE and then convert the data bytes coming out into real world values.

Thanks for the help on this!

PS: I will try to PM EOSbandi for a MSP reference or guide....

city_kid


The reference is the MultiWii source code... it's all there.


User avatar
city_kid
Posts: 64
Joined: Wed Apr 03, 2013 8:09 pm
Location: Birmingham UK

Re: MultiWii Serial Protocol help...

Post by city_kid »

@PatrikE

Thanks for the PDF link. There is some useful information in there!

I have a couple of questions for yourself or EOSbandi:

I have now created a pair of PHP functions that a) uses MSP_SET_RAW_RC to write RC values into the MultiWii and a) uses MSP_RC to read RC values from the MultiWii.

Both of these functions work, and when I set values then read them again I get the same values as I wrote.

The RC values equate to THR, ROlL, PITCH, YAW etc in two-byte format, between 1000 (us) and 2000 (us).

Here are my questions:

1) What order are the RC channels in? THR, ROLL, PITCH, YAW, AUX1, AUX2, AUX3, AUX4, maybe?

2) Which order are the two bytes sent / received? Most significant byte first or least significant byte first?

OK, technically three questions...?!

Many thanks in advance...

PS: I mean to make this suite of PHP function available on the forum once complete and tested. I will hopefully make functions that will be able to read and write any(?) MultiWii setting with easy to use real-world values....

Cheers!

city_kid

User avatar
city_kid
Posts: 64
Joined: Wed Apr 03, 2013 8:09 pm
Location: Birmingham UK

Re: MultiWii Serial Protocol help...

Post by city_kid »

Things have moved forward!

I now have a transparent 2.4GHz 200mW bi-directional serial link based on the Nordic nRF24L01+ transceiver.

I have some PHP functions that send and receive MSP data.

Now I'm going to build an Arduino based hand-held controller to control my Quad.

I'm keep you updated....

copterrichie
Posts: 2261
Joined: Sat Feb 19, 2011 8:30 pm

Re: MultiWii Serial Protocol help...

Post by copterrichie »

city_kid wrote:Things have moved forward!

I now have a transparent 2.4GHz 200mW bi-directional serial link based on the Nordic nRF24L01+ transceiver.

I have some PHP functions that send and receive MSP data.

Now I'm going to build an Arduino based hand-held controller to control my Quad.

I'm keep you updated....



This is very interesting. I also have been researching the nRF24L01 however, I made the mistake of only purchasing one. they are cheap enough but I just have not done it. Would you mind sharing mode details of how you have it wired?

Thank you.

User avatar
city_kid
Posts: 64
Joined: Wed Apr 03, 2013 8:09 pm
Location: Birmingham UK

Re: MultiWii Serial Protocol help...

Post by city_kid »

Copterrichie,

Yeah, it's not that easy.

An nRF24L01 transceiver module actually talks in SPI serial, not TTL RS232 style serial.

I've built a pair of Arduino based "convertors" that:

a) Wait for a serial (57600 baud) packet to come along, which it then sends on through the nRF24L01 module.
b) Waits for a packet to come over the air from the nRF24L01 and converts it back to 57600 baud serial.

The other problem is that the nRF module runs at 3v3 and will not take 5v TTL signals.

My boards have an onboard 3v3 regulator and the FET convertors to get everything to either 3v3 or 5v signaling (user selectable by jumper).

This weekend I'm gonna try to wire the whole thing up and send MSP type control string / packets to the MultiWii, plus try to relay MSP telemetry through the same link.

I'll let you know what happens...

city_kid

copterrichie
Posts: 2261
Joined: Sat Feb 19, 2011 8:30 pm

Re: MultiWii Serial Protocol help...

Post by copterrichie »

Very Interesting city_kid,

Just read today about some of these nRF24L01 being able to transmit up to 1100 meters with the stock antenna. I am very curious what they can do with a high gain antenna however this is only a dream for me. I have too many projects underway right now to add a new one.

chenkingwen
Posts: 7
Joined: Tue Mar 12, 2013 6:09 am

Re: MultiWii Serial Protocol help...

Post by chenkingwen »

Have you finish it?

User avatar
city_kid
Posts: 64
Joined: Wed Apr 03, 2013 8:09 pm
Location: Birmingham UK

Re: MultiWii Serial Protocol help...

Post by city_kid »

Project Update 25/04/2013

Finally got this system debuged.

It turns out that the MultiWii board (Cruis Lite) will not listen to another Arduino at 57600 baud.

Yes! I know that it should! I have wasted many days fixating on this issue!

Using terminal software I could see the serial bytes arriving at the MultiWii but it did not respond.

I then did a very controlled series of tests. Hardware = same. Wiring = same. Code = same.

9600 baud - Works!
19200 baud - Works!
38400 baud - Works!
57600 baud - Ignores MSP commands!
115200 baud - Works!

Strangely they ALL work using a straight TTL serial cable connection! Must be a weird timing issue at 57600 baud....?!

So now I'm using 115200 baud, which is good because:

a) That' the default baudrate for a MultiWii.
b) It's twice as fast as 57600 baud.

Now the trick is to get the TX / RX timing right so I can ask for some telemetry and get some data back in flight.

Keep you posted....

Mis
Posts: 203
Joined: Fri Apr 01, 2011 12:23 am

Re: MultiWii Serial Protocol help...

Post by Mis »

The another arduino board work at 8MHz or 16MHz ? If you have board working at 8MHz, you must define 58823 baud in multiwii as the serial speed, because with 8MHz the uart can't work at exactly 57600 baud.

User avatar
city_kid
Posts: 64
Joined: Wed Apr 03, 2013 8:09 pm
Location: Birmingham UK

Re: MultiWii Serial Protocol help...

Post by city_kid »

Build Update 10/05/2013

OK, now I've got my new serial data / MSP controller working.

Basic system overview:

Joysticks -> ATmega1284P running Arduino code -> RF2401+ RF Module -VVVVVVVV- Quad: RF2401+ -> MSP -> MultiWii FC

This all works very well and I can send MSP_SET_RAW_RC messages at about 50 per second. Very responsive.

In addition I'm now going to interleave some MSP telemetry requests in between the MSP RC data and feed the replies into a PC via Bluetooth serial from the controller.

The MSP telemetry data will then be displayed in a custom Processing app showing FPV video, bearing, attitude, artificial horizon etc etc.

I will post some screenshots of the Processing app when I get it looking good....

User avatar
city_kid
Posts: 64
Joined: Wed Apr 03, 2013 8:09 pm
Location: Birmingham UK

Re: MultiWii Serial Protocol help...

Post by city_kid »

@copterrichie

If you're looking to purchase some Nordic modules look for nRF24L01+PA+LNA on Ebay.

They have a PA (TX Power Amplifier) and a LNA (Low Noise RX Amplifier).

They produce 200mW (actually 189mW measured) at 2.4GHz, so they are really long range.

If I can find my range test diagrams I'll attach them to a post.

The downside is that the interface is SPI, so you can't just stick TLL Serial data into them, you need something to translate from one protocol to the other...

Another possibility might be a HopeRF HM-TRP module with the 3DR firmware loaded.

These are 100mW 915MHz SERIAL transceivers. No interfacing required. Power supply is 3v3 but the TX / RX pins are 5v TLL tolerant.

Please contact me if you want to know more...

Trinca
Posts: 9
Joined: Sat Apr 20, 2013 10:48 pm

Re: MultiWii Serial Protocol help...

Post by Trinca »

Hi, @city_kid.

Maybe you (or anyone else) can help me: I am doing something similar you're doing, the difference is in my case there's no joystick and (in this first phase of my project) the drone will be controlled using the keyboard of my MacBook.

The methods sending MPS messages without payload are working really well, but to send RC Data it's not. I am able to send the values between 1280 and 1530 only, any other value does not work.

Googling around I found some info about the 2 bytes each RC channel must have, and I think that's exactly my problem. Take a look at my code:

Code: Select all

uint16_t checksum = 0;
   
NSData *mspHeader = [@"$M<" dataUsingEncoding:NSUTF8StringEncoding];
[self.serialPort sendData:mspHeader];
   
// payload size
uint8_t msplenght = 16;
NSData *mspLenght = [NSData dataWithBytes:&msplenght length:1];
[self.serialPort sendData:mspLenght];
checksum ^= msplenght;
   
uint8_t mspcode = 200;
NSData *mspCode = [NSData dataWithBytes:&mspcode length:1];
[self.serialPort sendData:mspCode];
checksum ^=mspcode;
   
// payload <---- HERE I THINK I HAVE A PROBLEM
uint16_t rc_val1 = _throttle;
NSData *rcVal1 = [NSData dataWithBytes:&rc_val1 length:2];
[self.serialPort sendData:rcVal1];
checksum ^=rc_val1;
   
uint16_t rc_val2 = 1500;
NSData *rcVal2 = [NSData dataWithBytes:&rc_val2 length:2];
[self.serialPort sendData:rcVal2];
checksum ^=rc_val2;
   
uint16_t rc_val3 = 1500;
NSData *rcVal3 = [NSData dataWithBytes:&rc_val3 length:2];
[self.serialPort sendData:rcVal3];
checksum ^=rc_val3;
   
uint16_t rc_val4 = 1500;
NSData *rcVal4 = [NSData dataWithBytes:&rc_val4 length:2];
[self.serialPort sendData:rcVal4];
checksum ^=rc_val4;
   
uint16_t rc_val5 = 1500;
NSData *rcVal5 = [NSData dataWithBytes:&rc_val5 length:2];
[self.serialPort sendData:rcVal5];
checksum ^=rc_val5;
   
uint16_t rc_val6 = 1500;
NSData *rcVal6 = [NSData dataWithBytes:&rc_val6 length:2];
[self.serialPort sendData:rcVal6];
checksum ^=rc_val6;
   
uint16_t rc_val7 = 1500;
NSData *rcVal7 = [NSData dataWithBytes:&rc_val7 length:2];
[self.serialPort sendData:rcVal7];
checksum ^=rc_val7;
   
uint16_t rc_val8 = 1500;
NSData *rcVal8 = [NSData dataWithBytes:&rc_val8 length:2];
[self.serialPort sendData:rcVal8];
checksum ^=rc_val8;
   
uint16_t mspcheck = checksum;
NSData *mspCheck = [NSData dataWithBytes:&mspcheck length:1];

[self.serialPort sendData:mspCheck];

[self sendRequestWithCode:105];


It works only if the _throttle values is between 1280 and 1530.

After found some information, I tried:

Code: Select all

uint8_t rc_throttle_byte1 = _throttle%256;
uint8_t rc_throttle_byte2 = _throttle/256;
checksum ^=rc_throttle_byte1;
checksum ^=rc_throttle_byte2;
[self.serialPort sendData:[NSData dataWithBytes:&rc_throttle_byte1 length:1]];
[self.serialPort sendData:[NSData dataWithBytes:&rc_throttle_byte2 length:1]];


But it doesn't work with any value.

Do you have some ideas about how to solve this problem?
Or any other member following this thread?

Thanks a lot.

User avatar
city_kid
Posts: 64
Joined: Wed Apr 03, 2013 8:09 pm
Location: Birmingham UK

Re: MultiWii Serial Protocol help...

Post by city_kid »

*** Transceiver Update ***

I am now experimenting with two HopeRF HM-TRP modules. These form the basis of the 3DR 915MHz radio telemetry system.

I have just received two Shuncom SZ05-TTL-ADV Zigbee modules. These have the following features:

* 250mW of 2.4GHz TX power!
* Simple 5v operation
* Simple 5v TTL serial port at up to 115200 baud
* Easy terminal type config menu

I believe that these will be my best solution. I will be testing them tonight but they should provide an easy transparent 115200 baud serial link.

I will keep you posted....

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: MultiWii Serial Protocol help...

Post by crashlander »

city_kid wrote:I have just received two Shuncom SZ05-TTL-ADV Zigbee modules. These have the following features:
....
I will keep you posted....


Please do that and test also actual usable range, since APC802 have actual tested range more than 700m (probably more but that is all I tested by now), but baud/refresh rate sucks and it is not usable for control and telemetry at the same time.

Regards
Andrej

User avatar
city_kid
Posts: 64
Joined: Wed Apr 03, 2013 8:09 pm
Location: Birmingham UK

Re: MultiWii Serial Protocol help...

Post by city_kid »

@Trinca

Here is my (very) simple Arduino code for sending MSP_SET_RAW_RC messages:

Code: Select all

int MSP_SET_RAW_RC(boolean force){
   
    if(force==true or THR!=PREV_THR or PREV_PITCH!=PITCH or PREV_ROLL!=ROLL or PREV_YAW!=YAW or PREV_AUX1!=AUX1 or PREV_AUX2!=AUX2 or PREV_AUX3!=AUX3 or PREV_AUX4!=AUX4){
     
        byte checksum=0;
        byte command[23];
       
        command[0]=36;  // Start of command $
        command[1]=77;  // Start of command M
        command[2]=60;  // Start of command <
        command[3]=16;  // Length of data
        command[4]=200; // MSP_SET_RAW_RC
       
        command[5]=ROLL & 0xFF;     // ROLL LSB
        command[6]=ROLL >> 8;       // ROLL MSB
       
        command[7]=PITCH & 0xFF;    // PITCH LSB
        command[8]=PITCH >> 8;      // PITCH MSB
       
        command[9]=YAW & 0xFF;      // YAW LSB
        command[10]=YAW >> 8;        // YAW MSB
       
        command[11]=THR & 0xFF;      // THR LSB
        command[12]=THR >> 8;        // THR MASB   
       
        command[13]=AUX1 & 0xFF;     // AUX1 LSB
        command[14]=AUX1 >> 8;       // AUX1 MSB
       
        command[15]=AUX2 & 0xFF;    // AUX2 LSB
        command[16]=AUX2 >> 8;      // AUX2 MSB
       
        command[17]=AUX3 & 0xFF;    // AUX3 LSB
        command[18]=AUX3 >> 8;      // AUX3 MSB
       
        command[19]=AUX4 & 0xFF;    // AUX4 LSB
        command[20]=AUX4 >> 8;      // AUX4 MSB
       
        for(int x=3;x<21;x++){checksum=(checksum ^ command[x]);}
        command[21]=checksum;
       
        command[22]=0;
       
        if(debug_msp){
            Serial.print("Command: ");
            for(int x=0;x<22;x++){Serial.print(command[x]);Serial.print(" ");}
            Serial.println();
            }
       
        int bytes_transmitted=rf_transmit(command,22);         
               
        PREV_THR=THR;
        PREV_PITCH=PITCH;
        PREV_ROLL=ROLL;
        PREV_YAW=YAW;
        PREV_AUX1=AUX1;
        PREV_AUX2=AUX2;
        PREV_AUX3=AUX3;
        PREV_AUX4=AUX4;
       
        last_control_tx=micros();
        return bytes_transmitted;       
       
        }
   }


This has worked fine in Arduino (which it looks like you're using) and PHP via Raspberry Pi (Early control platform)

It checks to see if any of the 8 RC channels have changed OR you call the function using force=true.

It's commented because I spent a long time trying to get it to work. Once it does work, it's totally good.

Cheers!

city_kid

User avatar
city_kid
Posts: 64
Joined: Wed Apr 03, 2013 8:09 pm
Location: Birmingham UK

Re: MultiWii Serial Protocol help...

Post by city_kid »

@crashlander

I've just tried the Shuncom SZ05-TTL-ADV modules I have.

They seem to work really well on the bench, not tried in the air yet.

Currently I'm building a new hexacopter to carry them, but just using the MultiWii GUI program to produce traffic they seem pretty good.

I will try to do a walking range test this week.

Supplied antennas from Shuncom are a little big and heavy.....

Cheers!

city_kid

Trinca
Posts: 9
Joined: Sat Apr 20, 2013 10:48 pm

Re: MultiWii Serial Protocol help...

Post by Trinca »

@city_kid.

This has worked fine in Arduino (which it looks like you're using) and PHP via Raspberry Pi (Early control platform)


Actually, I'm developing for Mac OS X and iOS using bluetooth to communicate with MW. And because I'm studying and learning to deal with bytes, I'm sending each byte separately using NSData (a default class from the SDK) to convert the values to raw data.

I'm going to try using your code as a reference (and another C code I found googling around) to solve my problem. Once Objective-C is a subset of C, I think it will works.

Thanks very much for you infos.

dfruehwald
Posts: 26
Joined: Wed Feb 20, 2013 1:08 am

Re: MultiWii Serial Protocol help...

Post by dfruehwald »

I've been searching but can't find info on the protocol used for the Configuration program to talk to the MultiWii board.

Red Bear Lab makes a Bluetooth 4.0 module that can communicate between Arduino and iOS devices supporting Bluetooth 4.0. Bypasses the need for an MFI membership and all the trouble caused by not having the SPP profile under the previous Bluetooth spec.

http://redbearlab.com/blemini/

I'm new to iOS but this sounded like a fun way to mess around. Planning to start with a plain Arduino Uno or Mega and get it talking but I'd love to make an iOS Configuration program.

Trinca
Posts: 9
Joined: Sat Apr 20, 2013 10:48 pm

Re: MultiWii Serial Protocol help...

Post by Trinca »

@dfruehwald

Thanks to share the link of redbearlab. That's exactly the model I'm planning to work with the iOS version of my app. In my Mac it's working perfectly using the general bluetooth modules.

@city_kid

Your code is running fine in my Mac OS X project. Thank you. I did some tests last night and it was incredible to see the motors of the drone controlled by the keyboard, even using bluetooth. I'm using the arrow keys to Pitch and Roll and it's working pretty well. "A" and "S" to Throttle and "D" and "F" to Yaw.

Every command with payload is now working. Thanks a lot.

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: MultiWii Serial Protocol help...

Post by crashlander »

@city_kid
I have received Shuncom SZ05-TTL-ADV and have difficulties to configure it, all I get is

Ver:4.4--00

��ѡ������(Please Select Language)
1.���� 2.English
PLEASE INPUT��SHUNCOM
2
�����밲ȫ�룺SHUNCOM


and than it does responds with same prompt to whatever I key-in.
Any tips?

Regards
Andrej

User avatar
city_kid
Posts: 64
Joined: Wed Apr 03, 2013 8:09 pm
Location: Birmingham UK

Re: MultiWii Serial Protocol help...

Post by city_kid »

@crashlander

OK, good! This is all correct.

So when you see the first menu: Please select language -> Send a "2" to set English.

Then send the word "SHUNCOM" to enable config mode.

After that you should see a menu of different options like NetID, Node Type, Baud Rate etc etc .

This configuration menu is interactive.

I recommend the following:

1) Give each module it own "MAC_Addr" like "0001" and "0002". This must be unique for each module within the "network"
2) Give each module its own "Node_name" like "GROUND" or "AIR".
3) Set BOTH modules "Node_Type" to "END_Device".
4) Set BOTH modules "Net_Type" to "Peer"
5) Set BOTH modules to the same "Net_ID" like "FF" but the SAME on BOTH modules. This means that both modules are talking / listening on the same "network"
6) Set BOTH modules to the same "Channel" like "0F" (last channel).
7) Set BOTH modules "Data_Type" to "ASCII" This seems to work fine for MSP traffic.
8) Set BOTH modules to the "TX_Type" as "BROADCAST" mode so they listen to data from any transmitter.
9) Set BOTH modules to the same BAUD RATE. I use 115200 baud very well. Please be aware that the configuration baudrate is ALWAYS 38400 baud, regardless of the interface baud rate that you set.
10) Set BOTH modules to "Baud_Rate" as "115200" which I think is option "8"
11) Set BOTH modules to "Parity" as "None"
12) Set BOTH modules to "Data_Bit" as "8+0+1" = 8 data bits, No Parity, 1 stop bit
13) Set BOTH modules "SRC_Addr" to "NOT OUTPUT" so that the receiver doesn't spit out the transmitter address, only the data...

The modules remember their settings each time they are power-cycled as the settings are stored in flash.

Here is my config from testings. Please note that I was originally using 19200 baud for testing purposes...

================================================================================

1) Connect up first.
2) Set to 38400 baud.
3) Press "Config" button for three seconds. *** Actually really for 1 second ***
4) Send "2" for English menus.
5) Send "SHUNCOM" to get config mode.


Ground Module Config
====================

MAC_Addr: (H) 0001 (Unique)
Node Name: GROUND (Unique)
Node_Type: END_Device (Same)
Net_Type: Peer (Same)
Net_ID: (H) FF (Same)
Channel: (H) 0F (Same)
Data_Type: ASCII (Same)
TX_Type: Broadcast (Same)
Baud_Rate: 19200 (Same)
Parity: None (Same)
Data_Bit: 8+0+1 (Same)
SRC_Addr: NOT OUTPUT (Same)


Quad (Air) Module Config
========================

MAC_Addr: (H) 0002
Node Name: QUAD
Node_Type: END_Device
Net_Type: Peer
Net_ID: (H) FF
Channel: (H) 0F
Data_Type: ASCII
TX_Type: Broadcast
Baud_Rate: 19200
Parity: None
Data_Bit: 8+0+1
SRC_Addr: NOT OUTPUT

================================================================================

Once these two modules are setup correctly you can just put data into one and and it should fall out of the other end!

Hope this helps....

city_kid

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: MultiWii Serial Protocol help...

Post by crashlander »

city_kid wrote:@crashlander
Then send the word "SHUNCOM" to enable config mode.


Thank you! That was the missing/not understood part.

Regards
Andrej

User avatar
city_kid
Posts: 64
Joined: Wed Apr 03, 2013 8:09 pm
Location: Birmingham UK

Re: MultiWii Serial Protocol help...

Post by city_kid »

@crashlander

Great! So you've got comms between the modules?

I've just ordered another two modules from Shuncom. One for my new hexacopter and one for my ground station for direct telemetry....

Cheers!

city_kid

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: MultiWii Serial Protocol help...

Post by crashlander »

city_kid wrote:Great! So you've got comms between the modules?

I'm little slower so I only programed/set-up parameters and now I'm soldering necessary HW to communicate with them.
Hope I'll be able to test them in a day or two (range test, fly in straight line till it drops (low of course)). :lol:

Regards
Andrej

cocoludro
Posts: 7
Joined: Tue Sep 03, 2013 10:02 am

Re: MultiWii Serial Protocol help...

Post by cocoludro »

Hello, City could you tell me the connection between Arduino and SZ05, only (RX1 and TX1) and between SZ05 and PC?. Thanks you.

User avatar
city_kid
Posts: 64
Joined: Wed Apr 03, 2013 8:09 pm
Location: Birmingham UK

Re: MultiWii Serial Protocol help...

Post by city_kid »

@cocoludro

The connections are really easy!

On the Shuncom SZ05 module the four (4) pins that you need are all next to each other: [TX1] [RX1] [VCC] [GND]

See here:

Shuncom SZ05 pins
Shuncom SZ05 pins


Pretty obvious:

GND = 0v of supply
VCC = +5v DC of supply
RX1 = Receive Data to Arduino / PC
TX1 = Transmit Data to Arduino / PC

Very simply cross the two data lines over:

SZ05 <--------------> Arduino / PC

RX1 <----------------> TX Pin (like TX0 or TX1)
TX1 <----------------> RX Pin (like RX0 or RX1)

If you are connecting to a PC, then you MUST change the serial data voltage levels from +/-12v (RS232 on PC) to 5v TTL Serial using something like a MAX232 chip.

The Shuncom SZ05 modules work on 5v TTL serial data level, and may be damaged by putting +/- 12v RS232 data onto them!

On baud rates, I'm now using 19200 baud to send / receive MSP messages to MultiWii. Originally I was using 115200 baud, but I found that the messages were hitting the MutliWii so fast that it didn't have time to answer / acknowledge them before the next message arrived! My MultiWii is ATmega328 based so about the slowest simplest version.

At 19200 baud I can send 50+ MSP_SET_RAW_RC messages (for control) and receive about 20 MSP telemetry messages per second easily!

Hope this helps!

city_kid

cocoludro
Posts: 7
Joined: Tue Sep 03, 2013 10:02 am

Re: MultiWii Serial Protocol help...

Post by cocoludro »

Thanks City, I am connecting with PC SZ05 THROUGH USB port, Could I use the evaluation module that sends shuncom? or should I do it through RX1 and TX1 are TTL? A greeting.

User avatar
city_kid
Posts: 64
Joined: Wed Apr 03, 2013 8:09 pm
Location: Birmingham UK

Re: MultiWii Serial Protocol help...

Post by city_kid »

@cocoludro

If connecting to a PC, using the Eval board is ideal! I takes care of everything.

Then at the MultiWii end you can just connect the SZ05 module directly to the MultiWii Serial connector. It is already at 5v TLL levels.

Very simple!

city_kid

cocoludro
Posts: 7
Joined: Tue Sep 03, 2013 10:02 am

Re: MultiWii Serial Protocol help...

Post by cocoludro »

Thanks City, I'm not going to use for MultiWii is just to send serial data (ASCII) from the PC to arduino and arduino to PC. A greeting.
Last edited by cocoludro on Tue Sep 03, 2013 11:22 am, edited 1 time in total.

User avatar
city_kid
Posts: 64
Joined: Wed Apr 03, 2013 8:09 pm
Location: Birmingham UK

Re: MultiWii Serial Protocol help...

Post by city_kid »

@cocoludro

OK, really easy then:

PC End: Use the SZ05 Eval Baord via USB
Arduino End: Direct connection to supply and TX/RX pins.

city_kid

cocoludro
Posts: 7
Joined: Tue Sep 03, 2013 10:02 am

Re: MultiWii Serial Protocol help...

Post by cocoludro »

Thank you. I could not find any information of SZ05 by site, and you have solved my questions. A greeting.

User avatar
city_kid
Posts: 64
Joined: Wed Apr 03, 2013 8:09 pm
Location: Birmingham UK

Re: MultiWii Serial Protocol help...

Post by city_kid »

@cocoludro

Please PM me your email address and I will send you some datasheets for the SZ05 module....

Cheers!

city_kid

cocoludro
Posts: 7
Joined: Tue Sep 03, 2013 10:02 am

Re: MultiWii Serial Protocol help...

Post by cocoludro »

Thank you very much. Running 100%. It is very fast

User avatar
city_kid
Posts: 64
Joined: Wed Apr 03, 2013 8:09 pm
Location: Birmingham UK

Re: MultiWii Serial Protocol help...

Post by city_kid »

Excellent news!

The only problem with the SZ05 module is a lack of RSSI or signal strength reading.

Have you flown with it yet?

What baud rate are you using? I'm running at 19200baud which seems to work very well...

I would love to know how far it would go.

I have my Hex setup with Return to Home on GPS on FAILSAFE and I intend on testing it soon, but bad weather / wind here will stop me this weekend....

Let me know how you get on?!

Cheers!

city_kid

cocoludro
Posts: 7
Joined: Tue Sep 03, 2013 10:02 am

Re: MultiWii Serial Protocol help...

Post by cocoludro »

Hello city
Last edited by cocoludro on Fri Sep 13, 2013 12:00 pm, edited 1 time in total.

cocoludro
Posts: 7
Joined: Tue Sep 03, 2013 10:02 am

Re: MultiWii Serial Protocol help...

Post by cocoludro »

I myself used to send data series of a module to another,I will not use it for any flying machine, I'm using 9600 baud. It is the recommended speed arduino. I found this article in the forum by chance and really appreciate your help. Thanks city.

mabaka
Posts: 21
Joined: Thu Oct 17, 2013 12:03 pm

Re: MultiWii Serial Protocol help... -> error

Post by mabaka »

9600 baud - Works!
19200 baud - Works!
38400 baud - Works!
57600 baud - Ignores MSP commands!
115200 baud - Works!


I would suggest modifying SerialOpen() in Serial.ino as appears below. The original code has is weird and relies in optimizer, but should work at 57600. Code below also includes rounding. Obviously it is for little endian and takes advantage from F_CPU being multiple of 4.

I have tried succesfully at 57600 with both FTDI USB and 3DR.

Code: Select all

static void inline SerialOpen(uint8_t port, uint32_t baud) {
union
   {
      uint8_t u8[2];
      uint16_t u16;
   }ubr;

   ubr.u16 = ((F_CPU/4)+baud)/(baud<<1) - 1;
   
  switch (port) {
    #if defined(PROMINI)
      case 0: UCSR0A  = (1<<U2X0); UBRR0H = ubr.u8[1]; UBRR0L = ubr.u8[0]; UCSR0B |= (1<<RXEN0)|(1<<TXEN0)|(1<<RXCIE0); break;
    #endif
    #if defined(PROMICRO)
      #if (ARDUINO >= 100) && !defined(TEENSY20)
        case 0: UDIEN &= ~(1<<SOFE); break;// disable the USB frame interrupt of arduino (it causes strong jitter and we dont need it)
      #endif
      case 1: UCSR1A  = (1<<U2X1); UBRR1H = ubr.u8[1]; UBRR1L = ubr.u8[0]; UCSR1B |= (1<<RXEN1)|(1<<TXEN1)|(1<<RXCIE1); break;
    #endif
    #if defined(MEGA)
      case 0: UCSR0A  = (1<<U2X0); UBRR0H = ubr.u8[1]; UBRR0L = ubr.u8[0]; UCSR0B |= (1<<RXEN0)|(1<<TXEN0)|(1<<RXCIE0); break;
      case 1: UCSR1A  = (1<<U2X1); UBRR1H = ubr.u8[1]; UBRR1L = ubr.u8[0]; UCSR1B |= (1<<RXEN1)|(1<<TXEN1)|(1<<RXCIE1); break;
      case 2: UCSR2A  = (1<<U2X2); UBRR2H = ubr.u8[1]; UBRR2L = ubr.u8[0]; UCSR2B |= (1<<RXEN2)|(1<<TXEN2)|(1<<RXCIE2); break;
      case 3: UCSR3A  = (1<<U2X3); UBRR3H = ubr.u8[1]; UBRR3L = ubr.u8[0]; UCSR3B |= (1<<RXEN3)|(1<<TXEN3)|(1<<RXCIE3); break;
    #endif
  }
}
Last edited by mabaka on Fri Oct 25, 2013 10:59 pm, edited 1 time in total.

linkstatic
Posts: 31
Joined: Sun Jun 23, 2013 5:20 pm

Re: MultiWii Serial Protocol help...

Post by linkstatic »

city_kid wrote:@PatrikE

Thanks for the PDF link. There is some useful information in there!

I have a couple of questions for yourself or EOSbandi:

I have now created a pair of PHP functions that a) uses MSP_SET_RAW_RC to write RC values into the MultiWii and a) uses MSP_RC to read RC values from the MultiWii.

Both of these functions work, and when I set values then read them again I get the same values as I wrote.

The RC values equate to THR, ROlL, PITCH, YAW etc in two-byte format, between 1000 (us) and 2000 (us).

Here are my questions:

1) What order are the RC channels in? THR, ROLL, PITCH, YAW, AUX1, AUX2, AUX3, AUX4, maybe?

2) Which order are the two bytes sent / received? Most significant byte first or least significant byte first?

OK, technically three questions...?!

Many thanks in advance...

PS: I mean to make this suite of PHP function available on the forum once complete and tested. I will hopefully make functions that will be able to read and write any(?) MultiWii setting with easy to use real-world values....

Cheers!

city_kid



Did you get the answer to those questions? Also I have made a python based program on raspberry pi which is sending different commands to the MWII and getting reply, though still in hex values but It can be translated easily once I get time :). If you have the answers to the above questions please do share ^_^ . Have you started to send MSP_RAW_RC values to the MWII. If yes can u kindly tell me what was your exact AT Command to the MWII and what did it mean? If I am not clear please ask cause this means alot to me .

suricool99
Posts: 1
Joined: Tue Jan 07, 2014 3:47 pm

Re: MultiWii Serial Protocol help...

Post by suricool99 »

how to send a write command to multiwii using multiwii serial protocol ?

$M< followed by the data and the commands and the checksum

..
i tried using matlab and labview but its not getting written in the board when i check with multiwii gui ...

georgio
Posts: 1
Joined: Sat May 24, 2014 7:48 pm

Re: MultiWii Serial Protocol help...

Post by georgio »

city_kid wrote:@crashlander

OK, good! This is all correct.

So when you see the first menu: Please select language -> Send a "2" to set English.

Then send the word "SHUNCOM" to enable config mode.

After that you should see a menu of different options like NetID, Node Type, Baud Rate etc etc .

This configuration menu is interactive.

I recommend the following:

1) Give each module it own "MAC_Addr" like "0001" and "0002". This must be unique for each module within the "network"
2) Give each module its own "Node_name" like "GROUND" or "AIR".
3) Set BOTH modules "Node_Type" to "END_Device".
4) Set BOTH modules "Net_Type" to "Peer"
5) Set BOTH modules to the same "Net_ID" like "FF" but the SAME on BOTH modules. This means that both modules are talking / listening on the same "network"
6) Set BOTH modules to the same "Channel" like "0F" (last channel).
7) Set BOTH modules "Data_Type" to "ASCII" This seems to work fine for MSP traffic.
8) Set BOTH modules to the "TX_Type" as "BROADCAST" mode so they listen to data from any transmitter.
9) Set BOTH modules to the same BAUD RATE. I use 115200 baud very well. Please be aware that the configuration baudrate is ALWAYS 38400 baud, regardless of the interface baud rate that you set.
10) Set BOTH modules to "Baud_Rate" as "115200" which I think is option "8"
11) Set BOTH modules to "Parity" as "None"
12) Set BOTH modules to "Data_Bit" as "8+0+1" = 8 data bits, No Parity, 1 stop bit
13) Set BOTH modules "SRC_Addr" to "NOT OUTPUT" so that the receiver doesn't spit out the transmitter address, only the data...

The modules remember their settings each time they are power-cycled as the settings are stored in flash.

Here is my config from testings. Please note that I was originally using 19200 baud for testing purposes...

================================================================================

1) Connect up first.
2) Set to 38400 baud.
3) Press "Config" button for three seconds. *** Actually really for 1 second ***
4) Send "2" for English menus.
5) Send "SHUNCOM" to get config mode.


Ground Module Config
====================

MAC_Addr: (H) 0001 (Unique)
Node Name: GROUND (Unique)
Node_Type: END_Device (Same)
Net_Type: Peer (Same)
Net_ID: (H) FF (Same)
Channel: (H) 0F (Same)
Data_Type: ASCII (Same)
TX_Type: Broadcast (Same)
Baud_Rate: 19200 (Same)
Parity: None (Same)
Data_Bit: 8+0+1 (Same)
SRC_Addr: NOT OUTPUT (Same)


Quad (Air) Module Config
========================

MAC_Addr: (H) 0002
Node Name: QUAD
Node_Type: END_Device
Net_Type: Peer
Net_ID: (H) FF
Channel: (H) 0F
Data_Type: ASCII
TX_Type: Broadcast
Baud_Rate: 19200
Parity: None
Data_Bit: 8+0+1
SRC_Addr: NOT OUTPUT

================================================================================

Once these two modules are setup correctly you can just put data into one and and it should fall out of the other end!

Hope this helps....

city_kid


Hello,

In case I have 3 zigbee modules:

number_1 is connected through RS232 to my PC,
number_2 is connected through RS232 to microcontroller,
number_3 is connected through RS232 to microcontroller.

In code level how I make it the number_2 send data in number_1, and number_3 sends data to number_1?

Inside the manual it says

"D e s t i n a t i o n
address is the twobyte
MAC Address,
this address will
be added in front
of the data packet."

Below I write my code for PIC

Code: Select all

char uart_rd;

void main()
{
    ANSEL = 0; // Configure AN pins as digital
    ANSELH = 0;
 
    UART1_Init(9600); // Initialize UART module at 9600 bps
    Delay_ms(100); // Wait for UART module to stabilize

    UART1_Write_Text("Start");
    UART1_Write(10);
    UART1_Write(13);
 
    while (1)
    {                // Endless loop
       if (UART1_Data_Ready())
       {                // If data is received,
           uart_rd = UART1_Read(); // read the received data,
           UART1_Write(uart_rd); // and send data via UART
       }
    }
}



In other words, how do I specify in code level in which mac address to send data each time?

chs93114
Posts: 1
Joined: Tue Jan 05, 2016 3:14 pm

Re: MultiWii Serial Protocol help...

Post by chs93114 »

city_kid wrote:@Trinca

Here is my (very) simple Arduino code for sending MSP_SET_RAW_RC messages:

Code: Select all

int MSP_SET_RAW_RC(boolean force){
   
    if(force==true or THR!=PREV_THR or PREV_PITCH!=PITCH or PREV_ROLL!=ROLL or PREV_YAW!=YAW or PREV_AUX1!=AUX1 or PREV_AUX2!=AUX2 or PREV_AUX3!=AUX3 or PREV_AUX4!=AUX4){
     
        byte checksum=0;
        byte command[23];
       
        command[0]=36;  // Start of command $
        command[1]=77;  // Start of command M
        command[2]=60;  // Start of command <
        command[3]=16;  // Length of data
        command[4]=200; // MSP_SET_RAW_RC
       
        command[5]=ROLL & 0xFF;     // ROLL LSB
        command[6]=ROLL >> 8;       // ROLL MSB
       
        command[7]=PITCH & 0xFF;    // PITCH LSB
        command[8]=PITCH >> 8;      // PITCH MSB
       
        command[9]=YAW & 0xFF;      // YAW LSB
        command[10]=YAW >> 8;        // YAW MSB
       
        command[11]=THR & 0xFF;      // THR LSB
        command[12]=THR >> 8;        // THR MASB   
       
        command[13]=AUX1 & 0xFF;     // AUX1 LSB
        command[14]=AUX1 >> 8;       // AUX1 MSB
       
        command[15]=AUX2 & 0xFF;    // AUX2 LSB
        command[16]=AUX2 >> 8;      // AUX2 MSB
       
        command[17]=AUX3 & 0xFF;    // AUX3 LSB
        command[18]=AUX3 >> 8;      // AUX3 MSB
       
        command[19]=AUX4 & 0xFF;    // AUX4 LSB
        command[20]=AUX4 >> 8;      // AUX4 MSB
       
        for(int x=3;x<21;x++){checksum=(checksum ^ command[x]);}
        command[21]=checksum;
       
        command[22]=0;
       
        if(debug_msp){
            Serial.print("Command: ");
            for(int x=0;x<22;x++){Serial.print(command[x]);Serial.print(" ");}
            Serial.println();
            }
       
        int bytes_transmitted=rf_transmit(command,22);         
               
        PREV_THR=THR;
        PREV_PITCH=PITCH;
        PREV_ROLL=ROLL;
        PREV_YAW=YAW;
        PREV_AUX1=AUX1;
        PREV_AUX2=AUX2;
        PREV_AUX3=AUX3;
        PREV_AUX4=AUX4;
       
        last_control_tx=micros();
        return bytes_transmitted;       
       
        }
   }


This has worked fine in Arduino (which it looks like you're using) and PHP via Raspberry Pi (Early control platform)

It checks to see if any of the 8 RC channels have changed OR you call the function using force=true.

It's commented because I spent a long time trying to get it to work. Once it does work, it's totally good.

Cheers!

city_kid



how to use this code in c#??
what is micros()?? and last_control_tx?

Post Reply