Virtual Sensor

Introduction

 

QikEasy Adapter’s Virtual Wireless Sensor functionality allows your LEGO robotic hub to wirelessly receive measurement data from other devices.

Applications

 

 

 

There are many potential uses of the QikEasy Virtual Wireless Sensor.  Here are a few common use cases:

 

Integrate with sensors that not supported by LEGO

 

QikEasy’s Virtual Wireless Sensor’s open interface makes Spike Prime accessible by developers and DIYers for developing custom devices that wouldn’t be supported by the LEGO Spike Prime or Robot Inventor hub. Using a Wifi enabled microcontroller (such as ESP8266 or the Raspberry Pi Pico), you can easily integrate LEGO with devices like real time clock, temperature sensor, humidity sensor and any other device you can think of.

 

 

Sensor Data collection remote from your LEGO robot

 

Instead of installing the custom sensor on the robot, with QikEasy Virtual Sensor’s Wifi capability, it is  now possible to install the sensor device some distance away from the hub, as long as your custom device is able to access the same wifi network as QikEasy Adapter. Your custom hardware would periodically send measurement updates to our Virtual Sensor device through HTTP over Wifi.  This enables your LEGO to collect data wirelessly from devices such as ultrasonic distance sensor, color sensor, real time clock, temperature sensor, humidity sensor, etc.  The possibilities are limitless.

 

 

Wirelessly Control your LEGO Robot

 

The data sent to QikEasy Virtual Wireless Sensor do not need to be actually sensor measurement data. They can be input control values for your robot.  The remote could be a custom built device, or even a computer.  The device may either controlling your robot autonomously or may be controlled by you manually.

Configuring your QikEasy Adapter as a Virtual Wireless Sensor

 

QikEasy Adapter’s Virtual Wireless Sensor functionality allows you to wirelessly send measurement data from a custom device to the LEGO hub through HTTP GET requests.

 

By default, the virtual wireless sensor would appear as a Color sensor.  You may easily change it to another sensor type by a URL such as the following:

http://192.168.0.128/set?t=d&d=1500

 

This request would turn QikEasy adapter into a Spike Prime Distance sensor with a raw distance value of 1500 (or real world distance of 150cm).

 

QikEasy Adapter supports these emulated Virtual Devices:

    • Color Sensor (which is the default)
    • Distance Sensor
    • Force Sensor

 

Below is a brief overview of steps involved in setting up your QikEasy Adapter as a Virtual Wireless Sensor:

 

    1. Boot QikEasy Adapter into Setup Mode
    2. Connect your computer or mobile phone to the Adapter’s Setup Mode Wifi Access Point
    3. Connect your browser to the QikEasy Adapter Setup page
    4. In Setup mode, enable the Virtual Wireless Sensor Mode option by providing the credentials to your local Wifi router.

 

See below for more detailed instructions on each step.

 

Booting QikEasy Adapter into Setup Mode

Before configuring your virtual sensor, you must first set your QikEasy Adapter into Setup mode.

 

Go to this page for detailed instructions on how to get into Setup Mode.

 

Configuring your QikEasy Adapter as a Virtual Sensor

In order for other devices to wireless send data to QikEasy Adapter, it must establish a connection to your local Wifi network.  Therefore, part of the configuration procedure is to select the Wifi network and set the password for it.

    1. On the main menu of the QikEasy Adapter Setup Access Point website, select “Configure Virtual Wireless Sensor
    2. Check the checkbox to “Enable Virtual Sensor Mode
    3. Click the textbox for Network Name to scan for nearby Wifi networks.
    4. The Wifi Network with the highest strength will be shown.  If this is not the Wifi network/router you want your QikEasy Adapter to connect to, click the dropdown to select the appropriate network name.
    5. Type in the Password for the Wifi network you selected.
    6. Click “Save Configuration” to complete the setup procedure.
    7. To verify that your new settings are correct, the setup page would start counting down from 10 to 0.
    8. Once the count down is over, your QikEasy Adapter should have rebooted back to Setup mode.  The page would prompt you to reconnect your computer/mobile phone to your QikEasy Adapter’s Setup Mode Wifi Access Point (whose name is provided on the webpage).
    9. If everything goes well, it would show you that the Wifi settings are correct, and show you your QikEasy Adapter’s IP address.

      Note down the assigned IP address. It will be needed for your remote device to send data to this QikEasy Adapter later on.
    10. Click the “Start Virtual Server” button OR press the physical RESET button on the adapter to reboot the Adapter into Virtual Wireless Sensor mode.

 

Here’s the tutorial video for how to setup the QikEasy Virtual Wireless Sensor:

Determining your Virtual Sensor IP Address

As mentioned above, you will need to know this QikEasy Virtual Wireless Sensor’s IP address in order to be able to set its measurement data values remotely.  There are a couple possible ways to determine this IP address.

 

Method 1: The Virtual Sensor Setup Process

As above, at the end of the initial Virtual Sensor setup process, our web user interface will display the virtual sensor’s IP address.

 

Method 2: Through a Word Block program

Every time upon bootup of the Virtual Wireless Sensor, the device will start in virtual Color Sensor mode, and will preset its measurements based on the IP address. It is possible to use a Word Block program to read these measurements and display the IP address on your Spike Prime hub.

 

For example, when the IP address is 123.0.1.45, the color sensor measurements will be set as in this table:

MeasurementValueDescription
Red (Ranges from 0 to 1024)123First IP address number
Green (Range from 0 to 1024)0 x 1024 / 255Second IP address number
Blue value (Range from 0 to 1024)1 x 1024 / 255Third IP address number
Color (discrete color. Ranges from -1 to 10)1 x 1024 / 255The hundreds digit of the 4th IP address number
Reflected Light (Ranges from 0 to 100)45The tens and units digits of the 4th IP address number

We recommend that you use a program to display the IP address.  You should run this program immediately after you start your hub that has  the Virtual Sensor connected.  You may store this program into one of the hub’s storage positions so that you may run the program any time you need it.

The following is the Word Block program for Spike Prime 3.0. Make sure you remember to change the Port numbers for all the blue blocks to the port that your QikEasy Adapter is connected to.

The following is the Word Block program for Spike Prime 2.0 and Robot Inventor. The difference is mainly due to the fact that Spike Prime 3.0 interprets RGB as 0 to 1024, while the other systems interpret them as 0 to 255. Make sure you remember to change the Port numbers for all the blue blocks to the port that your QikEasy Adapter is connected to.

Reserving a Fixed IP Address for your Virtual Sensor

In most cases, restarting your QikEasy Virtual Sensor within a short period of time will result in your Wifi router assigning it the same IP address as before. However, if you attempt to restart it after several hours or days, your QikEasy adapter will likely be assigned a different IP address. The IP address assignment behavior solely depends on the design of your Wifi router.

 

Especially for long term usage, in many scenarios, it would be useful to ensure that your Virtual Sensor’s assigned IP address always stay the same. This would allow the remote client that sends data updates to  always use the same IP address to send updates.

 

To ensure that your QikEasy Virtual Sensor always gets the same IP address from your Wifi router, you can use a technique called IP address reservation, also known as DHCP reservation or static DHCP. This technique involves configuring the Wifi router to reserve a specific IP address for a particular Wifi client, based on its MAC address.

Here are the steps to set up IP address reservation on most Wifi routers:

 

    1. Determine the MAC address of the Wifi client device that you want to assign a static IP address to. You can usually find the MAC address in the device’s network settings.
    2. Log in to the Wifi router’s configuration page, which can typically be accessed through a web browser using the router’s IP address.
    3. Look for a section in the router’s configuration page called “DHCP Reservation,” “Static DHCP,” or similar.
    4. Add a new reservation, specifying the MAC address of the Wifi client and the IP address you want to assign to it.
    5. Save the changes, and restart the router and the Wifi client device.

 

Once you have set up IP address reservation on your Wifi router, the designated Wifi client will always receive the same IP address every time it connects to the network, as long as the router is configured properly and the reserved IP address is not in use by another device.

 

You may refer to this web page for more details on how to setup IP address reservation.

Wirelessly Send Measurements to your Virtual Sensor

You may change the virtual sensor type and update the measurement values of your QikEasy Virtual Sensor through HTTP requests from any web capable device that can connect to your local network.

 

Request URL Format

All requests to update the Virtual Sensor are HTTP GET requests.  Below is the general format for the requests:

 

http://<Virtual Sensor's IP address>/set?t=<sensor type>&<measurement value updates>

 

The parameter t can accept these values:

ParameterDescription
cSet Virtual Sensor Type to Color Sensor
dSet Virtual Sensor Type to Distance Sensor
fSet Virtual Sensor Type to Force Sensor
iReset the Virtual Sensor to initial state with its IP address

 

The specific measurement values that can be set through HTTP request varies depending on the Virtual Sensor’s current sensor type.  Below are description of the measurements available for each specific virtual sensor type.

 

Color Sensor

ParameterRangeDescription
d-1 to 10Discrete Color. Note: At bootup, this value is initialized to 3 until the device gets an IP address after Wifi gets connected.
r0 to 1024Red in RGB. Note: At bootup, this value is initialized to 2000 until the device gets an IP address after Wifi gets connected.
g0 to 1024Green in RGB.
b0 to 1024Blue in RGB.
R0 to 1024Reflective light.
a0 to 100Ambient light.

 

Note:

    • In Spike App 2 and Robot Inventor’s Word Block programs, the RGB values are scaled to the range [0, 255], while Python code would see these values with range [0, 1024].
    • In Spike App 2 & 3 and Robot Inventor Word Block programs, the Reflective light value is scaled to [0, 100], while Python code would see this value with range [0, 1024].
    • Ambient Light measurement value is only available in Python programs.
    • For the measurements d (discrete color), R (reflective light) and a (ambient light), when you make the HTTP request with these parameters equal to ‘a’, it will cause the corresponding measurement value(s) to be automatically calculated from the virtual color sensor’s RGB values.

 

 

Distance Sensor

ParameterRangeDescription
d0 to 2500Distance.

 

Note:

    • Word Block scales the range down by a factor of 10.  For example, a raw value of 2000 would be displayed as 200cm in the Word Block program.
    • Word Block’s maximum display value is 200cm.  This means any raw value 2000 and above would yield the same value in your Word Block program.
    • With Python code, you will be able to use the full range from 0 to 2500.

 

 

Force Sensor

ParameterRangeDescription
f0 to 100Force.

 

Note:

    • Word Block scales the range down by a factor of 10.  For example, a raw value of 100 would be displayed as 10 Newton in the Word Block program.
    • With Python code, you will be able to use the full range from 0 to 100.

 

 

Examples

The following are some valid example HTTP requests (where the IP address of the QikEasy Virtual Sensor is 192.168.11.231):

 

http://192.168.11.231/set?t=c&d=3&r=200&g=200&b=200&R=a

This request would configure the QikEasy Virtual Sensor as a Color Sensor with RGB value of {200, 200, 200}, Discrete Color value of 3, and Reflective Light value being calculated based on the aforementioned RGB value.

 

http://192.168.11.231/set?t=d&d=1900

This request would configure the QikEasy Virtual Sensor as a Distance Sensor with a distance of 190cm.

 

http://192.168.11.231/set?t=f&f=80

This request would configure the QikEasy Virtual Sensor as a Force Sensor with a force of 8 Newton.

 

http://192.168.11.231/set?t=i

This request would reset the QikEasy Virtual Sensor to a Color Sensor with initial measurement values set for its IP address.

Example Projects

 

QikEasy Adapter’s Virtual Sensor functionality enables LEGO makers to build projects that were never possible before.  Below are a few examples. The projects you can build is only limited by your imagination.

 

Control your LEGO Robot with Amazon Alexa voice assistant


Click here to learn how to control your Robot through Alexa or other voice assistant using IFTTT.

 

 

 

 

 

 

Drawing Mona Lisa on this LEGO Spike Prime Plotter


Click here to learn how to build this nifty plotter solely from LEGO hardware.

 

 

 

 

 

 

LEGO Smart Switch with Voice Assistant & Smartphone Control


Click here to learn how you can use Spike Prime system to control your light switch in a smart home environment.

 

 

Face Tracking Robot


Click here to learn how to build a Robot that detects and follows your face.

 

 

 

 

Object Following Robot


Click here to learn how to build a Robot that detects and follows your face.

 

 

 

 

 

A Product Identifying & Sorting Robot via Bar Code Scanning


Click here to learn how you can use your mobile phone to scan the barcode of a product, and move it to a designated location based on the code.

 

 

A High Precision Internet Clock

Click here to learn how you can build a highly accurate clock based on Internet time protocol (NTP).

 

A Custom build Remote Control for a LEGO Race Car

 

Click Here to learn how to implement this custom remote control.

 

 

 

 

 

 

 

Other Project Ideas

    • Integration with Raspberry Pi through HTTP.  And use Raspberry Pi’s IO capability and enormous processing power to work with custom sensors.
    • A fancier wall mount plotter with the hub hanging on the wall by two strings. The hub control its position on the wall by changing the length of the strings.

 

We are always exploring new use cases for this exciting capability.  We encourage you to email us with your ideas at info@novavolta.com. If we like your ideas, we may actually implement the ideas, and present videos and articles on them.

FAQ 

 

Can your virtual sensor be used over the internet?

 

Yes, it is possible. But, you will have to setup Port Forwarding on your Internet router so that internet traffic can be port forwarded to your QikEasy Virtual Sensor device. You may easily google and find tutorials on how to port forwarding on your specific brand of router.

 

 

Why is my virtual sensor not working at all?

 

It is most likely due to one of these reasons:

 

    • Your QikEasy Adapter is NOT in Virtual Sensor mode.
      By default, it is in EV3 Adapter mode.  Please go through the setup steps to make sure your adapter is in Virtual sensor mode. After setup, you may have to manually press the Reset button on your adapter to get out of Setup mode.

 

    • You have an EV3 sensor plugged into your QikEasy Adapter.
      By design, we disable the Virtual Sensor mode when an EV3 sensor is plugged in. To solve this, simply unplug the EV3 sensor.

 

    • Your LEGO hub has automatically shut off by itself after a period of inactivity.
      Make sure your hub is powered on and connected to you Spike Prime app.

 

    • Your QikEasy Adapter is not plugged into the LEGO hub.
      With many sensors and motors connected to your robot, sometimes we could simply forget to connect one of the wires.

 

    • Your QikEasy Virtual Sensor is NOT set with the correct Wifi credentials.
      Remember you will have to change these credentials every time you move to another environment or if you changed your Wifi router’s password.  Note that on boot up, your QikEasy Virtual Sensor will use these credentials to automatically sign in to  your Wifi network.  Once connected to Wifi, the red LED on QikEasy Adapter will light up permanently.  If you don’t see your Adapter’s red LED light up permanently after booting for more than a minute or so, it is a likely sign of Wifi credentials problem. Sometimes, if you Wifi router has very weak signal or if there are a lot of interference from other devices, you may also get network connection issues.  In such case, you may try rebooting again (by pressing the Reset button on the adapter), resetting would cause the adapter to reconnect using a different Wifi channel. Sometimes, using different Wifi channel would help.

 

    • The IP address you use to send measurement data to the QikEasy Virtual Sensor is incorrect.
      Depending on the behavior of your Wifi router, your IP address may change every time your QikEasy Adapter connects to it.  You may use the Word Block program provided in the documentation to read the IP address of your Virtual Sensor.  Also, you may want to look into affixing the QikEasy Adapter’s IP address by setting up a reserved IP address for your QikEasy Adapter on your router.