Meade Telescope Plugin and arduino

1 2 > >> (Page 1 of 2)
  • Francesco

    Francesco - 2012-04-15

    i'm trying to interface stellarium and an Arduino based telescope motor
    through the Telescope plugin using the meade lx200 protocol as described here-
    I have successfully answered to the getRA command but the getDEC command gives
    me problems:
    in fact in the protocol documentation it says that i have to send back the
    value of the Declination as


    i think s is the sign(+ or -) and i give random numbers on D and M (eg.


    . this is what i send back through Serial.
    But in the log message it says:

    15445, 11:34:00.890104Z: Lx200Connection::sendCommand(Lx200CommandGetRa)
    15445, 11:34:00.890104Z: Lx200Connection::writeFrontCommandToBuffer(Lx200CommandGetRa): queued
    15445, 11:34:00.890104Z: Lx200Connection::sendCommand(Lx200CommandGetDec)
    15445, 11:34:00.890104Z: Connection::performWriting: writeNonblocking(5) returned 5; #:GR#
    15445, 11:34:05.904390Z: Lx200Connection::resetCommunication
    15445, 11:34:05.921391Z: Lx200Connection::sendCommand(Lx200CommandGetRa)
    15445, 11:34:05.921391Z: Lx200Connection::sendCommand(Lx200CommandGetDec)
    15445, 11:34:15.952965Z: Lx200Connection::writeFrontCommandToBuffer(Lx200CommandGetRa): queued
    15445, 11:34:15.952965Z: Connection::performWriting: writeNonblocking(5) returned 5; #:GR#
    15445, 11:34:16.018969Z: Connection::performReading: readNonblocking returned 11; 03:00:00#
    15445, 11:34:16.018969Z: Lx200CommandGetRa::readAnswerFromBuffer: RA = 03:00:00
    15445, 11:34:16.018969Z: Lx200Connection::writeFrontCommandToBuffer(Lx200CommandGetDec): queued
    15445, 11:34:16.077972Z: Connection::performWriting: writeNonblocking(5) returned 5; #:GD#
    15445, 11:34:16.138976Z: Connection::performReading: readNonblocking returned 7; +45*00#
    15445, 11:34:16.138976Z: Lx200CommandGetDec::readAnswerFromBuffer: error: '+' or '-' expected
    15445, 11:34:16.138976Z: Lx200Connection::resetCommunication
    15445, 11:34:16.202979Z: Lx200Connection::sendCommand(Lx200CommandGetRa)
    15445, 11:34:16.202979Z: Lx200Connection::sendCommand(Lx200CommandGetDec)
    15445, 11:34:16.202979Z: Connection::performReading: readNonblocking returned 2;

    I don't know how to solve the

    errot '+' or '-' expected

    Thanks in advance for any help

  • barrykgerdes

    barrykgerdes - 2012-04-15

    That is the standard protocol for the LX200 but you may be having a speed
    problem where the arduino control is being converted to meade format.. I
    imagine you have written a program into the PIC (I think that is what is

    Speed of conversion was a problem we experienced with the ETX70 mounts and a
    slower version of the Stellarium control was developed and called ETX70

    Try this version and see if it works


  • Francesco

    Francesco - 2012-04-16

    Just tried it, nothing changed... :(
    the only thing i can send wrong is how the string with the DEC is formatted,
    maybe i do something wrong in how the + sign should be written;
    The better would be if somebody with that mount(lx200 compatible) could
    connect it to stellarium configure it and post the log files in
    AppData/Roaming/Stellarium, that would be really appreciate.

    Thanks anyway Barry for the try


  • barrykgerdes

    barrykgerdes - 2012-04-16

    I just connected to an LX200 and the telescope protocol worked fine.
    There is no information in the log file other than

    Creating telescope "New Telescope 1:TelescopeServerLx200:J2000:COM1:500000" ;
    name/type/equinox/params: "New Telescope 1" "TelescopeServerLx200" J2000
    TelescopeClientDirectLx200 paramaters: port, time_delay: "COM1" 500000

    What version of stellarium are you using
    Stellarium no longer users the old telescope control that had to be initiated
    separately and gave that log reading.

    I don't think I still have the programs unless they are still in the wiki


  • barrykgerdes

    barrykgerdes - 2012-04-16

    I found the older server program and ran it on my LX200

    Here is a portion of the log file I generated from it

    C:>TelescopeServerLx200.exe 10000 COM1:
    This is TelescopeServerLx200.exe, built on Sep 10 2006, 23:52:38
    15446,23:02:08.515625: Lx200Connection::sendCommand(Lx200CommandGetRa)
    Lx200Connection::writeFrontCommandToBuffer(Lx200CommandGetRa): queued
    15446,23:02:08.515625: Lx200Connection::sendCommand(Lx200CommandGetDec)
    15446,23:02:08.531250: listening on port 10000
    15446,23:02:08.531250: Connection::performWriting: writeNonblocking(5)
    returned 5; #:GR#
    15446,23:02:08.562500: Connection::performReading: readNonblocking returned 9;
    15446,23:02:08.562500: Lx200CommandGetRa::readAnswerFromBuffer: ra = 19:50:47
    15446,23:02:08.562500: ServerLx200::raReceived: 3551649634
    Lx200Connection::writeFrontCommandToBuffer(Lx200CommandGetDec): queued
    15446,23:02:08.578125: Connection::performWriting: writeNonblocking(5)
    returned 5; #:GD#
    15446,23:02:08.593750: Connection::performReading: readNonblocking returned 7;
    15446,23:02:08.609375: Connection::performReading: readNonblocking returned 3;
    15446,23:02:08.609375: Lx200CommandGetDec::readAnswerFromBuffer: dec =
    15446,23:02:08.609375: ServerLx200::decReceived: 105819907
    15446,23:02:09.015625: Lx200Connection::sendCommand(Lx200CommandGetRa)
    Lx200Connection::writeFrontCommandToBuffer(Lx200CommandGetRa): queued
    15446,23:02:09.015625: Lx200Connection::sendCommand(Lx200CommandGetDec)
    15446,23:02:09.015625: Connection::performWriting: writeNonblocking(5)
    returned 5; #:GR#
    15446,23:02:09.031250: Connection::performReading: readNonblocking returned 6;
    15446,23:02:09.046875: Connection::performReading: readNonblocking returned 3;
    15446,23:02:09.046875: Lx200CommandGetRa::readAnswerFromBuffer: ra = 19:50:47
    15446,23:02:09.046875: ServerLx200::raReceived: 3551649634


  • Francesco

    Francesco - 2012-04-17

    Unfortunately it doesn't work, in fact from your log file it seems the
    telescope has sent back "+08ß52:11#" through the serial port but if i use the
    ß character it doesnt work, it receives "Ã?", now i think there is only one
    chance more, to try connecting the telescope to arduino IDE and through the
    serial monitor send #:GD# and see exactly what it gets.

    Thanks alot anyway for the help

  • barrykgerdes

    barrykgerdes - 2012-04-17

    Hi Francesco

    That should be a do nothing character and not be interpreted. It is the
    position that is later occupied by a degree sign. It could be a problem with
    the language of you operating system. You should be able to program your
    arduino to return some other character (*) at this point.


  • Francesco

    Francesco - 2012-05-13

    I solved the problem two weeks ago, but want to share what the problem was;
    the problem consisted in how i send the DEC back to stellarium, in fact i used


    so it received the RA and after the string it added a


    which stellarium after appends to the DEC string and tries to analize it
    instead of the "+" or "-", i solved simply by using


    which doesn't append anything to what i send back.

    Thanks anyway to barry for the help

  • Yamini

    Yamini - 2012-06-18


    I have taken up exactly the same as a project and it'll be fair to call me a
    Could you please tell me how exactly do I need to program the arduino so that
    stellarium recognizes it as a "compatible Lx200" ? The LX200Command code in
    stellarium lists only 5-6 of the commands listed in the pdf. Will programming
    it only for those be sufficient? Also, do I need to make any changes in
    Stellarium's TelescopeControl code?

    Those are a lot of questions but even the slightest help will be appreciated.


  • Francesco

    Francesco - 2012-06-19


    first of all a bit of theory:

    1. Stellarium talks to the meade telescopes using the Lx 200 Communication Protocol through COM port, so any device connected to the COM port specified in Stellarium, which answers in the right way to the "protocol compliant questions" is recognized by stellarium as a Meade lx200 telescope and should work without problems;

    2.Stellarium is the first to send a question through the COM port, there is no
    verification process. It starts immediatly by asking the actual DEC and the RA
    the telescope points to.

    3.It goes on asking while the telescope is set on CONNECTED, so the telescope
    (Arduino in this case) has no need to say "i've changed position", the
    telescope just answers the Stellarium's questions.

    4.All the questions stellarium could do and how you have to structure the
    answers are described in the pdf i linked, so you can program an answer for
    quite all the situation (but to save space it is better to analyse which
    situations are possible to happen).

    5.Quite the most important, if you don't give stellarium an answer or give the
    wrong answer he just forget it and restart asking where are you pointed to,
    this is very useful if you didn't think something could happen but it
    happened, the program won't freeze.

    Now to the practice:

    The directory where you can find the log file is in AppData/Roaming/Stellarium
    , the log file is the one named log_TelescopeServer(n°) the one called simply
    "log" is unuseful.

    As you can see when stellarium connect to arduino it:
    1. sends via Serial the request for the current RA of the telescope with the command "#:GR#"
    2. i programmed the arduino in a way if the string received is equal to "#:GR#" it sends back his RA position structured as HH:MM:SS
    3. Stellarium accepted the position and set this as the telescope plugin position
    4,5,6 as before, only it is for DEC and not for RA so i send back DEC
    structured as (+ or -)DegDeg:MM:SS

    ONLY when he received also the declination and accepted it as valid it'll
    display the yellow circle in the sky map, if RA or DEC are not accepted it
    will restart and display the circle at the precedent RA, DEC values, if it was
    the first request then it will not display anything.

    IMPORTANT: make sure you send data via Serial with the command Serial.print
    and NOT Serial.println because the second one adds a \n which Stellarium
    doesn't accept.

    I wrote you only about the first connection, but you can experiment, just in
    stellarium do what you want your telescope to do(e.g. slew the telescope to
    somewhere), in the log file you see what it sends to arduino (Writenonblocking
    line) and search the protocol file to know how to answer that specific
    command, step by step you will write a program capable of interfacing itself
    with Stellarium.

    Hope this can help you,
    Francesco Servida

  • Francesco

    Francesco - 2012-06-19

    the second image is wrong it should have been:

  • Yamini

    Yamini - 2012-06-22


    Thanks a lot for taking the time to respond.

    I programed the arduino to accept the #:GR# and #:GD# command. The problem is
    that in Stellarium it shows the connection status as "Stopped". I checked the
    serial data coming to the arduino and it turns out it isn't receiving any data
    at all. (I used the serial monitor) Do I need to make any changes to the code
    of Stellarium? Which version of Stellarium are you working with?

  • Leon

    Leon - 2012-06-22

    you can't use the monitor and Stellarium at the same time on the port... that
    is why you dont see anything.
    youll need a program like serial sniffer to act as a men in the middle to see
    the communication between the two

  • Francesco

    Francesco - 2012-06-22

    Basically, if it shows stopped after you press connect it means you set in
    stellarium the false COM port,
    For the problem with the monitor, lion is right, only one program at a time
    can access the COM port, however you don't need a program like serial sniffer
    because all that is sent throug serial is registered in the log file, that you
    can open anytime you want.

  • Leon

    Leon - 2012-06-22

    ok guys, over the day i was able to write a code that communicates perfectly
    with stellarium.
    i am posting here the fuction that sends RA/DEC from degree format to RA in
    HH:MM:SS and DEC in sDD:MM:SS
    it is still bugged i think in the ra and dec calculations.

    String proccesCommand(String currCommand)//, double dec, double ra)
      az = (map(analogRead(A8),0,1023,0,359));//*(M_PI/180);
      alt = (map(analogRead(A15),0,1023,0,90));//*(M_PI/180));
      dec = calcDec(az, alt);
      ra= calcRa(az, alt, dec);
      double mod;
      int intPart;
    //attempt to stabilize
      if(dec > preDec + 50 || dec < preDec - 50){
        dec = preDec;
      if(ra > preRa +50 || ra < preRa- 50){
        ra= preRa;
      preDec = dec;
      preRa = ra;
      if(currCommand == "#:GR#"){
        currCommand = "";
        mod = fmod(ra/15, 1);
        intPart = (int)ra/15;
        if(intPart < 10){////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
          currCommand +="0";
        currCommand +=intPart;
        currCommand +=":";
        // next times the MOD1 of degrees by 60 so we can find the integer part for minutes.
        // get the MOD1 of the new coord to find the numbers after the decimal point.
       ra = mod * 60;
        mod =  fmod(ra,1);
        intPart = (int)ra;
        //Serial.print("MM ");//////////////////////////////////////////////////
        if(intPart < 10){///////////////////////////////////////////////////////////////////////////////
          currCommand +="0";
        currCommand +=intPart;
        currCommand +=":";
        ra = mod * 60;
        intPart = (int)ra;
        if(intPart < 10){/////////////////////////////////////////////////////////////////////////////
          currCommand +="0";
        currCommand +=intPart;
        currCommand +="#";
      if(currCommand == "#:GD#"){
        currCommand = "";
        if(dec > 0){
          currCommand +="+";
          //currCommand += "+";
          currCommand +="-";
          //currCommand +="-";
          dec *= -1;
        mod = fmod(dec,1);
        intPart = (int)dec;
        if(intPart < 10){////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
          currCommand +="0";
        currCommand +=intPart;
        currCommand +=":";
        dec = mod * 60;
        mod =  fmod(dec,1);
        intPart = (int)dec;
        if(intPart < 10){///////////////////////////////////////////////////////////////////////////////
          currCommand +="0";
        currCommand +=intPart;
        currCommand +=":";
        //do the same again for minutes
        //e.g. coord = 0.68336 * 60 == 40.0016
        //e.g. intPart = 40
        dec = mod * 60;
        intPart = (int)dec;
        if(intPart < 10){/////////////////////////////////////////////////////////////////////////////
          currCommand +="0";
        currCommand +=intPart;
        currCommand +="#";
  • Leon

    Leon - 2012-06-22

    i will be really glad if someone knows the way to properly convert AZ/EL to

  • barrykgerdes

    barrykgerdes - 2012-06-23

    At any given instant the positions of the astronomical objects which are
    measured in the equatorial plane (RA and DE) can be equated in the horizon
    plane (altitude and Azimuth) provided that the precise position in latitude
    and longitude, a function of hour angle and time) of the observing site, is
    known. This is calculated from the formula:-

    COS(P)=(SIN(Y) - (SIN(GP) x SIN(Q))) / (COS(GP) x COS(Q))
    SIN(Q)=(SIN(Y) - SIN(GP) + (COS(Y) x COS(GP) x COS(X))
    P= hour angle or azimuth
    Q= declination or altitude
    When given
    X= azimuth or hour angle
    Y= altitude or declination
    GP= geographical latitude

    The formulae are symetrical; i.e. conversion can be either way. Hour angle is
    a direct relationship between the current sidereal time and geographical
    longitude and is also quite easily calculated either way. The difficult
    calculation is calculating GP from the above formulae when all the other
    parameters are known.


  • Leon

    Leon - 2012-06-24

    my sensors tell me the angle in which my telescope is directed at, how can i
    convert from that to what i need to send to stellarium?

  • barrykgerdes

    barrykgerdes - 2012-06-24

    You will need to write an interface in your Arduino language using the above
    information to convert the alt/azm data into RA/Dec and add a
    date/time/location device. It would be far cheaper to buy an Argo Navis with
    encoders and use this on your telescope and forget about the Arduino interface
    until you learn more about astronomical calculations.


  • Leon

    Leon - 2012-06-25

    i already have date/time/location device and code for arduino, just stuck with
    the calculations

  • barrykgerdes

    barrykgerdes - 2012-06-25

    Hi Leon

    I think I got a PM from you for info on alt/azm-RA/Dec conversion but I was
    unable to answer it as such.
    I use the formula written in BASIC/QBASIC extracted fro peter Duffet Smith's
    book Astronomical calculations with a PC.

    This zip can be downloaded it has a program to convert alt/azm to RA/Dec or
    vice versa written in GWbasic and compiled with QB64 as a stand alone program.
    The source code is provided but you may need to read the original article from
    the reference to understand how it works. It takes the time from the computer
    clock and the location from an ASCII file containing your location.

    See if this is any help.


  • Leon

    Leon - 2012-07-01

    Hey all!

    Well i got a fully working code and will release it very soon!

    Meanwhile a short demo:

    • Anonymous - 2012-10-29

      Hi Leon.

      Have you released it yet?


  • Leon

    Leon - 2012-07-01

    my code is based on the work of simon box:

  • madan

    madan - 2013-02-20


    This link was very helpful for me in writing arduino codes for my home made eqmount.
    I am facing the same similar problem to the @Francesco's post.
    RA is getting accepted but DC gets error: degree sign expected.

    here is the part sending :GD# data,

    if (stringOne =="#:GR#"){
      hh -= previous;
      mm -= previous;
      ss -= previous;
      Serial.print (hh);
      Serial.print (':');
      Serial.print (mm);
      Serial.print (':');
      Serial.print (ss);
      Serial.print ('#');
      stringOne ="";


    if (stringOne =="#:GD#"){
      deg -= previous;
      mint -= previous;
      sec -= previous;
      Serial.print ("+");
      Serial.print (deg);
      Serial.print ("*");
      Serial.print (mint);
      Serial.print ("'");
      Serial.print (sec);
      Serial.print ("#");
      stringOne ="";  

    though i get the error: degree sign expected. scope is getting detected and i am able to see the scope in stellarium.
    please suggest.

    Thank you,

1 2 > >> (Page 1 of 2)


Cancel  Add attachments