Академический Документы
Профессиональный Документы
Культура Документы
spi = spidev.SpiDev()
spi.open(0,0)
while True:
resp = spi.xfer2([0x00])
print resp[0]
time.sleep(1)
4.INSTALLING THE AVRDUDE PACKAGE:
cd /tmp
wget http://project-downloads.drogon.net/gertboard/avrdude_5.10-4_armel.deb
sudo dpkg -i avrdude_5.10-4_armel.deb
sudo chmod 4755 /usr/bin/avrdude
(lets avrdude run spi without sudo)
+++http://project-downloads.drogon.net/gertboard/+++
cd /tmp
wget http://project-downloads.drogon.net/gertboard/setup.sh
chmod +x setup.sh
sudo ./setup.sh
cd /tmp
wget http://project-downloads.drogon.net/gertboard/boards.txt
wget http://project-downloads.drogon.net/gertboard/programmers.txt
cd /usr/share/arduino/hardware/arduino
sudo mv boards.txt board.txt.bak
sudo mv /tmp/boards.txt .
sudo mv programmers.txt programmers.txt.bak
sudo mv /tmp/programmers.txt
sudo reboot
avrsetup(important)+++
U can now program the Ardunio using ISP Programmer
******************----------------------------**************
SERIAL COMMUNICATION:
1.DISABLE GETTY:
/etc/inittab
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100(# it)
/boot/cmdline.txt
remove the line console=ttyAMA0,115200 kgdboc=ttyAMA0,115200(to prevent pi sendi
ng serial data when it switchs on)
sudo reboot
2.INSTALL MINICOM
sudo apt-getinstall minicom
minicom -b 9600 -o -D /dev/ttyAMA0 ( attach to serial terminal)
3.INSTALL PI-SERIAL:
sudo apt-get install python-serial
4.PROGRAM:
PI:
import serial
import string
rot13 = string.maketrans(
"ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuvwxyz",
"NOPQRSTUVWXYZnopqrstuvwxyzABCDEFGHIJKLMabcdefghijklm")
test=serial.Serial("/dev/ttyAMA0",9600)
test.open()
try:
while True:
line = test.readline(eol='\r')
test.write(string.translate(line, rot13))
except KeyboardInterrupt:
pass # do cleanup here
test.close()
OR
import serial
ser = serial.Serial('/dev/ttyAMA0', 9600, timeout=1)
ser.open()
ser.write("testing")
try:
while 1:
response = ser.readline()
print response
except KeyboardInterrupt:
ser.close()
ARDUINO:
void setup() {
Serial.begin(9600);
}
void loop() {
int incomingByte;
if(Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// echo
Serial.write(incomingByte);
}
**********************-------------------------**********************
WIRELESS COMMUNICATION:
1)AD-HOC NETWORK:
a)make a backup:sudo cp /etc/network/interfaces /etc/network/interfaces_backup
b)open network interfaces file: sudo nano /etc/network/interfaces
c)edit file:
auto lo
iface lo inet loopback
iface eth0 inet dhcp
auto wlan0
iface wlan0 inet static
address 192.168.1.1
netmask 255.255.255.0
wireless-channel 1
wireless-essid RPiAdHocNetwork
wireless-mode ad-hoc
d)restart the wlan0 network:sudo ifdown wlan0
sudo ifup wlan0
e)configure PI as a DHCP server:
sudo apt-get update
sudo apt-get install dhcp3-server
/etc/dhcp/dhcpd.conf
(the file shud contain the following)
ddns-update-style interim;
default-lease-time 600;
max-lease-time 7200;
authoritative;
log-facility local7;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.5 192.168.1.150;
}
e)try ssh: ssh -lpi 192.168.1.1
************
2)WIRELESS ACCESS POINT:
a)sudo nano /etc/network/interfaces
Place a # sign in front of all the lines which mention wlan0 and wpa, except for al
low hotplug wlan0 . Then add the following lines to the file:
iface wlan0 inet static
address 192.168.42.1
netmask 255.255.255.0
sudo reboot
b)DHCP SERVER:
sudo apt-get install isc-dhcp-server
sudo nano /etc/dhcp/dhcpd.conf
Add a # character in front of the option domain-name lines like this:
Remove the # sign in front of the authoritative; statement like this:
#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;
at the bottom, add these:
subnet 192.168.42.0 netmask 255.255.255.0 {
range 192.168.42.10 192.168.42.50;
option broadcast-address 192.168.42.255;
option routers 192.168.42.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name "local";
option domain-name-servers 8.8.8.8, 8.8.4.4;
}