Hello everyone. I welcome you to my one to last blog post as part of Experimenting with Gesture Sensors. In previous blog post I shown my final project. Today I will show one of my experiments which I have done as part of experimenting with the sensor. Today I will show how two MAX25405 sensor works.
If you remember my blog Blog #8: 12V Accident, I burned my kit, ordered new kit, but later I decided to fix broken kit, so now I have two kits (fixed burned kit and new kit). This allows me to try sensor synchronization features of the MAX25405 sensor when using two sensors at the same time. The issue is that when using two sensors, their infra-red LEDs interfere with LEDs form other kit.
Improving stand for allowing using two sensors
For my initial experiments with this setup, I upgraded my stand which I originally developed for using with single sensor and described in previous Blog #4: Building stand for MAX25405 EVKIT. Now it allows me to mount two sensors very near each other. Stands from, building set is much more flexible than plastic 3D printer stands as you can see. This is not practical setup for using two sensors. It does not make sense to place two sensors in the very similar position. Instead with two sensor practical use case is to set sensors at different positions allowing them sensing gestures from two points of view which can later allow more precise and accurate gesture detection. But this setup was done mainly for experimenting with sensor and allows me for example compare sensor outputs as you will see later.
Connecting Two Sensors
MAX25405 allows two interface and in both cases, it allows running two sensors by the same master. In case of I2C bus it is achieved by two I2C addresses and in case of SPI it can be achieved by using two chip select ports. In my experiments I used SPI bus, so I was driving and selecting sensor by CS pins. My library has support for this feature for both buses. As a microcontroller I used MAX78000 on FTHR board the same as in previous project. For an application I configured sensor, implemented support for receiving interrupt from both sensors and after they interrupted I read new screen data. These I printed over UART. For visualization I used WebSerial API. I edited it to support output format from my MCU application and also added second table for visualizing data from second sensor.
Running Two Sensor Unsynced
At beginning I tried running it simple without any synchronization. Just two sensors running totally independently. Result you can see on the following video:
I recommend opening this video on youtube and playing it slowed down.
As you can see there is very high noise. If you pause video, you can see that when I was holding hand in fixed position at highest value pixel, I have seen values flickering between values. For example, in one moment there were value of 1788 and soon later the same pixel returned 3719. It is very big difference!
But as you can see generally object is visible even it is flickering. With proper filter I think it is possible to detect gestures, but it of course always affects detection reliability significantly.
Methods of Syncing Sensors
MAX25405 allows two methods of syncing two sensors. Idea of syncing is that Sensor enables IR led if and only if other sensor is sleeping and do not sample sensor data. MAX25405 allows configuring time when the sensor is active and when it is inactive. The two methods of synchronization are following:
- Manually by registry writes and single shoot mode.
- Automatically by SYNC pin. One sensor is master, second is slave.
The first mentioned method is trivial. You write firmware in a way that it triggers conversion in single sensor, wait until it completes and then it does the same with second sensor. More tricky approach of first idea is that you can let sensor in continuous mode and regularly writes it SYNC bit in configuration register. Method is easy but need implementation in MCU and most probably will cost you one or two timers of your MCU.
The second approach is easier to implement. MAX25405 has SYNC pin and can be configured for making this pin as input or output (or disable the feature). In output (master) mode it output some signal which can second sensor configured as input (slave) process. Slave assures that enables LEDs if and only if master do not drive SYNC signal.
Syncing Sensors
I implemented this in firmware and connected first sensor as a master and second as a slave. Configuration code look as follows (error checks are for simplicity omitted):
MAX25405_Configuration config; MAX25405_GetDefaultConfiguration(&config); config.mainConfig.modeOfOperation = MAX25405_ModeOfOperation_TrackingMode; config.ledConfig.ledDrive = MAX25405_LedDrive_PWM_16_16; config.ledConfig.enableDrivePwmOutput = 1; config.ledConfig.columnGainMode = MAX25405_ColumnGainModeSelection_Internal; config.mainConfig.enableEndOfConversionInterrupt = 1; config.sequencingConfig.endOfConversionDelay = MAX25405_EndOfConversionDelay_12_49ms; config.sequencingConfig.integrationTime = MAX25405_IntegrationTime_25us; config.sequencingConfig.numberOfCoherentDoubleSamples = MAX25405_NumberOfCoherentDoubleSamples_8; config.mainConfig.externalSyncMode = MAX25405_ExternalSync_Master; MAX25405_SetConfiguration(&max1, &config); config.mainConfig.externalSyncMode = MAX25405_ExternalSync_Slave; MAX25405_SetConfiguration(&max2, &config);
Connecting sync signal
SYNC signals are exposed to pin header which is not placed by default. I had to solder it. For connecting sync signals of the sensor, you need to connect signals by jumper or other wire. It is good that signals are exposed to pin header. Instead of connecting jumper you can connect them to analysers like oscilloscope and easily look at it.
One Sensor “stopped” working
After I deployed new firmware withc synchronization configuration, I connected to the output again and see that flickering disappear from first (master) sensor, but second sensor (slave) stopped producing data. I was debugging it. If I removed jumper (and disconnect SYNC signal between two sensor) it start generating interrupts again, but when connected master worked well but slave do not generated any interrupt indicating new data collected. For some reason slave was blocked. I checked SYNC signal from master with logic analyser and signal look good. It was logic signal. Some time it was high and some time it was low. Later I was thinking about it and…
Timing Settings Requirements
Later I realized that when using synchronization there are some timing constraints. The issue which prevented slave collecting data was that time slot when master allowed slave to sense was too short. The condition is that slave sampling time must be shorter than master intermeasurement delay, otherwise slave will not have enough time to complete his sample and it abort collection in progress after master interrupt it. My initial settings were that both sensors was configured in a way that about 75% of time were sampling data (and IR LEDs were active) and sensor was sleeping for about 25% of time. In other words 25% of time was not sufficient for second sensor which also needed 75 % of time for completing measurement.
Resolution is simple but debugging took me some time. Easiest resolution is to increase delay between measurements or reduce time when sensor is sampling. I increased delay between measurements from 3.12ms to 12.49ms. 12.49ms is used in code above.
Result
After I fixed this issue, I was able to sense data from both sensor without any flickering. On the following video you can see this result:
Comparing results from two sensors
The reason why I did this experiment is that I want to see output from both sensor and compare if they produce exactly the same data or there are some differences. For a test look at following screen.
Experiment confirmed my hypothesis that there are differences. As you can see the sensor at right side produce systematically lower values. It is also visible on place where no subject was present (for example corners). Drift is about -200 to -300 in comparison to left sensor sensing the same (static in this case) scene. The difference is not very high but still is there. If you want to use two sensors in your design, you should not expect that data are exactly the same and rather pre-process them independently. There is possibility that MAX25405 is not the cause of a difference, but IR LEDs can also cause this drift.
Conclusion
This was my last blog as part of this competition. The only next blog will be my summary as part of this competition. In this blog I shown my experiment which I did and shown how to synchronize two sensors sensing the same scene for preventing interference between sensor, what are preconditions of timing configuration when syncing two sensors and finally, compared the data from two sensors. Using two sensors is feature with big potential but it is not possible to implement dual-sensor gesture detection as part of two-months long competition. Even implementing detection based on data from single sensor is quite complicated as I shown in previous blogs when I was describing my own algorithm, but it is good to know that MAX25405 has support for this and is designed in a way that it can be used in dual setup.
Next blog: Blog #16: Misaz’s Experimenting with Gesture Sensors Summary