iCloud RoboCore

Hi,

I am new to both RoboCore and programming in general but are giving it a go. I have been trying to program the RoboCore
unit so I can control the board motor ports and view the all readings of the sensor ports on the web. So far I got the motors working but cant manage to get the analog values firstly passed to the web page nor to update automatically.

If anyone could offer assistance it would be greatly appreciated.

index.html
!doctype html>
html>
head>
link rel=“stylesheet” type=“text/css” href="/static/theme-dark.less.css">
script src="/static/robocore.js">
/head>
body>
checkbox id=“led1”>LED1
checkbox id=“led2”>LED2
checkbox id=“led3”>LED3
label id=“sensor1”>sensor1
/center>
/html>

main.cpp
include hFramework.h>
include hCloudClient.h>

int channelStatus[6];
int sensor1;

void cfgHandler() {
platform.ui.loadHtml({Resource::WEBIDE, “/index.html”});
platform.ui.label(“sensor1”).setText("%d", sensor1);}

void onValueChangeEvent(hId id, const char* data) {

if (id == "led1") {
    if (atoi(data) == 1) {
        channelStatus[1] = 1;
        LED1.set(1);
        hMot1.setPower(-1000);
    }
    else {
        LED1.set(0);
        hMot1.setPower(0);
        channelStatus[1] = 0;
    }
}
if (id == "led2") {
    if (atoi(data) == 1) {
        channelStatus[2] = 1;
        LED2.set(1);
        hMot2.setPower(-1000);
    }
    else {
        channelStatus[2] = 0;
        LED2.set(0);
        hMot2.setPower(0);
    }
}
if (id == "led3") {
    if (atoi(data) == 1) {
        channelStatus[3] = 1;
        LED3.set(1);
        hMot3.setPower(-1000);
    }
    else {
        channelStatus[3] = 0;
        LED3.set(0);
        hMot3.setPower(0);
    }
}

}

void button1_thread_loop() {
while (true) {
hBtn1.waitForPressed();
//LED1.toggle();
if (channelStatus[1] == 1) {
channelStatus[1] = 0;
LED1.set(0);
hMot1.setPower(0);
}
else {
channelStatus[1] = 1;
LED1.on();
hMot1.setPower(-1000);
}
hBtn1.waitForReleased();
}
}

void button2_thread_loop() {
while (true) {
hBtn2.waitForPressed();
//LED2.toggle();
if (channelStatus[2] == 1) {
channelStatus[2] = 0;
LED2.set(0);
hMot2.setPower(0);
}
else {
channelStatus[2] = 1;
LED2.set(1);
hMot2.setPower(-1000);
}
hBtn2.waitForReleased();
}
}

void sensor1_thread_loop() {
sensor1 = hSens4.pin2.analogReadVoltage();
}

void hMain() {
hSens4.pin2.enableADC();
platform.begin(&Edison);
platform.ui.setProjectId(“9c6f661d18ff2452”);
platform.ui.configHandler = cfgHandler;
platform.ui.onValueChangeEvent = onValueChangeEvent;
sys.taskCreate(button1_thread_loop);
sys.taskCreate(button2_thread_loop);
sys.taskCreate(sensor1_thread_loop);
}

Hi, I slightly modified your code to show you how to display sensor output data on the web. Instead of Edison my code uses Android smartphone. To change this write:

platform.begin(&Edison);

instead of:

platform.begin(&Usb);

main.cpp:

#include <hFramework.h>
#include <hCloudClient.h>

int channelStatus[6];
int sensor1;

void cfgHandler()
{
	platform.ui.loadHtml({Resource::WEBIDE, "/index.html"});
}

void onValueChangeEvent(hId id, const char* data)
{
	if (id == "led1") {
		if (atoi(data) == 1) {
			channelStatus[1] = 1;
			LED1.set(1);
			hMot1.setPower(-1000);
		} else {
			LED1.set(0);
			hMot1.setPower(0);
			channelStatus[1] = 0;
		}
	}
	if (id == "led2") {
		if (atoi(data) == 1) {
			channelStatus[2] = 1;
			LED2.set(1);
			hMot2.setPower(-1000);
		} else {
			channelStatus[2] = 0;
			LED2.set(0);
			hMot2.setPower(0);
		}
	}
	if (id == "led3") {
		if (atoi(data) == 1) {
			channelStatus[3] = 1;
			LED3.set(1);
			hMot3.setPower(-1000);
		} else {
			channelStatus[3] = 0;
			LED3.set(0);
			hMot3.setPower(0);
		}
	}
}

void button1_thread_loop()
{
	while (true) {
		hBtn1.waitForPressed();
//LED1.toggle();
		if (channelStatus[1] == 1) {
			channelStatus[1] = 0;
			LED1.set(0);
			hMot1.setPower(0);
		} else {
			channelStatus[1] = 1;
			LED1.on();
			hMot1.setPower(-1000);
		}
		hBtn1.waitForReleased();
	}
}

void button2_thread_loop()
{
	while (true) {
		hBtn2.waitForPressed();
//LED2.toggle();
		if (channelStatus[2] == 1) {
			channelStatus[2] = 0;
			LED2.set(0);
			hMot2.setPower(0);
		} else {
			channelStatus[2] = 1;
			LED2.set(1);
			hMot2.setPower(-1000);
		}
		hBtn2.waitForReleased();
	}
}

void sensor1_thread_loop()
{
	sensor1 = hSens4.pin2.analogReadVoltage();
}

void hMain()
{
	hSens4.pin2.enableADC();
	platform.begin(&Usb);
	platform.ui.setProjectId("@@@PROJECT_ID@@@");
	platform.ui.configHandler = cfgHandler;
	platform.ui.onValueChangeEvent = onValueChangeEvent;
	sys.taskCreate(button1_thread_loop);
	sys.taskCreate(button2_thread_loop);
	sys.taskCreate(sensor1_thread_loop);
	while(1) {
	    sys.delay(500);
	    platform.ui.label("sensor1").setText("%d", sensor1);
	    sensor1 = sensor1 + 1;
	}
}

index.html:

<!doctype html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="/static/theme-dark.less.css">
    <script src="/static/robocore.js"></script>
</head>
<body>
    <checkbox id="led1">LED1</checkbox>
    <checkbox id="led2">LED2</checkbox>
    <checkbox id="led3">LED3</checkbox>
    <label id="sensor1">sensor1</label>
</body>
</html>

Hey Domink,

Thanks for the help, one other thing the hsens ports one to six, what is the initialising for it to be used as analog?
If I try the below modified from one of the examples, I get errors

sensor1 = hSens1.pin2.analogReadVoltage();
sensor2 = hSens2.pin2.analogReadVoltage();
sensor3 = hSens3.pin2.analogReadVoltage();
sensor4 = hSens4.pin2.analogReadVoltage();
sensor5 = hSens5.pin2.analogReadVoltage();
sensor6 = hSens6.pin2.analogReadVoltage();

ERROR;
main.cpp:88:27: error: ‘class hFramework::hGPIO’ has no member named ‘analogReadVoltage’
sensor1 = hSens1.pin2.analogReadVoltage();

Hi sag007,

in your first post in this topic you used “hSens4.pin2.analogReadVoltage();” function. The “pin2” works as ADC only for hSens4 port, because it’s a special port that is used with one of the LEGO Mindstorms sensors. The hSens4 port is a little exception and it has 2 ADC’s.
Generally, only the “pinIntAdc” is the pin that have the ADC functionality for each hSensor port. Please see our wiki to find more details:
https://wiki.robocore.io/hardware:hsensor
You should use the pin1 (hSensX.pinIntAdc) when you need the analog-to-digital converter.
Dominik has already sent you this example but there is the right example:

Try this way:

sensor1 = hSens1.pinIntAdc.analogReadVoltage();
sensor2 = hSens2.pinIntAdc.analogReadVoltage();
sensor3 = hSens3.pinIntAdc.analogReadVoltage();
sensor4 = hSens4.pinIntAdc.analogReadVoltage();
sensor5 = hSens5.pinIntAdc.analogReadVoltage();
sensor6 = hSens6.pinIntAdc.analogReadVoltage();

Of course, you have to change the electrical connections and initialize all the ADC pins:

hSens1.pinIntAdc.enableADC();
hSens2.pinIntAdc.enableADC();
hSens3.pinIntAdc.enableADC();
hSens4.pinIntAdc.enableADC();
hSens5.pinIntAdc.enableADC();
hSens6.pinIntAdc.enableADC();

Hi Radeknh,

thanks for the info, I have made the changes to the code but when I tried it I only got 0 on all the hsens ports. I then tried commenting out the platform.ui.label line and replaced it with printf to see what was going on. It too shows only 0 on all channels.

**MAIN.CPP**
#include <hFramework.h>
#include <hCloudClient.h>

int channelStatus[6];
int sensorReading1 = 0;
int sensorReading2 = 0;
int sensorReading3 = 0;
int sensorReading4 = 0;
int sensorReading5 = 0;
//int sensorReading6 = 0;

void cfgHandler() {
    platform.ui.loadHtml({Resource::WEBIDE, "/index.html"});
}

void onValueChangeEvent(hId id, const char* data) {
    
    if (id == "led1") {
        if (atoi(data) == 1) {
            channelStatus[1] = 1;
            LED1.set(1);
            hMot1.setPower(-1000);
        }
        else {
            LED1.set(0);
            hMot1.setPower(0);
            channelStatus[1] = 0;
        }
    }
    if (id == "led2") {
        if (atoi(data) == 1) {
            channelStatus[2] = 1;
            LED2.set(1);
            hMot2.setPower(-1000);
        }
        else {
            channelStatus[2] = 0;
            LED2.set(0);
            hMot2.setPower(0);
        }
    }
    if (id == "led3") {
        if (atoi(data) == 1) {
            channelStatus[3] = 1;
            LED3.set(1);
            hMot3.setPower(-1000);
        }
        else {
            channelStatus[3] = 0;
            LED3.set(0);
            hMot3.setPower(0);
        }
    }
}

void button1_thread_loop() {
    while (true) {
        hBtn1.waitForPressed();
        if (channelStatus[1] == 1) {
            channelStatus[1] = 0;
            LED1.set(0);
            hMot1.setPower(0);
        }
        else {
            channelStatus[1] = 1;
            LED1.on();
            hMot1.setPower(-1000);
        }
        hBtn1.waitForReleased();
    }
}

void button2_thread_loop() {
    while (true) {
        hBtn2.waitForPressed();
        if (channelStatus[2] == 1) {
            channelStatus[2] = 0;
            LED2.set(0);
            hMot2.setPower(0);        
        }
        else {
            channelStatus[2] = 1;
            LED2.set(1);
            hMot2.setPower(-1000);        
        }
        hBtn2.waitForReleased();
    }
}

void hMain() {
    platform.begin(&Edison);
    platform.ui.setProjectId("9c6f661d18ff2452");
    platform.ui.configHandler = cfgHandler;
    platform.ui.onValueChangeEvent = onValueChangeEvent;
    
    sys.taskCreate(button1_thread_loop);
    sys.taskCreate(button2_thread_loop);
    
    hSens1.pinIntAdc.enableADC();
    hSens2.pinIntAdc.enableADC();
    hSens3.pinIntAdc.enableADC();
    hSens4.pinIntAdc.enableADC();
    hSens5.pinIntAdc.enableADC();

	while(1) {
	    sensorReading1 = hSens1.pinIntAdc.analogReadVoltage();
	    sensorReading2 = hSens2.pinIntAdc.analogReadVoltage();
	    sensorReading3 = hSens3.pinIntAdc.analogReadVoltage();
	    sensorReading4 = hSens4.pinIntAdc.analogReadVoltage();
	    sensorReading5 = hSens5.pinIntAdc.analogReadVoltage();
	    
        printf("%f \r\n", sensorReading1);
        printf("%f \r\n", sensorReading2);
        printf("%f \r\n", sensorReading3);
        printf("%f \r\n", sensorReading4);
        printf("%f \r\n", sensorReading5);

	    //platform.ui.label("sensor1").setText(" %d ", sensorReading1);
	    //platform.ui.label("sensor2").setText(" %d ", sensorReading2);
	    //platform.ui.label("sensor3").setText(" %d ", sensorReading3);
	    //platform.ui.label("sensor4").setText(" %d ", sensorReading4);
	    //platform.ui.label("sensor5").setText(" %d ", sensorReading5);	    
	    sys.delay(500);
	}
}

INDEX.HTML

<!doctype html>
<html lang="en">
<html>
    
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <link rel="stylesheet" type="text/css" href="/index.css">
        <script src="/static/robocore.js"></script>
        <title>Chicken Coop Controller</title>
    </head>
    
    <center>
        
        <div class="container">
            <label>Chicken Coop</label>
            <label>ver1.0</label>
        </div>
        
        <div class="container">
            <label>Temperature</label>
            <label>Humidity</label>
            <label>Battery</label>
            <label>Actuator</label>
        </div>

        <div class="container">
        <label id="sensorReading1">sensor1</label>
        <label id="sensorReading2">sensor2</label>              
        <label id="sensorReading3">sensor3</label>
        <label id="sensorReading4">sensor4</label>
        <label id="sensorReading5">sensor5</label>
        </div>

        <div class="container">
        <checkbox id="led1">Lights Inside</checkbox>
        <checkbox id="led2">Lights Outside</checkbox>
        <checkbox id="led3">Water Sprayer</checkbox>
        <checkbox id="led4">Main Door</checkbox>
        </div>

    </center>
</html>

Hi, there are two ways to solve your problem:

a) declare sensorReadingX as “float”, not “int”, and use

hSens1.pinIntAdc.analogReadVoltage(); 

that returns analog voltage on the ADC pin as float number.

b) declare sensorReadingX as “int” and use

hSens5.pinIntAdc.analogReadRaw();

that returns integer value, not float.

working code is here:

#include <hFramework.h>
#include <hCloudClient.h>

int channelStatus[6];
float sensorReading1 = 0;
float sensorReading2 = 0;
float sensorReading3 = 0;
float sensorReading4 = 0;
int sensorReading5 = 0;
//int sensorReading6 = 0;

void cfgHandler() {
    platform.ui.loadHtml({Resource::WEBIDE, "/index.html"});
}

void onValueChangeEvent(hId id, const char* data) {
    
    if (id == "led1") {
        if (atoi(data) == 1) {
            channelStatus[1] = 1;
            LED1.set(1);
            hMot1.setPower(-1000);
        }
        else {
            LED1.set(0);
            hMot1.setPower(0);
            channelStatus[1] = 0;
        }
    }
    if (id == "led2") {
        if (atoi(data) == 1) {
            channelStatus[2] = 1;
            LED2.set(1);
            hMot2.setPower(-1000);
        }
        else {
            channelStatus[2] = 0;
            LED2.set(0);
            hMot2.setPower(0);
        }
    }
    if (id == "led3") {
        if (atoi(data) == 1) {
            channelStatus[3] = 1;
            LED3.set(1);
            hMot3.setPower(-1000);
        }
        else {
            channelStatus[3] = 0;
            LED3.set(0);
            hMot3.setPower(0);
        }
    }
}

void button1_thread_loop() {
    while (true) {
        hBtn1.waitForPressed();
        if (channelStatus[1] == 1) {
            channelStatus[1] = 0;
            LED1.set(0);
            hMot1.setPower(0);
        }
        else {
            channelStatus[1] = 1;
            LED1.on();
            hMot1.setPower(-1000);
        }
        hBtn1.waitForReleased();
    }
}

void button2_thread_loop() {
    while (true) {
        hBtn2.waitForPressed();
        if (channelStatus[2] == 1) {
            channelStatus[2] = 0;
            LED2.set(0);
            hMot2.setPower(0);        
        }
        else {
            channelStatus[2] = 1;
            LED2.set(1);
            hMot2.setPower(-1000);        
        }
        hBtn2.waitForReleased();
    }
}

void hMain() {
    platform.begin(&Edison);
    platform.ui.setProjectId("@@@PROJECT_ID@@@");
    platform.ui.configHandler = cfgHandler;
    platform.ui.onValueChangeEvent = onValueChangeEvent;
    
    sys.taskCreate(button1_thread_loop);
    sys.taskCreate(button2_thread_loop);
    
    hSens1.pinIntAdc.enableADC();
    hSens2.pinIntAdc.enableADC();
    hSens3.pinIntAdc.enableADC();
    hSens4.pinIntAdc.enableADC();
    hSens5.pinIntAdc.enableADC();

	while(1) {
	    sensorReading1 = hSens1.pinIntAdc.analogReadVoltage();
	    sensorReading2 = hSens2.pinIntAdc.analogReadVoltage();
	    sensorReading3 = hSens3.pinIntAdc.analogReadVoltage();
	    sensorReading4 = hSens4.pinIntAdc.analogReadVoltage();
	    sensorReading5 = hSens5.pinIntAdc.analogReadRaw();
	    
        printf("s1: %f \r\n", sensorReading1);
        printf("s2: %f \r\n", sensorReading2);
        printf("s3: %f \r\n", sensorReading3);
        printf("s4: %f \r\n", sensorReading4);
        printf("s5: %d \r\n", sensorReading5);
        printf("============================\r\n");

	    //platform.ui.label("sensor1").setText(" %d ", sensorReading1);
	    //platform.ui.label("sensor2").setText(" %d ", sensorReading2);
	    //platform.ui.label("sensor3").setText(" %d ", sensorReading3);
	    //platform.ui.label("sensor4").setText(" %d ", sensorReading4);
	    //platform.ui.label("sensor5").setText(" %d ", sensorReading5);	    
	    sys.delay(500);
	}
}

Dominik,

I implemented the code you suggested and got the following results;

With nothing connected to hsens ports 1 -3 i get;
Lux: 3.061682 Temperature: -60.429634 Humidity: -39.616444

If I connect an led as a simple lux sensor, with no light i gives 0v and when I shine a torch on it i get 1.5 volts the reading doesn’t reflect the correct readings. What I get is;
Lux: 1.691719 Temperature: -60.429634 Humidity: -39.616444

Any thoughts?

Thanks,
Nathan

Hi Nathan,

please send us a schematic showing how you connected sensors do hSensor ports. To give you an answer we need to check whether everything is connected well.

Send us also a piece of code where you calculate Lux, Temperature and Humidity.

This should be all to give you an answer to your question.

Hey Dominik,

Im not converting the readings to lux, temp of humidity yet. The issue is i dont think its reading the voltages correctly. What I started using originally was a Phidgets lux sensor, continually getting nowhere i decided to use an led for detecting light no light conditions. using a multimeter i measured 0v when there was no light and 1.5v when a high powered led torch was pointed at it. the positive output of the led output was connected to the analog input.of hsens1 being pin 1 and the ground was connected to the ground of the hsens1 point this being pin 2.

i tried both of the examples you mentioned but the readings were not correct. below is the code Im using;

#include <math.h>
#include <hFramework.h>
#include <hCloudClient.h>

int channelStatus[6];
float sensorReading1 = 0;
float sensorReading2 = 0;
float sensorReading3 = 0;
float sensorReading4 = 0;
float sensorReading5 = 0;
//int sensorReading6 = 0;

void cfgHandler() {
    platform.ui.loadHtml({Resource::WEBIDE, "/index.html"});
}

void onValueChangeEvent(hId id, const char* data) {
    
    if (id == "led1") {
        if (atoi(data) == 1) {
            channelStatus[1] = 1;
            LED1.set(1);
            hMot1.setPower(-1000);
        }
        else {
            LED1.set(0);
            hMot1.setPower(0);
            channelStatus[1] = 0;
        }
    }
    if (id == "led2") {
        if (atoi(data) == 1) {
            channelStatus[2] = 1;
            LED2.set(1);
            hMot2.setPower(-1000);
        }
        else {
            channelStatus[2] = 0;
            LED2.set(0);
            hMot2.setPower(0);
        }
    }
    if (id == "led3") {
        if (atoi(data) == 1) {
            channelStatus[3] = 1;
            LED3.set(1);
            hMot3.setPower(-1000);
        }
        else {
            channelStatus[3] = 0;
            LED3.set(0);
            hMot3.setPower(0);
        }
    }
}

void button1_thread_loop() {
    while (true) {
        hBtn1.waitForPressed();
        if (channelStatus[1] == 1) {
            channelStatus[1] = 0;
            LED1.set(0);
            hMot1.setPower(0);
        }
        else {
            channelStatus[1] = 1;
            LED1.on();
            hMot1.setPower(-1000);
        }
        hBtn1.waitForReleased();
    }
}

void button2_thread_loop() {
    while (true) {
        hBtn2.waitForPressed();
        if (channelStatus[2] == 1) {
            channelStatus[2] = 0;
            LED2.set(0);
            hMot2.setPower(0);        
        }
        else {
            channelStatus[2] = 1;
            LED2.set(1);
            hMot2.setPower(-1000);        
        }
        hBtn2.waitForReleased();
    }
}

void hMain() {
    LED3.set(1);
    platform.begin(&Edison);
    platform.ui.setProjectId("9c6f661d18ff2452");
    platform.ui.configHandler = cfgHandler;
    platform.ui.onValueChangeEvent = onValueChangeEvent;
    
    sys.taskCreate(button1_thread_loop);
    sys.taskCreate(button2_thread_loop);

	hSens1.pinIntAdc.enableADC();
    hSens2.pinIntAdc.enableADC();
    hSens3.pinIntAdc.enableADC();
    hSens4.pinIntAdc.enableADC();
    hSens5.pinIntAdc.enableADC();

	while(1) {

	    sensorReading1 = hSens1.pinIntAdc.analogReadVoltage();
	    sensorReading2 = hSens2.pinIntAdc.analogReadVoltage();
	    sensorReading3 = hSens3.pinIntAdc.analogReadVoltage();
	    sensorReading4 = hSens4.pinIntAdc.analogReadVoltage();
	    sensorReading5 = hSens5.pinIntAdc.analogReadVoltage();
	    
	    float temperature = ((sensorReading2 * 0.22222) - 61.11);
	    float humidity = ((sensorReading3 * 0.1906) - 40.2);
	    
        printf("Lux: %f \r", sensorReading1);
        printf("Temperature: %f \r", sensorReading2);
        printf("Humidity: %f \r\n", sensorReading3);
        //printf("%f \r", sensorReading4);
        //printf("%f \r\n", sensorReading5);

	    platform.ui.label("sensor1").setText(" %f ", sensorReading1);
	    platform.ui.label("sensor2").setText(" %f ", sensorReading2);
	    platform.ui.label("sensor3").setText(" %f ", sensorReading3);
	    platform.ui.label("sensor4").setText(" %f ", sensorReading4);
	    platform.ui.label("sensor5").setText(" %f ", sensorReading5);	    
	    sys.delay(500);
	}
}

Hi Nathan, there is a pull-up resistor in the hSensor ADC port - https://wiki.robocore.io/hardware:hsensor . Phidgets lux sensor should work well on hSensor but you should make some math to calculate the output voltage of your sensor. If output resistance of your sensor is 1k Ohm (please check your model), it should be something like this:

Uadc = Us + (3.3V - Us)*(1k/(10k + 1k)) = Us + (3.3V - Us)/11
Us = (Uadc - (3.3V)/11 ) * 11 / 10

where:
Uadc - is the voltage you should read in your program
Us - output voltage of your sensor

If you don’t want to calculate proper value due to pull-up resistor, use ADC at hExt port - https://wiki.robocore.io/hardware:hext .

Hey Dominik,

I don’t understand how if the input is being pulled up to 3.3v and I’m inputting 1.5v max how I will see any change. I would expect it to remain at the higher voltage.

Is it possible to remove the pull-up resistor so I can see 0v-1.5?

Hi Nathan,

as you can see here: https://wiki.robocore.io/hardware:hsensor , ADC input of CORE2 is pulled-up using 10k Resistor and output resistance of your sensor is (if I found right model) : 1k. So there is a voltage divider with 10k and 1k, because input resistance of ADC in RoboCORE is very high. Read more how resistive voltage divider here ( Voltage Dividers - learn.sparkfun.com ) .

Before removing the pull-up resistor at hSensor, test your sensor at hExt port (there is also ADC at pin6 - https://wiki.robocore.io/hardware:hext , and is not pulled-up) and give us know how your sensor works. Here is an example: About Husarion's manuals | Husarion .

Hey Dominik,

I think I have a reading that is usable now in my code for the coop, thank you for your patience.
I have tried to reduce the decimal places using;

Original
printf(“Lux: %f \r”, lux);
platform.ui.label(“sensor1”).setText("%f", lux);
Lux: 34.073215 Temperature: 99.290009 Humidity: 99.290009

Modified
printf(“Lux: %.2f \r”, lux);
platform.ui.label(“sensor1”).setText("%.2f", lux);
Lux: 34.073215 Temperature: 99.290009 Humidity: 99.290009

Why would the modified not working?

Thanks,

Nathan

Hi Nathan,

This is because we have written our own implementation of printf that is minimized and optimized for embedded systems. In this implementation specifying precision is done in slightly other way:

printf("Lux: %2f \r", lux);
platform.ui.label("sensor1").setText("%2f", lux);

Hey Krystian,

Thanks for that, if one wanted no decimal place however, what would be the method. For things such as lux and humidity I don’t require any decimal places and it will look neater without them.

Regards,

Nathan

You can cast float to integer to get no decimal places:

printf("Lux: %d \r", (int)lux);

Thanks Krystian, this worked.

Hey Krystian,

I have a question on the analog readings obtained by RoboCore. I have connected to the RoboCore in hsen1 the lux output of the Phidgets lux module part no.1127_0 - Precision Light Sensor, in hsens2 I have the temperature sensor output of the Phidgets Temperature/Humidity module part no. 1125_0 - Humidity/Temperature Sensor, in hsens3 I have the humidity sensor output Phidgets Temperature/Humidity module part no. 1125_0 - Humidity/Temperature Sensor.

The code I’m using that you partly supplied and some that I obtained from the Phidgets website for converting the reading to usable values, currently using is;

    sensorReading1 = hSens1.pinIntAdc.analogReadVoltage() + (3.3 - sensorReading1) / 11;
    sensorReading2 = hSens2.pinIntAdc.analogReadVoltage() + (3.3 - sensorReading2) / 11;
    sensorReading3 = hSens3.pinIntAdc.analogReadVoltage() + (3.3 - sensorReading3) / 11;
    sensorReading4 = hSens4.pinIntAdc.analogReadVoltage() + (3.3 - sensorReading4) / 11;

    float lux = sensorReading1;
    float temperature = ((sensorReading2 * 0.1902) - 40.2); // convert to degress celsius
    float humidity = ((sensorReading3 * 0.22222) - 61.11);  // convert to % humidity
    float actuator = sensorReading4;

    printf("Lux: %d \r", (int)lux);
    printf("Temperature: %1f \r", temperature);
    printf("Humidity: %d \r", (int)humidity);
    printf("Actuator: %d \r\n", (int)actuator);

    platform.ui.label("sensor1").setText("%d", (int)lux);
    platform.ui.label("sensor2").setText("%1f", temperature);
    platform.ui.label("sensor3").setText("%d", (int)humidity);
    platform.ui.label("sensor4").setText("%d", (int)actuator);

The readings though are nothing like I was getting when they were connected to an Arduino board. How would one get the lux into 0 - 1000 lux, the temperature into -40 - 100 deg C, the humidity into 0 - 100%.

Thanks for your time

Hi, your problems are probably because of 10k pull-up resistors from hSensor ports (https://wiki.robocore.io/hardware:hsensor). You can calculate the voltage that goes to the ADC, or unsolder these pull-up resistors. But be careful and do it only if you have experience in soldering! And don’t unsolder all resistors - at first try with hSens1 (on the attached image this is first resistor in the red circle from the top) and check whether your problem has disappeared.