How to use impExplorer grove ports for LED

I’m extremely new at this stuff. I know how to get the impExplorer’s own LED to work, but I want to use an LED connected to one of the grove ports and I can’t for the life of me figure out how to get it working. Will any kind person help me out?
For reference this is the LED I’m using; http://wiki.seeed.cc/Grove-LED_Socket_Kit/

First things first. Figure out which pins you want to use: https://electricimp.com/docs/hardware/imp/pinmux/

To understand what you can do with your device’s IO pins read this: https://electricimp.com/docs/api/hardware/

For Grove LED you just need a digital output pin.

Then write some device code. Something like:

//Define a pin for Grove LED to connect to LED <- hardware.pin1; // if you're using IMP001/IMP002 //LED <- hardware.pinA // if you're using IMP003/004 etc.

// This is your one and only function. Can call it what you like.
function loop() {
local LEDstate = !LED.read();
LED.write(LEDstate);
// Set the imp to trigger this function again in 0.5 seconds’ time
imp.wakeup(0.5, loop);
}

// configure your PIN name as a digital output pin with 0 start state
LED.configure(DIGITAL_OUT);

// Start of IMP device firmware
// Simply initiate your function and it will continue running due to repeating wakeup() function
loop();

1 Like

On the impExplorer Grove A0/D0 is pin 2, A1/D1 is pin 5, so as Gerrikoio says, you need to set these as DIGITAL_OUT as per the code above, eg.

LED <- hardware.pin2;
LED.configure(DIGITAL_OUT, 0);

You also need to add the following line to your code, to manage the board’s power gate:

hardware.pin1.configure(DIGITAL_OUT, 1);

For full details see our impExplorer technical page: https://electricimp.com/docs/hardware/resources/reference-designs/explorerkit/

That seems to be the thing about the Imp Explorer. With the April board, the breakout is layed-out with the pins in a row, numbered. With the Explorer, the pins go to the Grove connectors and the board also has other built-in sensors. Maybe someone should create a graphic map (or visual chart) that shows where the Grove pins match a normal April board?

Thank you very much. Very helpful!

So can the LEDs only be used with pins 2 & pin 5?

Those are the pins which drive, respectively, the A0/D0 and A1/D1 pins on the impExplorer board. So hardware.pin2 and hardware.pin5 are the imp API objects you use to control any Grove LED modules you plug into the impExplorer’s Analog/Digital connectors.

If you are not using I2C devices, you could plug an LED module into either of the impExplorer’s two Grove I2C connectors, in which case you’d control the LED with hardware.pin8, since the imp’s pin 8 is wired to the two I2C connectors’ SCL ports.

As mlseim says, the impExplorer doesn’t expose the imp001’s pins directly. For example, pin 7 is used to drive the RGB LED, and you can only use pin 7 for that purpose. Pin 1 is used solely for controlling the impExplorer’s power gate and as the interrupt signal line from the three sensors. You can’t use it as a general GPIO pin because, like pin 7, it’s not exposed as a pin on the board. Check out the board schematics via the link in my previous post.

If you want access to all of the imp001’s pins, you need April, our standard imp001 dev board, or one of the various imp module breakout boards (full details here — these have a lot more GPIO too).

1 Like

Okay, thank you a lot. While you’re hear. Do you happen to know if I can control the brightness of the LED with this rotary angle sensor?

I suppose you could connect the angle sensor to A1/D1 and set pin 5 as an analog input to get a reading between 0 and 65535. If you connect the LED to A0/D0 and set pin 2 as a PWM output with the duty cycle set by dividing the pin 5 reading by 65535 (to get a value in the range 0.0 - 1.0). Your code would be something like:

// Set the power gate for analog/digital operation
hardware.pin1.configure(DIGITAL_OUT, 1);

// Set up the pins
sensor <- hardware.pin2;
sensor.configure(ANALOG_IN);
led <- hardware.pin5;
led.configure(PWM_OUT, 0.001, 1.0);

function loop() {
    // Read analog value (0-65535)
    local a = sensor.read();
    // Convert to duty cycle value 0.0-1.0
    a = a / 65535.0;
    // Write to LED pin
    led.write(a);
    // Pause 0.5s then loop
    imp.wakeup(0.5, loop);
}

// Start the loop
loop()

Note that this code is guess-work, ie. it’s not tested or guaranteed to work!

That code made a flashing LED that i could control the speed of! Not exactly what I was looking for but I really appreciate your help and effort none the less! Thanks :slight_smile:

In that case try replacing the appropriate line above with

led.configure(ANALOG_OUT);

You actually already have an LED. The RGB LED. You can make it any color, any brightness by sending R,G,B values to it. Read the rotary sensor and write values to the RGB LED. You can add more RGB LED’s too, in a chain and address them individually. The same thing as the Imp tail (RGB tail).