Translate

Showing posts with label Raspberry Pi B. Show all posts
Showing posts with label Raspberry Pi B. Show all posts

Tuesday, July 5, 2016

My little VPN

Having around a Raspberry Pi I decided to set up a VPN to access to my network and from there, to internet.
There are a lot of tutorials, guides, suggestions, so in the end I opted for Open VPN since is well supported for Android, my main remote access to my network.

Wednesday, November 4, 2015

Embedded RPOf

The next thing to do about the RPOf is to embed it in a piggy back board over the Raspberry Pi.
The Raspberry Pi GPIO connector has both the 3.3V and 5V rail available, so to have a more compact system, embedding the RPOf on the "shield" connected to the Raspberry Pi, can helps to reduce the space and number of boards.

Saturday, October 25, 2014

Raspberry Pi - RPOf project


The Raspberry Pi can be used to run some kind of embedded Linux.
Like any *nix system, removing suddenly power is not a  good thing, it is very easy to corrupt  some SD card sector if the power removal happens during a writing cycle.

Saturday, October 11, 2014

Raspberry Pi - connecting a traditional LCD display (Update)

Raspberry Pi is a powerful enough platform and  it is possible to use many recent touchscreen with a nice graphic on it.
However often a traditional LCD is more useful, and surely is more cheap than a touchscreen solution.

Here one way to connect a traditional LCD and use it in projects, like the TeirmiLab one.
This article describes how to connect a traditional LCD but with RGB capabilities to the Raspberry Pi B.

We need :

It is possible to hook a display without the need of the GPIO expander, however a normal LCD uses at least 6 signals. 9 if the LCD display is an RGB one like the one used for this project.
Considering that the Raspberry Pi B doesn't have many GPIO available and that usually the speed required to handle the display is not critical, using a chip like the MCP23017 make sense.
In this way it will be enough to "hook" the  chip to the I2C bus, leaving all the Raspberry Pi GPIO free for other use.

Let see a schematic.


Software


There are many ways to control the hardware.
For now I found a ready-to-use Python library published by Adafruit that is working nicely.
Again, the important thing is that control an LCD is not a critical task, so a python script is Ok.
Maybe in future I'll explore the possibility to control it directly in C.

Python 

To use our display we need to install some code in our Raspberry.
Here a quick step-by-step guide (see Adafruit tutorials for a more detailed and easy instructions) :


  1. sudo apt-get update
  2. sudo apt-get install build-essential python-dev python-smbus python-pip
  3. sudo apt-get install i2c-tools
  4. sudo pip install RPi.GPIO
  5. cd ~
  6. git clone https://github.com/adafruit/Adafruit_Python_CharLCD.git
  7. cd Adafruit_Python_CharLCD
  8. sudo python setup.py install
Before to be able to use it, we need to be sure a configuration file is correctly set-up.

Execute : sudo nano /etc/modules

and if the file exists, add these two lines in the end.

i2c-bcm2708 
i2c-dev

Save the file then open another one in edit.
Execute : sudo nano /etc/modprobe.d/raspi-blacklist.conf

In this file comment out the two lines showed below, adding # at the beginning:

#blacklist spi-bcm2708
#blacklist i2c-bcm2708


Reboot Raspberry : sudo shutdown -r now
or : sudo reboot

At this point everything should be installed in order to use the display.
First is better to run an utility to see if the I2C GPIO expander is seen correctly.

sudo i2cdetect -y 1

The command should display a table and in the table should be present a 0x20 address.

pi@raspberrypi ~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
pi@raspberrypi ~ $ 


If so, the chip is correctly seen by Raspberry.

To test if the display is working you can execute a test script :
  1. cd Adafruit_Python_CharLCD/examples
  2. sudo ./char_lcd_mcp.py
Some test messages should be displayed on the LCD display.



Troubleshooting

It is possible to have some problems installing the libraries.
Here a couple of tips and resolutions.

apt-get missing


If you start from a fresh installation of Raspbian, especially a lite version, before to start to follow the instructions above, be sure to execute :


  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo apt-get update
It is important because updating the first time, include more repo on apt-get.

python build fail

If during the python building of the library you have this errors :


python ./setup.py build
Downloading https://pypi.python.org/packages/source/s/setuptools/setuptools-3.5.1.zip
Extracting in /tmp/tmpw6UbTx
Traceback (most recent call last):
  File "./setup.py", line 4, in
    use_setuptools()
  File "/home/pi/Adafruit_Python_CharLCD/ez_setup.py", line 128, in use_setuptools
    return _do_download(version, download_base, to_dir, download_delay)
  File "/home/pi/Adafruit_Python_CharLCD/ez_setup.py", line 108, in _do_download
    _build_egg(egg, archive, to_dir)
  File "/home/pi/Adafruit_Python_CharLCD/ez_setup.py", line 57, in _build_egg
    with archive_context(archive_filename):
  File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/home/pi/Adafruit_Python_CharLCD/ez_setup.py", line 88, in archive_context
    with get_zip_class()(filename) as archive:
  File "/usr/lib/python2.7/zipfile.py", line 770, in __init__
    self._RealGetContents()
  File "/usr/lib/python2.7/zipfile.py", line 813, in _RealGetContents
    raise BadZipfile, "File is not a zip file"
zipfile.BadZipfile: File is not a zip file


this happens because for some magic reason :) the python script screw up the download of a zipped file.
In my case the file was setuptools-3.5.1.zip.

Doing an ls -l showed up to be 122 byte big !! Definitively NOT a zip file.
The workaround was quite easy actually.

  • remove the file : sudo rm setuptools-3.5.1.zip
  • manually download the file :
    wget https://pypi.python.org/packages/source/s/setuptools/setuptools-3.5.1.zip 
  • Re-execute the build : sudo python ./setup.py build

Examples


Be aware about the type of kit you are using.
On the examples area there are different examples depending the type of display in use.

To test the basic display, use : char_lcd_mcp.py
To test the kit with RGB display and pushbutton use : char_lcd_plate.py

Wednesday, October 8, 2014

TeirmiLab - prepare Raspbian

For the TeirmiLab project, one of the platform I choose to prototype it, is the Raspberry Pi B (or B+).

This is a quick step-by-step reminder about how to prepare Raspbian for the Raspberry Pi B and B+ for this project.

There are on-line hundreds of places where is described how to install a Raspbian over a Raspberry Pi.


If this quick step-by-step is not enough for you, try this.
If you think that this is too technical ... are you sure you want to play with microcontrollers ? :)

Lets start.
I used a 8 Gbyte micro SD card with a low profile adapter. In this way is easy to eventually swap to the Raspeberry Pi B+.

It is necessary, at least for the installation, to have :
  • a 5 Volt 1A USB power supply
  • a USB cable (microUSB) for the power supply
  • an internet connection, better if wired
  • a computer (needed to download the image and prepare the SD card)
Optionally if you want to enable the graphic interface or plan to use Noobs, better to have also:
  • a HDMI monitor or a composite monitor (suggested an HDMI one)
  • an USB keyboard
  • an USB mouse

As keyboard and mouse, I used a wireless Logitech keyboard with an included touch-pad with USB dongle, in this way there is still available an USB Port.

SD card preparation  

Once all the HW components are available and connected, is possible to prepare the SD card.
Raspberry Pi does not have flash, it boots from the SD card that is used also as hard drive.
Because of that it needs to be formatted in Fat32.

Using kparted erase all the data on the SD card (new partition) and then simply format all the card in Fat32.
If you DON'T plan to use Noobs, there is no need to format the SD card.

Problems
Use a decent SD card for the job.
It should be fast and good quality/brand.
I had some SD cards not working properly because not fast enough or bad brand.
I found more reliable to use microSD cards with the adapter.

Installing distribution

There are two main choices about installing a distribution/OS on the SD card:

  • installing Noobs
  • installing a specific distribution

Noobs
If you choose to use Noobs, here some notes.
It is easier, shows you the latest available distributions and install automatically everything needed.
You must connect an HDMI monitor and a keyboard/mouse to the Raspberry Pi.

To install Noobs, simply download it and extract it on the SD card.
That's it. No strange formatting of the SD card, no partitions, secret code, ecc.
Just a plain copy.

Once copied, insert the card on the Raspberry Pi and turn it on.
After few seconds will appear on the HDMI screen the list of available OS to install.
If you have enough space on the SD card, it is possible to install more than one.

With 8Gbyte SD card, generally there is space for 1 or 2 OS.

The suggested distro to install is the Raspbian , accessible via the Noobs menu.

It is a Debian based distro and is probably the most used.
Once installed, a configuration menu' will allows to set up some parameters, like starting the distro in graphic mode rather than command line.
The default is command line ! So it is normal to boot in command line if no configuration modifications are made.

Raspbian
It is possible to install directly Raspbian. The main advantage is to have much more space on the SD card.
Here how to do it.
Go on the Raspberry Pi website download page , locate the Raspbian image and download it on your computer (look for Operating Systems Images - Raspbian).
Detailed explanations about how to do that are available on the Raspberry website, shortly here a quick reminder. I'm using Linux and I'm assuming you KNOW how to work on Linux.
  • download the image on your PC
  • extract the image from the zip file
  • open a terminal
  • df -h
    to see what memory devices are present
  • insert the new SD card
  • df -h
    identify the latest device inserted - ignore the partitions, we need to overwrite the entire card with the image
    If nothing appears, try with gparted or kparted to identify the new card
  • umount /dev/sdxx
    umount the device added if for any reason it was mounted.
    In case the card has more than one partition, umount all of them.
    Eventually better reformat the card with gparted so to have a single partition but is not necessary.
  • copy the entire image downloaded on the sd card with the command:

    dd bs=4M if=name_image_downloaded.img of=/dev/sdx

    where name_image_downloaded is the path/name of the downloaded Raspbian image and sdx is the name of the unmounted device (DEVICE !  NON PARTITION !)

    CAUTION!  Take your time and triple check ! If you use the wrong /dev you can lose your data !
At this point you have the SD card ready to be inserted in the Raspberry Pi.
Do it, be sure to have connected the board to the network, no need to have HDMI and keyboard/mouse, you can operate via ssh.

The image installed allows for the default user named 'pi' and password 'raspberry'.
Hook up  a terminal to the board, for example in ssh, is possible to login with:

- ssh pi@192.168.xxx.xxx   (address of the board - see your DHCP assignment)
- password : raspberry

Once gained access, is better to do an update with :  sudo apt-get update

After the reboot is better to configure Raspbian running the command sudo raspi-config.
At least run the option
- Expand Filesystem and the
- Advanced Options/A6 I2C in order to enable the I2C support.

No need to run other options.

The Raspberry Pi B (or B+) board is ready for the next step.

Tuesday, September 9, 2014

Raspberry Pi - reading a DS18S20

One of the most common things for any embedded device is the capability to read temperatures.

Raspberry Pi doesn't has any ADC by default, so unless to hook one, the common way to read temperatures is via digital chips, like the DS 18S20.

The DS 18S20 is a 1-wire protocol chip-set from Dallas.
Fortunately somebody already wrote a bit banging support for the 1Wire protocol used by this chip-set , so it is only matter to connect the chip and enable some kernel modules to do so, at least in Raspbian (Wheezi).

I was able to duplicate the results described in the article RaspberryPI DS1820 without problems.
The example is based on a Perl script using the kernel services.

Here some my extra notes (I don't understand why so many people stopped to draw standard electronic schematics in favor of "cartoon" schematics).

Basic schematic to connect a DS1820 to the Raspberry Pi Gpio port.


Raspberry Pi GPIO pinout

DS1820 pinout







By default (as described in the article) the kernel module capable to handle the 1-Wire is disabled.
As first thing is necessary to enable it.




Open a terminal, then :
  • sudo modprobe wire
  • sudo modprobe w1-gpio  
  • sudo modprobe w1-therm

After that, to test if the DS1820 is ready and connected correctly :
  • cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slave_count
The result should be the number of DS1820 connected.
To retrieve the serial number of the chip-sets :
  • cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slaves
This is the Perl script used to read a sensor, copied from the article of David Mills,  RaspberryPI DS1820 (read that article for more details and how to read two sensors).

#!/usr/bin/perl
$mods = `cat /proc/modules`; 
if ($mods =~ /w1_gpio/ && $mods =~ /w1_therm/) 
   print "w1 modules already loaded \n"; 
else  
   print "loading w1 modules \n"; 
   $mod_gpio = `sudo modprobe w1-gpio`; 
   $mod_them = `sudo modprobe w1-therm`; 

$sensor_temp = `cat /sys/bus/w1/devices/10-*/w1_slave 2>&1`; 
if ($sensor_temp !~ /No such file or directory/) 
   if ($sensor_temp !~ /NO/) 
   { 
      $sensor_temp =~ /t=(\d+)/i; 
      $tempreature = (($1/1000)-6); # My sensor seems to read about 6 degrees high, so quick fudge to fix value  
      print "rPI temp = $tempreature\n";  
      exit; 
   } 
   die "Error locating sensor file or sensor CRC was invalid";  
}