Sparky SBC Blink LED

Hi tech freaks, hobbyists, and professionals,

Getting your Hands Dirty with the Sparky SBC. This tutorial is indented to familiarize GPIOs of Sparky SBC .  Let’s Blink the builtin red LED in the sparky SBC first. Write a python script as below and save it as BuiltinLEDBlink.py some where inside the SBC.

__author__ = 'nithinkurian'
import os
class ElementzSparkyGPIO:
    def __init__(self):
        self.GPIO_PATH="/sbin/sparky_gpio "
        self.LOW   = '0'
        self.HIGH  = '1'
        self.pinMap=[-1,
                     -1,-1,-1,-1,-1,-1,46,-1,-1,-1,47,-1,48,-1,49,63,-1,62,-1,-1,
                     -1,44,-1,-1,-1,-1,-1,-1,-1,-1,50,35,36,-1,-1,45,51,-1,-1,-1
                     ]
        self.BUILTIN=114
    def set(self,pin,state):
        if pin!=self.BUILTIN:
            cmd = self.GPIO_PATH+str(self.pinMap[int(pin)])+" "+str(state)
        else:
            cmd = self.GPIO_PATH + str(self.BUILTIN) + " " + str(state)
        os.system(cmd)
if __name__ == '__main__':
    from time import sleep
    gpio = ElementzSparkyGPIO()
    while (1):
        gpio.set(gpio.BUILTIN, gpio.HIGH) # Built in Red LED
        sleep(1)
        gpio.set(gpio.BUILTIN, gpio.LOW)  # Built in Red LED
        sleep(1)

Run the code as python BuiltinLEDBlink.py . Then you can see that the red LED will be blinking in 2 second interval. Similary you can blink LEDs by connecting to any of the GPIO pins of Sparky SBC.

pinout

Let’s blink another LED by connecting it to pin 31 (GPIOB18). Write a python script as below and save it as LEDBlink.py

__author__ = 'pheonix'
import os
class ElementzSparkyGPIO:
    def __init__(self):
        self.GPIO_PATH="/sbin/sparky_gpio "
        self.LOW   = '0'
        self.HIGH  = '1'
        self.pinMap=[-1,
                     -1,-1,-1,-1,-1,-1,46,-1,-1,-1,47,-1,48,-1,49,63,-1,62,-1,-1,
                     -1,44,-1,-1,-1,-1,-1,-1,-1,-1,50,35,36,-1,-1,45,51,-1,-1,-1
                     ]
        self.BUILTIN=114
    def set(self,pin,state):
        if pin!=self.BUILTIN:
            cmd = self.GPIO_PATH+str(self.pinMap[int(pin)])+" "+str(state)
        else:
            cmd = self.GPIO_PATH + str(self.BUILTIN) + " " + str(state)
        os.system(cmd)
if __name__ == '__main__':
    from time import sleep

    pin = 31 # Board pin number 31, correseponds to GPIOB18
    gpio = ElementzSparkyGPIO()
    while (1):
        gpio.set(pin, gpio.HIGH)
        sleep(1)
        gpio.set(pin, gpio.LOW)
        sleep(1)

Run the code as python LEDBlink.py to blink the LED connected to pin 31.  We will be back with more and more tutorials about SPARKY SBC , thank you.

Previous

People with great passion can make the impossible happen

Advertisements

One thought on “Sparky SBC Blink LED

  1. Pingback: SSH Login to Sparky SBC | Random Codes - Elementz Tech Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s