View unanswered posts | View active topics It is currently Mon Jul 28, 2014 4:39 am






Reply to topic  [ 10 posts ] 
Robot C and Multiplexers 
Author Message
Expert

Joined: Sun Sep 09, 2007 10:12 am
Posts: 116
Post Robot C and Multiplexers
Is there any program to use multiplexers?

How that works?

Could i conect different sensors on one single port?

Thanks


Mon Sep 10, 2007 7:24 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post 
You can hook multiple sensors up to the same port if they use whats called I2C, which is a communication protocol. I2C lets you send and receive bytes of information between the sensor and the NXT. Only the sonar sensor that comes with the Lego kit is I2C capable, other special sensors can be bought from third party sellers.

Each I2C sensor is given an unique address and when a command is sent to that address, the sensor will carry out the command. You can hook up any number if I2C sensors onto one port, but each port is limited to one non I2C sensor, such as the touch or light sensors. Note you have to write special code to use the sonar sensor in I2C mode, it normally is used in analog mode.

You can also use multiplexers with the NXT. There are different multiplexers out that will work with the NXT. Usually they use I2C and you send commands to the multiplexer.

Here are some third part sellers of NXT compatible sensors. Not all of them are I2C sensors, many operate just like a light sensor.

http://www.mindsensors.com/
http://www.techno-stuff.com/
http://www.hitechnic.com/

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Tue Sep 11, 2007 6:58 pm
Profile WWW
Expert

Joined: Sun Sep 09, 2007 10:12 am
Posts: 116
Post 
Ok, so, can i use a light sensor with a sonar? or a touch sensor with the color sensor from hitechnic?

On program, i just need to define the normal sensor and send mensages to i2c, right?

Thanks


Wed Sep 12, 2007 4:33 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post 
Yes, you can do both of those combinations as long as you are reading the sonar and color sensor using I2C.

Yes, you will set up the sensor port as a light, touch, or similar, and then send I2C messages to the other sensors plugged into the same port.

Scott B-)

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Wed Sep 12, 2007 6:03 pm
Profile WWW
Expert

Joined: Sun Sep 09, 2007 10:12 am
Posts: 116
Post 
Nice.

Do you know any tutorial of that?

To do the special 2 in 1 cable, should i just connect all except digital on regular sensors, and all cables except analoge one, on i2c. right?

Thanks

_________________
http://www.apcsguarda.com
My Project: http://www.robotc.net/forums/viewtopic.php?f=15&t=712


Thu Sep 13, 2007 6:49 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post 
I dont know of any tutorials that show how to do this sadly :-(

Im confused about your second question, are you asking how to make a cable to hook up multiple sensors? You dont have to alter any cables to this this. You could, but one nice product iv seen is the mindsensors port spliter. You can plug one end into the NXT and it creates three more ports, very nice for conecting Lego and I2C sensors to the same port. You can also make your own, I posted mine on my page. It turned out fairly well being my first custom circuit board. All you need to do is make shure is all the ports are wired in parallel to each other. Did I answer your question?

Mindsensors Port Exspander:
http://www.mindsensors.com/index.php?mo ... PAGE_id=79

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Thu Sep 13, 2007 12:14 pm
Profile WWW
Expert

Joined: Sun Sep 09, 2007 10:12 am
Posts: 116
Post 
ok.

i will try to do a cable. My problem is order an sensor from usa... too expensive...

thanks for the help

last question... i2c sonar, color sensor from hitechnic, compass sensor, all them got 0x02 as address... so, just one of those in each port, right?

Thanks

_________________
http://www.apcsguarda.com
My Project: http://www.robotc.net/forums/viewtopic.php?f=15&t=712


Thu Sep 13, 2007 4:49 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post 
Yes, you cannot have sensors with the same address on the same port, however many sensors can have there addresses changed.

I'm not sure if its possible on a Hitechnic sensor, If possible you would use a I2C command to change the sensors address byte.

Good luck with your robots
Scott B-)

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Thu Sep 13, 2007 7:03 pm
Profile WWW
Expert

Joined: Sun Sep 09, 2007 10:12 am
Posts: 116
Post 
Now i sucessefully put a touch sensor and a sonar on same port.

the wire is simple, just connect the first and second wires to touch and all the others to sonar.

It works very well.

Thanks for your help

_________________
http://www.apcsguarda.com
My Project: http://www.robotc.net/forums/viewtopic.php?f=15&t=712


Fri Sep 28, 2007 3:12 pm
Profile
Rookie

Joined: Tue Mar 11, 2008 7:33 am
Posts: 11
Post 
Note: I've fixed the following problem. Well, more accurately, I ran the program again and now it's working. Strange. But I'll leave the full message here in case anybody needs code that will run 2 sensors like this.

I'm wanting to do a similar thing.
I've purchased a Port splitter from Mindsensors, and I can use it with a Mindsensors Compass and Accelerometer. But I was hoping it would be possible to use a Touch sensor and Compass sensor on the same port.
The program I've editted goes as follows:

Code:
/*
Utility program to use with mindsensors.com CMPS-Nx V2.0 compass sensor.
For use with RobotC 1.0.08 or higher.
This Demo uses the address of 0x02 for the CMPS-Nx
assuming NxT screen with 0.1 degree resolution

(c) mindsensors.com 2006, 2007
Revision History
Who                When           Why
-------------------------------------------------------------
Dr. Nitin Patil    Sep-2006       Initial Authoring
Deepak             Dec-08-2006    Compatibility related changes
-------------------------------------------------------------
*/
/*
for more info visit www.mindsensors.com
Watch Demo Video:
http://www.mindsensors.com/images/NXT-with-mindsensors-compass.mpg
*/

/*

NXT I2C register storage

*/


#define    CmpsID               0xa8
#define    CmpsCommandReg       0x41
#define    CmpsReadResult       0x42
#define    CmpsReadHeading      0x49
#define    CmpsCAL              0x43
#define    CmpsEndCAL           0x44
#define    CmpsSampleUS         0x55
#define    CmpsSampleEU         0x45
#define    CmpsAuto             0x41

#define    CmpsPort             S1    // Connect CMPS sensor to this port!!
#define       touchPort            S1


//////////////////////////////////////////////////////////////////////////////
//
//      Read the heading  data from Compass sensor
//
//
/////////////////////////////////////////////////////////////////////////////

int  cmpsHeading()
{
  byte replyMsg[2];
    int Heading;
  byte cmpsMsg[5];
  const byte MsgSize        = 0;
  const byte CmpsAddress    = 1;
  const byte ReadAddress    = 2;
  const byte CommandAddress = 2;
  const byte Command        = 3;

  // Build the I2C message
  cmpsMsg[MsgSize]          = 3;
  cmpsMsg[CmpsAddress]      = CmpsID ;
  cmpsMsg[CommandAddress]   = CmpsCommandReg ;
  cmpsMsg[Command]          = CmpsReadHeading;

  while (nI2CStatus[S1] == STAT_COMM_PENDING);   // Wait for I2C bus to be ready

  sendI2CMsg(S1, cmpsMsg[0], 0);                    // Send the message

  cmpsMsg[MsgSize]        = 2;
  cmpsMsg[CmpsAddress]    = CmpsID ;
  cmpsMsg[ReadAddress]    = CmpsReadResult ;

  while (nI2CStatus[S1] == STAT_COMM_PENDING);    // Wait for I2C bus to be ready
  sendI2CMsg(S1, cmpsMsg[0], 2);                    // Send the message

  while (nI2CStatus[S1] == STAT_COMM_PENDING);     // Wait for I2C bus to be ready
  if ( nI2CStatus[S1] != NO_ERR ) {  // probably sensor is missing.
    return (-1);
  }
  readI2CReply(S1, replyMsg[0], 2);

   if ( replyMsg[0] == -1 ) { // -1 is reserved to report errors, so
   Heading = 0; // change it to zero.
   }
   else {
   Heading = ( 0x00FF & replyMsg[0] );
   }
   Heading += ( (0x00FF & replyMsg[1]) <<8 );
   return (Heading);
}

//////////////////////////////////////////////////////////////////////////////
//
//     send command to Compass sensor
//
/////////////////////////////////////////////////////////////////////////////

void cmpsCommand(byte cmpsCommand)
{
  byte cmpsMsg[5];
  const byte MsgSize        = 0;
  const byte CmpsAddress    = 1;
  const byte ReadAddress    = 2;
  const byte CommandAddress = 2;
  const byte Command        = 3;

  // Build the I2C message
  cmpsMsg[MsgSize]          = 3;
  cmpsMsg[CmpsAddress]      = CmpsID;
  cmpsMsg[CommandAddress]   = CmpsCommandReg ;
  cmpsMsg[Command]          = cmpsCommand;

  while (nI2CStatus[S1] == STAT_COMM_PENDING);   // Wait for I2C bus to be ready
  sendI2CMsg(S1, cmpsMsg[0], 0);                    // Send the message
}

//////////////////////////////////////////////////////////////////////////////
//
//      Display the heading and touch state on Nxt screen
//
/////////////////////////////////////////////////////////////////////////////

task main()
{

  int currheading;
  bool in = true;

   nI2CBytesReady[S1] = 0;




  while(true)   //just keep running
  {
      SensorType[S1] = sensorTouch;

     if(!SensorValue(touchPort) && in){

       nxtDisplayTextLine(2,"Touch: Out");
       in = false;

     }else if(SensorValue(touchPort) && !in){

       nxtDisplayTextLine(2,"Touch: In");
       in = true;

     }


     SensorType[S1] = sensorI2CCustomFast9V;

     currheading = cmpsHeading();
     if ( currheading == -1 ) {
         nxtDisplayTextLine(5,"Error: Check connections");
     } else {
        nxtDisplayTextLine(5,"Read OK");
     }
     nxtDisplayTextLine(6,"Heading = %d", currheading / 10);

  }
  StopAllTasks();
}

// End of Program.


The Touch gives me a consistent correct reply. In or Out. However, the compass sensor constantly flicks back and forth between "Error" and "Read OK"; and it's difficult to pick up the actual readings, but generally either 25, 0 or -25. Perhaps occasionally, an actual compass reading, but I cannot be sure.

Anybody's help or advice on this is deeply appreciated, Kit.

Edit: Also, the same program works 100% if only one of either sensor is plugged in.


Tue Mar 11, 2008 7:40 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 10 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.