Shop OBEX P1 Docs P2 Docs Learn Events
propellor c USb connection — Parallax Forums

propellor c USb connection

Patrick222122Patrick222122 Posts: 30
edited 2014-03-01 11:30 in Propeller 1
I am having trouble having the propeller communicating with the pi, which is critical for my project. I have had success with transmitting from the propellor c to the pi using Libfd_serail writeStr function but cannot get the propeller to read from the pi. I have tried how it is done in the demo code but still come up empty. As always working demo code would be appriciated.

Comments

  • mindrobotsmindrobots Posts: 6,506
    edited 2014-02-28 19:09
    What are you talking to on the Pi side?

    Does the demo you are using provide code for boyh sides of the connection?

    Can you post the demo code?
  • Patrick222122Patrick222122 Posts: 30
    edited 2014-03-01 10:40
    replying to the previous post here are the two programs for the usb. First the propellor c code
    /*
      Blank Simple Project.c
      http://learn.parallax.com/propeller-c-tutorials 
    */
    #include "simpletools.h"                      // Include simple tools
    #include "simpletext.h"
    #include "fdserial.h"
    
    
    int main()                                    // Main function
    {
      // Add startup code here.
      fdserial *term = fdserial_open(31,30,0,115200);
     char datai,datao;
    int toob;
    //this portion here I took from the demo program
        readStr(term, datai, 80);
        sscan(datai,"%s",datao);
    
    
    writeStr(term, datao);
    pause(1000);
     
    }
    
    
    
    and now the python code
    import serial
    
    
    ser=serial.Serial("/dev/ttyUSB0",115200)
    while(True):
        inpt=raw_input("enter a number")
        ser.write(inpt)
        outpt=ser.read()
        print outpt
        
    
    
    
    Ps: I have used this python code before when I was using spin so I know it works
  • FredBlaisFredBlais Posts: 370
    edited 2014-03-01 11:26
    Hi Patrick,

    I've done serial communication a couple of time between Prop and Pi, using Spin and Python.
    Are you sure that your serial port is on /dev/ttyUSB0 ?
    I used ser = serial.Serial("/dev/ttyAMA0",115200)
  • jazzedjazzed Posts: 11,803
    edited 2014-03-01 11:30
    If you need fdserial.h with simple libraries, you have to play a game with the default port pointer (dport_ptr). See below.
    #include "simpletools.h"                      // Include simple tools
    #include "fdserial.h"
    
    int main()                                    // Main function
    {
      // Add startup code here.
      extern text_t *dport_ptr;                   // default port pointer
      char datai[80];                             // an array of char i.e. a string
    
      simpleterm_close();                         // close the default port
      dport_ptr = fdserial_open(31,30,0,115200);  // get a new default port pointer
    
      putStr("Enter some text: ");                // prompt
      getStr(datai, 80);                          // get some data
      putLine(datai);                             // print some data
      putLine("All done");                        // program over, go relax.
    }
    
Sign In or Register to comment.