Skip to content

Instantly share code, notes, and snippets.

@max-mapper
Created November 27, 2012 06:55
Star You must be signed in to star a gist
Save max-mapper/4152815 to your computer and use it in GitHub Desktop.
droneduino

droneduino

parrot ar drone 2.0 arduino communication with node

possible other names: ardrono, dronenodeuino, ardronenodeuino, arnodedroneduino ahahahah

above shot is from @rem

getting node on the drone

  • download node and node-serialport from https://github.com/felixge/node-cross-compiler/downloads
  • untar node-serialport and put node and the node-serialport folder onto a usb thumbstick thingy
  • put the thumbstick thingy into the drone (like in the above photo)
  • telnet into drone, telnet 192.168.1.1
  • cd /data/video
  • cp usb/node . (it might be usb1)
  • chmod +x node
  • mkdir node_modules
  • cp -r usb/node-serialport/ node_modules/
  • note: you can use node-serialport to get data from arduino but you can't use johnny-five because it depends on firmata which doesn't support Tx/Rx serial communication
  • this last point means you have to write actual arduino sketches and upload them to the arduino directly, but you can still write node code that runs on the drone to reads the serial data
  • also I found out that since the serial port on the drone is intended as a debug console you will get a bunch of debug data spewing out at you from the boards Tx pin. I don't know how to turn it off at this time. what this means is you can send data into the drone over serial but you can't (to my knowledge -- someone should hack this) send data from the drone over serial to a device yet

here is where things get tricky

  • be very careful that you don't eff up your drone! proceed with caution
  • the drone has a female USB port exposed next to the battery connector but unfortunately it is hardcoded into host mode so it can only be used with mass storage devices :(
  • that last point is based on my naive understanding of electronics. prove me wrong and fork these instructions!
  • there is another serial console on the drone motherboard
  • open up the bottom of the drone under the little piece of black tape to expose a buncha plastic hole thingies:

  • turns out this has pins for TTL serial communication and USB serial communication. this awesome post by jazzomaniak is where I figured this out
  • here is a pinout from jazzomaniak:

  • ** it has come to my attention that the serial console tx/rx pins on the AR Drone 2 run at 1.8v which means you'll need a level converter to talk to the arduino. here is a schematic from the mirumod project that shows where the level converter should be installed **
  • without a level converter i still was able to receive and transmit serial data from arduino to drone but it was flaky. i believe (but have not yet tested) that after fixing the voltage mismatch that communication will be much more reliable
  • you'll wanna get some thinnish gauge wire (around AWG 16 I reckon, AWG 22 is for most breadboards and my 22 wire didn't fit into the drone serial ports)
  • get an arduino uno which provides 5v or 3.3v TTL serial via digital ports (Rx and Tx). due and uno have this, not sure about others
  • here is a shot from @rem of drone with the entire bottom cover removed

  • you can also theoretically power the arduino from #8 and #9 on the drone if you hook them up to a barrel power jack thingy for the arduino (or use the Vin and GND pins for the same effect). I haven't hooked this up yet cause I ran out of cables. @rem in the comments below said he got it working
  • you can also use the other USB port on the drone to power the arduino, but I don't have a short enough USB cable for this
  • upload the sketch in this gist called helloworld.pde to the arduino
  • in a telnet shell on the drone type cat /proc/cmdline and find out which tty device the 'console' is set to. on my drone it was ttyO3
  • set the tty socket to raw mode: stty -F /dev/ttyO3 -raw
  • verify the baud rate of the socket: stty -F /dev/ttyO3. mine originally said 115200 but after messing with it it seems to change to 9600. the arduino sketch and the node code running on the drone need to both contain whatever stty tells you the baud rate is for communication to work.

  • the Input/output error above is because I was sending serial data from the arduino into the drone. I unplugged the serial cables from the arduino and tried the command again and it worked. I think it was around this time that the drone decided to switch baud rates to 9600

  • go into a node repl (./node) and copy paste in helloworld.js from this gist

var serialport = require('node-serialport')
var sp = new serialport.SerialPort("/dev/ttyO3", {
parser: serialport.parsers.raw,
baud: 9600
})
sp.on('data', function(chunk) {
console.log(chunk.toString('hex'), chunk.toString(), chunk)
})
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println("hello");
delay(10);
}
@eendeego
Copy link

This is so full of awesome!!

BTW, where you say " if you hook them up to a barrel power jack thingy ", you can also use Vin and Gnd pins for exactly the same effect.

@brianleroux
Copy link

wat! this is rad!!!

@max-mapper
Copy link
Author

@luismreis OHH thanks!

@remy
Copy link

remy commented Nov 27, 2012

Just got this working - awesome work @maxogden.

For other people playing - my drone would give a red light in the motherboard when it booted with the arduino attached - this meant that the boot up had failed and thus wifi wasn't going to start up.

The solution is to simply attach the arduino after the drone has booted up.

I also powered the arduino from the USB+GND (8) and USB+5 (9) and just wired them in to the GND and Vin connectors respectively on my arduino and the power runs through.

One thing to note (IIRC) - when I tested the helloword.pde file from my machine to the arduino, the RX+TX lights were flashing away. Once connected to the drone, this didn't happen - and I initially assumed it wasn't working. But lo and behold, connect using node.js - and you get your "hello world" pumped down the serial connection.

I should also add that my baud rate remained at 115200 - but my sketch and node.js code used 9600. Not sure how it changed, but it just seemed to work (when I checked the baud rate after running the node.js script - it was showing 9600).

Awesome work Max. My next plans: Plan A - upload a sketch to read proximity data. Plan B: wire up a USB female connector (already on it way to me) so I can use @rwldrn's Johnny-five :)

@rklancer
Copy link

Do you know offhand if this would (be expected to) work on a "1.0" ardrone? I might have access to one shortly...

@max-mapper
Copy link
Author

@rklancer there will be differences in the drone serial pinout as well as processor architecture so you may need to cross compile node and node-serialport against a different target.

@csanz
Copy link

csanz commented Nov 28, 2012

This is so cool

@rwaldron
Copy link

Rad

@A-L-E-X
Copy link

A-L-E-X commented Nov 29, 2012

Hi
Does anybody know what kind of chip is on the AR drone main board?
It is marked U1600, having the following inscription on it:
YE 06
(It is placed near the double LED and nav board connector)

@ProZachJ
Copy link

So having node onboard you are able to program flight control? Does this take away the ability to use the highlevel APIs provided by the manufacture to control the drone via wifi?

@max-mapper
Copy link
Author

@ProZachJ the firmware is closed source so you still have to interface with the drones flight control but being able to run node on the drone allows for autonomous control rather than having to rely on wifi range

@afosterw
Copy link

afosterw commented Dec 1, 2012

Why would you want to do this? Is the idea to write flight control code in JS?

@alyberty
Copy link

I want to get my GPS(uBlox Lea6) running. The problem is, I only receive the first 16 ASCII caracters. For those who are interested in it, it is an NMEA GGA message. Is it normal, or did I do anything wrong. Or is there a way to fix it. I am trying to avoid an extra arduino which would convert the message.

@kenkenrep1ew
Copy link

Thank you!!
I can get 'hello' from arduino via ARDrone console by following this page.

@Cherrybombas
Copy link

I was beginning to open the serial port rxtx, today I connect my arduino to the ar drone and I get the data from the ardrone (port ttyO3) through of telnet, I want to do a control program the ardrone and I can get the dato from the serial port, do you know, How I can get the data from the serial port in a program?
thanks

@chiarae
Copy link

chiarae commented Aug 12, 2013

Hi,
is this the correct way to wire the level shifter?
http://img822.imageshack.us/img822/1589/je6e.jpg

When connected to the Arduino, is it be possible to send the emergency landing command (client._ref.emergency = true) with a wireless device like a mobile or a pc?

Thanks in advance!

@kielg01
Copy link

kielg01 commented Apr 3, 2014

can i connect 3 sensors with this? tnx.

@pchatrath
Copy link

Hello,
This is really cool! I have 2 questions to be asked.

  1. According to the post and comments we can display "Hello" using serial connection. I didnt get this point clearly. Does this means we have a code transmitting data serially TO AR Drone writeen in Arduino. And then AR Drone connected to PC via Wifi connection. So does the "Hello" travel from Arduino serially into AR Drone and from there we see the hello on PC using Telnet?? Is this correct? If not then what is the route?
  2. My aim is to control 1 leader drone manually and then the leader drone communicate its control signals to 2 other drones. And I want decentralized processing. So cant include PC in between. So can I have an arrangement as follows:

Leader Drone -> Arduino ->XBee ---------------- XBee -> Arduino -> Follower Drone

Here Leader drone transmit control signal serially to Arduino.
Arduino has 2 serial port. 1 Rx/Tx for communicating with drone and 2nd for connecting to XBee.
XBee to XBee - Wireless communication
And receiver side same type of arrangement

It will be great if someone can provide some info on this. Thank in advance

@kris1e
Copy link

kris1e commented Jun 11, 2014

Hello I want to ask you if these steps are the same for ar.drone 1.0?
The ports are the same? I mean do i have a place to wire the arduino with the ardrone 1.0?
Thank you in advance

@icyore
Copy link

icyore commented Jun 13, 2014

do you get sensor data using telnet ,thx?

@agatefirmament
Copy link

Hello! thanks for this reaaaally useful walk-through. I'm running into some problems when i'm in the REPL. As soon as I get into the ./node, the cursor that comes up is [0J> instead of just a >. The code I put in doesn't get the returned messages like what you have so I suspect it's not working properly. I've done a bit of googling to no avail. Do you or anyone visiting this page know why node.js is being weird?

I'm using windows 10, AR drone 2.0 with the new 5 pin port at the bottom.

@hyejin930107
Copy link

Thanks for your post. Hi, I am a student in Korea. I'd like to add another electromagnetic to the drone. And I want the drone to send signal to electromagnetic when i sign to the drone. I mean signal in app-> the drone-> the magnetic(connected to the drone) working. So I am wondering weather i need to modify the drone code or not. As I understand, there is no post about the drone code in your post. I want you to help.Thank you.

@KatherineJames
Copy link

Does anyone know how to overcome the problem in the image below? I get this instead of input from the Rx port, despite having followed the above instructions exactly.

I am using an atmega32u4 and just sending 'hello' in a similar fashion to the demonstrated .pde file. I'm using windows 7 and the AR Drone 2.0.

image

@KatherineJames
Copy link

Solved the problem by using 'baudrate' instead of 'baud' on line 5. Still get the other thing, but the data comes out too. Thanks @maxogden for a very useful gist!

@jumping08
Copy link

jumping08 commented Nov 12, 2016

Hi @maxogden

You said,

"I don't know how to turn it off at this time. what this means is you can send data into the drone over serial but you can't (to my knowledge -- someone should hack this) send data from the drone over serial to a device yet"

Is there a possibility now to send drone data to a device? Can this be done using the Drone's Wifi?

@jb-91
Copy link

jb-91 commented Nov 25, 2016

Hi @maxogden.
I connect USB pen to ArDrone but in telnet there isn't usb/ or usb1/ folder.
What is the problem?

@wzsyq1995
Copy link

Hello,
This is really cool! I have 2 questions to be asked.

  1. According to the post and comments we can display "Hello" using serial connection. I didnt get this point clearly. Does this means we have a code transmitting data serially TO AR Drone writeen in Arduino. And then AR Drone connected to PC via Wifi connection. So does the "Hello" travel from Arduino serially into AR Drone and from there we see the hello on PC using Telnet?? Is this correct? If not then what is the route?
  2. My aim is to control 1 leader drone manually and then the leader drone communicate its control signals to 2 other drones. And I want decentralized processing. So cant include PC in between. So can I have an arrangement as follows:

Leader Drone -> Arduino ->XBee ---------------- XBee -> Arduino -> Follower Drone

Here Leader drone transmit control signal serially to Arduino.
Arduino has 2 serial port. 1 Rx/Tx for communicating with drone and 2nd for connecting to XBee.
XBee to XBee - Wireless communication
And receiver side same type of arrangement

It will be great if someone can provide some info on this. Thank in advance

hi have you solved these problems because i am doing similar project as you(use Parrot AR 2.0)
Can you email me to chen.he@ucdconnect.ie
Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment