树莓派点亮一盏灯,喜迎新春到来。
树莓派吧
全部回复
仅看楼主
level 7
1:放假了,有空把积灰的树莓派拿出,玩玩
2:目的回顾一下知识。
使用GPIO--13口。
1):程序代码:启动灯 True
import RPi.GPIO
RPi.GPIO.setmode(RPi.GPIO.BOARD)
RPi.GPIO.setup (13, RPi.GPIO.OUT)
while 1:
RPi.GPIO.output(13,True)
2):熄灭 False
import RPi.GPIO
RPi.GPIO.setmode(RPi.GPIO.BOARD)
RPi.GPIO.setup (13, RPi.GPIO.OUT)
while 1:
RPi.GPIO.output(13,False)
2016年02月06日 04点02分 1
level 14
要是配置好以后 重启之后还会亮吗 还是要重新配置
2016年02月06日 04点02分 2
得执行程序的,,这个配置启动程序就可以了吧?我也不太会啊。。哈哈
2016年02月06日 05点02分
level 7
3:安装serial,用于串口通信及USB通信:
sudo apt-get install python-serial
2016年02月06日 07点02分 3
level 7
想在树莓派装串口调试工具就装minicom
sudo apt-get install minicom
配置minicom:
sudo minicom -s
启动出现配置菜单:选serial port setup
进入串口配置
输入A 配置串口驱动为/dev/ttyAMA0
输入E 配置速率为9600 8N1
输入F 将 Hardware Flow Control 设 为 NO
回车 退出
2016年02月06日 08点02分 4
level 7
在执行串口调试的过程中间出现错误。。
程序:
import serial
import time
ser = serial.Serial('/dev/ttyAMA0', 9600, timeout=1)
print ser.isOpen()
words="hello"
while 1:
getchr = ser.read()
ser.write(words)
time.sleep(5)
ser.close()
但是执行代码已经是返回了True了
pi@raspberrypi ~/1 $ sudo python 3.py
True------------------------打印的
Traceback (most recent call last):
File "3.py", line 7, in <module>
getchar=ser.read(8)
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 456, in read
raise SerialException('device reports readiness to read but returned no data (device disconnected?)')
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected?)
2016年02月06日 08点02分 5
level 7
补充一个串口的前提:
1.修改两处文件
【1】/boot/cmdline.txt
【输入以下指令】 sudo nano /boot/cmdline.txt
【删除部分】------ console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 ----【最终变为】dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
【2】/etc/inittab
【输入以下指令】 sudo nano /etc/inittab
【注释最后一行内容】#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
2016年02月06日 11点02分 7
level 11
没必要那么麻烦,直接加个实体开关不就行了?
2016年02月06日 12点02分 8
[啊]好吧。。只是为了学习如何控制GPIO的,
2016年02月06日 14点02分
回复 终结者默默 :呵呵
2016年02月07日 09点02分
level 7
5:WiringPi is maintained under GIT for ease of change tracking, however there is a Plan B if you’re unable to use GIT for whatever reasons (usually your firewall will be blocking you, so do check that first!)、
安装WiringPi函数库
1:下载解压后。。、、./build
tar xfz wiringPi.tar.gz
cd wiringPi
./build
2016年02月06日 14点02分 9
level 7
在/wiringPi/examples目录中有一些例子,例如blink.c
2016年02月11日 13点02分 10
level 7
1)IO的编号方式略有不同,采用wiring编码方式。
2)-lwiringPi表示动态加载wiringPi共享库。
2016年02月12日 01点02分 12
level 7
以上旧版本的wiringPi所以没有点亮LED。现在重新编译最新安装包可以了
sudo apt-get install libi2c-dev
sudo apt-get install git-core#获取安装包
git clone git://git.drogon.net/wiringPi
cd wiringPi
git pull origin#切换到编译目录
cd wiringPi/
#编译并安装
./build
#检查安装
gpio -v
gpio readall
2016年02月12日 02点02分 13
level 2
最近要做一个c语言的树莓派project 可不可以给点建议
2016年02月12日 03点02分 14
level 7
控制GPIO简单例子:
#include <wiringPi.h>
int main (void)
{ wiringPiSetup () ;
pinMode (0, OUTPUT) ;
for (;;)
{ digitalWrite (0, HIGH) ; delay (500) ; digitalWrite (0, LOW) ; delay (500) ; }
return 0 ;
}
2016年02月12日 12点02分 15
编译gcc -Wall -o blink blink.c -lwiringPi sudo ./blink
2016年02月12日 12点02分
level 7
点亮1206LCD
#include <wiringPi.h> //WiringPi headers
#include <lcd.h> //LCD headers from WiringPi
#include <stdio.h>
#define LCD_RS 3 //Register select pin
#define LCD_E 0 //Enable Pin
#define LCD_D4 6 //Data pin 4
#define LCD_D5 1 //Data pin 5
#define LCD_D6 5 //Data pin 6
#define LCD_D7 4 //Data pin 7
int main(){ int lcd; //Handle for LCD
wiringPiSetup(); //Initialise WiringPi //Initialise LCD(int rows, int cols, int bits, int rs, int enable, int d0, int d1, int d2, int d3, int d4, int d5, int d6, int d7)
if (lcd = lcdInit (2, 16,4, LCD_RS, LCD_E ,LCD_D4 , LCD_D5, LCD_D6,LCD_D7,0,0,0,0))
{ printf ("lcdInit failed! \n");
return -1 ; }
lcdPosition(lcd,0,0); //Position cursor on the first line in the first column
lcdPuts(lcd, "Character LCD");
//Print the text on the LCD at the current cursor postion
getchar();
//Wait for key press
lcdClear(lcd);
//Clear the display}
2016年02月12日 13点02分 16
level 7
LCD1602液晶屏提供了16列x2行的ASCII字符显示能力,工作电压5V,提供4位数据与8位数据两种工作模式,因为Raspberry Pi的GPIO口数量很有限,所以使用4位数据模式。LCD1602液晶屏模块提供了16个引脚,我们只需接其中的12个即可–请参考GPIO命名规则:
VSS,接地,RPi PIN 6
VDD,接5V电源,PRi PIN 2
VO,液晶对比度调节,接电位器中间的引脚
RS,寄存器选择,接GPIO 14,RPi PIN 8
RW,读写选择,接地,表示写模式,PRi PIN 6
EN,使能信号,接GPIO 15,RPi PIN 10
D0,数据位0,4位工作模式下不用,不接
D1,数据位1,4位工作模式下不用,不接
D2,数据位2,4位工作模式下不用,不接
D3,数据位3,4位工作模式下不用,不接
D4,数据位4,接GPIO 17,RPi PIN 11
D5,数据位5,接GPIO 18,RPi PIN 12
D6,数据位6,接GPIO 27,RPi PIN 13
D7,数据位7,接GPIO 22,RPi PIN 15
A,液晶屏背光+,接5V,RPi PIN 2
K,液晶屏背光-,接地,RPi PIN 6
2016年02月13日 01点02分 17
1