There is a version of Google Chrome that will run on the Raspberry Pi. I think it is much better than the default browser that comes on the Pi. The key is that the linux version on the Google Chrome download page will not run on the Pi. To get the version that does work, go to the terminal window and at the Linux command line on your Pi and type:
$ sudo apt-get install chromium-bsu
This will take a few minutes but it will install the browser. To find it once you have it installed, look under the menu button, and in the “internet” selection, and you should see “Chromium”. If you right click on it, you can then choose to have it show up on your desktop.
Play around with it, I think it is the best browser for the Pi.
If you have been following along in these lessons, we have been operating from the terminal window and the Linux command line. You have learned that you can simply and efficiently do whatever you want from the terminal window. Raspberry Pi does, however have a graphical interface. In this tutorial we show you how to boot in the graphical interface, and then how to find your way around.
At this point we have learned how to write digital values to the GPIO pins, we have learned to simulate analog out using PWM, and we have learned how to do digital reads from the pins. If you are like me and came from the Arduino world, then you will likely be asking, “Now what about analog reads”. The arduino has pins A0-A5 that make quick and easy work of reading analog values from things like photometers, sensors and various other circuit elements.
The bottom line is, unfortunately, there are no analogous capabilities on the Raspberry Pi. There is no way to directly read analog voltages.
Some suggest incorporating various analog to digital converter chips into your circuits requiring analog reads. For me, my preferred solution is the simply add an Arduino to the Raspberry Pi circuit. There are many very small form factor versions of the Arduino. For example, the nano is very small, and there are some examples that are even smaller. Some of these small implementations can be found for under $10.
If you take this approach, then all you have to do is learn how to communicate between the Raspberry Pi and Arduino either over USB or over ethernet. I show you how to do both of these things in the Lesson series on this WEB site “Using Python with Arduino”. This shows how to communicate between python and arduino using the USB, using Ethernet, or using the Xbee radios. Since python runs on the Raspberry Pi, all the techniques taught in those lessons can be applied to the raspberry pi.
In our high altitude balloon instrumentation package, we actually run a raspberry pi that is controlling two arduino nano microcontrollers. The one arduino is controlling the 9-axis IMU, and the other arduino is running GPS, Temperature, Pressure, and other sensors. The raspberry pi and Arduinos communicate over a small onboard Ethernet switch. The system communicates back to the ground via 1 watt ubiquity bullet radios.
So, the Raspberry Pi should not be viewed as a replacement for the Arduino, it should be viewed as a complementary device that can work nicely alongside the Arduino.
In this lesson we are ready to bring together a lot of what we learned in earlier lessons. We will create dimable LEDs which will respond to two buttons. If one is pressed the LED will gradually grow dimmer. If the other is pressed, the LED will gradually grow brighter. This will require us to use our skills in using GPIO inputs, pullup resistors, GPIO outputs, and PWM.
For convenience we will use the same circuit we used in LESSON 30, shown below. Also, if you want to follow along with these lessons, you can buy the gear you need HERE.
The objective of this circuit is that we want the LEDs to grow brighter each time the right button is pushed, and we want them to grow dimmer each time to left button is pushed.
The video above steps through and explains this code.
fromtimeimportsleep# Library will let us put in delays
importRPi.GPIO asGPIO# Import the RPi Library for GPIO pin control
GPIO.setmode(GPIO.BOARD)# We want to use the physical pin number scheme
button1=16# Give intuitive names to our pins
GPIO.setup(button1,GPIO.IN,pull_up_down=GPIO.PUD_UP)# Button 1 is an input, and activate pullup resisrot
GPIO.setup(button2,GPIO.IN,pull_up_down=GPIO.PUD_UP)# Button 2 is an input, and activate pullup resistor
GPIO.setup(LED1,GPIO.OUT)# LED1 will be an output pin
GPIO.setup(LED2,GPIO.OUT)# LED2 will be an output pin
pwm1=GPIO.PWM(LED1,1000)# We need to activate PWM on LED1 so we can dim, use 1000 Hz
pwm2=GPIO.PWM(LED2,1000)# We need to activate PWM on LED2 so we can dim, use 1000 Hz
pwm1.start(0)# Start PWM at 0% duty cycle (off)
pwm2.start(0)# Start PWM at 0% duty cycle (off)
bright=1# Set initial brightness to 1%
while(1):# Loop Forever
ifGPIO.input(button1)==0:#If left button is pressed
print"Button 1 was Pressed"# Notify User
bright=bright/2.# Set brightness to half
pwm1.ChangeDutyCycle(bright)# Apply new brightness
pwm2.ChangeDutyCycle(bright)# Apply new brightness
sleep(.25)# Briefly Pause
print"New Brightness is: ",bright# Notify User of Brightness
ifGPIO.input(button2)==0:# If button 2 is pressed
print"Button 2 was Pressed"# Notify User
bright=bright*2# Double Brightness
ifbright>100:# Keep Brightness at or below 100%
print"You are at Full Bright"
pwm1.ChangeDutyCycle(bright)# Apply new brightness
pwm2.ChangeDutyCycle(bright)# Apply new brightness
print"New Brightness is: ",bright#Notify User of Brightness
In this lesson we will show how you can control LED’s from push buttons. In order to get started, you will want to expand the circuit we built in LESSON 29 to include two LEDs. The schematic below shows how you will want to hook things up (Also, remember you can see the Raspberry Pi pinout in LESSON 25). Also, as we have mentioned before, if you want to follow along with us in these lessons you can get a kit that has all the gear you need HERE.
In the video lesson, we take you through the code step-by-step. We use the techniques learned in LESSON 29 to detect if a button has been pushed. We introduce two new variables, BS1 and BS2, so indicate the state of the LED’s. A BS1=False means the LED1 is off. A BS1=True means the LED is on. This concept allows us to determine whether we should turn the LED on or off when the button is pushed. Basically, we want to put it in the opposite state when a button is pushed. The code is below. The video shows how it works.
fromtimeimportsleep# Import sleep Library
importRPi.GPIO asGPIO# Import GPIO Library
GPIO.setmode(GPIO.BOARD)# Use Physical Pin Numbering Scheme
button1=16# Button 1 is connected to physical pin 16
button2=12# Button 2 is connected to physical pin 12
LED1=22# LED 1 is connected to physical pin 22
LED2=18# LED 2 is connected to physical pin 18
GPIO.setup(button1,GPIO.IN,pull_up_down=GPIO.PUD_UP)# Make button1 an input, Activate Pull UP Resistor
GPIO.setup(button2,GPIO.IN,pull_up_down=GPIO.PUD_UP)# Make button 2 an input, Activate Pull Up Resistor
GPIO.setup(LED1,GPIO.OUT,)# Make LED 1 an Output
GPIO.setup(LED2,GPIO.OUT)# Make LED 2 an Output
BS1=False# Set Flag BS1 to indicate LED is initially off
BS2=False# Set Flag BS2 to indicate LED is initially off
while(1):# Create an infinite Loop
ifGPIO.input(button1)==0:# Look for button 1 press
print"Button 1 Was Pressed:"
ifBS1==False:# If the LED is off
GPIO.output(LED1,True)# turn it on
BS1=True# Set Flag to show LED1 is now On
else:# If the LED is on
GPIO.output(LED1,False)# Turn LED off
BS1=False# Set Flag to show LED1 is now Off
ifGPIO.input(button2)==0:#Repeat above for LED 2 and button 2
We are now ready to learn how to “read” values from the Raspberry Pi GPIO pins. In order to demonstrate this, we will show a simple example using buttons. If you ordered the Raspberry Pi kit we recommend, you already have everything you need, or you can pick your kit up HERE. To start with, you need to put together a simple circuit that connects two push buttons to your Raspberry Pi. Connect according to this schematic.
Note that one leg of each button is connected to the ground rail on the breadboard, that is connected to the Pi ground at physical pin 6. Then we connect the left leg of the left button to physical pin 16, and the left leg of the right button to physical pin 12.
In order to read the state of these buttons, that is, whether they are being pressed or not, we need to write a python program. To begin with we must import GPIO library and specify that we want to
fromtimeimportsleep# Import time library
importRPi.GPIO asGPIO# Import RPi Library
GPIO.setmode(GPIO.BOARD)# Specify We Want to reference Physical pins
Now we are ready to set the pin modes on the pins we are using. We are using pins 12 and 16. We will set up variables so that we can reference the pins by descriptive variables.
button1=16# Descriptive Variable for pin 16
button2=12# Descriptive Variable for pin 12
GPIO.setup(button1,GPIO.IN,pull_up_down=GPIO.PUD_UP)# Set button1 as input and Activate pull up resistor
GPIO.setup(button2,GPIO.IN,pull_up_down=GPIO.PUD_UP)# Set button2 as input and Activate pull up resisor
Note in our GPIO.setup commands, we are not just defining the pins as inputs, we are also activating pullup resistors with
With this command, the raspberry pi places a pullup resistor between the designated pin and the 3.3 V rail. This means that if we simply read the pin, we will read a “1”, “True”, or “High”, since the pin will see the rail through the pullup resistor. If we connect the pin to ground by pressing a button or switch, the pin will then read a “0”, “False” or “Low” because it will be a straight connection to ground, and as current flows through the pullup resistor, the 3.3 Volts will drop across the pullup resistor. Hence, the pin sees 0 volts.
The result is that with the pullup resistor activated, the pin will always report a “1” until something connects the pin to ground, and then it will read a “0”. This configuration should work for most things, but if you are getting unpredictable results which can result from electrical noise, then try using external pullup resistors.
Now we are ready to read the values from the pins.
while(1):# Create an infinite loop
ifGPIO.input(button1)==0:# button1 will report 0 if it is pressed
print"Button 1 Pressed"
ifGPIO.input(button2)==0:# button 2 will report 0 if it is presses
print"Button 2 Pressed"
Notice that we read from the pin using the GPIO.input command. Also note that for reliable results you need to usually put a small delay in your code. This will help debounce the button, and will also give more stable results.