Announcement

REXYGEN forum has been moved. This one is closed.
Head over to the new REXYGEN Community Forum at https://forum.rexygen.com.

Looking forward to meeting you there!
 

#1 2016-04-11 18:01:59

tomwoehlke
Member
Registered: 2016-04-11
Posts: 2

Start of I2C TSL2561 lux sensor REXLANG block and question about param

Hello,

I just wanted to say that Rex Draw is my introduction to PLC software and I think it is really cool, same with the rpi rex core.

Last night I finished a very crude REXLANG block for hooking up an I2C TSL2561 lux sensor to the raspberry pi. I was hoping I could maybe get some input on the block and then hopefully add it to the github Rex I2C repository after I add a few more features.

In it's current state It uses the default gains and integration times, with no interrupts, to add them I want to use parameters, but I'm struggling with them.

In the .c file I state:

double parameter(0) paramZero; //testing parameters
double output(0) paramZero; //testing parameters

In the tsl2561_task.mdl file I specified parameter p0 to be '1', but when I track the y0 value it says the output is '0'. Probably something I overlooked, but it seems to be in line with the example in the Rex Function Block documentation on I2C.

Another minor issue I'm having is when I open the tsl2561_exec file it does not also open the tsl2561_task file, I have to open them separately, how do I fix that?

I uploaded tsl2561_task.mdl, tsl2561_exec.mdl, and tsl2561.c file.

tsl2561_task.mdl
tsl2561_exec.mdl
tsl2561.c

Last edited by tomwoehlke (2016-04-11 18:03:19)

Offline

#2 2016-04-12 08:23:43

tomáš čechura
Administrator
Registered: 2016-02-22
Posts: 371

Re: Start of I2C TSL2561 lux sensor REXLANG block and question about param

Hello tomwoehlke,

first of all, let me thank you for your question and mainly for your will to share your code with our community. This can save others hours of coding and debugging wink Thank you!

According to your issue with parameters:
Unfortunately I don't have the TSL2561 to test your project, however it seems that the executive is not running and therefore the output of "p0" is not assigned yet. Did you make it work and received any data from the sensor?
See REXLANG output "iE" for errors. You can also inspect task diagnostics to see if the executive is running as it should be. Open RexView, connect to your running target, select the task in the left tree view, choose "Task" tab and tick "Enable":

task_diagnostics2.png

It is also good to check "System log" tab to see any errors and their short description which can serve as a hint in debugging.

Opening the project files together:
When I downloaded your files and executed "tsl2561_exec.mdl" it also opened the task file. However, try to open manually both exec file and task file in one RexDraw. Click to the exec file and go to menu: File --> Set as main. Hope it will solve your issue.

One more thing to your code - check variable i2c_bufTx for typo in indexes of read Ch.0 H, Ch.1 L and Ch.1 H:

    i2c_bufTx[0] = 0x8D; //there should be zero index I think

Let us know about your progress.

Good luck!
Tomas

Last edited by tomáš čechura (2016-04-12 09:54:26)

Offline

#3 2016-04-12 09:49:41

tomáš čechura
Administrator
Registered: 2016-02-22
Posts: 371

Re: Start of I2C TSL2561 lux sensor REXLANG block and question about param

Edit to the parameter issue:

The problem is in variable declaration. The first declaration of paramZero is overwritten by the second one. This is a bug - the compile process should have ended up with an error.

Please try this workaround:

Declaration:

double parameter(0) paramZero; //testing parameters
double output(0) output0; //testing parameters

Add to main method:

output0 = paramZero;

Regards, Tomas

Offline

#4 2016-04-12 15:54:42

tomwoehlke
Member
Registered: 2016-04-11
Posts: 2

Re: Start of I2C TSL2561 lux sensor REXLANG block and question about param

[Edit: You are right about the Tx buffer index, but when I changed them back to zero I'm getting no output, I'll have to look more into this later, it probably means Channel Zero is reading as zero.]

I implemented your changes and the params are working now. I'll upload the fixed code. I changed some of the variable names to more closely match the documentation I've read so far; i.e. paramZero is changed to param_p0. No changes were made to the exec or task functions

tsl2561.c
tsl2561_task.mdl
tsl2561_exec.mdl

Before the compiler did not produce any errors; Tracking the function block gave an IE 000: Success output, and the y_10 output was changing for different light levels, but the y_0 output did not match the parameter input, I see now why that is. Thanks for the first post on tracking variables, as the .c file gets more robust from adding intregration times and gains.

Thomas

Last edited by tomwoehlke (2016-04-12 16:01:29)

Offline

Board footer

Powered by FluxBB