I am trying to get some code to work on my new Due but I am hitting a wall. I think this is likely straightforward and so I thought I would see if someone can explain it to me.
I have this running nicely on my Uno.
It basically allows me to access the distance traveled from an optical mouse chip. Obviously it works through the SPI protocol. The nice thing about the tutorial is that it also has a Fritzing layout of the hardware wiring diagram (I am ignoring the display and just using the serial monitor for now). I think transferring it from the Uno to the Due is given me trouble both in tweaking the code and where to send the chip info to.
Here's what I had on the Uno.
Slave Select to Pin 10
Mosi to Pin 11
SK (clock) to pin 13
Miso to pin 12
Motion (MOT) to pin 2
Voltage in (5V) to +5V pin
Analog Ground to GND
Digital Ground to GND
On the Due I am making most of the connections to SPI header Just to the left of the Atmel chip. I found this confusing as the Due documentation said to place them on the header with ICSP written below it.
Nevertheless, I put them on SPI. When viewed such that the word SPI is normally oriented, I placed the wires on the following pins.
Upper left Pin = MISO
Upper Right Pin = Voltage In (VI)
Middle Left pin = SC
Middle Right pin = MOSI
Lower Right Pin = DG (Digital Ground)
I then placed the analog ground to a random ground on the board.
I placed the motion pin from the chip to pin 2 on the Due because that's where it was on the Uno. Does this seem right?
I placed the SS of slave select on pin 10 because that's where it was on the Uno.
Given that I tried to keep things similar between the two boards, should this work to run the same code. The behavior that I get now is that it automatically increase the x and y displacement infinitely. So it does not appear to be behaving as it did on the UNO.
The code is un-altered from the link above. I tried to insert it here but it exceed the character limit. I can post it separately if that helps.
Thank you so much for any help as it is obviously much appreciated!
FB
Thanks for the help. The chip and data sheet can both be found here.
I believe the chip by default operates at 3.3V. To make it work on the Uno, I had to convert it to 5V by cutting a couple traces and making a solder bridge elsewhere. To use it at 3.3V, my understanding is that I didn't need to modify it at all and thus I just wired it as is.
Thanks again and let me know if there's anything else I can add to clarify things.
Brief checking with data sheet, 2 MHz clock maximum, I'd set SPI.setClockDivider at least 42, DUE running at 84 MHz.
And also, interrupt 0, I know on UNO it's pin 2 , but I'm not sure if it same on DUE.
The Arduino Due board has powerful interrupt capabilities that allows you to attach an interrupt function on all available pins. You can directly specify the pin number in attachInterrupt().
And, try to change SPI.setClockDivider(8); to SPI.setClockDivider(42);
Do you have a scope? W/o one debugging interface may be very tricky.