Shop OBEX P1 Docs P2 Docs Learn Events
Connect Basic Stamp 2 to Raspberry pi with C — Parallax Forums

Connect Basic Stamp 2 to Raspberry pi with C

satriaoosatriaoo Posts: 20
edited 2015-05-05 17:02 in BASIC Stamp
Dear sir,

I hava a project to connect raspberry Pi model B to Basic Stamp 2 Board of Education Development Board via LXTerminal with C .
Do you know how to connect it? Code?

Please help. Thanks. :)

Comments

  • Heater.Heater. Posts: 21,230
    edited 2015-04-28 02:54
    I do not understand your question.

    I know nothing of the BASIC Stamp 2 but I'm certain you cannot program it in C.

    LXTerminal is a terminal program used on the Pi. That can be used to talk to connected devices connected over a serial line.

    So, where does the C code fit into this?

    Any questions about writing programs to talk to the serial ports on a Pi are better asked on the Raspberry Pi forum.

    A quick google search for "linux serial port programming C" will probably get you a lot of advice.

    Unless it is a specific requirement of your homework or something to learn and do this in C I would suggest using Python or JavaScript instead.
  • Mike GreenMike Green Posts: 23,101
    edited 2015-04-28 08:11
    The BS2 (Basic Stamp 2) transmits and receives standard serial data at pretty much any speed below 9600 Baud. It can transmit at 9600 Baud, but tends to miss data receiving if there's any significant interpretation needed. The Stamp Basic Syntax and Reference Manual has lots of information and examples in the chapters on the SERIN and SEROUT statements.

    The RaspberriPi uses the LXTerminal program for serial input and output using the console and C has some standard serial I/O

    There are all sorts of ways to connect these two including via USB (if you have the USB Board of Education). You just need to connect the programming / debugging port on the Board of Education to one of the USB ports of the RaspberryPi and it'll show up as a serial port in /dev. LXTerminal should see it and be able to connect to it. In this case, you will be able to use the DEBUGIN and DEBUG statements in Stamp Basic which are simplified versions of SERIN and SEROUT. Look in the Reference Manual for details and examples.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-04-28 10:20
    The "Similar Threads" section shows this isn't the first thread on this topic.

    The first two threads listed have a lot of useful information on the topic.

    One thing I didn't see mentioned in the earlier threads was the need to protect the Raspberry Pi from the Stamp's 5V logic level. It would probably be a good idea to use a level shifter between the Stamp and Pi.
  • satriaoosatriaoo Posts: 20
    edited 2015-04-28 22:07
    Heater. wrote: »
    I do not understand your question.

    I know nothing of the BASIC Stamp 2 but I'm certain you cannot program it in C.

    LXTerminal is a terminal program used on the Pi. That can be used to talk to connected devices connected over a serial line.

    So, where does the C code fit into this?

    Any questions about writing programs to talk to the serial ports on a Pi are better asked on the Raspberry Pi forum.

    A quick google search for "linux serial port programming C" will probably get you a lot of advice.

    Unless it is a specific requirement of your homework or something to learn and do this in C I would suggest using Python or JavaScript instead.

    I mean, i program it from raspberry pi. :/ btw, thanks for advice, sir. :)
  • satriaoosatriaoo Posts: 20
    edited 2015-04-28 22:10
    hmm, okay, thanks sir. :)
  • Mike GreenMike Green Posts: 23,101
    edited 2015-04-28 22:54
    You can't program the Stamp using the RaspberryPi. The only compilers for the Stamp are for Windows, MacOS, and Intel Linux and you can only program a Stamp in Stamp Basic, not in C. You can write a program for the Stamp in Stamp Basic and compile and download it using one of the Stamp compilers, then have that program interact with a C program on the RaspberryPi.
  • Heater.Heater. Posts: 21,230
    edited 2015-04-29 01:13
    Mike,
    The only compilers for the Stamp are for Windows, MacOS, and Intel Linux
    I have no interest in STAMPs but this caught my eye. If there is a Stamp compiler for Mac and Intel Linux that tells me there could very easily be one for the Raspberry Pi. It's just a rebuild away.

    Or is this another of Chip's assembler only creations that will only ever live on Intel?
  • Mike GreenMike Green Posts: 23,101
    edited 2015-04-29 11:34
    @Genetix,
    Unfortunately, the downloads for Linux that you referenced won't work on the RaspberryPi. "tokenizer.so" is a binary library that contains the actual compiler for Stamp Basic and will only run on an Intel-compatible processor. The rest of the Linux code is in C++, but is only the editor and interface to "tokenizer.so".
  • GenetixGenetix Posts: 1,754
    edited 2015-04-29 11:46
    Mike Green wrote: »
    @Genetix,
    Unfortunately, the downloads for Linux that you referenced won't work on the RaspberryPi. "tokenizer.so" is a binary library that contains the actual compiler for Stamp Basic and will only run on an Intel-compatible processor. The rest of the Linux code is in C++, but is only the editor and interface to "tokenizer.so".

    Thanks for correcting me because I didn't see any comments for those downloads other than they weren't supported by Parallax.
  • satriaoosatriaoo Posts: 20
    edited 2015-05-03 23:47
    Heater. wrote: »
    Mike,

    I have no interest in STAMPs but this caught my eye. If there is a Stamp compiler for Mac and Intel Linux that tells me there could very easily be one for the Raspberry Pi. It's just a rebuild away.

    Or is this another of Chip's assembler only creations that will only ever live on Intel?

    Hmm, so, i have a project to running hexapod with Raspberry Pi and Basic Stamp (Basic stamp connected with Raspberry Pi using serial USB). I must controlling the hexapod via raspberry pi. But, i have a problem. I dont know what the C code (btw, im using LXTerminal) to connect them. :/

    Btw, my Basic stamp using MAC BS2 pre-release. I didnt have any problem on this. My problem only on "Connecting Raspberry with Basic Stamp"

    Could you help me please? :(
  • Heater.Heater. Posts: 21,230
    edited 2015-05-04 02:15
    So you want a C program on the Pi to talk to a BASIC program on the STAMP, correct?

    If you want to make a director connection between The Pi's serial port on GPIO and STAMP you will first need to prevent Linux using it: http://elinux.org/RPi_Serial_Connection#Preventing_Linux_using_the_serial_port

    Do you really need to use C on the Pi? Life is much easier if you use say Python:
    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))
    
    http://elinux.org/Serial_port_programming

    Or JavaScript:
    var SerialPort = require("serialport").SerialPort
    var serialPort = new SerialPort("/dev/tty-usbserial1", {
      baudrate: 57600
    }, false); // this is the openImmediately flag [default is true]
    
    serialPort.open(function (error) {
      if ( error ) {
        console.log('failed to open: '+error);
      } else {
        console.log('open');
        serialPort.on('data', function(data) {
          console.log('data received: ' + data);
        });
        serialPort.write("ls\n", function(err, results) {
          console.log('err ' + err);
          console.log('results ' + results);
        });
      }
    });
    
    https://github.com/voodootikigod/node-serialport


    If you want to do it in C it's a bit more long winded. See HOWTO article here:
    http://tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html
  • satriaoosatriaoo Posts: 20
    edited 2015-05-04 20:07
    Heater. wrote: »
    So you want a C program on the Pi to talk to a BASIC program on the STAMP, correct?

    If you want to make a director connection between The Pi's serial port on GPIO and STAMP you will first need to prevent Linux using it: http://elinux.org/RPi_Serial_Connection#Preventing_Linux_using_the_serial_port

    Do you really need to use C on the Pi? Life is much easier if you use say Python:
    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))
    
    http://elinux.org/Serial_port_programming

    Or JavaScript:
    var SerialPort = require("serialport").SerialPort
    var serialPort = new SerialPort("/dev/tty-usbserial1", {
      baudrate: 57600
    }, false); // this is the openImmediately flag [default is true]
    
    serialPort.open(function (error) {
      if ( error ) {
        console.log('failed to open: '+error);
      } else {
        console.log('open');
        serialPort.on('data', function(data) {
          console.log('data received: ' + data);
        });
        serialPort.write("ls\n", function(err, results) {
          console.log('err ' + err);
          console.log('results ' + results);
        });
      }
    });
    
    https://github.com/voodootikigod/node-serialport


    If you want to do it in C it's a bit more long winded. See HOWTO article here:
    http://tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html

    WOOOW! Thanks sir, connected! Iam using Python btw. Nice advice. :P

    But one more sir. hehe. How to calling function (my code on Microcontroller) from python? Iam using MAC BS2-pre release btw.

    Thank you, sir. :)
  • Heater.Heater. Posts: 21,230
    edited 2015-05-05 01:36
    satriaoo,
    How to calling function (my code on Microcontroller) from python?
    You cannot call a BASIC function on your STAMP from a Python function on the Pi.

    Both BASIC and Python can only call functions within the same program. Making calls from one language to another, even in the same program running on the same machine is generally impossible or hard.

    What you have to do is write a function in Python that sends a message, some string of characters/bytes, to the STAMP over the serial line. The program in the STAMP receives those bytes, recognizes the message and does whatever action the message implies. Perhaps it then sends a message back to the Pi where to tell the Python program the result of the action.

    Or the other way around of course.

    I know nothing of BASIC STAMPS so I cannot help much with that.

    Given your apparent level of experience I would suggest starting with something really simple:

    Can you send a single character, say "1", from the Pi and have the STAMP receive it? Perhaps turn a LED on to indicate success. Then send a "0" and have the STAMP turn the LED off.

    With that working we can look at what you actually want to do and how to send and decode messages between Pi and STAMP.
  • satriaoosatriaoo Posts: 20
    edited 2015-05-05 17:02
    Heater. wrote: »
    satriaoo,

    You cannot call a BASIC function on your STAMP from a Python function on the Pi.

    Both BASIC and Python can only call functions within the same program. Making calls from one language to another, even in the same program running on the same machine is generally impossible or hard.

    What you have to do is write a function in Python that sends a message, some string of characters/bytes, to the STAMP over the serial line. The program in the STAMP receives those bytes, recognizes the message and does whatever action the message implies. Perhaps it then sends a message back to the Pi where to tell the Python program the result of the action.

    Or the other way around of course.

    I know nothing of BASIC STAMPS so I cannot help much with that.

    Given your apparent level of experience I would suggest starting with something really simple:

    Can you send a single character, say "1", from the Pi and have the STAMP receive it? Perhaps turn a LED on to indicate success. Then send a "0" and have the STAMP turn the LED off.

    With that working we can look at what you actually want to do and how to send and decode messages between Pi and STAMP.

    Hmmm, okay. i'll try. Thank you sir. :)
Sign In or Register to comment.