NXT Light sensor


#1

Hi there,
Just started using Bricktronics.
I only have NXT sensors here (no color sensor, only light).
I’ve downloaded the light sensor libraries from github but appears that the Arduino IDE is not compatible to the libs C++ coding.
Any workaround for that?
Thanks
Alexandre.


#2

Hey there, is this the repository you are talking about?

I don’t think we’ve officially released that library, but I seem to remember that it was at least compiling without errors the last time I was working on it. We have been slowly trying to upgrade our Bricktronics libraries to a more logical cross-platform structure, so they can work on non-Arduino platforms and not have so much duplicate code for both Bricktronics Shields and Bricktronics Megashields, etc. I will take a look at it later today to see where we’re at with this specific library.

Sorry about that, expect to hear back later today.


#3

Just found the issue. I had forgotten to fix one of the BricktronicsLight object constructors after I renamed a configuration struct to BricktronicsSensorSettings. Details of the change are here:

The code compiles for all three base use cases: With the BricktronicsShield library, with the BricktronicsMegashield libray, and standalone with the Bricktronis Breakout Board.

Let us know how it goes!


#4

Dear Layne,

Thank you. I’m up and running my lightsensor now.

Now I’m having another issue: when I put together the following libraries (mixing new and old sensor libs) (code without # and “” and <> ) :

include BricktronicsLight.h // for the light sensor
include Wire.h
include Adafruit_MCP23017.h
include BricktronicsShield.h

include Bricktronics.h // for the motors

I’m having errors regarding the duplication of the adafruit library

… multiple definition of `Adafruit_MCP23017 …

Can both bricktronics libs work together?

Thanks.
Best, Alexandre.


#5

Hi,

We are currently in the process of upgrading how all our libraries work, since we’ve found some better ways to handle including third-party libraries from the Wayne and Layne libraries. Technically all the individual libraries on our github are pre-release libraries (such as the light sensor library).

The only officially-released Bricktronics code is here: https://github.com/wayneandlayne/Bricktronics/tree/master/software

I don’t think we’ve finished the “new style” motor library, and it isn’t going to work to combine new-style and old-style bricktronics libraries. I can’t remember if we finished the new BricktronicsMotor, but you can give it a shot here:

Hopefully I can find time to take another look at this this weekend.


#6

Dear Layne,
I tried to use a library BricktronicsLight.h, with the configuration 2, to Arduino Mega.
But when I compile the sketch, I have the folowing error:

LightSensor:47: error: ‘SENSOR_4’ is not a member of ‘BricktronicsMegashield’
‘SENSOR_4’ is not a member of ‘BricktronicsMegashield’

How can I fix this?
I only have NXT sensors here (no color sensor, only light).

Thanks.

Rachel


#7

Hi Rachel,

Please post your sketch, it is very difficult to help without seeing the code.

I have been working actively on these arduino libraries this past weekend, so there may be newer versions available since you last tried this library. Please re-download from github to try the latest library code.


#8

Dear Layne,
actyally, I downloaded yersterday. So, I think I’m using the last version for this library.
I’m using the example included in the library BricktronicsLight-master, LightSensor.ino.
Above the sketch:

#include <BricktronicsLight.h>
Config 2 - arduino:avr:mega:cpu=atmega2560
#include <BricktronicsMegashield.h>
BricktronicsLight ls(BricktronicsMegashield::SENSOR_4);

void setup()
{
Serial.begin(115200);

// Only call this if you are using a Bricktronics Shield,
// otherwise leave it commented-out.
// Config 1 - arduino:avr:uno
//BricktronicsShield::begin();
// Config end

ls.begin();
}

void loop()
{
Serial.print("Raw value: “);
Serial.print(ls.value());
Serial.print(” - scaled value: ");
Serial.println(ls.scaledValue());

// Flash the light sensor’s built-in led, just for fun
ls.setFloodlightAlways(true);
delay(100);
ls.setFloodlightAlways(false);

delay(500);
}

Try to compile this sketch. The error is:
LightSensor:47: error: ‘SENSOR_4’ is not a member of ‘BricktronicsMegashield’
‘SENSOR_4’ is not a member of ‘BricktronicsMegashield’

Thanks,
Rachel


#9

That is very strange, when did you download the BricktronicsMegashield library? Is there a SENSOR_4 defined in the BricktronicsMegashield.cpp file? How does that file compare with the one in git: https://github.com/wayneandlayne/BricktronicsMegashield/blob/master/BricktronicsMegashield.cpp


#10

Layne, I download from site http://www.wayneandlayne.com/bricktronics/downloads/#hardware.
Isn’t work?

Rachel


#11

Dear Layne,
It all worked out now. But it was not quite what I wanted.
I do not want to abuse your goodwill, but I would like a sketch I could do the sensor readings. I could not do it.
Can you help me?
Thankfully.


#12

Hi Rachel, I’m really glad that it has started working! Please do not worry about our goodwill, we are very happy to help people. :smile: It is honestly the best part of my work with Wayne and Layne!

Which kind of sensor readings do you mean? The readings from the light sensor? What kind of readings do you have, with the sketch above? What kind of readings do you want to have?