XinaBox – SL01: LUX, UVA and UVB

You know how sometimes its much easier to focus when you’re away from the environment of your own home? Yeah, I feel that way most of the time. Truth is, I never really liked working from home during the day time. The only timing that I enjoy working at home is at nights when it peaceful and quiet. That’s usually when it’s best for me to think. But right now, sadly, I have to try and save money. Or rather, I am trying to cut down on my expenses, so staying at home is the only way for me to do that. At least until I can find some form of freelance consulting gig that pays more per project (on average), then perhaps I can spend a little bit more time outside of the house on weekdays. I am currently still looking for a full-time job though. The bills are not going to pay themselves right?

SL01 β˜’CHIP

The SL01 β˜’CHIP measures Luminousity, UVA & UVB readings. // XinaBox

So, a little while ago, when I posted on Twitter about XinaBox, I mentioned that I’m on a mission to write something about the different xCHIPs that are available from the brand. It is my understanding that by the end of July, we’re going to be seeing a total number of 90 different xCHIPs within their product collection. As an enthusiast, it would be my goal to explore every single one of those chips and figure out how we can maximise their potential. As an individual chip, they probably can’t do a lot. If you look at my feature photo above, you can tell that most builds using XinaBox usually comes as a set of chips, connected together to serve a particular purpose. Sure, I could remove the OLED, but blinking the RGB LEDs alone isn’t going to be that helpful when you’re trying to make sense of the readings.

So, over the next couple of months, we’ll embark on a journey to better understand every single xCHIP’s purpose, functionalities, features and how we can use them in a project. For today, we will start with the SL01 xCHIP.

Luminosity (or LUX)

An example of a portable lux meter.

When we talk about luminosity, we’re actually referring to the brightness of a room. Well, that’s the simplest layman example I can think of. When we measure the level of brightness in a room, the higher the value is, the better it is. I remembered studying about the design of an office environment and how in order for the workers to be effective, the lighting in the office has to be of a recommended luminosity level. Too dark and we may need to strain our eyes. The lux meter that you see on the left, is a classic example of what the sensor can be used for.

UVA & UVB

Understanding the effects of UVA and UVB has on our skin is important to help prevent skin cancer.

For many of us around the world, right now is probably summer time, as for others like me that lives in a constant tropical climate all year round, everyday is summer time. LOL. Are you aware that most of what reaches our skin from the sun is actually UVA? In fact, only a very small amount of UVB actually reaches our skin. In a more medical term, UVA is what we would call the long-wave and UVB is the shortwave. Too much of both is just as bad for our skins, unless you’re the kind that loves to get a sunburn out on the beach. πŸ˜‰

One of the most meaningful home automation IoT projects I can think of using this xCHIP, is to control the blinds in your room/living room. For some of us, our living rooms have glass doors that face the rising morning sun. And in such cases, maybe you want to detect the level of UVA/B readings and then draw or open the blinds/curtains. This is actually quite a doable intermediate level IoT project that you can make yourself at home. I’m sure there are many other useful applications as well. It’s just something that popped into my head as I was writing this article.

The β˜’CHIP has been designed such that it’s really easy to differentiate between which is which.
UVA, UVB Light SensorAmbient Light Sensor (LUX)
VEML6075 by Vishay SemiconductorsTSL4531 by Texas Advanced Optoelectronic
-40 Β°C to +85 Β°C 3 lux to 220K lux

Choosing Either a Python or C++ Approach

One of the things that you will come to appreciate about working with XinaBox products is that you can choose to either program your project using the Python programming language or stick to C++. If you choose to do it via the Python approach, I’m going to show you in awhile, the coding that you can run from within Zerynth Studio (a development tool that is already in partnership with XinaBox). If you prefer using the C++ approach, you can either do it from the Arduino IDE or using PlatformIO (something that I prefer myself).

NOTE: This article isn’t intended to be a programming tutorial article, but rather to simply explore the functions and features of the different xCHIPs that are available as well as to provide the necessary links to the relevant resources to help you along with your own projects. I will create another series of blog articles that would actually focus on programming with Zerynth. In that series, we will dive more into the programming aspect.

Coding with Python in Zerynth

The screenshot that I have captured only show the implementation for the Ambient Light (lux) reading. You can copy-and-paste the below program code into the Zerynth editor and save it and run.

# xb_esp32_lux_example
# Created at 2019-06-30 16:45:34.433587

import streams
from xinabox.sl01 import sl01

streams.serial()

# SL01 instance
SL01_T = sl01.TSL4531(I2C0)

# configure and start TSL4531
SL01_T.init()

pinMode(D25, OUTPUT)
pinMode(D26, OUTPUT)

while True:
    lux = SL01_T.getLUX()   # return ambient light level as lux
    print('Light level: ', lux, ' LUX')
    
    if lux >= 151:
        digitalWrite(D26, HIGH)
        digitalWrite(D25, LOW)
    else:
        digitalWrite(D26, LOW)
        digitalWrite(D25, HIGH)
    
    sleep(1000)

If you are looking for the library reference, you can find it here:
https://docs.zerynth.com/latest/official/lib.xinabox.sl01/docs/index.html

On the very same page, you will also find the relevant code samples for working with the ambient light and UVA/UVB sensors. Tapping on the classes will show you their constructor method as well as the methods that are available within each class.

Coding with C++ (PlatformIO)

DOWNLOADING & UNPACKING THE NECESSARY LIBRARIES

Now, if you haven’t done any Arduino-related tinkering before, you can download their IDE here: https://www.arduino.cc/en/Main/Software

In my article series, I will however be more focused on using PlatformIO within Visual Studio Code because I find the intellisense always so helpful. You should be happy to know that both PlatformIO and Visual Studio Code are 100% free. Personally, I have been supporting both the platform tool and editor for a very long time now, and they always help me to be a lot more productive as a developer. To be fair, Arduino did mention before that they will be releasing a version of the Arduino IDE that supports intellisense (autocomplete) functionality, but there hasn’t been any concrete news on when that will be available. So I’m just going to stick to PlatformIO.

To work with XinaBox’s Core xCHIPs, you will need to download the following library: https://github.com/xinabox/arduino-CORE

Next, we will need to download the SL01 library: https://github.com/xinabox/arduino-SL01

Finally, all you need to do is unzipped both files and copy their folders to the Libraries folder within your arduino workspace folder, or within .platformio if you are using PlatformIO like me. It’s probably helpful to note that in some cases, you may need to restart the Visual Studio Code for the libraries to be active. Otherwise, when you import the necessary header files, it will just prompt an error saying that it can’t find the header file that you are trying to import.

Full C++ Code:

#include <Arduino.h&gt;
#include <Wire.h&gt;
#include <xCore.h&gt;
#include <xSL01.h&gt;

const int DELAY_TIME = 1000;

xSL01 SL01;

void setup() {
	// Start the Serial Monitor
	Serial.begin(115200);

	// Start the I2C Communication
	Wire.begin();

	// Start the SL01 Sensor
	SL01.begin();

	// Delay for sensor to normalise
	delay(DELAY_TIME);

	Serial.println("===============================");
	Serial.println(" XINABOX SL01 LUX MEASUREMENTS ");
	Serial.println("===============================");
}

void loop() {
	float lux = 0;

	SL01.poll();	// Poll Sensor for Data.

	lux = SL01.getLUX();

	// Display data on the Serial Monitor
	Serial.print("Ambient Light Level: ");
	Serial.print(lux);
	Serial.println(" LUX");
	Serial.println();

	delay(DELAY_TIME);
}

What Will Be Your Preferred Approach?

When it comes to programming, tinkering, and well…overall hacking, I don’t always have a preference. In some kind of weird way, I’ve learned to appreciate the power of the different programming languages. So maybe for me, it’s a little hard to answer that question. But for some others, I would assume that Python might be the preferred approach. Why? Well, when you have a really powerful editor like Zerynth, and it makes everything so easy for you, why wouldn’t you choose that approach?? On the other hand, most people would associate the C++ programming language with a more “serious”, or “hardcore” programming skill level. Erm…technically, if you were to compare C++ and Python side-by-side, yeah, I would say that there are certain constructs within C++ that are probably a little more challenging to understand for beginners. Again, that’s really just what I think. Doesn’t necessarily mean that I’m right. What do you think? Do you prefer coding in Python or C++?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.