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






Reply to topic  [ 39 posts ]  Go to page Previous  1, 2, 3  Next
NXT + PCF8574 
Author Message
Rookie

Joined: Fri Apr 20, 2007 3:22 am
Posts: 36
Post 
these are some basic functions.

first the header

Code:
typedef struct{
   byte i2cMessageSize;
   byte i2cDeviceAddress;
   byte i2cWriteMessage;
   } i2cBlock;

i2cBlock PCF8574A_I2C;
byte PCF8574AwriteMessage = 0;
tSensors PCF8574Aport;

void setupPCF8574A(tSensors setPort)
{
   PCF8574Aport = setPort;
   SensorType[PCF8574Aport] = sensorI2CCustomFast;
   PCF8574A_I2C.i2cMessageSize=1;
   PCF8574A_I2C.i2cDeviceAddress=0x70;
   PCF8574A_I2C.i2cWriteMessage=0xFF;
}

void writePCF8574A(byte mess)
{
   PCF8574A_I2C.i2cMessageSize=1;
   PCF8574A_I2C.i2cDeviceAddress=0x70;
   PCF8574A_I2C.i2cWriteMessage=mess;
   PCF8574AwriteMessage = mess;

   if (nI2CStatus[PCF8574Aport] == NO_ERR)
       sendI2CMsg(S1,PCF8574A_I2C.i2cMessageSize,1);

}

int readPCF8574A(byte ioMask)
{
   byte value[1];
   PCF8574A_I2C.i2cWriteMessage=0xFF;
   PCF8574A_I2C.i2cWriteMessage=PCF8574AwriteMessage|ioMask;

   if (nI2CStatus[PCF8574Aport] == NO_ERR)
       sendI2CMsg(PCF8574Aport,PCF8574A_I2C.i2cMessageSize,1);
   wait1Msec(20);

   if (nI2CStatus[PCF8574Aport] == NO_ERR)
      readI2CReply(PCF8574Aport, value[0],1);

   return (int)value[0];
}




then a test program

Code:
#include "PCF8574A.h"

task main
{
   int input,cnt=0;
   setupPCF8574A(S1);

   while(true)
   {
      input = readPCF8574A(0xFF);
      nxtDisplayTextLine(2,"%d",input&0x00FF);
      nxtDisplayTextLine(3,"%d",cnt++);

      wait10Msec(1);
   }
}



to read an input the PCF8574A pins must first be set high. The input will drive them low.
The read function does this using a mask. So if you just want to read the first four pins, you would call var = readPCF8574A(0x0F) etc.


if you want to use the PCF8574A's outputs use the writePCF8574A function. The bits in the byte message corrispnd to the io pins on the PCF8574A

It's actually really simple.

As I said in my previous post, the addressing needs to be set on the board. Pulling all the adress pins(pads) low will give you the defualt address of Ox70.


Wed Jun 04, 2008 12:08 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3164
Location: Rotterdam, The Netherlands
Post 
Hey thanks for that! I will be sure to play with it once the I2C bugs have been ironed out of the Betas.

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 Jun 04, 2008 12:33 am
Profile WWW
Expert

Joined: Sun Sep 09, 2007 10:12 am
Posts: 116
Post 
thanks squiggy, thanks all

I will now test it with the 1.38B1... and i hope that it works...

Any other sugestion?

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


Tue Jun 10, 2008 4:24 am
Profile
Rookie

Joined: Fri Apr 20, 2007 3:22 am
Posts: 36
Post 
if it doesn't work let us know.

I haven't down loaded the beta, so I can can't test it, but the code is good with the current release.


Thu Jun 12, 2008 2:36 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3164
Location: Rotterdam, The Netherlands
Post 
squiggy wrote:
if it doesn't work let us know.

I haven't down loaded the beta, so I can can't test it, but the code is good with the current release.

Hey there,

I tried it but it is not working. I am not sure if this is because I am not understanding the addressing pads or what? I didn't do anything with them, left all the little pads, A0-A2 alone. What address would it be using then?

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 Jun 18, 2008 3:09 pm
Profile WWW
Expert

Joined: Sun Sep 09, 2007 10:12 am
Posts: 116
Post 
Don't work also here...

i connected a0 to a2 on ground (000)

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


Wed Jun 18, 2008 3:36 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3164
Location: Rotterdam, The Netherlands
Post 
OK, I got it working without shorting any of the pads. I was trying to use write() but that didn't work. Probably because I wasn't quite sure what I was doing yet. Anyway, I hooked up a microswitch to a breadboard and got that working with the read program. Hurray!

Thanks for the program :)

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 Jun 18, 2008 3:39 pm
Profile WWW
Expert

Joined: Sun Sep 09, 2007 10:12 am
Posts: 116
Post 
nothing working here... and example of assembly and code?

Just testing

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


Wed Jun 18, 2008 5:27 pm
Profile
Rookie

Joined: Fri Apr 20, 2007 3:22 am
Posts: 36
Post 
the pads set the address.

They must either be dropped low, connected to ground, or pulled high, connected to 5volts power.

I would suggest grounding them.

They are the three sets of three pads on the back of the circut board near the jack connector dingus.

The pad nearest the edge is ground, middle is the pin, and the inner most is 5 volts.

Just use a little solder to jump the jap between the ground and pin pad.

That will give you an address of 0x70

I can post a picture if that doesn't make sense.


Wed Jun 18, 2008 6:52 pm
Profile
Rookie

Joined: Fri Apr 20, 2007 3:22 am
Posts: 36
Post 
Actualy, if someone's not using the mind sensors boards little me explain a little more.

Pins A0-A2 are the addressing pins.

The base address of the the PCF8574A is 0x70. The PCF8574 is different, you'd have to look at it's data sheet to see what it is. Mindsensors data sheet is for the PCF8574 but they give you the PCF8574A. You have to look at the chip to see wich one you have. I spent four days trying to get mine to work before I fugured that out.

Anyway, if all the addressing pins (A0-A2) are connected to ground you get the base address of 0x70. If you connect A0 to 5 volts, it changes the address to 0x72. Connecting A1 to 5 volts changes it to 0x74. A1 and A@ to 5 volts gives you 0x76.

Its just a binary setting. It skips odd numbers because of the way I2C communications are structured. The address is passed in the comand byte and the lowest bit of that byte is the command operation, read or write. Then seven highest bits are the address device address.

What chip do you have, docilio?
Are you using the mindsensors board?


Wed Jun 18, 2008 7:10 pm
Profile
Expert

Joined: Sun Sep 09, 2007 10:12 am
Posts: 116
Post 
Sorry, it seams similar to what i got, a picture would be nice.
I only want to understand how to get info about anything conected on the circuit, with an robotc example

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


Wed Jun 18, 2008 7:22 pm
Profile
Rookie

Joined: Fri Apr 20, 2007 3:22 am
Posts: 36
Post 
Let me ask you again are you using the mindsensors PCF8574?

I just want to make sure. =)

I'll post a picture tonight when I get home


Wed Jun 18, 2008 8:02 pm
Profile
Expert

Joined: Sun Sep 09, 2007 10:12 am
Posts: 116
Post 
that's the one... tomorrow i test it... thanks

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


Wed Jun 18, 2008 8:38 pm
Profile
Rookie

Joined: Fri Apr 20, 2007 3:22 am
Posts: 36
Post 
Here's a picture, hope it's not too large

http://home.comcast.net/~squig/pics/pcf8574-nx.jpg

The sample I posted in this thread should work. There's a header and then a sample program.

Are you trying to output or input?


Wed Jun 18, 2008 11:42 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3164
Location: Rotterdam, The Netherlands
Post 
squiggy wrote:
Here's a picture, hope it's not too large

http://home.comcast.net/~squig/pics/pcf8574-nx.jpg

The sample I posted in this thread should work. There's a header and then a sample program.

Are you trying to output or input?

Thanks for the picture. I noticed that those pins are connected with a very narrow strip already. Do I need to add the solder on top of that or will the default suffice?

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 Jun 19, 2008 12:42 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 39 posts ]  Go to page Previous  1, 2, 3  Next

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:  
cron



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