I have already talked about the great hardware specifications of the Teensy board. But combined with the Arduino software environment, the Teensy also offers some great possibilities. But first let's install the plug-in
Now you should see a category "Teensy" when you choose your board. And if you select it, you have access to several other options like the "USB Serial Type" to instantly transform your board into a USB keyboard or mouse (some possibilities can be found on Arduino Leonardo). The USB communication type is a "Full Speed" which means it can communicate at 12Mb/s. You can also change the speed of the board (on this project I used the overclock at 92Mhz).
For now, all of my Arduino UNO codes have been successfully built on the Teensy which means the adaptation between the ARM Cortex M4 and the AVR Atmega328 have been very well made. I tried to write the code to be understandable. Here is the structure of the main loop :
- A for loop from 0 to the number of LED
- Turn an LED on (as the LEDs are wired with the Anode on VCC and Cathode on the PIN, you have to give a LOW state to turn it ON)
- ClearCIS(), The sensor has to be cleared once before reading the value... I don't know why. If anyone has an idea of how I could speed up this part, I would very much appreciate it.
- readCIS(), read the sensor, if a value is above the calibration it is stored and the function return 1. If something have been detected, the flag_detect is set to 1.
- Turn the LED off (HIGH state for OFF in this configuration)
- If something has been detected, then the flag_detect is set to 1 and you enter the IF function. You can then choose your calibration between the following :
- OPTION 1; send Serial monitor.
Basic debugging : This option allows you to read the 16 clusters directly on the serial monitor.
- OPTION 2; calculate position + send Serial monitor
Debugging position : send the coordinates X and Y to the serial monitor
- OPTION 3; send Processing interface
Debugging visual : look at the CIS results on a Processing GUI. The interface is going to have to be adapted to the number of LED (16 default).
- OPTION 4; calculate position + send Python Pi interface
Send the position to the PyQT interface
- OPTION 5; calculate position + send mouse (only on Teensy)
Send the position as a USB mouse interface. To use this option you will have to go to "Tools" -> "USB Type" -> "Keyboard + Mouse + Joystick". (See the Warning at the bottom of this Step)
- OPTION 6; calculate position + send Keyboard (only on Teensy)
Send the position as a USB keyboard interface. To use this option you will have to go to "Tools" -> "USB Type" -> "Keyboard + Mouse + Joystick".
- OPTION 7; Point and click. Same as mouse but click instead of following the position
- You can eventually add a delay at the end of the loop(). Depending on the speed you need
WARNING: OPTION 5 uses the command mouse.mouveTo(X, Y) which doesn't work on a Linux station. If you want to do the same configuration as me with a Linux Raspberry Pi you are going to need to use the UGLY HACK made by Paul Stoffregen who seems to be one of the developers of the Teensy Project. He is really good and he helps a lot with debugging if you have any questions. Thank you Paul!
For this hack, you need to modify a part of the file name usb_desc.c It should be installed in your Arduino folder. The new configuration given by Paul is slightly different but he makes it work! By then, the mouse.move() function is not working anymore.