Samsung ARTIK 530 GPIO PIN programming
来源:互联网 发布:温暖的句子 知乎 编辑:程序博客网 时间:2024/05/18 06:26
- Summary
- ARTIK 530 LED and Switch GPIO
- Blink LED
- Use Switch to Control LED
- Reference
Summary
Tested ARTIK 530 on the GPIO function, implemented the switch to control the LED light on and light off, with successful result.
ARTIK 530 LED and Switch GPIO
For ARTIK 520, the board already implement an LED circuit, so no need to prepare the switch and LED, the GPIO number shows as below,
On the Artick 530 board Switch and LED looks like below,
Blink LED
Follow this Link, you can use Arduino IDE, Python or C to control the LED.
Below shell command can shows controlling the blue LED (GPIO 38). Blue light will light on and off.
[root@artik ~]# echo 38 > /sys/class/gpio/export[root@artik ~]# echo out > /sys/class/gpio/gpio38/direction[root@artik ~]# echo 1 > /sys/class/gpio/gpio38/value[root@artik ~]# echo 0 > /sys/class/gpio/gpio38/value[root@artik ~]# echo 38 > /sys/class/gpio/unexport[root@artik ~]#
Python code can be downloaded, tested and it’s working properly, here I am using c code below to control the Blue light on and off every one second.
/* ============================================================================ Name : main.c Author : Xiong HuiLin Version : Copyright : No Description : Hello World in C ============================================================================ */#include <stdio.h>#include <string.h>#include <stdlib.h>#include <unistd.h>#define HIGH 1#define LOW 0#define INPUT 1#define OUTPUT 0FILE *fp;FILE *p=NULL;int pin_input = 38;/* * * Print a greeting message on standard output and exit. * * On embedded platforms this might require semi-hosting or similar. * * For example, for toolchains derived from GNU Tools for Embedded, * to enable semi-hosting, the following was added to the linker: * * --specs=rdimon.specs -Wl,--start-group -lgcc -lc -lc -lm -lrdimon -Wl,--end-group * * Adjust it for other toolchains. * */intmain(void){ printf("Hello ARM World!" "\n"); char fName[128]; //linux equivalent code "echo 139 > export" to export the port if ((fp = fopen("/sys/class/gpio/export", "w")) == NULL){ printf("Cannot open export file.\n"); exit(1); } fprintf( fp, "%d", pin_input ); fclose(fp); // linux equivalent code "echo low > direction" to set the port as an input sprintf(fName, "/sys/class/gpio/gpio%d/direction", pin_input); if ((fp = fopen(fName, "w")) == NULL){ printf("Cannot open direction file.\n"); exit(1); } fprintf(fp, "out"); fclose(fp); for(int i=0;i<100;i++) { sprintf(fName, "/sys/class/gpio/gpio%d/value", pin_input); p = fopen(fName,"w"); fprintf(p,"%d",1); sleep(1); fclose(p); sprintf(fName, "/sys/class/gpio/gpio%d/value", pin_input); p = fopen(fName,"w"); fprintf(p,"%d",0); sleep(1); fclose(p); } p = fopen("/sys/class/gpio/unexport","w"); fprintf(p,"%d",pin_input); fclose(p); printf("End1!!!" "\n"); return 0;}
The result shows as below video,
Use Switch to Control LED
Follow this Link to read the Button / Switch. Below c code to read Switch 403 (pressed status) to light on the Red LED, and read Switch 404 (pressed status) to light off the Red LED.
/* ============================================================================ Name : main.c Author : Xiong HuiLin Version : Copyright : No Description : Hello World in C ============================================================================ */#include <stdio.h>#include <string.h>#include <stdlib.h>#include <unistd.h>#include <stdbool.h>#define HIGH 1#define LOW 0#define INPUT 1#define OUTPUT 0FILE *fp;FILE *p=NULL;int pin_input = 38;/* * * Print a greeting message on standard output and exit. * * On embedded platforms this might require semi-hosting or similar. * * For example, for toolchains derived from GNU Tools for Embedded, * to enable semi-hosting, the following was added to the linker: * * --specs=rdimon.specs -Wl,--start-group -lgcc -lc -lc -lm -lrdimon -Wl,--end-group * * Adjust it for other toolchains. * */bool digitalPinMode(int pin, int dir){ FILE * fd; char fName[128]; //Exporting the pin to be used if(( fd = fopen("/sys/class/gpio/export", "w")) == NULL) { printf("Error: unable to export pin\n"); return false; } fprintf(fd, "%d\n", pin); fclose(fd); // Setting direction of the pin sprintf(fName, "/sys/class/gpio/gpio%d/direction", pin); if((fd = fopen(fName, "w")) == NULL) { printf("Error: can't open pin direction\n"); return false; } if(dir == OUTPUT) { fprintf(fd, "out\n"); } else { fprintf(fd, "in\n"); } fclose(fd); return true;}int digitalRead(int pin) { FILE * fd; char fName[128]; char val[2]; //Open pin value file sprintf(fName, "/sys/class/gpio/gpio%d/value", pin); if((fd = fopen(fName, "r")) == NULL) { printf("Error: can't open pin value\n"); return false; } fgets(val, 2, fd); fclose(fd); return atoi(val);}bool digitalWrite(int pin, int val) { FILE * fd; char fName[128]; // Open pin value file sprintf(fName, "/sys/class/gpio/gpio%d/value", pin); if((fd = fopen(fName, "w")) == NULL) { printf("Error: can't open pin value\n"); return false; } if(val == HIGH) { fprintf(fd, "1\n"); } else { fprintf(fd, "0\n"); } fclose(fd); return true;}intmain(void){ printf("Hello ARM World!" "\n"); //LED //– Red LED: sysfs GPIO 28 on ARTIK 530/710 //– Blue LED: sysfs GPIO 38 on ARTIK 530/710 //sysfs GPIO 30 for SW403 (next to board edge, alongside Red LED) //sysfs GPIO 32 for SW404 (alongside Blue LED) do { digitalPinMode(30,INPUT); //INPUT = 1 printf("digitalPinMode(30,INPUT)!" "\n"); if (!digitalRead(30)) { digitalPinMode(28,OUTPUT); //OUTPUT = 0 digitalWrite(28,HIGH); //HIGH = 1 } printf("11111111111111111111111111" "\n"); digitalPinMode(32,INPUT); if (!digitalRead(32)) { digitalPinMode(28,OUTPUT); //OUTPUT = 0 digitalWrite(28,LOW); //HIGH = 1 } printf("22222222222222222222222222222" "\n"); } while(true); printf("End1!!!" "\n"); return 0;}
The result is as below video shows,
Reference
Samsung ARTIK Pin Programming
Samsung ARTIK Blink an LED
Samsung ARTIK Reading a Button
Samsung ARTIK Programmable Pins
Samsung ARTIK GPIO Header Maps
- Samsung ARTIK 530 GPIO PIN programming
- Samsung ARTIK 530 Image Update
- Samsung ARTIK 530 connect ARTIK Cloud by using Node-RED
- Samsung ARTIK 530 use Arduino IDE
- Samsung ARTIK 530 test on Node-RED
- Samsung ARTIK 530 cloud connectivity test
- Samsung ARTIK 530 Wi-Fi Access Point (AP) and Wi-Fi Direct (P2P)
- Samsung ARTIK Wi-Fi Client Configuration
- ARTIK 530 use Eclipse IDE for Windows
- Having trouble with a BeagleBoard GPIO interrupt pin
- Win10 IoT C#开发 2 - GPIO Pin 控制发光二极管
- mt2523 [keypad]how to config keydata mapping with GPIO pin?
- pin
- Osless programming on mini2440--GPIO LED
- linux内核中的GPIO系统之(2):pin control subsystem
- Linux内核中的GPIO系统之(3):pin controller driver代码分析
- linux内核中的GPIO系统之(2):pin control subsystem
- linux内核中的GPIO系统之(2):pin control subsystem
- 中国大数据和人工智能技术大会DACon2017将于7月在上海举行!
- 隐藏响应头apache和php版本号
- win10系统安装了多个版本的JDK如何切换
- windows编译生成protobuf库(使用minGW编译)
- struts2之Tabbedpanel标签实现选项卡
- Samsung ARTIK 530 GPIO PIN programming
- AS上传资源的时候,不需要的文件夹
- DWR3 学习笔记
- UVa 1592Database(map的妙用)
- 图像识别的深度残差学习
- Mybatis介绍
- 19、linux分区fdisk与自动挂载
- 微信动态生成分享链接
- ip地址段的