NXC: Sensor port as I/O pin

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
madscripter
Posts: 7
Joined: 19 Feb 2011, 15:56
Location: Germany

NXC: Sensor port as I/O pin

Post by madscripter »

Hi,
i am trying to use one of the NXT sensorports as an out pin. My idea was to use out signal with an opto-isolator to comtrol a second cicuit which runns two motors.(And as the nxt battery run down fast i didn't want to use them to power these motors).The Problem is that I still need to control them.
And as i am a complete newbee to circuits and the NXT, that is were the problems begin:
-fist of all id dont even know the layout of the NXT port
(somthing like which wire is GND for 9v for 5V where which Vcc+ is and where the logical pins are)
-second point is how to control the logical pins
I saw the

Code: Select all

 
    void SetSensorDigiPinsDirection(const byte port,const byte & direction)
    void SetSensorDigiPinsOutputLevel(const byte port,const byte &    outputLevel)
    void SetSensorDigiPinsStatus(const byte port, const byte & status)
but i cant really understand these commands and as I tried them(I put them into a loop a wrote down all the currents between all the pins)
i found something aubout thaat I had to set the sensor to custom mode, but the commands I found didnt really help
there was nothing like

Code: Select all

void SetSensorCustom( const byte port)
but only

Code: Select all

void SetCustomSensorActiveStatus ( const byte  port, const byte & activeStatus )
void SetCustomSensorPercentFullScale ( const byte  port, const byte &  pctFullScale )
void SetCustomSensorZeroOffset ( const byte  port, const int &  zeroOffset	)
i dont even know what offset is :(

Julian
Julian
nxtreme
Posts: 246
Joined: 29 Sep 2010, 03:53
Location: 192.168.1.2

Re: NXC: Sensor port as I/O pin

Post by nxtreme »

As far as hardware goes, check out the Extreme NXT book. It's a great book (I have the first and second edition) and very cheap (~$6 US) from Amazon.com, if you live in Canada or the US. It explains the basics (and some of the not-so-basics) of interfacing with the NXT.
One King to rule them all, One King to find them,
One King to bring them all and in the darkness bind them
On Earth where Shadows lie.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC: Sensor port as I/O pin

Post by mattallen37 »

If you want to make a motor multiplexer, and you don't care about PWM (speed control), try using a PCF8574, and as many H-Bridges as you need motors. I have made a motor multiplexer before using one PCF8574, and one SN754410. It was able to control two motors, and was really easy to setup and program for.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
madscripter
Posts: 7
Joined: 19 Feb 2011, 15:56
Location: Germany

Re: NXC: Sensor port as I/O pin

Post by madscripter »

nxtreme wrote:As far as hardware goes, check out the Extreme NXT book. It's a great book (I have the first and second edition) and very cheap (~$6 US) from Amazon.com, if you live in Canada or the US. It explains the basics (and some of the not-so-basics) of interfacing with the NXT.
I allready have the NXT EXtreme book but I had forgotten about it, because when i began using the NXT (about 3 months ago) i was more interesten in coding and undestanding NXC. And as that book does not contain that much code(in special not much of NXC code) and because you have to understand electrics i didnt really read it until now. So i found the pin layoutthat I needed (pin5 and 6 green and yellow are the logic pinsand GND should be 3(red))
sothank you of reminding me of this great book
mattallen37 wrote:If you want to make a motor multiplexer, and you don't care about PWM (speed control), try using a PCF8574, and as many H-Bridges as you need motors. I have made a motor multiplexer before using one PCF8574, and one SN754410. It was able to control two motors, and was really easy to setup and program for.
well yes I do want to controll two motor and dont care about PWD(that was the thing with the length of the pusle right?) but I didnt want to build the constuction, because using an relais seems much easier and I didnt want to start ICs as a new project because this will take a lot of time and be quite expensive

and the competition is this sunday(it is just a local set-up competition to see if everything works and what the other teams have built)

but I still need to know how the software works

Code: Select all

void SetSensorType 	(port,SENSOR_TYPE_CUSTOM)
i guess this will get the sensor to custom mode
and this will define if it is input or output

Code: Select all

void SetSensorDigiPinsDirection(const byte port,const byte & direction)
in the example forom john i saw that the output level was set to 100 so i guess it is 100% of 3.3V

Code: Select all

SetSensorDigiPinsOutputLevel(const byte port,const byte &    outputLevel)
can this be?
Julian
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC: Sensor port as I/O pin

Post by mattallen37 »

Actually, pin five and six are yellow and blue. Pin 4 is green (4.7v supply). On the sensor ports, pins two AND three (black and red) are GND.

PWM, "pulse width modulation", is a (usually) fixed frequency square wave, and the duty cycle is adjustable from 0-100% (thus varying the speed of a motor, or the brightness of an LED...).

Assuming "relais" means "relay", don't use them. Unless you are keen about diodes, transistors, current... it could be very dangerous to your NXT. If you were considering relays, then you must not need direction control, right? In that case, just a single transistor and diode per motor should be enough. An NPN transistor (a very common type, and one that should be suitable for your application) is sort of like a relay, where you have a "coil" (gate) a voltage input (collector), and an output (emitter). Using an H-Bridge IC though, would be a lot more simple (you would just need to wire the IC properly, which is pretty straight forward).

IMO, IC's are really easy to use, you just need a solderless breadboard (for prototyping/temporary use). Also, most general purpose IC's are pretty cheap. I have gotten the quad half H-Bridges (two H's in one IC) for $1.75 US each (I have gotten PCF8574's for the same price).

AS far as controlling the NXT pins directly, I haven't done it yet.

BTW, isn't NXC not allowed for the competitions?
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
madscripter
Posts: 7
Joined: 19 Feb 2011, 15:56
Location: Germany

Re: NXC: Sensor port as I/O pin

Post by madscripter »

well the problem was that the nxt only gives 110mA of power so and as i didnt want to fry the nxt(and save the nxts battery) i decided to put the motors i want to control in a different circuit. I was actually thinking about using an optical relay wich consists of a diode and an photo transistor, or a photoresistor.
and as far as I have undestood a relay alway inducts that the control circuit and the circuit that has the controled units have the same power suply, in this case it doesent help much as the motors need a lot of power.
but i dont really understand electronics...
madscripter wrote:IMO, IC's are really easy to use, you just need a solderless breadboard (for prototyping/temporary use). Also, most general purpose IC's are pretty cheap. I have gotten the quad half H-Bridges (two H's in one IC) for $1.75 US each (I have gotten PCF8574's for the same price).
and i think there is the same problem with that that all works with the same power suly
mattallen37 wrote: BTW, isn't NXC not allowed for the competitions?

i think this imitation is only for NXG last year some peole from my school took part in the competition last year and they were using robotc so it shouldnt be a problem
mattallen37 wrote: AS far as controlling the NXT pins directly, I haven't done it yet.
maybee John has an idea
Julian
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC: Sensor port as I/O pin

Post by mattallen37 »

madscripter wrote:well the problem was that the nxt only gives 110mA of power so and as i didnt want to fry the nxt(and save the nxts battery) i decided to put the motors i want to control in a different circuit. I was actually thinking about using an optical relay wich consists of a diode and an photo transistor, or a photoresistor.
and as far as I have undestood a relay alway inducts that the control circuit and the circuit that has the controled units have the same power suply, in this case it doesent help much as the motors need a lot of power.
but i dont really understand electronics...
You can use a separate power supply. An "optical relay" (actually called an "optoisolator"), would serve no purpose in this case. There is no need for isolation, you just need to be careful not to connect the nxt supply to your power supply (Gnd from both should be connected as a reference point).
madscripter wrote:
mattallen37 wrote:IMO, IC's are really easy to use, you just need a solderless breadboard (for prototyping/temporary use). Also, most general purpose IC's are pretty cheap. I have gotten the quad half H-Bridges (two H's in one IC) for $1.75 US each (I have gotten PCF8574's for the same price).
and i think there is the same problem with that that all works with the same power suly
No, you can use the NXT power supply for the PCF8574, and the other supply (higher voltage and current) to power the H-Bridges (I know it, I have done it myself).
madscripter wrote:i think this imitation is only for NXG last year some peole from my school took part in the competition last year and they were using robotc so it shouldnt be a problem

...
NXG? I have never heard of that one. I know that ROBOTC is allowed, but NXC is not (I have never read the rules, I have just heard so).
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC: Sensor port as I/O pin

Post by afanofosc »

I think I wrote something about this here a while back. Does this help?

http://sourceforge.net/apps/phpbb/mindb ... tion#p2305

I need to update the help examples. If you come up with some functional code I would be happy to use your sample in the help files.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
madscripter
Posts: 7
Joined: 19 Feb 2011, 15:56
Location: Germany

Re: NXC: Sensor port as I/O pin

Post by madscripter »

I tried a lot and found out that the

Code: Select all

SetSensorDigiPinsDirection
command changes the current on the logical pins 5 and 6
but there wasn't enogh power to use a transitor with it so i found something verry interesting

Code: Select all

SetSensorType(IN_X,SENSOR_TYPE_LIGHT_ACTIVE);
will set pin 5 to a bit more than 3.15 V and give it enogh power to use a transitor with it

Code: Select all

SetSensorType(IN_X,SENSOR_TYPE_LIGHT_INACTIVE);
will turn pin 5 to 0V
I verry sorry I didn't sepend more time on finding out exactly how all the DigiPin commands work but this trick helped me so I hpe it will help others as wel
Julian
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC: Sensor port as I/O pin

Post by mattallen37 »

Almost any amount of power is enough to operate a transistor. I have made circuits that are so sensitive, that placing one finger to supply, and a finger on the other hand to a transistor base, would trigger the circuit. The transistors weren't special ones either, they were 3904's. I only used three or four. Sensitivity all really depends on your circuit design.

I am glad you got it working.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest