dlktdr / HeadTracker

This project is built to record the orientation a FPV headset to allow the camera on your RC to follow your head movements.
GNU General Public License v3.0
361 stars 81 forks source link

export roll, tilt, pan values through pins #174

Closed TalalSultan closed 1 month ago

TalalSultan commented 1 month ago

hello, i have 2 arduinos ,1 arduino nano BLE which has the software installed in it, and another arduino uno.

all i want is to export the values of the roll, tilt, pan from the nano BLE and read them in the arduino uno, how can i do that ?

rotorman commented 1 month ago

One option would be to output inverted S.BUS (=std UART) from your nano BLE with HeadTracker firmware and read in the S.BUS signal using your Arduino Uno serial port.

In HeadTracker use the following settings: image

Attach GND and P1.03 of Arduino Nano 33 BLE to your Arduino Uno GND and serial RX pin (D0). For S.BUS processing on Arduino Uno, see e.g.: https://github.com/bolderflight/sbus -> https://www.arduino.cc/reference/en/libraries/bolder-flight-systems-sbus/ (available in Arduino IDE)

(Note that the microcontroller on Arduino Nano 33 BLE runs at 3.3V, whereas on Arduino Uno R3 it runs at 5V. Nevertheless, the 3.3V logic signal from Nano 33 BLE should be high enough to be able to read correctly on 5V Arduino Uno R3).

TalalSultan commented 1 month ago

Thank you for replaying, i did the connection but im getting weird values code example from sbus i used :

/*
* Brian R Taylor
* brian.taylor@bolderflight.com
* 
* Copyright (c) 2022 Bolder Flight Systems Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the “Software”), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

#include "sbus.h"

/* SBUS object, reading SBUS */
bfs::SbusRx sbus_rx(&Serial);
/* SBUS object, writing SBUS */
bfs::SbusTx sbus_tx(&Serial);
/* SBUS data */
bfs::SbusData data;

void setup() {
  /* Serial to display data */
  Serial.begin(9600);
  while (!Serial) {}
  /* Begin the SBUS communication */
  sbus_rx.Begin();
  sbus_tx.Begin();
}

void loop () {
  if (sbus_rx.Read()) {
    /* Grab the received data */
    data = sbus_rx.data();
    /* Display the received data */
    for (int8_t i = 0; i < data.NUM_CH; i++) {
      Serial.print(data.ch[i]);
      Serial.print("\t");
    }
    /* Display lost frames and failsafe data */
    Serial.print(data.lost_frame);
    Serial.print("\t");
    Serial.println(data.failsafe);
    /* Set the SBUS TX data to the received data */
    sbus_tx.data(data);
    /* Write the data to the servos */
    sbus_tx.Write();
  }
}

i get random outputs 35iZ��M! 35iZ����5��\�q�_��3MУZ=�

dlktdr commented 1 month ago

It looks like your using the same Serial device for the communication for sbus and the connection to your computer.

Should use &Serial2 for the SBUS connection. As soon as you call the sbus_rx.Begin() it would change your baud values on Serial(the pc connection)

If the board your trying to get this to with on doesn't have Serial2 might be able to look into soft serial for the pc connection.

Oops didn't mean to close..

rotorman commented 1 month ago

I wonder if it might actually work out with only a single serial, as the inverted S.BUS input on Arduino Uno is only using the RX pin and the output stream from the code above the TX line. Try using on the computer terminal the S.BUS serial parameters, thus instead of 9600 baud 8N1 (8 data bits, no parity bit and 1 stop bit), try 100.000 baud and 8E2 (8 data bits, even parity and 2 stop bits -> https://github.com/bolderflight/sbus/blob/003c5c33a75fc3e54dee90caff1f84e0fb9a5666/src/sbus.cpp#L41 and https://github.com/bolderflight/sbus/blob/003c5c33a75fc3e54dee90caff1f84e0fb9a5666/src/sbus.cpp#L77 )

TalalSultan commented 1 month ago

it worked! i had to use platformIO to open a custom serial port with 100000 baud and 8E2 and i managed to get all the channel readings thankfully, thank you all for helping