삼성 아틱 (ARTIK) 710S와 조도센서 ADC 아두이노 IDE 예제 / C언어

메이커 2018-09-11 (화) 09:23 5년전 2133  

본 튜토리얼의 전체 PDF는 다음의 링크에서 참고하실 수 있습니다. 

 

https://goo.gl/JVMp9q 



1f7c3ee5d7e718d5cf0b1a77c77892dc_1536643


아두이노 IDE 사용

 

1.    OTG, Debug 케이블 연결 후

2.    VCC-5V, GND-GND, SIG-ADC1

3.    Putty 접속 후, 터미널에서 /root/watcher 입력

4.    아두이노에서 삼성 아틱의 COM포트 설정

5.    소스코드 업로드

 

 

#include <DebugSerial.h>

int sensorpin = 1;

void setup()

{

   DebugSerial.begin(115200); 

}

 

void loop()

{

   DebugSerial.println(analogRead(sensorpin));

   delay(1000);

}

 

 

6.    Putty로 모니터링


1f7c3ee5d7e718d5cf0b1a77c77892dc_1536643

C언어 사용시

#include <stdio.h>

#include <stdlib.h>

#include <stdbool.h>

 

#define HIGH            1

#define LOW 0

 

#define ANALOG_PIN          0 // A0

#define PWM_PIN 0

 

#define PERIOD 1000000

 

bool pwmPin(int pin, int period, int duty_cycle, int enable){

    FILE * fd;

    char fName[128];

 

    if(( fd = fopen("/sys/class/pwm/pwmchip0/export", "w")) == NULL) {

        printf("Error: unable to export pin\n");

        return false;

    }

    fprintf(fd, "%d\n", pin);

    fclose(fd);

 

    sprintf(fName, "/sys/class/pwm/pwmchip0/pwm%d/period", pin);

    if((fd = fopen(fName, "w")) == NULL) {

        printf("Error: can't open pin period\n");

        return false;

    }

    fprintf(fd, "%d\n", period);

    fclose(fd);

 

    sprintf(fName, "/sys/class/pwm/pwmchip0/pwm%d/duty_cycle", pin);

    if((fd = fopen(fName, "w")) == NULL) {

        printf("Error: can't open pin duty_cycle\n");

        return false;

    }

    fprintf(fd, "%d\n", duty_cycle);

    fclose(fd);

          

메카리워즈 Image Map


모바일 버전으로 보기