DmxSimple and Ps2 libraries

Hello,

In my project, where I want to control a dynamic lighting environment using a ballmouse, I'm running into trouble.
In order to control the light I include DmxSimple: Google Code Archive - Long-term storage for Google Code Project Hosting.
In order to read the mouse I include Ps2: Arduino Playground - Ps2mouse

Somehow these two don't go together. Could someone explain to me why this is and whether I can work around it?

Thank you!

Don

Somehow these two don't go together. Could someone explain to me why this is and whether I can work around it?

Somehow they don't go together, huh?

That doesn't convey ANY information to me. Does using both of them together cause compilation errors? Are there common pin usage expectations? What do you mean about them not going together?

Sorry, you're right.

When using another input system, for example pressure sensors, I can control the lights using dmx.
When using the Ps2mouse code on itself, I can read the values no problem.

But when I initiate both the mouse and the dmx; it compiles but does not print any values from the mouse.
I stripped the code to see where the problem is and this is what is left. The printing of the x and y values of the mouse stops working if I uncomment the bold line:

#include <ps2.h>
#include <DmxSimple.h>
/*
 * an arduino sketch to interface with a ps/2 mouse.
 * Also uses serial protocol to talk back to the host
 * and report what it finds.
 */

PS2 mouse(2, 3);

void dmx_init(){
   DmxSimple.usePin(11);
 DmxSimple.maxChannel(8);
}

/*
 * initialize the mouse. Reset it, and place it into remote
 * mode, so we can get the encoder data on demand.
*/
void mouse_init()
{
  mouse.write(0xff);  // reset
  mouse.read();  // ack byte
  mouse.read();  // blank */
  mouse.read();  // blank */
  mouse.write(0xf0);  // remote mode
  mouse.read();  // ack
  delayMicroseconds(100);
}

void setup()
{
  Serial.begin(9600);
 [b]//dmx_init();[/b]
 mouse_init();
}

/*
 * get a reading from the mouse and report it back to the
 * host via the serial line.
 */
void loop()
{
  char mstat;
  char mx;
  char my;

  /* get a reading from the mouse */
  mouse.write(0xeb);  // give me data!
  mouse.read();      // ignore ack
  mstat = mouse.read();
  mx = mouse.read();
  my = mouse.read();

  /* send the data back up */
  Serial.print(mstat, BIN);
  Serial.print("\tX=");
  Serial.print(mx, DEC);
  Serial.print("\tY=");
  Serial.print(my, DEC);
  Serial.println();  
}

Please let me know if I'm not clear,

Don

A bump as I hope to be able to solve this tonight and apply tomorrow morning for a user test.

A quick look at the DmxSimple library reveals it uses TIMER2 - which is pin3. PS2mouse doesn't appear to use any interrupts.

You might want to pick different pins for your PS2 connections, and use pin3 for DmxSimple.

AndyCC:
A quick look at the DmxSimple library reveals it uses TIMER2 - which is pin3. PS2mouse doesn't appear to use any interrupts.

You might want to pick different pins for your PS2 connections, and use pin3 for DmxSimple.

Thanks! I will test it as soon as possible.

Instead of pin 3, I used pin 8 for the mouse. This does not change a thing, it still does not work.

Could it be that the timer interferes with the communication (read and write) with the mouse?

Any other ideas why the two do not go together?

Thank you!

does it works if you exhange the 3 lines in setup ?

mouse_init();
dmx_init();
Serial.begin(9600);

What is the board you are using ? Arduino Uno, Mega, ?

Elsewhere you can try to get few mouse mouvements (100) and then activate the dmx to know is this is the real trouble.

like (pseudo code);

init mouse
init serial

loop

get 100 values from mouse
are they ok ?
end loop

init dmx pin
init dmx channels

loop

get values from mouse
are they ok ?
apply to dmx

end loop

I added this piece of code to the loop to test it:

if (mx > 20){
dmx_init();
Serial.println("DMX ON!");
}

It printed the values of the mouse until mx was higher than 20 for an instance, it printed the DMX ON!, but then stopped printing the mouse values (and the whole loop).

Any other suggestions?

Found a solution.

Disabling the timers when communicating with the mouse in order to make sure the dmx does not interrupt the mouse when sending and receiving data.

Added this to the code:

  cli(); // Disabling timers
  /* get a reading from the mouse */
  mouse.write(0xeb);  // give me data!
  mouse.read();      // ignore ack
  mstat = mouse.read();
  mx = mouse.read();
  my = mouse.read();
  sei(); // Enabling timers