Filter results by

Blink an LED

Having learned how to build and flash load an ARTIK 053 app, you'll be wanting to try it out. In this example, we'll do the IoT universe's equivalent of the famous "Hello World" program –- use ARTIK to blink an LED with the Sensor app.

The app works the same whether you're using the firmware that came pre-loaded on your module, you used the ARTIK IDE to build the SystemIO example, or you cross-compiled the sensorbd_demo from Linux. But depending on its build source, the command name may be either sensorbd or sensor .

For the first part of this tutorial, you won't need any additional hardware – you'll just run code to blink the built-in LEDs on the board. For the second part, you'll build an external circuit, like what you'd build for your own hardware application.

Using Built-in LEDs / Buttons

The Sensor Board test app has many options. The first test we'll run reads buttons on the board and turns on corresponding LEDs. It runs for several seconds and then exits.

  1. Identify the location of the buttons and LEDs.

  2. From the TASH> prompt, run
    sensor ledst

  3. Press and hold each button to see the corresponding LED illuminate.

Using External LED

Now that you've verified that the app is working, it's time to try your own external circuit.

Hardware Required

For this second part, you'll build an external circuit, just like what you'd use for a real application. You'll need:

  • ARTIK 053 Starter Kit
  • LED (SMD 2012 is one example)
  • One ~10 kohm and one ~200 ohm resistor
  • One NPN transistor (MMBT3904 is one example)

The resistor values are not crucial; approximate matches work too. Likewise, the LED and transistor do not have to match these numbers; just make sure you use an NPN transistor, and that you know its pinout – find its datasheet online and adjust your wiring if its pin orientation is not E-C-B.

Build the Circuit

Here you'll be building the same circuit that is on the board for the red LED.

Make the connections as shown, assuming you have a transistor with pinout E-C-B:

  • Emitter (left pin) to GND
  • Collector (center pin) to LED Cathode
  • Base (right pin) through ~10 kohm resistor to CON703 pin 21 (gpio51)
  • LED Anode through ~200 ohm resistor to 3.3V

If you don't know the orientation of your LED, it won't hurt to install it backwards and then reverse it if it doesn't light.

Run the code

From the TASH> prompt, run
sensor led

You should see the LED blinking according to the code. If not, disconnect the wire from CON703 pin 21 and connect it to 3.3V to verify that the LED lights; if it doesn't, check your wiring.

If it works as expected, feel free to play with the code and with the wiring to test other GPIO pins!

You've wired up a very flexible control circuit. It's not limited just to LEDs. For example, depending on the transistor and resistor choices, you can activate relays and possibly even small motors.

Mapping the code to the pins

As you can see, the program is hard-coded to use gpio 51-55, 39, and 41. You'll find that mapping in the ARTIK 053 Header Map – leave it open for reference. Note that:

  • gpio 51-55 map into pins 21-19-17-15-13 of CON703

  • gpio 46-48 and 50 map into the Arduino-friendly connector

  • gpio 39 and 41 map into pins 11 and 9 of CON704.

The 'XGPIO' numbers you see on the headers are the module schematic names for the same signals. You probably won't need to use these for anything until you do your own printed circuit board design.

Summary

Now that you know how the gpio code maps to the header pins, you can change the code as you like to create your own app. The ARTIK 053 GPIO pins are quite simple to adapt to your needs. Just start with an existing app and modify it to your liking!

If you are trying to use an Arduino shield that requires the ARTIK GPIO outputs to be driven, you may find that you need to modify it with a circuit similar to the one shown here to obtain the necessary drive strength.

Last updated on: