Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
James Stephanick
Published © CC0

Let's Get Started: The ARTIK 5 Beta Development Board

Getting started on the Samsung ARTIK 5 beta board and controlling its I/O pins using Python.

BeginnerFull instructions provided2,657
Let's Get Started: The ARTIK 5 Beta Development Board

Things used in this project

Hardware components

ARTIK 5
Samsung ARTIK 5
×1

Story

Read more

Code

Python source code to control ARTIK 5's I/O

Python
to execute, first change the file's mode to executable (chmod +x hello.txt), and then execute with elevated permissions (sudo ./hello.txt)
#!/usr/bin/python

import time

print "Hackster.io demo of Artik digital and analog inputs"

# export pin 121 by opening file and writing the pin number to it
pinctl = open("/sys/class/gpio/export","wb",0);
pinnum = 121
try:
	pinctl.write( str(pinnum) )
	print "exported pin",str(pinnum)
except:
	print "assuming pin",str(pinnum),"is already exported"
pinctl.close()

# set pin 121 to be a digital input
pinctldir = open("/sys/class/gpio/gpio121/direction","wb",0)
try:
	pinctldir.write( "in" )
	print "pin set to read"
except:
	print "failed to set pin direction"
pinctldir.close()

# loop once every second checking the sensors
while True:
	# read the digital pin
	pin = open("/sys/class/gpio/gpio121/value","rb",0)
	print "digital value read is:",pin.read(2)
	pin.close()
	
	# read then analog pin
	pin = open("/sys/devices/126c0000.adc/iio:device0/in_voltage0_raw","rb",0)
	print "analog value read is:",pin.read(8)
	pin.close()
	
	# go to sleep for a second
	time.sleep(1)

Credits

James Stephanick
4 projects • 33 followers
Contact

Comments

Please log in or sign up to comment.