Shop OBEX P1 Docs P2 Docs Learn Events
Raspberry Pi RXD/TXD to Activity Board — Parallax Forums

Raspberry Pi RXD/TXD to Activity Board

RsadeikaRsadeika Posts: 3,837
edited 2014-02-23 17:09 in General Discussion
I just fired up my RPi board, and I was thinking about connecting an Activity Board via RX/TX pins, has anybody done this, and is it safe for both boards? What I have seen on so far are some confusing discussions, for me at least, about doing this. In some cases their is talk about level shifters, which make it sound like a real RS232 connection, but I am thinking about a straight connection to the Activity Board from the RPi board.

Thanks
Ray

Comments

  • Heater.Heater. Posts: 21,230
    edited 2013-07-24 04:00
    Ray,

    If you mean this Activity Board http://www.adafruit.com/products/1371 I don't see any RS232 interface or drivers on it.
    I presume your serial connection would go to the Prop pins.
    In that case you have no problem with level shifters and such.

    I have connected a Propeller to the Tx/Rx on the PI GPIO header and it worked just fine.
    I actually put 200 ohm resistors in line with Tx and Rx just for safety but if things are working and you Prop I/O is programmed correctly there is no need for even that.
    We even drive the Prop reset pin from a Pi GPIO pin so that we can reprogram the Prop from the Pi.

    You will probably want to configure your Pi OS not to use the GPIO Tx/x as the Linux console port.
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-07-24 05:03
    I was thinking of using, lets say, P11, P12 plus gnd, on the Activity Board; plus I would be using the TXD, RXD plus gnd GPIO pins on the RPi, making it a direct connection. Probably I would have to write a comm program for the RPi, using python, that uses the GPIO, and I could use FDS on the Activity Board. I think I read somewhere that the GPIO pins on the RPi are 3.3V, so that should be quite safe when connected to the Activity Board. The real concern that I have right now is a comm program on the RPi board, the GPIO commands are very terse, and I am not sure how I would set the pins for a comm session.

    After reading what I just wrote about the RPi, working with the Activity Board is a breeze compared to working with the RPi board. If the above gets too complicated, I guess my next option would be, plug the USB cable from the Activity Board into the USB on the RPi, start up minicom, and it should be communicating with the Activity Board via P31/P30. I will be using the RPi in a headless manner, so I guess I am very limited as to comm programs that I can use with something like PuTTY.

    Ray
  • Heater.Heater. Posts: 21,230
    edited 2013-07-24 05:34
    Sounds like you are all set to go.

    I like to add the resistors in series with the Tx and Rx lines just in case the Prop accidentally get a pin set as an output that conflicts with a GPIO pin.

    Using the serial port on the Pi GPIO is very easy. Especially if you are using Python. All you have to do is install the Python serial module python-serial and then write some simple code in your application. Like so:
    import serial
    
    port = serial.Serial("/dev/ttyAMA0", baudrate=115200, timeout=3.0)
    
    while True:
        port.write("\r\nSay something:")
        rcv = port.read(10)
        port.write("\r\nYou sent:" + repr(rcv))
    

    One slight difficulty is that by default the Pi operating systems, like Raspian, will send Linux boot messages over that serial port and then use it as a console port when it's booted. This may well mess with your application. Disabling that only requires:
    1) Removing one line from /etc/inittab. Look for the line with the AMA0 device in it.
    2) Remove the kernel command line parameter that sets the console port. It's in one of the configuration files in /boot. Can't remember what that's called just now.

    Lets us know if you have difficulties.

    Here is a nice page describing using serial from Python: http://www.elinux.org/Serial_port_programming
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2013-07-24 07:22
    Insert a couple of full-duplex RS422 criver/receiver chips at 3.3 volts and you can have the Raspberry Pi up to 4000 feet away from the activity board! I am using 5 volt DIP* chips, the sn75179 and they can work with just a 3.9K series resistor protecting the 3.3 volt i/o.

    Even having 2 or 3 feet of flexible wire is a good thing, but low-power hard-wire remote control begins to get very handy with a few chips.
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-07-24 08:02
    Rsadeika wrote: »
    I just fired up my RPi board, and I was thinking about connecting an Activity Board via RX/TX pins, has anybody done this, and is it safe for both boards?

    For Propforth, Sal uses an RPi to talk to the prop. He connects the prop pins dierctly to the RPi GPIO. Not only that, he solders them while both boards are live. This way he can check the connections with communication in progress. I haven't done it, but he said it takes longer to warm up the soldering iron than it takes to get it set up and working.
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-07-26 12:53
    I decided to try out an RPi python program with it having an XBee attached to the RPi, /dev/ttyUSB0 port, and an XBee that is attached to my PC. This contraption sort of works as expected. The problem is, 'port.write("\n> ") ', I am not receiving anything on the PC side. Any python guys that can show me the error of my ways?

    I thought that I would try this out before I make an actual attachment to the Activity Board. If I do a 'port.write()' with an Activity Board attched, I think I would become very frustrated, so, work out the kinks before hand.

    Ray
    #!/usr/bin/python
    
    import serial
    import time
    
    # XBee attached
    port = serial.Serial("/dev/ttyUSB0", baudrate=9600)
    
    try:
            port.open()
    except Exception, e:
            print "Error opening serial port:" + str(e)
            exit()
    
    print "This is the mterm.py program."
    
    while True:
    
            rcv = port.read(1)
            if (rcv == 'q'):
                    break
    
            print "" + rcv  # Print on local screen
            port.write("\n> ") # This does not appear on other end
            time.sleep(0.5)
    
    print "Program Stopped!\n"
    port.close()
    
  • Heater.Heater. Posts: 21,230
    edited 2013-07-26 16:39
    What happens when you do port.write("Hello world\n") ?

    No idea really but I have seen things like this not write anything until an end of line is sent.

    That is why the is a flush() call in many situations to force characters to be output.

    Is the a flush() method in that serial module?
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-07-27 04:07
    So, I tried a couple of things to make this /dev/ttyUSB0 XBee attachment work, but RPi does not know how to handle it correctly. I installed the real minicom, and tried accessing the USB0 port, minicom just did not respond in the terminal mode. The python short program did not work to my satisfaction, so I have to rethink this whole experiment with the RPi and XBee or Activity Board.

    Ray
  • tech-mectech-mec Posts: 9
    edited 2014-02-23 17:01
    So it is possible to program from the GPIO. Besides the rx/tx and gnd which other pin do you use?

    I think that a prop and the RPi go very good together to make a very powerful system for robots.
  • Heater.Heater. Posts: 21,230
    edited 2014-02-23 17:09
    Yes it is possible to program a Propeller from the Pi GPIO.

    You need to hook up Rx, Tx, Gnd and GPIO 17 has the Propeller rest signal.

    Sadly the version of SimpleIDE I had that does that is very old now. I am working on making the same adaptions to the most recent IDE and loader. Ready "real soon now"

    Yes, the Pi and the Prop make a great team.
Sign In or Register to comment.