View unanswered posts | View active topics It is currently Tue Oct 21, 2014 8:03 am






Reply to topic  [ 8 posts ] 
NXT to NXT Communication with RS485 - help required. 
Author Message
Rookie

Joined: Wed Nov 10, 2010 11:08 am
Posts: 4
Post NXT to NXT Communication with RS485 - help required.
Hi, I'm looking for someone to help me with understanding how communication between NXT's work using the RS485 cable.

First off, is the cable the standard one that come's with the NXT system (I case you couldn't tell I'm knew)

Secondly what is the code that you need to use to achieve this. If anyone has any example I would be truly appreciative, this thing has been bringing me down for some time now as it's due for a project.

Thanks in advance :D

Kind Regards,
Serj


Sun Mar 20, 2011 4:18 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3225
Location: Rotterdam, The Netherlands
Post Re: NXT to NXT Communication HELP!!!
This is the slave:
Code:
int counter = 0;
task main () {
  int num;
  int chksum;
  ubyte incoming[16];
  nxtEnableHSPort();
  nxtHS_Mode = hsRawMode;
  nxtSetHSBaudRate(9600);
  wait1Msec(2000);
  writeDebugStreamLine("slave alive");
  while(true) {
    num = nxtGetAvailHSBytes();
    if (num > 0) {
      nxtReadRawHS(incoming[0], num);
      if (num == 16)
      {
        chksum = 0;
        for (int i = 1; i < 15; i++) {
          chksum ^= incoming[i];
        }
        if ((chksum == incoming[0]) && (chksum == incoming[15]))
        {
          counter++;
          writeDebugStreamLine("%d %d", counter, incoming[0]);
        }
        else
          writeDebugStreamLine("BAD CHKSUM");
      }
      else
      {
         writeDebugStreamLine("SMALL %d", num);
      }
    }
  }
}


This is the master:
Code:
task main () {
  int num;
  ubyte outgoing[16] = {15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
  //memset (outgoing, 0x00, 16);
  nxtEnableHSPort();
  nxtHS_Mode = hsRawMode;
  nxtSetHSBaudRate(9600);
  wait1Msec(2000);


  for (int i = 0; i < 100; i++) {
    outgoing[0] = i;
    nxtWriteRawHS(outgoing[0], 16, 0);
    wait1Msec(100);
  }
}

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Mar 21, 2011 5:13 pm
Profile WWW
Rookie

Joined: Wed Nov 10, 2010 11:08 am
Posts: 4
Post Re: NXT to NXT Communication HELP!!!
Hi thanks for the response absolutely brilliant just one quick question I am correct in thinking that they join via port 4?

Hi sorry I hadn't tested the code before I sent that last message, two things have flagged up in the code.

The first error is as follows:

**Error**:Undefined procedure 'writeDebugStreamLine'

I don't know if there is any light which you could shed on this, I'll start looking to see if it's drivers but thought I should post the question first

Secondly on the master code it says that int num; is declared but not used, I didn't know as to whether this was intentional but thought I should just ask incase

Just to emphasise how grateful I am for your support and I apologize for PMing you earlier I was getting stressed about the whole project

Serj


Last edited by Serj.Alexandrov on Mon Mar 21, 2011 5:38 pm, edited 1 time in total.



Mon Mar 21, 2011 5:22 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3225
Location: Rotterdam, The Netherlands
Post Re: NXT to NXT Communication HELP!!!
Serj.Alexandrov wrote:
Hi thanks for the response absolutely brilliant just one quick question I am correct in thinking that they join via port 4?

You are indeed correct, sir. It is the only one equipped with the RS485 chip :)

Quote:
Just to emphasise how grateful I am for your support and I apologize for PMing you earlier I was getting stressed about the whole project

No worries. I just wanted to post an answer to the forums, rather than PM, so that others can also see it. I will change the subject of the thread to make it a bit clearer what it's about.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Mar 21, 2011 5:33 pm
Profile WWW
Rookie

Joined: Wed Nov 10, 2010 11:08 am
Posts: 4
Post Re: NXT to NXT Communication with RS485 - help required.
Hi dunno if you can give me any advice about the problem with the writeDebugStreamLine, sorry never used that code before and it won't let me download it to the robot whilst it's there?


Tue Mar 22, 2011 7:20 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3225
Location: Rotterdam, The Netherlands
Post Re: NXT to NXT Communication with RS485 - help required.
What version of ROBOTC are you using? If it's not 2.26, you should consider downloading it.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Mar 22, 2011 7:32 am
Profile WWW
Rookie

Joined: Thu May 26, 2011 12:41 pm
Posts: 1
Post Re: NXT to NXT Communication with RS485 - help required.
Hi:
I have some robots with NXTBee module incorporated. I need to communicate between them. I have the XBees configurated in API (1) mode and I can do unicast from the PC through a Gateway, configuring the XBee of Gateway as coordinator and the XBee of the robots as end devices.
Can you specify the configuration of the XBee for this example?
I was trying but it does not work.
Thank you in adance...


Thu May 26, 2011 12:48 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Dec 21, 2010 1:38 pm
Posts: 24
Post Re: NXT to NXT Communication with RS485 - help required.
Hi guys,

I've done a number of projects in this area.
If you're interested in learning more visit the following links.

NXTBee - http://dexterindustries.com/NXTBee.html
Multi-robot communication- http://www.robotc.net/firewiki/index.ph ... =Main_Page
My Projects - http://www.ericsmalls.com/p/my-projects.html

If you have any more questions post them in the ROBOT-C multi-robot forum:
viewforum.php?f=58

Thanks!

_________________
Eric Smalls
About Me: http://www.stanford.edu/~esmalls/
My Projects: http://www.ericsmalls.com/p/my-projects.html


Mon May 14, 2012 7:48 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.