Keyboard, PICAXE, and Lego NXT

mattallen37

New Member
I want to make a keyboard interface to a Lego NXT, using a PICAXE 20X2.

I have made working I2C code for both the 20X2, and the NXT, so they can "talk" (NXT is the master).

I have also made a program for the 20X2 that successfully gets key strokes (I know it is successful, as I have it send the data over serial to a computer terminal program).

The problem, is that the PICAXE won't do both, I2C and KB commands. It works fine for either one, but totally fails as an I2C slave when using the keyboard.

I attempted to "fix" the problem by using a second 20X2 to read the serial output from the first, and write it into a register (scratchpad) for the NXT to read using I2C. Again, no go. The PICAXE doesn't work at all as an I2C slave (it's like it isn't even physically connected).

I know that the keyboard and two 20X2's were drawing a lot of power (seemed to be too much for a 7805), so I diverted to using the 7805 for the PICAXE's, and a 25 amp (yes it is regulated 5V) supply for the keyboard (I know it is way overkill, but that's all I have at the moment). Now I know for SURE lack of power isn't an issue.

Why does the 20X2 totally fail as an I2C slave whenever I use the KBIN or SERIN commands, and seemingly only then? I2C works fine when I use the SEROUT command.
 

BCJKiwi

Senior Member
Most likely a timing issue and/or a conflicting command.

e.g. kbin ceases all other processing while waiting for the input so i2c will stop.

Check the manual carefully for the commands being used and the section at the end of manual 2 regarding conflicting commands and commands using the internal timer(s) for conflicts.
 

hippy

Ex-Staff (retired)
Drawing 1 Amp, which is the usual limit for a 7805, seems excessive for two 20X2 and a keyboard and I recommend investigating that.

The problem is most likely in a conflict of commands when trying to do keyboard reading and act as an I2C Slave; while the PICAXE is waiting for key presses it cannot be responding to I2C requests from the master. Likewise if your dual 20X2 and serial link is using SERIN.

A dual solution, blocking on KBIN and sending serial data out, with the other 20X2 reading that serial with background receive of high-speed serial (HSERSETUP) and handling I2C would be the best approach.
 

Andrew Cowan

Senior Member
The last project I had that used much more current than I expected turned out that the problem was different ground potentials I had tied together - this might be worth looking at.

With a resistor connecting the two circuit's grounds, is there a voltage across it?

A
 

mattallen37

New Member
I will look into conflicting commands. According to one of the manuals (I forget where), I2C slave operations are not affected by the program running, and vice versa, but I will look into it.

I haven't confirmed it yet, but I suspect that the 7805 is defective, so I will look into changing the power supplies.

The master controller (Lego NXT) has one IO as well as the I2C bus, so I could have the PICAXE drive that high (or low) to signal the NXT to read the register.

I could also digitally isolate the two, using a PCF8574, and having the 20X2 drive the pins, for the NXT to read.

Thanks all for the replies.
 

hippy

Ex-Staff (retired)
I2C Slave can be affected by other commands, particularly blocking commands.

The PICAXE can receive I2C bus commands no matter what it is doing, but the firmware needs to respond to those to store or return data. If the PICAXE is doing something else it must give its full attention to then it cannot respond.
 
Top