Shop OBEX P1 Docs P2 Docs Learn Events
P1<--Raspberry Pi — Parallax Forums

P1<--Raspberry Pi

RsadeikaRsadeika Posts: 3,837
edited 2013-12-31 05:52 in Propeller 1
I have a set up where I have a Raspberry Pi(RPi) and a breadboard right next too it which has access to the RPi GPIO. Now, on this breadboard I have plenty of room for a P1 chip, and access to 3.3V from the GPIO to draw the power. Also, the GPIO has access to SPI and I2C, plus other things, which could be connected to the P1. Now, my question is, what would it take, on the RPi side, to get access to and/or be able to program(use) the P1 from either C or Python on the RPi side. I know that SimpleIDE for the RPi is available, but I would like to have access to the P1 while using either C or Python on the RPi.

I am not sure if anybody has thought about this approach or maybe somebody has already done something like this. A good test project would be to have an LED on the P1 p0 pin, an LED on the GPIO available pin, and be able to use C or Python program on the RPi to blink the LEDs of both chips within the same program.

For the RPi there is bcm2835.h which I use to get usage out of the GPIO, what would it take to do a similar thing for the P1 chip? If I am not mistaken, I believe that the add on boards for the RPi that have an Arduino has a similar approach, you access the Arduino via C or Python on the RPi.

Are there tools available for accomplishing this?

Ray
«1

Comments

  • mindrobotsmindrobots Posts: 6,506
    edited 2013-12-28 07:56
    Ray,

    Generally, when I see something like this talking to an Arduino, there is some sort of monitor program running on the micro. In the case of the Arduino, it could be Firmata or some custom monitor written to support the library functions of the RasPi. That's one of the problems with the Propeller and something that needs to be developed. You want the RasPi program to be able to send a "P1 HIGH" command to the Propeller and have the Propeller understand and act on it. This means you need to have code running on the Prop. This makes your potential usefulness of the Prop only as great as the sophistication of the monitor code.

    The big issue isn't the physical connectivity between the RasPi and the Prop, it's the glue software: the library on the RasPi and the monitoring code on the Prop. This is one of the reasons I like PropForth (or tachyon or pfth) - these give you a very capable and expandable "monitor" program running on the Prop. The connection is a simple serial link and the "Command Library" on the RasPi is only limited by what you can generate and send/receive across a com port. I haven;t set this up with my RasPi yet but I've done it across a serial link from a PC so it's the same thing.

    If you want to use SPI, then you need to have code loaded in the Prop so it can be an SPI slave - I don't believe this currently exists, The P1 can be a SPI master but currently not a slave. I2C would require the same type of code on the Prop. Once you could see it as an SPI or I2C generic device, then you would write soft peripherals to run on the Prop to provide specific capabilities. Letting the Prop do what it does best in becoming a GIGANTIC SPI or I2C soft peripheral. Again, though, this a case of needing a bunch of "monitor" type code to run on the Prop that doesn't exist yet.

    I'm not sure about powering all of the Prop from the GPIO 3.3v supply. One place the RasPi is fragile is in it's power supply. I'd grab power from the same powered USB hub that is supplying the RasPi.

    Certainly a fun and doable project. Anything you come up with as far as Prop software to act as glue will be usable by others exploring in these areas.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2013-12-28 08:03
    This was explored in a previous thread.

    And I strongly suspect that the same conclusions might be arrived at. The Raspberry Pi to the P1 would best use a RS232 via ttl as its link.

    Programing could be done with any Parallax software and IDE as they all use RS232. The Raspberry Pi would need to be in a Linux OS to support such.

    And if you wanted real-time control of the P1, any of the Forth on Propeller solutions would allow you to program scripts in Python, or just about any language that provides for scripting and an RS232 interface in Linux.

    Due to the Raspberry Pi being an SOC (system on a chip), it seems that you either have to use Android or Linux. And since Linux is open source, it is likely the best fit. Though the GPIO seems like in might do fantastic things, the OS dependency really limits the GPIO to being rather limited in tasks. It is much better to off load ADC, DAC, PWM, and real-time motor control to the P1, while have the Rasp Pi provide a terminal, file storage, and an IDE environment. In some case,the Rasp Pi can provide a RTC and a communications link onward to a LAN.

    My opinion is based on the realities of the available software resources and the original purpose of the SOC concept.
  • Heater.Heater. Posts: 21,230
    edited 2013-12-28 08:19
    Ray,
    ...what would it take, on the RPi side, to get access to and/or be able to program(use) the P1 from either C or Python on the RPi side.
    On the Raspi GPIO header there is a UART Tx and Rx available.

    You can connect those pins directly to the Propeller programming pins (or other) and have a serial link between Pi and Prop.

    On the Pi this UART shows up as /dev/ttyAMA0 you can use it from C. Python, whatever just like any other serial port.

    BUT:

    1) The Raspi Linux kernel uses that port as it's console port. Boot messages are sent to it as as well as any run time errors. You can disable this by removing the console port configuration from the kernel command line arguments that is in one of the text files in the boot partition. I forget what it's called now.

    2) Raspbian also runs a login session on /dev/ttyAMA0. If you connect that UART to your PC you can login to the Pi using Hyperterminal or minicom or whatever terminal program. You can disable that by commenting out the line in /etc/inittab that runs "getty" on /dev/ttyAMA0.

    With those little changes you are free to use that UART for whatever you like.
    For the RPi there is bcm2835.h which I use to get usage out of the GPIO, what would it take to do a similar thing for the P1 chip?
    On the Prop side you are going to use Spin and the FullDuplexSerial object. You just have to write a few lines of code to accept your commands from the serial link and do the required action, turn LED's on and off etc.

    You can use C on the Prop if you like. Either way SimpleIDE is available to run on the Pi itself. I'm haven't yet finished hacking the loader to use that UART yet so it still needs a PropPlug to program the Prop via USB serial.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-12-28 08:29
    Heater. wrote: »
    Ray,

    On the Raspi GPIO header there is a UART Tx and Rx available.

    You can connect those pins directly to the Propeller programming pins (or other) and have a serial link between Pi and Prop.

    On the Pi this UART shows up as /dev/ttyAMA0 you can use it from C. Python, whatever just like any other serial port.

    BUT:

    1) The Raspi Linux kernel uses that port as it's console port. Boot messages are sent to it as as well as any run time errors. You can disable this by removing the console port configuration from the kernel command line arguments that is in one of the text files in the boot partition. I forget what it's called now.

    2) Raspbian also runs a login session on /dev/ttyAMA0. If you connect that UART to your PC you can login to the Pi using Hyperterminal or minicom or whatever terminal program. You can disable that by commenting out the line in /etc/inittab that runs "getty" on /dev/ttyAMA0.

    With those little changes you are free to use that UART for whatever you like.

    On the Prop side you are going to use Spin and the FullDuplexSerial object. You just have to write a few lines of code to accept your commands from the serial link and do the required action, turn LED's on and off etc.

    You can use C on the Prop if you like. Either way SimpleIDE is available to run on the Pi itself. I'm haven't yet finished hacking the loader to use that UART yet so it still needs a PropPlug to program the Prop via USB serial.
    Does the RaspPi have only a single UART?

    I finally got tired of hearing you all talk about the Pi and feeling left out so I ordered one to get in on the action! :-)
  • Heater.Heater. Posts: 21,230
    edited 2013-12-28 08:41
    According to this http://elinux.org/RPi_BCM2835_GPIOs there are two UARTs but only one of them can be used at a time given the constraints of the pinouts on the GPIO header.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2013-12-28 09:34
    NEVERMIND, i reread the material and Heater is right.... one GPIO RX and one GPIO TX
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-12-28 09:56
    One of the reasons that I brought this subject back up again, is because of the discussion that is going on in the P2 forum about having some kind of Pi plate with a P2 on it, or something along those lines. Let say that through a miracle there appears a Pi plate with a P1 on it which mounts to the RPi GPIO, so you have the hardware, now what do you do with it? I was trying to get an idea as to what would be involved in that "glue" program that would be running on the P1. It also looks like the use of the UART is the only reasonable way to go.

    As for the "glue" program on the P1, it almost looks like it would have to be some kind of kernel with a lot of drivers for the anticipated use of the pins. This would be one heck of a way to learn PASM, I do not see anything else that could do the kernel justice.

    On the RPi side, first you would have to work in some code that would prep the UART for a condition to talk to the P1, then reinstate it back to its original state once you are done with the P1PiPlate. Also you would probably have to develop some sort of library for the C and Python programs so you could have some kind of commands or functions that would access the P1.

    I just had a strange thought, am I having a senior moment, could the "glue" on the P1 be written in FORTH? But then how would FORTH behave with a C or Python master? Wouldn't that be a strange beast, an RPi to do the heavy lifting, a P1 to do the slave work, and FORTH to bind the two together, what a strange beast indeed.

    Ray
  • mindrobotsmindrobots Posts: 6,506
    edited 2013-12-28 10:38
    The monitor program on the prop can be written in anything (you will have trade-offs between execution speed, memory footprint, development speed and ease in testing depending on which tool you choose to implement it in).

    It's like the command shell (DOS Prompt) it can be written in anything and as a user, you really don't care as long as you can type in "dir" and get a list of files displayed, etc.

    The monitor needs to be able to accept input from the RasPi in comes manner (serial, SPI, I2C), understand and process that input (recognize P1 HIGH and run code on the Prop to raise P1 to a high), and then respond to the RasPi in some manner to acknowledge the command or return a status or value or something you have agreed upon as being meaningful. That's it, anything from a very simple serial pin# and state (1 1 0r 1 0) to a complex protocol to set up completely independent functions like you would do for an SPI or I2C peripheral. It can be very simple just to meet your immediate needs or it can be a more sophisticated kernel/driver arrangement - your choice since one hasn't been written yet!

    Personally, I'm going to choose a Forth for the monitor just because it is quick to get running (for me), easy to develop and debug by just using a terminal and writing the Forth code you need interactively, and probably speedy and memory efficient enough for doing the things I want to do with the Prop. Others will write their monitors in SPIN/PASM (if you want a soft peripheral that already has OBEX code), C (because that's what those people do), BASIC, etc.

    If Parallax develops a standard library for the RasPi and a standard monitor for the Prop, all the better, otherwise as with most things in Propeller Land, there will be many choices of different implementations and capabilities buried in the forum threads for people to hunt for and use and change as they see fit.

    I'd try to use the existing RasPi libraries for Python, C, etc. so at least one side of the connection is consistent. If someone takes the micro-controller code that exists for other controllers and ports it to the Prop, more the better for the Propeller users, new and old!
  • David BetzDavid Betz Posts: 14,516
    edited 2013-12-28 10:56
    I looked a bit at Linux SPI support and there seems to be a kernel SPI library available. It should be a fairly simple matter to write a device driver that uses that library to talk to a P1 chip. Is there a reason we should shy away from writing a custom Linux driver for the P1? What I'm not sure of is whether the kernel SPI library is capable of running in slave mode. It might be easier to let the P1 be master if the RaspPi can be the slave.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2013-12-29 04:17
    NEVERMIND, i reread the material and Heater is right.... one GPIO RX and one GPIO TX

    I spent the night tossing and turning about that second UART on the Raspberry Pi. Is it being deployed to the USB interface?

    Also I wonder why one cannot have the USB interface connected to a USB to RS232 adapter and have that provide a second active serial port. This would mean that the Raspberry Pi could provide a role as a headless Linux machine simultaneously with having an active Propeller hooked up to the other serial port.
  • mindrobotsmindrobots Posts: 6,506
    edited 2013-12-29 04:44

    Also I wonder why one cannot have the USB interface connected to a USB to RS232 adapter and have that provide a second active serial port. This would mean that the Raspberry Pi could provide a role as a headless Linux machine simultaneously with having an active Propeller hooked up to the other serial port.

    This is normal configuration at my house. A headless RasPi with a powered USB hub and multiple Propeller boards connected to it. Works like a champ!
  • David BetzDavid Betz Posts: 14,516
    edited 2013-12-29 05:24
    mindrobots wrote: »
    This is normal configuration at my house. A headless RasPi with a powered USB hub and multiple Propeller boards connected to it. Works like a champ!
    What are the Propeller boards doing that you have connected to your RaspPi?
  • mindrobotsmindrobots Posts: 6,506
    edited 2013-12-29 06:03
    David Betz wrote: »
    What are the Propeller boards doing that you have connected to your RaspPi?

    Same thing most of my Propellers are doing right now. Not much! :lol:

    I think I have 3 Quickstarts currently. One is running Propforth 5.5, one has the new 6.0 on it and I don't think the other one is currently doing anything. I had just hooked them up to the RasPi so I could SSH to it and then minicom to the Propellers to play with Forth. The one that isn't doing anything was going to be a target for SimpleIDE on the RasPi but I got distracted/interrupted before I got all the pieces working.

    It's more just to show that you can have multiple USB connected Propellers than anything practical.

    I often find myself not near a Propeller and wanting to play, so I hooked them up this way for remote access.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-12-29 06:19
    mindrobots wrote: »
    Same thing most of my Propellers are doing right now. Not much! :lol:

    I think I have 3 Quickstarts currently. One is running Propforth 5.5, one has the new 6.0 on it and I don't think the other one is currently doing anything. I had just hooked them up to the RasPi so I could SSH to it and then minicom to the Propellers to play with Forth. The one that isn't doing anything was going to be a target for SimpleIDE on the RasPi but I got distracted/interrupted before I got all the pieces working.

    It's more just to show that you can have multiple USB connected Propellers than anything practical.

    I often find myself not near a Propeller and wanting to play, so I hooked them up this way for remote access.
    Makes sense. I have more Propeller boards than ought to be legal but none of them are doing anything besides running propgcc test programs. The only "project" I ever did with a Propeller is creating a Christmas ornament using a C translation of JonnyMac's NeoPixel driver.
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-12-29 06:40
    Giving it more thought, I think the more sensible thing to do is too take one of my P1 boards and connect it to the RPi via the USB; and probably write a C monitor program for the P1. Since I have already played with Python on the RPi, I think that I will see how far I can get with a program that will access the P1 and use it as a slave.

    I just did a mini project with the RPi and a Sensirion sht11 module which was done in C, but I think that I would like the sht11 attached to the P1, and then have access to it from the RPi. This would get me some experience in attaching gadgets to the P1, and then controlling/using them with the RPi. I think that this might be more suited to my programming capabilities at this time.

    Ray
  • mindrobotsmindrobots Posts: 6,506
    edited 2013-12-29 06:53
    Sounds like a good choice, Ray. It should give you the same experience as being connected to the GPIO UART with the cost of a usb cable. If you were connecting to the GPIO through a breadboard, the USB is even better. You can also use higher speeds with the USB.

    The monitor program on the P1 won't care how it is connected.

    The only real GPIO advantage I see is if you have a dedicated Pi-P1plate or want to use SPI or I2C.

    Gurus, please advise if I'm missing something.
  • KC_RobKC_Rob Posts: 465
    edited 2013-12-29 17:29
    David Betz wrote: »
    The only "project" I ever did with a Propeller is creating a Christmas ornament using a C translation of JonnyMac's NeoPixel driver.
    Really!? I wouldn't have guessed that.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-12-29 17:41
    KC_Rob wrote: »
    Really!? I wouldn't have guessed that.
    Yes, I'm afraid so. I had a lot of fun making my ornament even though it was an utterly trivial project. I'm looking forward to doing something a bit more challenging!
  • KC_RobKC_Rob Posts: 465
    edited 2013-12-29 17:45
    David Betz wrote: »
    Yes, I'm afraid so. I had a lot of fun making my ornament even though it was an utterly trivial project. I'm looking forward to doing something a bit more challenging!
    Well, I'm sure you have spent many more hours with the Propeller than I. But I don't feel quite so unworthy now that I have one project (almost) under my belt. And the chances are looking good that I'll pick up a few more this year. :)
  • David BetzDavid Betz Posts: 14,516
    edited 2013-12-29 17:49
    KC_Rob wrote: »
    Well, I'm sure you have spent many more hours with the Propeller than I. But I don't feel quite so unworthy now that I have one project (almost) under my belt. And the chances are looking good that I'll pick up a few more this year. :)
    Are these paying projects or hobby projects?
  • KC_RobKC_Rob Posts: 465
    edited 2013-12-29 17:50
    David Betz wrote: »
    Are these paying projects or hobby projects?
    Paying. I hardly have time (or energy) for hobby projects anymore.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-12-29 17:56
    KC_Rob wrote: »
    Paying. I hardly have time (or energy) for hobby projects anymore.
    I assume you've done projects with other microcontrollers. What made you switch to the Propeller?
  • KC_RobKC_Rob Posts: 465
    edited 2013-12-29 18:07
    David Betz wrote: »
    I assume you've done projects with other microcontrollers. What made you switch to the Propeller?
    Oh yeah, all kinds. I didn't really switch to Propeller 100%, but I do see clearly its usefulness for certain applications; I/O aggregation, sniffing/translating serial data, converting interfaces, and so on. I've been reading about and playing with Propeller for a couple of years now but hadn't until recently been able to get it into a design. (Most of my clients aren't familiar with it and prefer to stick with the tried and true.) Now that I've done that and they've seen how well it worked for this application -- it made something that should have been messy not quite so messy -- it'll be much easier to get it into more designs, with this particular client anyway.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-12-29 18:16
    KC_Rob wrote: »
    Oh yeah, all kinds. I didn't really switch to Propeller 100%, but I do see clearly its usefulness for certain applications; I/O aggregation, sniffing/translating serial data, converting interfaces, and so on. I've been reading about and playing with Propeller for a couple of years now but hadn't until recently been able to get it into a design. (Most of my clients aren't familiar with it and prefer to stick with the tried and true.) Now that I've done that and they've seen how well it worked for this application -- it made something that should have been messy not quite so messy -- it'll be much easier to get it into more designs, with this particular client anyway.
    I've enjoyed working with the Propeller. It's not boring like most MCUs. I really wanted to learn to program the Cell processor that was in the PS3 but that doesn't seem to have gone anywhere. I'd also like to figure out how to get freelance projects although I guess I'd have to team up with someone who could handle the hardware side of things. I've done quite a bit of Spin/PASM/C programming on the Propeller but I've never done any hardware design.
  • KC_RobKC_Rob Posts: 465
    edited 2013-12-29 18:27
    David Betz wrote: »
    I've enjoyed working with the Propeller. It's not boring like most MCUs.
    I couldn't agree more.
    I'd also like to figure out how to get freelance projects although I guess I'd have to team up with someone who could handle the hardware side of things.
    They are out there generally. You might see if there are any small shops or consultants in your area looking for help on the software side. If you don't have any contacts to reach out to now, try looking around online and in local publications. If you can just get your foot in the door, make some contacts, you won't have much trouble from then on.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-12-29 18:41
    KC_Rob wrote: »
    They are out there generally. You might see if there are any small shops or consultants in your area looking for help on the software side. If you don't have any contacts to reach out to now, try looking around online and in local publications. If you can just get your foot in the door, make some contacts, you won't have much trouble from then on.
    Thanks for the advice!
  • KC_RobKC_Rob Posts: 465
    edited 2013-12-29 18:49
    David Betz wrote: »
    Thanks for the advice!
    You're welcome! By the way, it's not uncommon to see postings on Craigslist for sw/hw contract work.
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-12-30 15:06
    I made some progress on my monitor program for the Propeller, and some progress on the Python side, also. I decided to use the Activity Board as the test device because it has the two LEDs on board, and I may add the Sensirion sht11 module on the Activity breadboard to see if I can get access to that. The next thing I guess I should add is access to the COGs, but I am not sure as to how to approach that in terms of Python commands and how to set it up in monitor program, which is coded in PropGCC. So far I have these commands on the Python side:
    Control the Propeller
    Prop1_IO.high()
    Prop1_IO.low()

    Control the GPIO
    extgpio.high()
    extgpio.low()
    extgpio.waitMS()

    I have an LED on the breadboard with the GPIO, so now I can program, using Python, to blink the LED via GPIO, and have the Activity Board LEDs on P26 and P27 blinking all at the same time.

    This is what the monitor program looks like so far:
    /*
      test2.c
      December 30, 2013
    */
    #include "simpletools.h"
    #include "simpletext.h"
    #include "fdserial.h"
    
    int main()
    {
      // Add startup code here.
      char inBuff[40];
      int inDec;
    /*                             Rx Tx Mode BAUD*/
      serial *term = fdserial_open(31,30,0,115200);
     
      while(1)
      {
        // Add main loop code here.
        readStr(term,inBuff,40);
        if(!strcmp(inBuff,"high"))
        {
          readStr(term,inBuff,40);
          {
            inDec = atoi(inBuff);
            high(inDec);
          }
        }
        else if(!strcmp(inBuff,"low"))
        {
          readStr(term,inBuff,40);
          {
            inDec = atoi(inBuff);
            low(inDec);
          }
        }
        else
        {
          print("?\n");
        }
        pause(50);  
      }  
    }
    
    
    Ray
  • David BetzDavid Betz Posts: 14,516
    edited 2013-12-30 15:18
    The RaspberryPi has an RCA video jack on it. Isn't it possible to start a console on that and use a USB keyboard?
  • hinvhinv Posts: 1,255
    edited 2013-12-30 19:20
    Rsadeika wrote: »
    I made some progress on my monitor program for the Propeller, and some progress on the Python side, also. I decided to use the Activity Board as the test device because it has the two LEDs on board, and I may add the Sensirion sht11 module on the Activity breadboard to see if I can get access to that. The next thing I guess I should add is access to the COGs, but I am not sure as to how to approach that in terms of Python commands and how to set it up in monitor program, which is coded in PropGCC. So far I have these commands on the Python side:
    Control the Propeller
    Prop1_IO.high()
    Prop1_IO.low()

    Control the GPIO
    extgpio.high()
    extgpio.low()
    extgpio.waitMS()

    I have an LED on the breadboard with the GPIO, so now I can program, using Python, to blink the LED via GPIO, and have the Activity Board LEDs on P26 and P27 blinking all at the same time.

    This is what the monitor program looks like so far:
    /*
      test2.c
      December 30, 2013
    */
    #include "simpletools.h"
    #include "simpletext.h"
    #include "fdserial.h"
    
    int main()
    {
      // Add startup code here.
      char inBuff[40];
      int inDec;
    /*                             Rx Tx Mode BAUD*/
      serial *term = fdserial_open(31,30,0,115200);
     
      while(1)
      {
        // Add main loop code here.
        readStr(term,inBuff,40);
        if(!strcmp(inBuff,"high"))
        {
          readStr(term,inBuff,40);
          {
            inDec = atoi(inBuff);
            high(inDec);
          }
        }
        else if(!strcmp(inBuff,"low"))
        {
          readStr(term,inBuff,40);
          {
            inDec = atoi(inBuff);
            low(inDec);
          }
        }
        else
        {
          print("?\n");
        }
        pause(50);  
      }  
    }
    
    
    Ray

    Why don't you just use TACHYON Forth or PropForth for this? Otherwise, you will either have to do a lot of programming(which may be the point), or have the P1 just serve as a glorified port expander.
    The thing the Pi needs is real time IO, and the Propeller can handle that. The Prop needs a good interface, and for me, I like Tcl/Tk for that which the Pi can provide.
    I am guessing if you wanted to make a P1Piplate, you could pass through most of the GPIOs and use other GPIOs to bitbang an interface to the prop. Has anybody done a bitbanged serial port yet on the Pi?
Sign In or Register to comment.