Raspberry Pi
Raspberry Pi
Hello everyone this week is Raspberry Pi week .this is my first time using Raspberry Pi it was not completely simple as it distinct from AVR family-like Arduino but it has more power for processing rather than Arduino.it considers a mini-computer on your hand you can programing it as you like
Arduino is a microcontroller, which is a part of the computer. It runs only one program again and again.
Arduino can be powered using a battery pack.
It is very simple to interface sensors and other electronic components to Arduino.
It is available for low cost.
Arduino requires external hardware to connect to the internet and this hardware is addressed properly using code.
Arduino can provide onboard storage.
Processor used in Arduino is from AVR family Atmega328P
This is a just plug and play device. If power is connected it starts running the program and if disconnected it simply stops.
Arduino uses Arduino, C/C++.
It is a mini computer with Raspbian OS.It can run multiple programs at a time
It is difficult to power using a battery pack.
It requires complex tasks like installing libraries and software for interfacing sensors and other components
It is expensive
Raspberry Pi can be easily connected to the internet using Ethernet port and USB Wi-Fi dongles.
Raspberry Pi did not have storage on board. It provides an SD card port.
Raspberry Pi has 4 USB ports to connect different devices.
The processor used is from ARM family.
This should be properly shutdown otherwise there is a risk of files corruption and software problems.
The Recommended programming language is python but C, C++, Python, ruby are pre-installed.
A Raspberry Pi is such a compact device and yet can run a full-featured Linux OS. It would take out all the fun if it is attached to all those mouse, keyboard, monitor and ethernet. In this tutorial, we will setup our Pi such that it only requires one USB cable as power source. First, we flash the official Raspberry Pi OS onto an SD card.
Enable SSH
We will use SSH to connect to our Pi and finish our configuration.Enable SSH access by creating an empty file ssh in the boot folder (the actual boot folder location depends on you OS):
from the terminal type ((sudo raspi-config)) and press enter, follow the following screen.
after that you can get the ip adress an gconnect the the Rassperry pi to your computer via wifi and programing it
now your pi is on the go to be programmed .
One of the things that makes the Raspberry Pi better for learning electronics than most other computers is its ability to control the voltage on several of its easily accessible pins. If you hold your Pi facing up in portrait mode (as shown in the photo below), on the right side, you will see a header with 40 pins. This header contains outputs for 3.3V, 5V, Ground, and lots of General Purpose Input/Output (GPIO) pins!
Note that pin 1 is on the top left of the header, as shown in the photo. With pin 1 in this position, we can see what each of the pins is used for:
You can connect the Raspberry Pi to the LED and button directly, or you can go through the SparkFun Pi Wedge to make the connections easier on a breadboard. The important thing is to note that we are using the GPIO numbers in our code (listed as Gx on the Pi Wedge, where x is the GPIO number). These GPIO numbers are shown in the yellow boxes in the GPIO Pinout diagram above.
Connect GPIO12 (pin 32) to the 330Ω resistor, and the resistor to the LED
Connect GPIO4 (pin 7) to the button
Make the power (3.3 V) and ground (GND) connections as shown in the Fritzing diagram
In a new file, enter the following code:
Save the file (i named my file as led.py). Run the code from the terminal by entering: python led.py or press run in thony
Code to Note:
To control hardware from the Raspberry Pi, we rely on the RPi.GPIO module. This module (likely known as a "library" in other languages) is specifically designed to help us toggle pins and talk to other pieces of hardware. Lucky for us, it comes pre-packaged with Raspbian!
In the first two lines, you see that we imported modules, but we added a few things onto those imports. First up, we used the keyword as:
The first odd thing you might notice is the try: and finally: statements. These are part of the error and exception handling abilities in Python (you can read more about them in the Exceptions chapter in Byte of Python).
If we press ctrl + x while the program is inside the while True: loop, an exception will be thrown. We don't care to do anything with that exception (hence why you don't see an except block, like you might have read about in "exception handling"). Regardless of whatever the exception is, we do want to call our GPIO.cleaup() function. That way, we can close down the GPIO and not have to worry about any more errors!
The other odd thing you might see is that if GPIO.input(btn_pin) is True (which means the pin is logic high, or 3.3V), we turn the LED off. Wait, what?
In our circuit, our button has a pull-up resistor connecting one of the pins to a constant 3.3V. This means that in its default state (not pressed), the pin connected to the button is 3.3V. When we press the button, the pin is connected to ground (through the button's internal contacts), and the pin becomes logic low (0V).
As a result, when the button is not pressed, we get logic high (GPIO.input() returns True), and when the button is pressed, we get logic low (GPIO.input() returns False).
Challenge: Write a program so that whenever you press the button, a variable is incremented by one and is printed to the screen. This should work as a simple button counter. Start at 0, and each time you press the button, it counts up on the screen.
i was bit confused between Arduino and Raspberry pi syntax and GPIO pin configration
so i follow the pinout configration instructions to follow up and testing the code
What I learned this week is...
what is raspberry pi
difference between Raspberry and Arduino
how to setup raspberry pi
blinking led using Raspberry PI