View unanswered posts | View active topics It is currently Mon Dec 22, 2014 11:43 am






Reply to topic  [ 12 posts ] 
Multi I2C device at same NXT port 
Author Message
Rookie

Joined: Wed Jul 15, 2009 11:13 am
Posts: 2
Post Multi I2C device at same NXT port
Does any one try put more one of I2C devices in LEGO Mindstorm NXT input port?
Such us IN_1 with 2 I2C devices one address is 0x70 and another is 0x60.

Due I am try put lot's of I2C deivce use NXT input port on NXC/NBC but it's not work.
I hope can have this feature that I can do some cool things.

Regards,
Sog


Wed Jul 15, 2009 11:30 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post Re: Multi I2C device at same NXT port
Hi there Sog,

I have had multiple I2C devices attached to a single I2C port. They each had their own address so it was fine. What exactly is you're trying to make? NXC is also capable of this. Perhaps you were doing something wrong? Give us more details so we can help you better.

Regards,
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]


Wed Jul 15, 2009 12:39 pm
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: Multi I2C device at same NXT port
Xander,
how did you do it with RobotC?
Each time polling a sensor, do have to init that specific sensor each time anew?

Like
Code:
Setsensor(0, SensorSonar);
value=SensorValue(0);

SetSensor(0, SensorMightyBoard);
value=...

SetSensor(0, SensorHTTouchMux) // or however or whatever
value=...


or somehow different?

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Wed Jul 15, 2009 1:19 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post Re: Multi I2C device at same NXT port
Ford,

For one thing, I almost never use the built-in drivers and the original poster talks about devices at address 0x60 and 0x70. That leads me to believe that he's not using Lego certified sensors, they (mostly) use address 0x02. If you send your own I2C messages on the bus, you can make use of the normal I2C addressing system. If you use the built-in drivers, you have to reconfigure the port each time you want to switch between one type and another. This is quite cumbersome.
If you look the mightyboard driver, you'll see that I don't switch between different sensor types. That port is *always* a normal I2C port. I just send different messages when I want to query the MAX127 or when I want to set an output port with the MCP23008.

Regards,
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]


Wed Jul 15, 2009 3:15 pm
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: Multi I2C device at same NXT port
that's sth for very advanced system programmers. And to be honest: I don't understand 1 single of your Mightyboard control programming lines :(

the RobotC I²C controlling is far too complicated and cumbersome to ME!

So how else shall you do it if you are a programming starter, just using the simplest robotc sensor configuring and access commands?

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Wed Jul 15, 2009 4:13 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post Re: Multi I2C device at same NXT port
Quote:
So how else shall you do it if you are a programming starter, just using the simplest ROBOTC sensor configuring and access commands?

Simple, you don't. It's using the I2C bus in an advanced way, so you can expect to have to use more advanced methods for accessing it. It is like wanting to build a particle accelerator without all the nasty quantum mechanics and other mathematical "nonsense". You simply can't. ROBOTC allows users to use the standard Lego, HiTechnic and Mindsensors sensors in a very easy to use manner. You have a simple configuration window. If you want to go beyond this, you need to learn how to use the lower level calls. There is no way around it. It is no easier in NXC or nxtOSEK.

Regards,
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]


Wed Jul 15, 2009 4:20 pm
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: Multi I2C device at same NXT port
no, the question is:
what is the simplest way to use RobotC commands in order to control multiple sensors plugged to a port splitter?

Robotc should allow to do it in a simple way, just like a black box, just like the NXT-G blocks do.

I want to write sophistated robot programs, I don't want to write sophisticated machine code ^^

show us a way how to do it! :poke: :D

(EDIT: I'd like to try nxtosek, no question, but what I needed were German tutorials and German fellows who support me.
I understand English (or Dutch) manuals maybe as good as you understand German or Kaukasian ones ;) )

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Wed Jul 15, 2009 5:34 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post Re: Multi I2C device at same NXT port
Ford,

The simplest way to do this is to just switch between sensor types. However, this will only work if all devices are on different addresses.

The NXT-G blocks work by setting the sensor type to, say, "I2C with 9V pin" and then perform an I2C operation. The NXT-G blocks don't allow you to use multiple sensors on a MUX any more than ROBOTC does. If the sensor addresses are the same, you will not get it working, with either NXT-G or with ROBOTC or any other programming environment. The built-in ROBOTC drivers all assume that a device is on address 0x02, the Lego standard. The NXT-G blocks are no different. There are very few blocks out there that do allow you to set the address of your target sensor. As far as I know, the Mindsensors ones are the *only* ones that allow you to use a ROBOTC program to change the sensor address. The "raw" I2C blocks for NXT-G only allow you to send a single byte to the sensor and require a lot of very convoluted actions to read more than one byte back from the device.

Another issue with using multiple sensors on the same port are pull-up resistors. The I2C bus requires a pull-up resistor on each channel (SDA, SCL). All sensors have these built-in. That means that as soon as you have one sensor attached to the bus, you have the pull-ups. When you attach a second sensor, you have *two* pull-ups per channel and that won't work. The Mindsensors ones allow you to switch their built-in resistors off. So, even if you wanted to connect multiple sensors to your bus, like a HiTechnic compass, IR Seeker and an EOPD, you couldn't, unless you had a way to disable the resistors on all but one. This is an electrical thing, not a programming thing.

You want a sophisticated program that makes use of advanced I2C features but you don't want to learn about the advanced features? That sounds contradictory. It's like trying to solve a 3rd order differential equation without the use of math.

nxtOSEK is much more difficult than ROBOTC. You think you're having a hard time dealing with the advanced features of ROBOTC? nxtOSEK will have you pulling your hair out in no time. Just for fun, nxtOSEK uses device address as calculated without the r/w bit. That means that a sensor which would be 0x02 on NXC, ROBOTC or NXT-G would be 0x01 on nxtOSEK. Also, nxtOSEK doesn't allow any I2C bus speed other than 9600 baud.

There is a reason I started writing my driver suite. It allows people access to the advanced features of the HiTechnic and a few Mindsensors sensors (6 new drivers are on their way) without the need for the low level I2C calls. However, neither my drivers, nor anyone else's will allow you to connect more than one sensor to your ports without, somehow, modifying their pull-ups. I2C is not complex, but I can assure you that the ROBOTC's I2C API is quite easy to use when compared to a lot of other I2C implementations I've worked with (ATmel, Parallax Propeller, etc).

Maybe someday I'll write a tutorial on how to write a driver using my framework or the built-in stuff, but at the moment I'm kind of busy. I2C is a low level protocol, you are talking to the hardware directly, that means you need a low level protocol to deal with it. It's the nature of the beast. No amount of jumping up and down or waving your arms is going to change that.

Regards,
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]


Thu Jul 16, 2009 1:08 am
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: Multi I2C device at same NXT port
Quote:
It's like trying to solve a 3rd order differential equation without the use of math.

yes.
and: no.
and actually: I think you know what I mean.

Using I²C is sort of using the sinus function.
What I want is this:
Code:
float x;
float y=sin(x);


what you want me to do is this:
Image
(Taylor series for the sinus function)


But thx for your posting anyway, though the real bad message is this, which I didn't know till now:

Quote:
So, even if you wanted to connect multiple sensors to your bus, like a HiTechnic compass, IR Seeker and an EOPD, you couldn't, unless you had a way to disable the resistors on all but one. This is an electrical thing, not a programming thing.

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Thu Jul 16, 2009 11:35 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post Re: Multi I2C device at same NXT port
Ford,

I like the way you think, but no that is not what I meant. What you want is more like:
Code:
int x = GetMeTheSensorData[S1];

for any device without specifying or wanting to get into how to fetch this data or how to process it when you get it. There is no "universal" I2C driver, just like the GUT (Grand Unification Theory), it has not been created. If you want a driver for a specific device you need to know how to chat with that device. You can't do that without knowing how I2C works, just like you can't talk to a Chinese person (who can't speak English or German) without knowing Chinese.
ROBOTC's interface is closer to sin(x) than the Taylor series. The Taylor series would be making I2C work on an AVR without the use of a library and having to create the entire I2C state engine from scratch and reading the bits as they come in. ROBOTC makes I2C about as easy as it can get. You don't have to check if an incoming message is correct, generate start and stop conditions, etc, etc.

Regards,
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]


Thu Jul 16, 2009 11:46 am
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: Multi I2C device at same NXT port
no no, what I want is more this (2 sensors at 1 splitter at the same port):

Code:
SetSensor(S1, SensorSonar);
int x = GetMeTheSensorData[S1];

SetSensor(S1, SensorHTGyro);
int x = GetMeTheSensorData[S1];


first sensor specification, then sensor polling.
then next sensor specification, then sensor polling.
a.s.o.

maybe, if there should be sent an I²C address of the sensor, it might even be like this:

Code:
SetSensor(S1, SensorSonar);
int x = GetSensorData(S1,0x02);

SetSensor(S1, SensorHTGyro);
int x = GetSensorData(S1, 0x3a];

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Thu Jul 16, 2009 11:59 am
Profile
Rookie

Joined: Wed Jul 15, 2009 11:13 am
Posts: 2
Post Re: Multi I2C device at same NXT port
Hi! Xander,

Thanks your answer, I am trying :). And if I got good news will feedback.
:breakcomputer:

Regards,
Sog

mightor wrote:
Hi there Sog,

I have had multiple I2C devices attached to a single I2C port. They each had their own address so it was fine. What exactly is you're trying to make? NXC is also capable of this. Perhaps you were doing something wrong? Give us more details so we can help you better.

Regards,
Xander


Fri Jul 17, 2009 5:30 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 12 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.