1. Summary
  2. Files
  3. Support
  4. Report Spam
  5. Create account
  6. Log in

NXT : I2C communication with PCB

Discussion specific to the intelligent brick, sensors, motors, and more.

NXT : I2C communication with PCB

Postby angusfr » 07 Dec 2010, 15:57

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 :

Image

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 :oops:
angusfr
 
Posts: 5
Joined: 07 Dec 2010, 15:39

Re: NXT : I2C communication with PCB

Postby mattallen37 » 07 Dec 2010, 21:45

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.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
User avatar
mattallen37
 
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA

Re: NXT : I2C communication with PCB

Postby mattallen37 » 07 Dec 2010, 23:25

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
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
User avatar
mattallen37
 
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA

Re: NXT : I2C communication with PCB

Postby nxtreme » 08 Dec 2010, 00:52

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 :).
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.
User avatar
nxtreme
 
Posts: 246
Joined: 29 Sep 2010, 03:53
Location: 192.168.1.2

Re: NXT : I2C communication with PCB

Postby philoo » 08 Dec 2010, 13:00

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...???
Philo
User avatar
philoo
 
Posts: 76
Joined: 29 Sep 2010, 09:04
Location: Paris, France

Re: NXT : I2C communication with PCB

Postby angusfr » 10 Dec 2010, 10:55

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 :/
angusfr
 
Posts: 5
Joined: 07 Dec 2010, 15:39

Re: NXT : I2C communication with PCB

Postby philoo » 10 Dec 2010, 12:21

Are you sure you have a PCF8574? PCF8574A has a different base address (0x70 instead of 0x40)
Philo
User avatar
philoo
 
Posts: 76
Joined: 29 Sep 2010, 09:04
Location: Paris, France

Re: NXT : I2C communication with PCB

Postby sparramc » 11 Dec 2010, 04:02

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.
regards

Ray McNamara

www.rjmcnamara.com

'The Universe Consists of 1% Hydrogen, & the Rest is Ignorance!'
User avatar
sparramc
 
Posts: 83
Joined: 29 Sep 2010, 08:44
Location: Launceston, Tasmania, Australia

Re: NXT : I2C communication with PCB

Postby angusfr » 14 Dec 2010, 10:43

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 ;)
angusfr
 
Posts: 5
Joined: 07 Dec 2010, 15:39

Re: NXT : I2C communication with PCB

Postby angusfr » 14 Dec 2010, 16:56

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 =)
angusfr
 
Posts: 5
Joined: 07 Dec 2010, 15:39

Next

Return to Mindstorms Hardware

Who is online

Users browsing this forum: No registered users and 0 guests