Page 1 of 2
NXT : I2C communication with PCB
Posted: 07 Dec 2010, 15:57
by angusfr
Hi,
i m trying to create a nxc file to communicate with a PCB with a PCF8574.
On my PCB i have some buttons and leds. I want to display an information on the NXT screen and light a led when i press a button :
My problem is that i can't see when a button is pressed, i try to use :
Code: Select all
if(ReadBuf[0]==0xF2) // F2 is the adress of a button
I don't understand how to find the right adress of my buttons and leds tu use them.
(I m not the one who created this PCB but i try to use it).
Thanks for help
I didn't pratice english for a long time :/ Sorry
Re: NXT : I2C communication with PCB
Posted: 07 Dec 2010, 21:45
by mattallen37
For one thing, if you copied the circuit identically as the schematic shows, you WILL have problems.
SDA connects to pin 6 of the NXT (blue wire). SCL connects to pin 5 of the NXT (yellow wire). Ground connects to either or both, pins 2 and 3 (black and red wires).
To read an IO pin, you must first write it high, and then have the switch pull it LOW. the 8574 has internal pullups, so when you "write it high" you really just release the pin, and the internal pullup does the rest. If you have a switch connected as I said, it will be able to pull the pin low.
Edit: Also instead of using that SPDT switch, you should just use another pushbutton.
I don't know if you happen to have the book "Extreme NXT" but it has the exact schematic I think you want. If I knew it was okay with the right people, I would just post it. Since I don't know, I will try to just draw my own schematic sometime.
Re: NXT : I2C communication with PCB
Posted: 07 Dec 2010, 23:25
by mattallen37
Here is a quick MS paint drawing of the schematic you probably want.
[The extension rar has been deactivated and can no longer be displayed.]
The NXT wires connect as follows:
2-3 (Black and red) Gnd
4 (Green) Vcc
5 (Yellow) SCL
6 (Blue) SDA
Re: NXT : I2C communication with PCB
Posted: 08 Dec 2010, 00:52
by nxtreme
I heartily suggest picking up a copy of the Extreme NXT book that Matt mentioned if your at all interested in making your own sensors. The second edition can be found on
Amazon.com for $9 (-EDIT- Actually, $8) US dollars shipped. Get it, you'll never look back. I did, I never have
.
Re: NXT : I2C communication with PCB
Posted: 08 Dec 2010, 13:00
by philoo
You may be interested by this
Mindsensors kit
If I knew it was okay with the right people, I would just post it. Since I don't know, I will try to just draw my own schematic sometime.
I personnally wouldn't mind, but perhaps the publisher...???
Re: NXT : I2C communication with PCB
Posted: 10 Dec 2010, 10:55
by angusfr
My PCB looks like this >
http://lh4.ggpht.com/_0K31UaBLvno/TQH5F ... 0titre.jpg
Someone give me 10 cards like this one that's why i would like to use it without exchange components.
You can see that it respect the drawing of matt.
I think the pcb is ok, i would had some tips about my nxc program.
Code: Select all
#define I2Cport S4
#define I2CAddr8574 0x40
int RdCnt=5;
byte WriteBuf[]={I2CAddr8574, 0xFF};
byte ReadBuf[]={I2CAddr8574};
task main(){
SetSensorLowspeed(I2Cport);
I2CBytes(I2Cport, WriteBuf, RdCnt, ReadBuf);
while(true){
if(ReadBuf[0]==0xF1) // read to know if the first button is pressed
{
ResetScreen();
TextOut(30, LCD_LINE3,"Button 1"); // Show wich button is pressed
Wait(150);
}
if(ReadBuf[0]==0xF2)
{
ResetScreen();
TextOut(30, LCD_LINE3,"Button 2");
Wait(150);
}
etc ...
}
The problem is that i tried to use address from F1 to FF but i never get any answer from pcf :/
Re: NXT : I2C communication with PCB
Posted: 10 Dec 2010, 12:21
by philoo
Are you sure you have a PCF8574? PCF8574A has a different base address (0x70 instead of 0x40)
Re: NXT : I2C communication with PCB
Posted: 11 Dec 2010, 04:02
by sparramc
Hi Angus,
This article of mine may be of some help:
NXC Library for ‘RCX Touch Sensor Mux’. My ‘
RCX Touch Sensor Mux’ uses a PCF8574 with address 0x40.
Re: NXT : I2C communication with PCB
Posted: 14 Dec 2010, 10:43
by angusfr
Woot \o/
Thanks to sparramc, i used code from ‘
RCX Touch Sensor Mux’ and it work !
Now i'm gonna try to give order to my pcf8574 to light my leds. And then i'll try to use my switch to change adress =)
See you
Re: NXT : I2C communication with PCB
Posted: 14 Dec 2010, 16:56
by angusfr
Hi there,
i m experiencing some diffuculty to optimize my program.
After i have read which button is pressed i ligh a led :
Code: Select all
switch(ReadBuf[0]){
case 8 : WriteBuf[1] = 0xf7;
break;
case 4 : WriteBuf[1] = 0xfb;
break;
case 2 : WriteBuf[1] = 0xfd;
break;
case 1 : WriteBuf[1] = 0xfe;
break;
default:
break;
}
I2CBytes(I2Cport, WriteBuf, RdCnt, ReadBuf);
This program work has i expected but i would like to be able to push 2 or 3 buttons at the same time. I don't want to create a switch with 16 case >_> (4 buttons) that's why i wanna to try this >
Code: Select all
WriteBuf[1] = 0xf+(~ReadBuf[0]) ;
I2CBytes(I2Cport, WriteBuf, RdCnt, ReadBuf);
Msg:" Error: Enhanced firmware is required for this operation"
The aim is to convert the button adress, exemple : 0001 linked to the led 1110 ( 0 level to light)
This could work with any combination =)