3.Basic I/O experiments

First I want to know how bread board works. For this I constructed basic LED connection with one resistor and one LED and wires.

Connections:

  • Anode(long leg) to 3V
  • cathode(short leg) to resistor
  • resistor (other end) to GND(ground).

After this connections we should connect pi to power source  then we can see ignition of LED.20170206_193050.jpg

fullsizerender1

A Python program is used to read temperature and humidity sensor. In order to do, I used following procedure.

Python Program to get values from sensor:

import sys

import Adafruit_DHT

sensor_args = { ’11’: Adafruit_DHT.DHT11,
’22’: Adafruit_DHT.DHT22,
‘2302’: Adafruit_DHT.AM2302 }

if len(sys.argv) == 3 and sys.argv[1] in sensor_args:
sensor = sensor_args[sys.argv[1]]
pin = sys.argv[2]
else:
print(‘usage: sudo ./Adafruit_DHT.py [11|22|2302] GPIOpin#’)
print(‘example: sudo ./Adafruit_DHT.py 2302 4 – Read from an AM2302 connected to GPIO #4’)
sys.exit(1)

# Try to grab a sensor reading. Use the read_retry method which will retry up

humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)

# Un-comment the line below to convert the temperature to Fahrenheit.
# temperature = temperature * 9/5.0 + 32

# Note that sometimes you won’t get a reading and
# the results will be null (because Linux can’t
# guarantee the timing of calls to read the sensor).
# If this happens try again!
if humidity is not None and temperature is not None:
print(‘Temp={0:0.1f}* Humidity={1:0.1f}%’.format(temperature, humidity))
else:
print(‘Failed to get reading. Try again!’)
sys.exit(1)

By running this program using sudo ./AdafruitDHT.py 2302 04  we can get surrounding temperature and humidity

OUTPUT:  TEMPERATURE:23.0 HUMIDITY:42.0

Now we can loop this and get temperature and humidity a regular intervals.fullsizerender-11

By executing the above python program

img_1528.jpgSPI in PI: 

SPI on Pi

Configuration

The SPI peripheral is not turned on by default. To enable it, do the following.

  1. Run  sudo raspi-config.
  2. Use the down arrow to select 9 Advanced options
  3. Arrow down to A6 SPI.
  4. Select yes when it asks you to enable SPI,
  5. Also select yes when it asks about automatically loading the kernel module.
  6. Use the right arrow to select the <Finish> button.
  7. Select yes when it asks to reboot.

alt text

Raspi-config for SPI

The system will reboot. When it comes back up, log in and enter the following command

>ls/dev/*spi*

The Pi should respond with

/dev/spidev0.0 /dev/spidev0.1

These represent SPI devices on chip enable pins 0 and 1, respectively. These pins are hardwired within the Pi. Ordinarily, this means the interface supports at most two peripherals, but there are cases where multiple devices can be daisy-chained, sharing a single chip enable signa