Pages

Sunday, November 29, 2015

Quick List of Raspberry Pi Cyber Monday Sales 2015

List of Online Stores That Have Sales For Cyber Monday! 


Pololu
Raspberry Pi Model B+ Sale price: $22.95
Regular price: $29.95.   Coupon code: BF15P2752 (limit 3)

Raspberry Pi Expansion Boards Sale discount: 30% off
code: BF15C188 (limit 5 per item)


Farnell (UK)
15% OFF online orders over £200
Add voucher code CYBERW15 to your basket
Raspberry Pi A+ Media Streaming Kit only £22
Raspberry Pi A+ Night Vision Camera Kit for only £47
Raspberry Pi A+ Multi Room Audio Player from only £38.50


BC-Robotics


PiSupply




Black Friday: 15% off Sitewide (some restrictions apply). code BLACKFRIDAY15


Sensors


SainSmart
 Cyber Monday Deals storewide 15%OFF Coupon code: "CBM15%" Over $150 will be upgraded to Express Shipping from Standard Shipping for FREE.

Solarbotics
Various good deals :-)

Friday, November 27, 2015

Raspberry Pi - Computing Pi and Outputing Results Realtime w/ Python




Since I'm in the United States I was able to celebrate Thanksgiving.  One of my favorite parts of this day is eating pie.  Over the last couple weeks I've been comparing streaming algorithms that output Pi(the number) as it's calculated.  One handy python library I found was the PiDigits Library.  I was amazed at how well it did.  I also (through a lot of googling) found a couple more variations of those pi algorithms.  Of course I wanted to find the fastest.  I hopefully try to optimize it with the gmpy python library which handles very large numbers better.

  1. One I found here: https://github.com/DaveMDS/pigreco Gosper? algorithm? 
  2. And another here https://github.com/spmacdonald/pi_spigot 
  3. And another here https://github.com/CSC-IT-Center-for-Science/scalable-python/blob/master/Demo/scripts/pi.py Lambert


All of which I compared to the Pidigits python library and found a close winner between the

found the 3rd to be the quickest but really close to the first 1st.. I wrapped much of the equation with mpz functions (which handles large integers).

import gmpy

def pi_decimal_generator(): #gosper        
        global j
        q, r, t, j = mpz(1), mpz(180), mpz(60), 2        
        while 1:
            u, y = mpz(3*(3*j+1)*(3*j+2)), mpz((q*(27*j-12)+5*r)/(5*t))
            q, r, t, j = mpz((20*j**2-10*j)*q), mpz(10*u*(q*(5*j-2)+r-y*t)), mpz(t*u), j+1            
            yield int(y)

def pi_lambert_mpz(): 
    #lambert    
    k, a, b, a1, b1 = 2, mpz(4), mpz(1), mpz(12), mpz(4)
    while 1:
        p, q, k = mpz(k**2), mpz(2*k+1), (k+1)
        a, b, a1, b1 = mpz(a1), mpz(b1), mpz(p*a+q*a1), mpz(p*b+q*b1)
        d, d1 = mpz(a/b), mpz(a1/b1)
        while d == d1:
            yield int(d)
            a, a1 = mpz(10*(a%b)), mpz(10*(a1%b1))
            d, d1 = mpz(a/b), mpz(a1/b1)


Graph of 20,000 digits of before mpz and after (on a non overclocked Raspberry Pi 2):




You can see that adding mpz (from the gmpy python library) increased digit output by over double.

Lamberts and Gospers seemed really close so I did a calc to 100,000 digits normal CPU speed and overclocked to 1ghz.


Looks better right :-)


I then looked at my CPU and noticed it was only using one of the 4 Cores that the Pi 2 has :-(.

I doing my research on seeing if this can be split into multiple processes. But so far my attempts have been unsuccessful.  Maybe a reader(much smarter then myself) can help enlighten me on this quest.  Please comment and share.

Happy Thanksgiving weekend..


Sunday, November 15, 2015

Raspberry Pi - Tools to Program on a Headless Raspberry Pi Remotely in Python!



I've found some very useful tools to help me program on my Raspberry Pis.  Most all of which are not connected to screens, unless you count the Picture Frame Pi which is on the wall and would be impractical to connect a mouse and keyboard to and start coding.  Here are the tools I use for Mac and PC operating systems.

IDE

PyCharm Community Edition


PyCharm is Available for Linux,Mac, and Windows environments.  With the next tool you can mount your Raspberry Pi's as a network volume using sshfs or winscp (Window's)



Mounting your Pi on Mac

Here there are a couple of options. Installing and setting up a samba share or use the currently built in features of ssh and scp.  I decided to go the ssh route and used the following tools for that on my Mac
First you need to install Macfusion. Macfusion allows you to mount various filesystems on your Mac including network filesystems with a couple plug-ins.  Without installing samba on your raspberry pi you can mount your filesystem using the sshfs plugin. Notice in the link to install the dependencies before installing Macfusion.

Mounting your Pi on Windows

There's also a couple options but again if you don't have samba setup and don't want to go through the hassle you can do the sshfs or scp mount in windows as well with a couple tools:
  • A great post for mounting is found here: SSHFS For Windows. This makes the sshfs share appear as a mounted network drive.  
  • Another way is to use WINSCP. You are able to browse through your Pi's filesystem and modify, copy, move, and delete files.  If you go to your settings within winSCP you can modify the editors for each filetype.  You will want to choose PyCharm for your .py extension filetype.  When you edit a file from winSCP it creates a temporary file in a temporary directory within windows.  It then checks for file changes and syncs it back to the pi  (or whichever ssh file system you mounted).   

Mounting your Pi on Ubuntu/Debian

Since Ubuntu and Debian are similar you can follow the basic procedure here.  You can mount using the "Connect to Server" tool for mounting the SSHFS.  

Opening your project


After mounting you can open a current python project folder or create a new one.  Since I'm on my Mac you'll see the open dialog screen similar to that.  


Debugging your Project

PyCharm is an awesome tool with debugging. I found this article( which I couldn't have explained it better) on how to debug remotely http://www.codeproject.com/Tips/987276/Remote-Programming-of-RaspberryPi-using-PyCharm 


Hope this has been helpful.. If you don't like writing in nano and running.  Or opening up a VNC viewer and running the PyCharm IDE on the Pi..

Please Share if you found this helpful!!

Monday, November 9, 2015

Build your own Raspberry Pi Din Rail Enclosure

If you want to make your pi more industrial and connect it to some din rail and want a relatively cheap solution I found a couple parts that can your Raspberry Pi for under $15.
Comes with a 24v power input and doesn't take too long to make...
Parts:
BUD Industrial Plastic Din Rail Box.

7-24v to 5v 3A DC-DC Converter:












And some time cutting tools... I was able to use a Dremel. (and even with that I made some crooked cuts)


Cut out slot for the  24v dc converter

 Cut out usb & lan slots