Servers by jDrones

Bluetooth Integration of Pixhawk w/ Android - Read?

Hello,

I have created a database accessible by an Android app that stores GPS waypoints. You can insert waypoints into the database by clicking on a Google Map or writing them out. I have created Bluetooth capabilities in the app that can relay GPS cordinates, either of the phone or from the DB.

But how can I write a python script that reads from the bluetooth dongle I have in the TELEM 1 port of my Pixhawk? I have spent this whole Sunday trying to connect the App with the board. I have not yet even connected my phone with the bluetooth dongle I bought from 3DR. However, I have sent the GPS information from my phone to PC over bluetooth.

I know there has to be a way to serially read the inputs of the TELEM 1 port with a python script.

If anyone would be able to help me read Bluetooth data from the TELEM 1 port through a Mission Planner script I would be very excited to report how it all works.

Thanks,

Craig :slight_smile:

What I really need help with is figuring out how to read the bluetooth with so I can fill these values in my python script:

MissionPlanner.Utilities.Locationwp.lat.SetValue(item,lat)
MissionPlanner.Utilities.Locationwp.lng.SetValue(item,lng)
MissionPlanner.Utilities.Locationwp.alt.SetValue(item,alt)

I just do not know how to read from the TELEM1 port with the Mission Planner python. If I could then I could fill lat, lng and alt with appropriate values. I’m sure I could figure out/find a py module to do this, unfortunately I can not figure out how to even read the pin’s input, or really where to look.

I have been digging around the internet all day, and have started sifting through the source code, but no luck so far. I will continue digging through the source code, but hopefully someone here can help!

Thanks!

Sorry for continually replying to my own thread:

But it looks like somebody reads from the USB port with this script:

[code]import serial
ser = serial.Serial(port=’/dev/ttyUSB0’, baudrate=57600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=0)

print("connected to: " + ser.portstr)

while True:
print ser.readline()[/code]

Which I will try when I get home, however I am confused as to what port the TELEM1 port is? If someone could point me to where I can find that information I would apreciate it. I assume I will read it with something like:

ser = serial.Serial(port='/dev/ttyTELEM1', baudrate=57600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=0)

But I am not sure. Thanks!

Source: stackoverflow.com/questions/2422 … sing-cable

Well, havent gotten help yet so I’m just going to post my progress (or lack of it! :unamused: ) as well my ideas for going forward this weekend.

I believe I will have to go into the ArduPilot code and expose the reads from the TELEM pin to the Mission Planner python scripts. Since this code is written in c++ I think this will just be:x = serialRead(TELEMPIN); After reading this data my new plan of attack is to go and transform the recieved bluetooth data into a message/packet for the python to access somehow. Then the script will be able to read a gps cord from the bluetooth data and set it to the current waypoint, as outlined above.

It looks like I will be able to expose the class with this code:

scope = engine.CreateScope(); scope.setVariable("btRead", btGeoMessage);

If anyone can think of an easier way, or see’s a flaw in this one, I would apreciate you letting me know prior to me begining this effort this weekend.

If the above is succesfully done in the ArduPilot code, then I beleive I will have exposed the btGeoMessage class I will implement to my python script. Then I will be able to read geo data over bluetooth from my android phone that it recieves from my server via REST. :smiley:

P.S. I have made a similar post in diy drones: diydrones.com/forum/topics/readi … e=activity

Well, I mostly got it. It was easy once I redid the tutorials. I plugged my bluetooth module into the TELEM1 port and used the following code:

The read method:

[code]static void test_uart(AP_HAL::UARTDriver *uart, const char *name)
{

if (uart == NULL) {
    // that UART doesn't exist on this platform
    return;
}

uart->printf("Hello on UART %s at %.3f seconds\n",  name, AP_HAL::millis()*0.001f);


//read loop:

char c = 0;

   while(hal.uartC->available() > 0){

      c     = hal.uartC->read();
     hal.console->print(c);
     readBTdata = true;
   }
   
   if(readBTdata == true){
	   readBTdata = false;
	   hal.console->printf("\n");
	   
	   set_tune(TONE_ZELDA_LULLABY);
   }   

}
[/code]
I do wonder if there is any issue to just reading until nothing is available. Perhaps it would be better to read into a fixed size array. Also, readBTdata is a global private bool declared in the begining of the script. It is not needed, as a line is added at the end. However, it is useful to add any other methods/functions you want to do in this if block.

I modified one of the examples, UART_TEST , to accomplish this. So if you are using this make sure you grab the other methods called in this example to initialize the uart port. To use I first tested with the bluetooth terminal Android app on the playstore, then with my own app. This should print a line to your phone with the time in seconds, and print whatever is received to a serial port. I’ll be releasing my app soon!

Servers by jDrones