Some time ago we showed you how to efficiently read Yoctopuce sensors from Excel, using an RTD server written in C# .NET. As this solution works quite well, we have been asked whether it was possible to extend our sample code to handle other Yoctopuce devices. It's Christmas time, here you are :-)
We have made several enhancements to the RTD server sample code.
Although categorized as a sensor, the Yocto-Knob has no data logger and is (for historical reasons) not usable with the YSensor class. It was therefore not possible to use it with the first version of our RTD server. We have now added the support for the YAnButton class in the example, and it is therefore possible to read from Excel a potentiometer or a phototransistor for instance, using the same YSensorValue() function. For instance, if you define a cell as
its value will instantly show the value read from potentiometer 3, between 0 and 1000.
We have added a YRelayState() function that can drive Yoctopuce relays from Excel. As for sensors, the relay can be referenced either using its unique hardware ID, or using the logical name that was given to it. The new state value can be either "A" or "B". The function returns the newly selected state. For instance, to switch the relay based on the value of cell B2, one can use:
If the function is invoked with a single argument, the current relay state is returned, without changing it:
RGB LED support
In the same way, the function YColorLedRGB() can drive a Yocto-Color or a Yocto-PowerColor directly from Excel. The value passed as argument is the RGB color, either as hexadecimal string (like an HTML color code), or as 3 separate color components passed as numbers. For instance, the formula below sets the LED to a green color whose intensity depends on the value B2 in the interval 0...1000 :
One more function named YServoPosition() can drive the 5 channels of the Yocto-Servo. The position given as argument is an integer between -1000 et 1000. For instance, to move the servo position based on the content of cell B2 in the range 0...1000, use the following formula:
Our previous RTD server was opening the console window each time a message was logged, which was not very convenient. This has been changed, and now the window is only showed when explicitely opened in the "Yoctopuce Sensor RTD Server" menu. This menu also provides a finer granularity for choosing the RTD server refresh rate.
A small demonstration
To conclude, here is a quick-and-dirty demonstration showing what can be done with this simple plug-in. As Excel automatically recomputes all dependent cells when the value provided by a RTD server changes, if a call to YRelayState, YColorLedRGB or YServoPosition uses as argument a cell computed using YSensorValue, the actuator will be automatically updated each time the sensor value changes. It is therefore possible to create a simple automaton using nothing but a simple Excel sheet...
The new plug-in can be downloaded here. You will find installation instructions in the previous post. Merry Christmas !