'연결'에 해당되는 글 2건

자 그럼 스타트는 라즈베리파이를 먼져 열고 시작해 보겠습니다.

 

푸티를 열어주고

 


잘됫으

 

 

아두이노 설치부터 해야됨

 

  $ sudo apt-get install arduino

끗!!

  $ sudo usermod -a -G tty pi

  $ sudo usermod -a -G dialout pi

 

똭 써주고

뭔가 됫음 근뭔지는 모름 일단 됫음

그리고 파일하나 만들자

 

/*
 Pi_Serial_test.cpp - SerialProtocol library - demo
 Copyright (c) 2014 NicoHood.  All right reserved.
 Program to test serial communication
 
 Compile with:
 sudo gcc -o Pi_Serial_Test.o Pi_Serial_Test.cpp -lwiringPi -DRaspberryPi -pedantic -Wall
 sudo ./Pi_Serial_Test.o
 */
 
// just that the Arduino IDE doesnt compile these files.
#ifdef RaspberryPi 
 
//include system librarys
#include <stdio.h> //for printf
#include <stdint.h> //uint8_t definitions
#include <stdlib.h> //for exit(int);
#include <string.h> //for errno
#include <errno.h> //error output
 
//wiring Pi
#include <wiringPi.h>
#include <wiringSerial.h>
 
// Find Serial device on Raspberry with ~ls /dev/tty*
// ARDUINO_UNO "/dev/ttyACM0"
// FTDI_PROGRAMMER "/dev/ttyUSB0"
// HARDWARE_UART "/dev/ttyAMA0"
char device[]= "/dev/ttyACM0";
// filedescriptor
int fd;
unsigned long baud = 9600;
unsigned long time=0;
 
//prototypes
int main(void);
void loop(void);
void setup(void);
 
void setup(){
 
  printf("%s \n", "Raspberry Startup!");
  fflush(stdout);
 
  //get filedescriptor
  if ((fd = serialOpen (device, baud)) < 0){
    fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
    exit(1); //error
  }
 
  //setup GPIO in wiringPi mode
  if (wiringPiSetup () == -1){
    fprintf (stdout, "Unable to start wiringPi: %s\n", strerror (errno)) ;
    exit(1); //error
  }
 
}
 
void loop(){
  // Pong every 3 seconds
  if(millis()-time>=3000){
    serialPuts (fd, "Pong!\n");
    // you can also write data from 0-255
    // 65 is in ASCII 'A'
    serialPutchar (fd, 65);
    time=millis();
  }
 
  // read signal
  if(serialDataAvail (fd)){
    char newChar = serialGetchar (fd);
    printf("%c", newChar);
    fflush(stdout);
  }
 
}
 
// main function for normal c++ programs on Raspberry
int main(){
  setup();
  while(1) loop();
  return 0;
}
 
#endif //#ifdef RaspberryPi

 

 

 

미쿡 형이 잘 설명도 써놧음 찬찬 히 읽으면 이해됨

 

나는 시리얼 보드벤드?? baud??? 이거 115200 이라 

바꿔줫음

 

그리고 실행!!

아 

이거 아두이누는 

이렇게 넣어주고

 

#include <DHT.h>
#define DHTTYPE DHT11

int pinGnd = 4;
int pinVcc = 3;
int pinDht = 2;

DHT dht(pinDht, DHTTYPE);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(pinVcc, OUTPUT);
  pinMode(pinGnd, OUTPUT);
  digitalWrite(pinVcc, HIGH);
  digitalWrite(pinGnd, LOW);

  dht.begin();
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(2000);
  float fTemp = dht.readTemperature();
  float fHumi = dht.readHumidity();

  if(isnan(fTemp) || isnan(fHumi)) {
    Serial.println("Falled to read from DNT semsor!");
    return;
  }
  Serial.print("Temperature : ");
  Serial.print(fTemp);
  Serial.print("[C]\t ");
  Serial.print("Humidity: ");
  Serial.print(fHumi);
  Serial.print("%\n");    
  }

이거 칩 셋팅은

 

 

이렇게 햇음

 

 

자그럼 작성도 다됫고

 $ dmesg|tail

아두이노 잘 읽히나 잘보고

 

 

$ sudo gcc test.c -o hello -l wiringPi -DRaspberryPi

  $ sudo ./hello

이렇게

잘 만들어주면

습도 보내기 완료!!

좋았스~

 

 

 

 

블로그 이미지

Or71nH

,

 

 

사람들이 너무 쉬워서 무시하는 경향이 있지만 쉽게 만들수 있으면 

더좋은 시대가 왔다

 

 

 

인터럭트(interrunt)

운영체제가 없기 때문에 쓰레드흉내내는 

함수들이 있다

 

라즈베리파이 아두이노
장점 단점 장점 단점
데이터를 모으는 중간관리제어 안되는 것이 있다. 센싱하고 운전하고  멀티쓰레드가 안된다

 

 

아두이노는 센서 입장에서 생각을 하며 영어를 읽어야한다

 

 

###아두이노 보드판

16000 심장 수정으로 진동시커 신호를 줌
DIGITAL 13 디지털 값을 받는다
  12 디지털 값을 받는다
  ~11 빠르게 되는 디지털 값을 받는다
  ~10 빠르게 되는 디지털 값을 받는다
  ~9 빠르게 되는 디지털 값을 받는다
  8 디지털 값을 받는다
  7 디지털 값을 받는다
  ~6 빠르게 되는 디지털 값을 받는다
  ~5 빠르게 되는 디지털 값을 받는다
  4 디지털 값을 받는다
  ~3 빠르게 되는 디지털 값을 받는다
  2 디지털 값을 받는다
  TX ->1 입력을 한다(센서에 출력을 한다
  RX<-0 출력을 한다(센서에 입력을 한다)
ANALOG IN A0 아날로그 값을 받는다
  A1 아날로그 값을 받는다
  A2 아날로그 값을 받는다
  A3 아날로그 값을 받는다
  A4 아날로그 값을 받는다
  A5 아날로그 값을 받는다
POWER IOREF 전원이라고 하신거같음
  RESET 1값이면 리셋
  3.3V 3.3V전압출력
  5V 5V전압출력
  GND ??
  GND ??
  VIN ??

https://www.arduino.cc/

 

Arduino - Home

 

www.arduino.cc

 

 

 

다운하자

 

 

 

아두이노(arduino드라이버가 설치가 안되있다

설치파일 드라이버 눌러서

USB 인식 안된곳을 업데이트해준다

위치는

아두이노 설치한곳에 드라이브라고 된 파일을 선택

 

 

생김 됨

 

 

 

 

다운로딩

업로딩을 

해보자

시리얼 포트가 생겻다

C:\arduino-1.8.10-windows\arduino-1.8.10\hardware\arduino\avr\cores\arduino

여기에 메인 함수가 숨어있다

이와같이 메인 함수가 아두이노 프로그램을 무한루프시켜주고 있다

블로그 이미지

Or71nH

,