2
$\begingroup$

Here is the background. I am trying to write a service for the HiTechnic prototype board.

Using the Appendix 2 from the blue tooth developers kit from Lego's site I am able to understand what is going on with this service I am trying to build however the response I get is always 221 = 0xDD = "Communication Bus Error" or 32 = 0x20 = "Pending communication transaction in progress".

I figured out that the HiTechnic prototype board is using i2c address 0x08 so I modified the brick code to use that address instead of the standard 0x02. It goes out and configures the device, I get a response and then it does an LSWrite which seems OK then I get a get an error when it does the LSGetStatus.

I know this thing works - I can bit bang it all day long with an Arduino but I only did that to test it out - see this link

I am not sure what else to try. Here is how I am setting it up in the connect to brick handler.

 pxbrick.Registration registration = new pxbrick.Registration(
                new LegoNxtConnection(LegoNxtPort.Sensor1),
                LegoDeviceType.DigitalSensor,
                Contract.DeviceModel,
                Contract.Identifier,
                ServiceInfo.Service,
                _state.Name);
        Debugger.Break();
        // Reserve the port
        LogInfo("ConnectToBrickHandler");
        yield return Arbiter.Choice(_legoBrickPort.ReserveDevicePort(registration),
            delegate(pxbrick.AttachResponse reserveResponse)
            {
                Debugger.Break();
                if (reserveResponse.DeviceModel == registration.DeviceModel)
                {
                    registration.Connection = reserveResponse.Connection;
                }
            },
            delegate(Fault f)
            {
                Debugger.Break();
                fault = f;
                LogError("#### Failed to reserve port");
                LogError(fault);
                registration.Connection.Port = LegoNxtPort.NotConnected;
            });

I have also tried setting AnyPort as well so that it will hit the TestPortForI2CSensorHandler that just does what I explained before - it seems to set the mode fine and then gets an error when it tries to read the device information.

Here is the data. - this first part is the set input more - both the message and response - You can see it is totally fine.

Send command data.

0 
5
0 
11 
0 
receive command data. (_commState.SerialPort.Read(receiveData, 0, packetSize);) 
2 
5 
0

Then it does an LSWrite - everything still seems fine... You can see I have modified the NxtComm code to use 0x08 instead of 0x02 which it would normally use, then the last byte is also 0x08 which is the starting address of the manufacturer. It's asking for 16 bytes which would be the manufacturer and sensor type. like I said - I know that works I can print that info out using the Arduino.

128 
15 
0 
2 
16 
8 // i2c address
8 //I assume this is what address I want to read from? 
Got response: True Error code Success [02/25/2013 02:20:31]
-- SendCommandHandler (NxtComm) [02/25/2013 02:20:31]
--- RequestResponseHandler (NxtComm) [02/25/2013 02:20:31]
--- CommSendImmediateHandler (NxtComm) [02/25/2013 02:20:31]
Send command data.

Then it tries to get the status

0 
14 
0 

Here is the response...

 2 
14 
32 
 0 

It's either 32 or 221. It's making me nuts...

If anyone has anything that might help me out I would so much appreciate it. At this point I am running out of ideas. I can see what is going on, I can understand the entire transaction but can't seem to figure out why it just errors out like that.

Also - just for grins I tried 0x10 which is what they tell you on the HiTechnic website. That gets a response of 2,14,0,0 from the NXT brick - that would indicate there is no data but as I pointed out I can get data using the Arduino. How could I have two different I2C device addresses?

$\endgroup$
0
$\begingroup$

Triumphant

Check this out. Under normal circumstances you would configure your sensor by giving it a port. It would look like the following.

pxbrick.Registration registration = new pxbrick.Registration(new LegoNxtConnection((LegoNxtPort)_state.SensorPort), 

Well, inside of the NxtBrick code there is a method called TestPortForI2CSensorHandler and reading the code you can see that if you pass in “AnySensorPort” it will try all four ports. Genuis that I am thought! Oh great. I will just let the already created code do the work for me, after all, at that point all I wanted to do was see of the thing worked. Well here is the problem. When you do that it creates a type of I2CReadSensorType inside of the ctor it executes this line of code.

ExpectedI2CResponseSize = 16;

That doesn’t seem to work. OK - not seems, it doesn’t work. It won’t work for the sonsor sensor or any other digital sensor. I assume because it’s 0 based, so 16 is actually 17 bytes? I am guessing. At anyrate, I changed it to 15 and low and behold it works. I even went back and tried it with the LEGO sonar sensor. It works to a point - that is to say it actually gets data back but it seems like the sensor type data (which is “SuperPr” on the prototype board) is 0xFF for all the bytes. The name manufacturer is indeed set to LEGO though so I know it read data. if you change the ExpectedI2CResponseSize back to 16 it fails.

The other issue I had is that the NxtCommType contains the following.

[DataMember, Description("The default I2C Bus Address of the Ultrasonic or other I2C Sensor.")]
public const byte DefaultI2CBusAddress = 0x02;

For my purposes at the moment I am just flipping it to 0x10 for the prototype board (which oddly enough when connected to my Arduino

shows up as 0x08 but that is another story). I need to modify things so I can use sensors that have differing i2c addresses but for now I am thrilled!

I would love to see someone like Trevor Taylor comment on this as to how it ever worked with 16 as the ExpectedI2CResponseSize.

Awesome!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.