nmcli dev wifi
nmcli dev wifi connect Jessie password 1234567890
ip addr show wlan0
ifconfig
也可以git clone https://github.com/orangepi-xunlong/wiringOP //下载源码
cd wiringOP //进入文件夹
sudo ./build clean //清除编译信息,实测可以不用
sudo ./build //编译
通过 windows 浏览器打开 https://github.com/orangepi-xunlong/wiringOP
下载压缩包至本地
把压缩包通过xterm传到开发板
解压 unzip xxx.zip
cd xxx
sudo ./build
gpio readall
sudo vi /etc/vim/vimrc
set tabstop=4 //设置tab键缩进4个空格(默认是8)
set nu //显示行号
set shiftwidth=4 //设置批量对齐时候的tab键空格数为4(默认是8)
./build.sh
//build.sh
gcc beep.c -lwiringPi -lwiringPiDev -lpthread -lm -lcrypt -lrt
#include
#include
#include
#define BEEP 0 // 设置针脚0为蜂鸣器的控制引脚
int main(void)
{
wiringPiSetup(); // 初始化wiringPi库
pinMode(BEEP, OUTPUT); // 设置IO口的输入输出,输出
while (1)
{
// sleep(1); // 1s
usleep(100000); // 100ms
digitalWrite(BEEP, LOW); // 设置IO口输出低电平,蜂鸣器响
// sleep(1);
usleep(100000);
digitalWrite(BEEP, HIGH); // 设置IO口输出高电平,蜂鸣器不响
}
return 0;
}
gcc $1 -lwiringPi -lwiringPiDev -lpthread -lm -lcrypt -lrt
型号:HC-SR04
怎么让它发送波
怎么知道它开始发送了
怎么知道接收了返回波
怎么算时间
Echo引脚维持高电平的时间!
计算出中间经过多少时间。
怎么算距离
#include
int gettimeofday(struct timeval *tv,struct timezone *tz )
- gettimeofday() 会把目前的时间用 tv 结构体返回,当地时区的信息则放到 tz 所指的结构体中
struct timeval
{
long tv_sec;/*秒*/
long tv_usec;/*微妙*/
};
#include
#include
void mydelay()
{
int i, j;
for (i = 0; i < 100; i++){
for (j = 0; j < 1000; j++);
}
}
int main()
{
struct timeval startTime;
struct timeval stopTime;
gettimeofday(&startTime, NULL);
mydelay();
gettimeofday(&stopTime, NULL);
long diffTime = 1000000 * (stopTime.tv_sec - startTime.tv_sec) +
(stopTime.tv_usec - startTime.tv_usec);
printf("全志H6的Linux数到10w耗时%ldus\n", diffTime);
return 0;
}
#include //printf
#include //gettimeofday
#include //gpio
#include //exit
#include //usleep
#define Trig 0
#define Echo 1
double getDistance()
{
struct timeval start;
struct timeval stop;
pinMode(Trig, OUTPUT);
pinMode(Echo, INPUT);
digitalWrite(Trig, LOW);
usleep(5);
digitalWrite(Trig, HIGH);
usleep(10);
digitalWrite(Trig, LOW);
/* above init CSB*/
while(!digitalRead(Echo));
gettimeofday(&start, NULL);
while(digitalRead(Echo));
gettimeofday(&stop, NULL);
long diffTime = 1000000*(stop.tv_sec - start.tv_sec) +
(stop.tv_usec - start.tv_usec);
//printf("diffTime = %ld\n",diffTime);
double dis = (double)diffTime/1000000 * 340*100 / 2;
return dis;
}
int main()
{
double dis;
if(wiringPiSetup() == -1){
fprintf(stderr,"%s","init wiringPi error");
exit(-1);
}
while(1){
dis = getDistance();
printf("dis = %lf\n\n",dis);
usleep(500000);
}
return 0;
}