update on 10-03-2013


Joystick to drive IMU disp GUI

Arduino rhymes with simplicity. Creating a set with four analog joysticks, and writing a Joystick-USB code that reads the variable resistors with ADC and serially sends the values through the same USB used for programming to the GUI, is just a matter of few hours.

Once again I've used the same light protocol to exchange data. It is easy, portable in every development environment and efficient enough to reduce the CPU load at minimum.

The command received from GUI requesting data is parsed to check validity and a "true" returns if all is ok.

The 4 x 16 bit analog values are arranged into the 8 bit UART register and requested data are sent to the GUI using standard Arduino library.

ADC readings are continuously averaged at each loop. Adding the previous value with the current one and dividing by 2 it computes a mean value without taking care of number of samples. Division by 2 can also be achieved with a shift operation for integer numbers, reducing even more the CPU load.
After sending averaged data, the previous value is reset to start a new average.
This acts as a low-pass filter that gets out most of the possible noise on readings.

The use of powerful libraries to perform complex operations is one of the biggest add-on of the Arduino environment, but you have to know the limits to avoid strange behavior.
The A/D converter inside the MCU is just one and it is multiplexed among the 8 channels. Performing an analogRead() on one port the ADC's Sample and Hold capacitor is connected to that input and it remains connected to that one until you perform another reading. If your circuit under measure has not a very low impedance and you rapidly switch from one input to another one, the capacitor has not enough time to discharge itself before next measure (see also this) returning incorrect values. It is useless to wait even a lot of time (I've seen also example with 10ms) if you don't switch in advance to the new input. This is the reason of this dummy reading to the next port in the loop.

Here an updated version of the joystick with switch, push button and LEDs