NXC: I²C drivers for Hitechnic Tetrix motor muxer ?

Discussion specific to the intelligent brick, sensors, motors, and more.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: I²C Tetrix drivers (motor controller)?

Post by HaWe »

ok, I must have misunderstood your "I wish I had one of each of these controllers so I could test this code", because the code you posted unfortunately currently doesn't work.
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: NXC: I²C Tetrix drivers (motor controller)?

Post by mightor »

I would've done some testing if I had had them right then and there, but I don't want to commit to anything else at the moment.

- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: I²C Tetrix drivers (motor controller)?

Post by HaWe »

I meanwhile tested a different Hitechnic motor controller, and it's the same issue:

The motor start/stop commands are often not executed correctly.

So either it's a hardware (firmware?) failure of both Hitechnic motor muxers or it's a general NXC I2C driver problem .

I can't recommend to buy those Tetrix sets to anyone if it should be used with NXC unless Hitechnic will provide a stabile NXc driver and a stabile firmware!
(Nevertheless I'm curious how it works with NXT-G or RobotC !)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC: I²C drivers for Hitechnic Tetrix motor muxer ?

Post by mattallen37 »

It sounds like John will be working on the drivers before real long, but I have another suggestion of something you could try. I just made this as a lib file to interface with a PICAXE, but you should be able to use it with almost any I2C device, including your controllers.

Code: Select all

//Name this "20X2 lib.nxc"
void ReadPicaxe(byte port, byte addr, byte reg, byte cnt, byte& outbuf[])
{
  byte cmdbuf[];  // register number holder
	int             loop;
	byte            nByteReady = 0;

  ArrayBuild(cmdbuf, addr, reg);

  loop = STAT_COMM_PENDING;              //Wait until bus is free
  while (loop == STAT_COMM_PENDING ){    //        ''
    loop = I2CStatus(port, nByteReady);  //        ''
  }                                      //        ''

  I2CBytes(port, cmdbuf, cnt, outbuf)    //Read the registers
}

void WritePicaxe(byte port, byte addr, byte reg, byte data[])
{
  byte result = -1;            // default: error value
  byte cmdbuf[];               // register number holder
	int loop, n, nByteReady;

  ArrayBuild(cmdbuf, addr, reg, data);

  loop = STAT_COMM_PENDING;              //Wait until bus is free
  while (loop == STAT_COMM_PENDING ){    //        ''
    loop = I2CStatus(port, nByteReady);  //        ''
  }                                      //        ''
  
  n = I2CWrite(port, 0, cmdbuf);        //When the I2C bus is ready, send the message you built
  while (I2CStatus(port, nByteReady) ==  STAT_COMM_PENDING); //Wait until bus is free
}
To use these functions, I use the following lines.

Code: Select all

ReadPicaxe(Port, Address, Register, number of bytes to read, returned array);
WritePicaxe(Port, Address, Register, Data array);
Here is an example that writes random numbers to 8 registers, and then reads the numbers back.

Code: Select all

#include "20X2 lib.nxc"

#define PICAXEPort S1
#define PICAXEaddr 0x30

byte Result[];
byte Data[8];
byte i;

task main(){
  SetSensorLowspeed(PICAXEPort);
  while(true){
    i=0;
    repeat(8){
      Data[i]=Data[Random(8)]*(Random(7)+1)+1;
      i++;
    }

    WritePicaxe(PICAXEPort, PICAXEaddr, 0x0F, Data);
    
    ReadPicaxe(PICAXEPort, PICAXEaddr, 0x0F, 8, Result);

    i=0;
    repeat(8){
      TextOut(0,(56-(i*8)), "   ");
      NumOut(0,(56-(i*8)), Result[i]);
      i++;
    }

    Wait(250);
  }
}
If any of this works for you, you should probably change the names, as it is based on PICAXE terms.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: I²C drivers for Hitechnic Tetrix motor muxer ?

Post by HaWe »

no, thanks, picaxe is no choice.
I have a I2C motor controller (for Tetrix by Hightechnic, very expensive, but doesn't work with regular NXC code (by Xander)) and HT gives no support).
I will have to wait for John's implementation.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC: I²C drivers for Hitechnic Tetrix motor muxer ?

Post by mattallen37 »

What I meant, was that the code I wrote was originally for NXT-PICAXE I2C communication, thus the terms.
I know, and I think it might be worth a shot to try these functions.
I just thought, that you could try it in the meantime if you wanted, and if you had time.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: I²C drivers for Hitechnic Tetrix motor muxer ?

Post by HaWe »

aah, thx, I see now.
But Xander's code was quite logic and clear, I have no idea what could be improved in any aspects.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC: I²C drivers for Hitechnic Tetrix motor muxer ?

Post by mattallen37 »

Well, quite honestly, I have no idea of any differences, but I didn't base mine off of his by any means, so perhaps mine takes a slightly different approach. Xander's code (in general), is likely better than mine (although in this case, his is defunct), but if you want, you could try my functions.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: NXC: I²C drivers for Hitechnic Tetrix motor muxer ? Update

Post by h-g-t »

Out of in interest, I had a look through the Hitechnic site to see what this Tetrix motor muxer was like and whether it would be any use in my project. I could not find any trace of it at all - the only reference to it appears in the Lego Education site. Perhaps this was withdrawn because of problems (although the Lego site are still accepting orders).

That site refers to this and other products being supplied from TETRIX-FRC, but I cannot find this in a Google search either! Perhaps there are parallel universes overlapping at this point and your code has to allow for quantum effects, etc?

Update - TETRIX FRC are a Tetrix modelling group who seem to get discounts from Lego.

Found a video of someone using this device - http://www.youtube.com/watch?v=r7KRbwwomUc and he has a YouTube channel here - http://www.youtube.com/user/imrobotics. The video appears to be using a custom NXT-G block, it's hard to tell. Might be worth sending an e-mail to see if he can give details of what code he was using.

New update - Googled Hitechnic motor lego and got quite a few hits mentioning the subject. Do not have time to go through them or even list them all but the first few which seem to be relevant are :-

http://code.google.com/p/nxt-python/issues/detail?id=18
http://www.robotc.net/forums/viewtopic.php?f=33&t=1160
http://robotc.net/forums/viewtopic.php? ... 38&start=0
http://community.legoeducation.us/media/p/5633.aspx
http://www.tetrixrobotics.com/Building_ ... .aspx?ap=2

Hope this helps.
Last edited by h-g-t on 08 Feb 2011, 10:38, edited 3 times in total.
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.
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: NXC: I²C drivers for Hitechnic Tetrix motor muxer ?

Post by mightor »

I am hoping to get access to some of this hardware soon but I wouldn't hold your breath (asphyxiation is a horrible way to go). When I do, however, I will write some drivers for it, both for ROBOTC and NXC.

The reason they are not listed on the HiTechnic website is because they are sensors that are specifically made for Lego Education and not resold through HiTechnic at all. It was explained to me that the sensors are shipped straight from manufacturing to Lego Education and doesn't even pass through HiTechnic's offices. I found this out when I asked them if they had any of them to send to me for writing drivers :)

- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests