Comunication between 1 PC and 1 arduino via another adruino

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

Moderators: adafruit_support_bill, adafruit

Comunication between 1 PC and 1 arduino via another adruino

Postby ygreq » Mon May 02, 2011 11:44 am

Hi folks,

The internet is full of examples where you have one Xbee connected directly to the computer another one connected to an arduino.

What I haven't found is a PC communicating with an arduino via another arduino, all through Xbee. Like in the following example:

Sensor - > Arduino -> Xbee ---> Xbee -> Arduino -> PC.

Thus we need the SoftwareSerial library or an Arduino Mega which I happen to have.

The problem is I am having difficulties playing with serial3 (for example). I admit I am a bit of a novice.

Is anyone willing to help with some code?

Thank you very much,
ygreq
ygreq
 
Posts: 13
Joined: Mon May 02, 2011 10:17 am


Re: Comunication between 1 PC and 1 arduino via another adruino

Postby ygreq » Mon May 02, 2011 12:28 pm

Ok! Here goes!

I have a Humidity and Temperature sensor from seeedstudio (http://www.seeedstudio.com/depot/electr ... d33d7b2a74) that is connected to a Seeduino Stalker with an Xbee module stuck into it. As I need to process some info coming in from the sensor before sending it via Xbee, I actually think I need the Arduino (instead of opting for the Xbee Adaptor).

On the other module I now realize I could use an Xbee Adapter without the arduino to connect to a PC running Max 5. But if I were to use an Arduino to get info coming through Xbee into the PC, I guess I would have to use Arduino Mega or NewSoftSerial library to connect my Xbee as the "normal" serial is occupied with communicating with the PC, right?

I looked at some examples on the net but it doesn't help!

This is the code for the HT Sensor which in the end sends info through serial (which I guess the Xbee connected to it should send). I don't know how the code for the Arduino connected to the computer should be! :( I would like to grab it from Xbee serial and send it to the PC

Thank you so much,
ygreq

[EDIT moderator - use code block]
Code: Select all
#define DHT11_PIN 0      // ADC0

byte read_dht11_dat()
{
  byte i = 0;
  byte result=0;
  for(i=0; i< 8; i++){


    while(!(PINC & _BV(DHT11_PIN)));  // wait for 50us
    delayMicroseconds(30);

    if(PINC & _BV(DHT11_PIN))
      result |=(1<<(7-i));
    while((PINC & _BV(DHT11_PIN)));  // wait '1' finish


  }
  return result;
}


void setup()
{
  DDRC |= _BV(DHT11_PIN);
  PORTC |= _BV(DHT11_PIN);

  Serial.begin(9600);

  Serial.println("Ready");
}

void loop()
{
  byte dht11_dat[5];
  byte dht11_in;
  byte i;
  // start condition
  // 1. pull-down i/o pin from 18ms
  PORTC &= ~_BV(DHT11_PIN);
  delay(18);
  PORTC |= _BV(DHT11_PIN);
  delayMicroseconds(40);

  DDRC &= ~_BV(DHT11_PIN);
  delayMicroseconds(40);

  dht11_in = PINC & _BV(DHT11_PIN);

  if(dht11_in){
    Serial.println("dht11 start condition 1 not met");
    return;
  }
  delayMicroseconds(80);

  dht11_in = PINC & _BV(DHT11_PIN);

  if(!dht11_in){
    Serial.println("dht11 start condition 2 not met");
    return;
  }
  delayMicroseconds(80);
  // now ready for data reception
  for (i=0; i<5; i++)
    dht11_dat[i] = read_dht11_dat();

  DDRC |= _BV(DHT11_PIN);
  PORTC |= _BV(DHT11_PIN);

  byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];
  // check check_sum
  if(dht11_dat[4]!= dht11_check_sum)
  {
    Serial.println("DHT11 checksum error");
  }

  Serial.print("humidity = ");
  Serial.print(dht11_dat[0], DEC);
  Serial.print(".");
  Serial.print(dht11_dat[1], DEC);
  Serial.print("%  ");
  Serial.print("temperature = ");
  Serial.print(dht11_dat[2], DEC);
  Serial.print(".");
  Serial.print(dht11_dat[3], DEC);
  Serial.println("C  ");

  delay(2000);
}
ygreq
 
Posts: 13
Joined: Mon May 02, 2011 10:17 am

Re: Comunication between 1 PC and 1 arduino via another adruino

Postby adafruit_support_bill » Mon May 02, 2011 4:19 pm

Using NewSoftSerial is very much like using Serial. You just need to define a transmit and receive pin for each additional 'soft' serial port. Check this site for details: http://arduiniana.org/libraries/NewSoftSerial/
User avatar
adafruit_support_bill
 
Posts: 15918
Joined: Sat Feb 07, 2009 9:11 am


Return to XBee products from Adafruit

Who is online

Users browsing this forum: No registered users and 0 guests

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


New Products [105]

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[108]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[69]
 
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]