일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- homeassistant
- flask
- raspberry
- 에버온
- thread
- 플라스크
- IOT Core
- 전기차충전기
- 전기차
- 안드로이드
- 급속충전기
- 디자인패턴
- 완속충전기
- OCPP
- Android
- dynamodb
- everon
- 라즈베리파이
- YMODEM
- 전기차충전
- AWS
- 보안
- esp8266
- 파이썬
- STM32
- 홈어시스턴트
- 서버리스
- 펌웨어
- lambda
- 충전기
Archives
- Today
- Total
Louie NRT Story
[RaspberryPi] Rapsberry and Arduino Communicates using USB 본문
코딩테스트
[RaspberryPi] Rapsberry and Arduino Communicates using USB
hyeok0724.kim@gmail.com 2019. 5. 6. 21:13반응형
[Design]
[Arduino Code]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
String msg = "";
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
if(Serial.available())
{
msg = Serial.readString();
Serial.println(msg);
}
Serial.println("Hello World");
delay(1000);
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs |
[RaspberryPi Code]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
//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>
// Typying "dmesg|tail"
// 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;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs |
반응형
'코딩테스트' 카테고리의 다른 글
[DB] How to Coding DB Connect (0) | 2019.12.12 |
---|---|
[Algorithm] Cyclic Redundancy Check(CRC) (0) | 2019.11.07 |
[C언어] Semaphore & Mutex(세마포어, 뮤텍스) (0) | 2019.04.17 |
[Algorithm] 이진트리 후위계산법 (0) | 2019.04.17 |
[Algorithm] 이진트리 삽입 삭제 탐색 (0) | 2019.04.16 |
Comments