Need help with PCF8574
Need help with PCF8574
Hi everyone,
I'm trying to control 8 leds using a PCF8574 according to the scheme as seen in the attachment (from the book NXT Extreme).
The problem is that I can't control the leds. If I connect the PCF to the NXT only 4 leds are turned on continously (the leds connected to P0, P1, P2 and P3) and the other 4 leds are all off. I tried multiple software programs like NXT-G or NXC but I can't switch any leds on or off. It also doesn't matter which port I use (sensor port 1 to 4 or motor port A, B, or C) while I only programmed to control the PCF by sensor port 1.
Can anyone tell me what I'm doing wrong?
Greetings,
Brandts
I'm trying to control 8 leds using a PCF8574 according to the scheme as seen in the attachment (from the book NXT Extreme).
The problem is that I can't control the leds. If I connect the PCF to the NXT only 4 leds are turned on continously (the leds connected to P0, P1, P2 and P3) and the other 4 leds are all off. I tried multiple software programs like NXT-G or NXC but I can't switch any leds on or off. It also doesn't matter which port I use (sensor port 1 to 4 or motor port A, B, or C) while I only programmed to control the PCF by sensor port 1.
Can anyone tell me what I'm doing wrong?
Greetings,
Brandts
Re: Need help with PCF8574
Are you wiring it up using discrete parts or using a ready-made board?
If using a commercial board, have you set the jumpers to enable the pull-up resistors?
Have you used the nbc program in the book?
If using a commercial board, have you set the jumpers to enable the pull-up resistors?
Have you used the nbc program in the book?
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
Re: Need help with PCF8574
I use discrete parts. I bought a PCF8574AP fabricated by NXP: http://www.nxp.com/documents/data_sheet/PCF8574.pdf and got some leds, wires and resistors from my work. I soldered it all together on a standard solder board (similar like: http://itp.nyu.edu/physcomp/Tutorials/S ... APerfBoard).
I have no idea what you mean setting the jumpers to enable. Could you explain that a bit further?
I tried the program from the book (which I believe is NXC instead of NBC) and also tried the NXT-G software which I downloaded from www.mindsensors.com
I have no idea what you mean setting the jumpers to enable. Could you explain that a bit further?
I tried the program from the book (which I believe is NXC instead of NBC) and also tried the NXT-G software which I downloaded from www.mindsensors.com
Re: Need help with PCF8574
Mini boards like this http://www.futurlec.com/Mini_PCF8574.shtml have jumpers which enable you to add in various resistors but that is not relevant in your case.
The program in the (excellent) book is definitely nbc (see below) - if you used that did you compile it with the Bricx Command Center?
The program in the (excellent) book is definitely nbc (see below) - if you used that did you compile it with the Bricx Command Center?
Code: Select all
#include "NXTDefs.h"
#define I2CPort IN_1
#define I2CAddress 0x40
// 0x40 for PCF8574 or 0x70 for PCF8574A
dseg segment
lswArgs TCommLSWrite // Write structure
lscsArgs TCommLSCheckStatus // Status structure
Value byte
dseg ends
thread main
// Initialize variables
mov lswArgs.Port, I2CPort
mov lscsArgs.Port, I2CPort
// Initialize input port to I2C
SetSensorType(I2CPort,IN_TYPE_LOWSPEED)
SetSensorMode(I2CPort,IN_MODE_RAW)
ResetSensor(I2CPort)
Loop: // Top of loop
// Build buffer and write port
arrbuild lswArgs.Buffer, I2CAddress, Value
set lswArgs.ReturnLen, 0 // Read back 0 bytes
syscall CommLSWrite, lswArgs
Wait: // Wait till done
syscall CommLSCheckStatus, lscsArgs
brtst GT, Wait, lscsArgs.Result
// Increment
add Value, Value, 1
// Start over
jmp Loop
endt
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
Re: Need help with PCF8574
The book I used is "Extreme NXT: Extending the LEGO MINDSTORMS NXT to the Next Level".
The program I used looks like this:
The compiler I use is indeed Bricx Command Center. I believe I've read somewhere on a forum that I had to be sure to use firmware 1.05 so I tried the program on 1.05 and also on the latest firmware but nothing changes. I also tried both adresses (0x40 and 0x70) but also that won't help.
The program I used looks like this:
Code: Select all
#define I2Cport S1 // Port number
#define I2CAddr8574 0x70 // I2C address x040 8574 or 0x70 for 8574A
byte WriteBuf[]={I2CAddr8574,0x00}; // write buffer is addr and data
task main() {
int nbytes;
SetSensorLowspeed (I2Cport); // Configure I2C port
while (true) {
WriteBuf[1]++; // update data byte
I2CWrite(I2Cport, 0, WriteBuf); // send buffer
while(I2CStatus(I2Cport, nbytes)==STAT_COMM_PENDING); // wait
}
}
Re: Need help with PCF8574
I'm dry... what bothers me most is the 4 LEDs continuously on. Are you sure your IC is not fried?
As for the NBC/NXC discussion, first edition of Extreme NXTused NBC as NXC was not yet available. But sample code were rewritten into (more palatable) NXC for the second edition.
As for the NBC/NXC discussion, first edition of Extreme NXTused NBC as NXC was not yet available. But sample code were rewritten into (more palatable) NXC for the second edition.
Philo
Re: Need help with PCF8574
In not sure that the IC is fried. Is it possible that I damaged something inside the chip with soldering the contacts? Is there a way to measure this with a multimeter?
I have the second edition of Extreme NXT so that indeed explains why the sample code is different.
I have the second edition of Extreme NXT so that indeed explains why the sample code is different.
Re: Need help with PCF8574
That can happen, but it's quite rare. Stupid question: are you sure the IC is not upside down?brandts wrote:In not sure that the IC is fried. Is it possible that I damaged something inside the chip with soldering the contacts?
Not really...Is there a way to measure this with a multimeter?
Philo
Re: Need help with PCF8574
Have you tried changing the port address in case you have bought an 'A' model chip?
"#define I2CAddr8574 0x70 // I2C address x040 8574 or 0x70 for 8574A"
If you tried it in a motor port it is possible that the extra voltage available (9v cf ~ 4.5v) has damaged your chip since it operates between 2.5 & 6v.
"#define I2CAddr8574 0x70 // I2C address x040 8574 or 0x70 for 8574A"
If you tried it in a motor port it is possible that the extra voltage available (9v cf ~ 4.5v) has damaged your chip since it operates between 2.5 & 6v.
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Need help with PCF8574
I used to use the PCF8574 for all sorts of things. Here is an old program of mine (modified to not require my library). I know it works, as I just tested it.
At the top, set the port and address.
Code: Select all
#define Port S1
#define Address 0x40
void WritePins(byte port, byte addr, byte input){
byte I2CMsg[];
//byte Command = ~input; //with enhanced FW
byte Command = input*(-1)+255; //with standard FW
byte nByteReady = 0;
int loop;
ArrayBuild(I2CMsg,addr,Command);
while (loop == STAT_COMM_PENDING) {
loop = I2CStatus(port, nByteReady);
}
I2CWrite(port, 1, I2CMsg);
while (loop == STAT_COMM_PENDING) {
loop = I2CStatus(port, nByteReady);
}
}
int LEDtoDrive;
bool LR;
task main()
{
SetSensorLowspeed(Port);
LR=1;
LEDtoDrive=1;
while (true)
{
WritePins(Port, Address, LEDtoDrive);
if (LR==1)
{
LEDtoDrive=LEDtoDrive*2;
if (LEDtoDrive>128)
{
LEDtoDrive=128;
LR=0;
}
}
if (LR==0)
{
LEDtoDrive=LEDtoDrive/2;
if (LEDtoDrive==1)
{
LR=1;
}
}
ClearScreen();
NumOut(0,LCD_LINE1,LEDtoDrive);
Wait (30); //Slow down a little, but must be at least 7ms
}
}
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Who is online
Users browsing this forum: Bing [Bot], Semrush [Bot] and 0 guests