I2C Communication between NXT and Arduino failure

This is where you talk about the NXJ hardware related topics such as the brick, sensors, LEGO pieces, etc.

Moderators: 99jonathan, roger, imaqine

I2C Communication between NXT and Arduino failure

Postby MaR1oC » Tue Jan 28, 2014 5:09 pm

Hello dudes,

I am currently testing TWI communication between my Arduino and my NXT v2.0. However, I am encountering some problems. I have also set NXT as master and Arduino as slave (REGISTER =1).

Hardware Connections
NXT and Arduino are connected via the sensorport S4 and pins A4,A5,GND and Vin on the Arduino. I have also added two 10kOhm pullup resistors.

Software Part
My Arduino Code:

Code: Select all
#include <Wire.h>
#define REG 1
byte value = 10;
void setup() {
  Wire.begin(REG);
  Wire.onRequest(requestEvent);
}

void requestEvent() {
 while(Wire.available()) {
   Wire.write(value);
   delay(50);
}

void loop() {}


Explaination: When the NXT asks (requests) for a byte, Arduino sends value

My LeJOS Code:

Code: Select all
import lejos.nxt.I2CSensor;
import lejos.nxt.SensorPort;

public class I2CTester {
final static int ADDR = 1;
static I2CSensor s = new I2CSensor(SensorPort.S4);
   
   public static void main(String[] argv) {
            while(true) {
               gotcha();
            }

   
   public static void gotcha()  {
      byte[] response = new byte[8];   
      int v =s.getData(ADDR, response, 1);
      System.out.println(v);      
   }
}


My NXT prints negative value error (-1).What's happening?

Thanks in advance
Robotic Platforms currently being used:
1. LEGO Mindstorms NXT v.2.0
2. Arduino Uno
Projects currently under development:
http://code.google.com/p/lego-mindstorms-3d-printing-machine/

OS: Linux (Ubuntu, Arch, Sabayon) | IDE: Eclipse (+LeJOS Plug-in)
Java: Amateur User :D :D
User avatar
MaR1oC
New User
 
Posts: 20
Joined: Thu Jul 05, 2012 8:14 am
Location: Athens, Greece

Re: I2C Communication between NXT and Arduino failure

Postby gloomyandy » Tue Jan 28, 2014 7:30 pm

10K is way to low for the pullups for the NXT, they need to be more like 80K search the web and this forum for details of other people doing what you are trying to do.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4183
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: I2C Communication between NXT and Arduino failure

Postby jshao » Sat Mar 15, 2014 10:20 am

MaR1oC wrote:Hello dudes,

I am currently testing TWI communication between my Arduino and my NXT v2.0. However, I am encountering some problems. I have also set NXT as master and Arduino as slave (REGISTER =1).

Hardware Connections
NXT and Arduino are connected via the sensorport S4 and pins A4,A5,GND and Vin on the Arduino. I have also added two 10kOhm pullup resistors.

Software Part
My Arduino Code:

Code: Select all
#include <Wire.h>
#define REG 1
byte value = 10;
void setup() {
  Wire.begin(REG);
  Wire.onRequest(requestEvent);
}

void requestEvent() {
 while(Wire.available()) {
   Wire.write(value);
   delay(50);
}

void loop() {}


Explaination: When the NXT asks (requests) for a byte, Arduino sends value

My LeJOS Code:

Code: Select all
import lejos.nxt.I2CSensor;
import lejos.nxt.SensorPort;

public class I2CTester {
final static int ADDR = 1;
static I2CSensor s = new I2CSensor(SensorPort.S4);
   
   public static void main(String[] argv) {
            while(true) {
               gotcha();
            }

   
   public static void gotcha()  {
      byte[] response = new byte[8];   
      int v =s.getData(ADDR, response, 1);
      System.out.println(v);      
   }
}


My NXT prints negative value error (-1).What's happening?

Thanks in advance


Are u able to make it work? Could you share some experience like how to connect them, I have one Arduino Mega board.
jshao
New User
 
Posts: 6
Joined: Tue Feb 18, 2014 1:44 pm


Return to NXJ Hardware

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff