Shop OBEX P1 Docs P2 Docs Learn Events
fdserial between two propeller 'flip' modules.; A Reopening — Parallax Forums

fdserial between two propeller 'flip' modules.; A Reopening

bbrienbbrien Posts: 561
edited 2022-02-14 06:39 in General Discussion
I having lots of problems with fdserial with two flips. I am using propeller C. Flip1 is running a program which uses 5 switches, 1 for speed and four for directions. The final output sends four bytes(0-255) by means of
fdserial_txChar(RmotorPin);
fdserial_txChar(RdirPin);
fdserial_txChar(DmotorPin);
fdserial_txChar(DdirPin);
now my understanding is that the commands send a byte to the transmit buffer. the next question is do I setup the buffers in the (MAIN) or not.When the second flip reads the input (rxpin) nothing happens.Sending the files. Can you please check them. I think I may need a receive buffer.
«134

Comments

  • I am a Spin guy, but I know fdserial buffers are maintained by the object. You don't have to account for them. The default buffers on the original fdserial object are a bit short at only 16 bytes, but there are enhanced versions that provide for increasing the buffer size. If you are receiving nothing, the serial object is probably not your actual problem.
  • First of all the LX 50 Ver 3 program will not work. Wrong use of fdserial_rxCheck.

    Based on the master program do you have pin 3 (TX) on master wired to pin 0 (RX) on slave flip wired together. Data send by master program will be send and received to an internal buffer on the receiving flip. No buffers required.

    Mike
  • Also if you are not receiving any data on the flip you may have damaged that pin when it was connected to the Arduino as pulling this pin to 5 volts may have damaged it.

    Mike
  • Maybe you could build a simple test program.

    On the master flip set pin 3 high and on the slave flip read the state of pin 0. If you see it does return a high value then it worked.
    Now change the master program and set pin 3 low and see if you can see a low value on pin 0. If this all works then serial should work as well.

    Master program test
    #include "simpletools.h"
    
    int main()
    {
    
     
      while(1)
      {
        high(3);
        pause(5000);  //<-- pause 5 seconds
        low(3);
        pause(5000);
      }  
    }
    

    Slave program test
    #include "simpletools.h"
    
    int i;
    
    int main()
    {
     
      while(1)
      {
        i = input(0);
        print("Pin 0 State: %d\n", i);
        pause(1000);
      }  
    }
    

    The Slave program will output the state of pin 0 every second on the terminal screen.

    Mike
  • 1; no the masterflip has rx = 0 and tx = 1
    2; I have two new flips,should not have any damages unless factory defects.
    3; will try the new tests
  • I just look at the master code and it's using 2 and 3.
    #define rx 2
    #define tx 3
    
      fd = fdserial_open(rx, tx, FDSERIAL_MODE_NONE, 115200);
    
    

    Mike
  • 1; no the master flip has rx = 0 and tx = 1. I must have sent a different file
  • Tried the sketches and the print is pin 0 state 0 . how does master work without any initialisers.
  • The propeller is a simpler processor and doesn't have any states that need to be set. Only input or output state which is set automatically by the high and low function used in the program.

    The Arduino code has to worry about Input, Output, Pull up, Pull down, Analog, Digital as some pins have special functions and can be connected to internal timers.

    There are two programs. One to run on the master and the other to run on the slave flip. The master will set the pin state that is wired to the slave and the slave program will tell you what the state of that pin is. If everything is wired up correctly the state of the pin will change as the master program runs. Sort of like serial data running in slow motion.

    Mike

  • I set connect pin 3 of master to pin 0 of slave and I have 0 or 1 for pin state now, what next ?
  • Now we know the pins and wiring are correct and we can go back to the original code and see if we can get serial to work or we could build a master/slave serial program and see if we can get that to work.

    Your choice.

    Mike
  • My master program looks like it works ok. The print output values and the 0 or 1 states. but I cant get a print on the buffers or even the "value" in the print in the slave.
  • Need to make sure you are using the correct pins for tx and rx.

    Mike
  • In the programs LX50A(master and the program LX50 ver 3 rx = 0 and tx = 1.
  • bbrien wrote: »
    I set connect pin 3 of master to pin 0 of slave and I have 0 or 1 for pin state now, what next ?

    So pin 3 on master would be your transmit(tx) pin 3 and pin 0 on the slave would be the receive(rx).

    Mike
  • As you suggested. Lets do some more testing.
  • Here are some test programs. One is labeled "Master" and the other "Slave" as before.

    These program will run two test. The first is as before setting a pin high and then low.

    The second test actually send a character using serial.

    In the program is a define for TEST which can be set to 0 for test 1 or 1 for test 2. Each program will display what it is doing.

    MASTER:
    #include "simpletools.h"
    #include "fdserial.h"
    
    void Test1(void);
    void Test2(void);
    
    // Change the value after TEST to 0 or 1
    #define Tx 0
    #define Rx 1
    #define TEST 0
    
    fdserial *fd;
    int i;
    
    int main()
    {
      
      if (TEST == 0)
        Test1();
      
      if (TEST == 1)
        Test2();
     
      while(1)
      {
        print("Test %d\n", TEST);
        pause(1000);
      }  
    }
    
    void Test1()
    {
      while (1)
      {
        low(Tx);
        print("Pin: %d => High\n", Tx);
        pause(1000);
        high(Tx);
        print("Pin %d => Low\n", Tx);
        pause(1000);
      }
    }
    
    void Test2()
    {
      fd = fdserial_open(Rx, Tx, FDSERIAL_MODE_NONE, 115200);
      
      while (1)
      {
        fdserial_txChar(fd, '1');
        print("Pin: %d => 1\n", Tx);
        pause(1000);
        fdserial_txChar(fd, '0');
        print("Pin: %d => 0\n", Tx);
        pause(1000);
      }
      fdserial_close(fd);
    }
    

    SLAVE
    #include "simpletools.h"
    #include "fdserial.h"
    
    
    void Test1(void);
    void Test2(void);
    
    // Change value after TEST to 0 or 1
    #define Rx 0
    #define Tx 1
    #define TEST 0
    
    fdserial *fd;
    int i;
    
    int main()
    {
    
      if (TEST == 0)
        Test1();
      
      if (TEST == 1)
        Test2();
     
      while(1)
      {
        print("TEST: %d\n", TEST);
        pause(1000);
      }  
    }
    
    void Test1()
    {
      while (1)
      {
        i = input(Rx);
        print("Pin: %d => %d\n", Rx, i);
        pause(1000);
      }
    }
    
    void Test2()
    {
      fd = fdserial_open(Rx, Tx, FDSERIAL_MODE_NONE, 115200);
      
      while (1)
      {
        i = fdserial_rxCount(fd);
        if (i > 0)
        {
          i = fdserial_rxChar(fd);
          print("pin: %d => %d \n", Rx, i);
        }
      }
      fdserial_close(fd);
    }
    

    Mike
  • Files loaded and will try them real soon. Thanks.
  • bbrienbbrien Posts: 561
    edited 2020-06-07 19:29
    Print output 0 changing to 1 and back to 0 on both lines. Now can we get a pulse going from master to slave outputting on pin #17. pulse between 50 to 150/255.
  • Most problems due to damaged io's. Changing from PWM to frequency (4 - 80 Hz) generation. Does anyone have Square_wave method.

  • I've reopened this thread with these new files . I am changing to a frequency generation around 4 - 80 Hz. Does any one have the Square_wave method available.

  • bbrien,

    There is a SquareWave function built into the SimpleTools library.
    https://github.com/parallaxinc/Simple-Libraries/blob/master/Learn/Simple Libraries/Utility/libsimpletools/source/squareWave.c

    void square_wave(int pin, int channel, int freq)
    

    It looks like there is a Square_Wave function that you call where you put in the Pin, Channel (counter), and Frequency.

    There used to be a webpage that listed all the functions and how to use them.

  • bbrienbbrien Posts: 561
    edited 2022-02-14 21:10

    I tried to find them but couldn't get in. Maybe I could use the data for the serial in the spin program.

  • bbrienbbrien Posts: 561
    edited 2022-02-18 05:55

    Regarding the program shown below ;where should the method "square_wave" Be inserted ? , where it is now or elsewhere.I get an error at b1 = input(4); "expected a Declaration or statement at end of input"

  • How sand when do I use the Void statement as in "void square_wave"

  • bbrien,

    Square_Wave is VOID because it doesn't return anything.

    Square_Wave(26, 0, 1000) ' 1000 Hz on Pin 26 using Counter A.
    

    Call this function to stop.

    Square_Wave_Stop ' Kills BOTH Counters
    

    Now for the stupid questions so forgive me.
    Can more than one button on the HandBox be pressed at the same time?
    I assume the HandBox takes over from the AutoGuider when a button is pressed.
    Is the Telescope always moving or can it be turned off and if so how?

    Anything else that you can think of so the program is structured correctly.
    Buttons work and motor control works, so now it's putting everything together.
    Since the HandBox only has switches currently, why not just send which switch is active at that moment.
    The BrainBox on the telescope should determine what to do based on what is in control at that moment.
    A State Machine makes that easy because the State will change as the inputs change, and each State will move the Motors differently.
    There is Manual Control, AutoGuiding, No Guiding (Move with the Earth), and then North, South, East, and West.
    If I remember correctly West is the default direction to counter the Earth's movement.

    Let me know if I am missing anything.

  • As I have said before the Hand box has a brain which communicate by serial. Yeah The mount has a on-off switch.
    Hand Box is the Master and the mount is the slave. The auto guider is a secondary system.
    The hand box is manual control with N,S,E,W,
    Check out post #22, Since I am using two counters it is possible but not normally.
    Auto Guide also has N,S,E,W, . The Last Is Tracking Which is sidereal, or for the rotation of the earth. It doesn't matter at this time.

  • bbrienbbrien Posts: 561
    edited 2022-02-21 02:54

    Where would I insert the "Square_Wave Stop in the Program. Also tested and no RmotorPin or DmotorPin output
    and have several errors

  • bbrien,

    In the Switch...Case statement why do you have IF statements?
    The Case statement will only execute when that button was pressed and to the program a human will take an eternity to release it.

    I am not familiar with how telescopes work so do the motors normally run one at a time or do they both sometimes run at the same time.

    Unfortunately Square_Wave_Stop kills everything so it may be best to just change the pin and rate depending on the direction.

    Are you doing Astrophotography or is that your end goal or are you just observing objects.
    I ask because movement especially for RA is critical for astrophotography since the object must remain in the same spot to get clear image.

  • When I started this project a Poster by the name of "Iseries" Convert the Arduino Program to Propeller C. It was originally written by an Arduino programmer so I never changed it.
    2) It is possible to use two motors at once but I usually only run one at a time.
    3) I observe but sometimes I use a DSLR to take Photos. I also use a Live feed video camera which is able to image a Stacked 85 second image. The DSLR can only be used on a 6 inch scope which I can use on the mount.

Sign In or Register to comment.