arduino to rasp pi usb

XBee projects like the adapter, xBee tutorials, tweetawatt/wattcher, etc. from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
cfloryiv
 
Posts: 38
Joined: Tue Dec 27, 2011 10:06 am

arduino to rasp pi usb

Post by cfloryiv »

HI, I'm having trouble with my first xbee project. I have an app on the arduino that send a prompt to the pi over xbee, then waits for a command from the pi. The prompt is making it to the pi, but the data from the pi never makes it back to the arduino.

Code: Select all

// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!

#include <AFMotor.h>
int test_mode=1;
int live_mode=not(test_mode);
int speed=250;

AF_DCMotor left_motor(1);
AF_DCMotor right_motor(2);

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  //Serial.println("Robot Controller");

}

void loop() {
  Serial.print("cmd:");
  execute();
  delay(1000);
}
void execute() {
  while(!Serial.available());
  char cmd=Serial.read();
    switch(cmd) {
    case 'f':
      if (live_mode) {
        left_motor.run(FORWARD);
        left_motor.setSpeed(speed);
        right_motor.run(FORWARD);
        right_motor.setSpeed(speed);
      }
      Serial.print("ok!");
      break;
    case 'b':
      if (live_mode) {
        left_motor.run(BACKWARD);
        left_motor.setSpeed(speed);
        right_motor.run(BACKWARD);
        right_motor.setSpeed(speed);
      }
      Serial.print("ok!");
      break;
    case 'r':
      if (live_mode) {
        left_motor.run(FORWARD);
        left_motor.setSpeed(speed);
        right_motor.run(FORWARD);
        right_motor.setSpeed(0);
      }
      Serial.print("ok!");
      break;
    case 'l':
      if (live_mode) {
        left_motor.run(FORWARD);
        left_motor.setSpeed(0);
        right_motor.run(FORWARD);
        right_motor.setSpeed(speed);
      }
      Serial.print("ok!");
      break;
    default:
      Serial.print("error!");
      break;
    }
    if (live_mode) {
      left_motor.run(RELEASE);
      right_motor.run(RELEASE);
    }
  }

Code: Select all

Linux raspberrypi 3.1.9adafruit+ #8 PREEMPT Wed Aug 1 18:02:42 EDT 2012 armv6l



The programs included with the Debian GNU/Linux system are free software;

the exact distribution terms for each program are described in the

individual files in /usr/share/doc/*/copyright.



Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent

permitted by applicable law.



Type 'startx' to launch a graphical session



You have new mail.

Last login: Thu Aug 30 08:19:54 2012 from 192.168.1.114


pi@raspberrypi ~ ccdd  pprroojjeeccttss


pi@raspberrypi ~/projects llss


robot.py  test_serial.py  test_udp.py

pi@raspberrypi ~/projects $ccaatt  rroobboott..ppyy




import serial

ser=serial.Serial("/dev/ttyUSB0",19200)

ser=serial.Serial("/dev/ttyUSB0",9600)

while True:

    prompt=""

    while True:

        ch=ser.read(1)

        prompt+=ch

        if ch == ":":

            break

    cmd=raw_input(prompt)

    cmdx="%s\n" % cmd

    print "sending " + cmdx

    ser.write(cmdx)

    if cmd=="e":

        ser.close()

        quit()

    data=""

    while True:

        ch=ser.read(1)

        print ch,

        data+=ch

        if ch=='!':

            break

    print data

pi@raspberrypi ~/projects $
pi@raspberrypi ~/projects $
pi@raspberrypi ~/projects $
pi@raspberrypi ~/projects $
pi@raspberrypi ~/projects $ nano robot.py

































































































  GNU nano 2.2.6                                            File: robot.py


import serial
ser=serial.Serial("/dev/ttyUSB0",19200)
ser=serial.Serial("/dev/ttyUSB0",9600)
while True:
    prompt=""
    while True:
        ch=ser.read(1)
        prompt+=ch
        if ch == ":":
            break
    cmd=raw_input(prompt)
    cmdx="%s\n" % cmd
    print "sending " + cmdx
    ser.write(cmdx)
    if cmd=="e":
        ser.close()
        quit(
    data=""
    while True:
        ch=ser.read(1)
        print ch,
        data+=ch
        if ch=='!':
            break
    print data

























                                                                           [ Read 26 lines ]
^G Get Help                 ^O WriteOut                 ^R Read File                ^Y Prev Page                ^K Cut Text                 ^C Cur Pos
^X Exit                     ^J Justify                  ^W Where Is                 ^V Next Page                ^U UnCut Text               ^T To Spell


Locked
Please be positive and constructive with your questions and comments.

Return to “XBee products (discontinued)”