arduino to rasp pi usb

Xbee projects like the adapter, xbee tutorials, tweetawatt/wattcher, etc. purchased at Adafruit

Moderators: adafruit_support_bill, adafruit

arduino to rasp pi usb

Postby cfloryiv » Thu Aug 30, 2012 3:24 am

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

cfloryiv
 
Posts: 10
Joined: Tue Dec 27, 2011 9:06 am

Return to XBee products from Adafruit

Who is online

Users browsing this forum: No registered users and 1 guest

Stuff to buy from the Adafruit store and links to product documentation!


New Products [102]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[109]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]