Tuesday, 15 March 2016

Making Dumb Robots Evolve

Evolution is a fact of life, except in Kansas. It is the defining characteristic of life itself, but that doesn’t mean a stupid robot can’t evolve. For his entry into the Hackaday Pi Zero contest, [diemastermonkey] is doing just that: evolution for robots built around microcontrollers and a Raspberry Pi.

[diemastermonkey]’s project is a physical extension to genetic algorithms. Just like DNA and proteins have no idea what they’re actually doing, microcontrollers don’t either. Instead of randomly switching up base pairs and amino acids, [diemastermonkey]’s project makes random connections pins depending on the values of those pins.

The potential of these crappy, randomly programmed robots is only as good as the fitness function, and so far [diemastermonkey] has seen some surprising success. When putting these algorithms into a microcontroller connected to a tilting table mechanism and a PIR sensor, the robot eventually settled on a bit of code that would keep a ball in motion. You can check out the video of that below.


Raspberry_Pi_LogoSmall

The Raspberry Pi Zero contest is presented by Hackaday and Adafruit. Prizes include Raspberry Pi Zeros from Adafruit and gift cards to The Hackaday Store!
See All the Entries


Filed under: robots hacks

from raspberry pi – Hackaday http://ift.tt/1LntmmY
via Hack a Day

Monday, 14 March 2016

A $5 Graphics Card For Homebrew Computers

While not very popular, building a homebrew computer can be a fun and rewarding process. Most of the time, though, the video capabilities of these computers is as bare bones as it can get – running headless, connected to a terminal. While this is an accurate reproduction of the homebrew computers of the 1970s and 80s, there’s a lot to be said about a DIY computer with an HDMI-out port.

[spencer] built a Z-80-based homebrew computer a few years ago, and while connecting it to a terminal was sufficient, it was a build that could use a little more pizzazz. How did he manage to stuff a terminal in a tiny project box? With everyone’s favorite five dollar computer, the Raspberry Pi Zero.

The computer [spencer] built already had serial inputs, outputs, power, and ground rails – basically, a serial port. The Raspberry Pi also has TX and RX pins available on the 40-pin header, and with a stupidly simple board that [spencer] whipped up in KiCad, he could plug a Pi into the backplane of his homebrew computer. A few setup scripts, and a few seconds after turning this computer on [spencer] could mash a keyboard and wail away on some old school BASIC.

This isn’t a use case that is the sole domain of the Pi Zero. A Parallax Propeller chip makes for a great video terminal with inputs for PS/2 keyboards and mice. A largish AVR, with the requisite NTSC video library, also makes for a great video interface for a homebrew computer. The Pi Zero is only five dollars, though.


Raspberry_Pi_LogoSmall

The Raspberry Pi Zero contest is presented by Hackaday and Adafruit. Prizes include Raspberry Pi Zeros from Adafruit and gift cards to The Hackaday Store!
See All the Entries


Filed under: contests, Raspberry Pi

from raspberry pi – Hackaday http://ift.tt/1S0D4ej
via Hack a Day

Sunday, 13 March 2016

A Pi Powered Recording Studio

In the mid-90s, you recorded your band’s demo on a Tascam cassette tape deck. These surprisingly cheap four-track portable studios were just low tech enough to lend an air of authenticity to a band that calls itself, ‘something like Pearl Jam, but with a piano’. These tape decks disappeared a decade later, just like your dreams of being a rock star, replaced with portable digital recording studios.

The Raspberry Pi exists, the Linux audio stack is in much better shape than it was ten years ago, and now it’s possible to build your own standalone recording studio. That’s exactly what [Daniel] is doing for our Raspberry Pi Zero contest, and somewhat predictably he’s calling it the piStudio.

Although the technology has moved from cassette tapes to CompactFlash cards to hard drives, the design of these four-track mini recording studios hasn’t really changed since their introduction in the 1980s. There are four channels, each with a fader, balance, EQ, and a line in and XLR jack. There are master controls, a few VU meters, and if the technology is digital, a pair of MIDI jacks. Since [Daniel] is using a Raspberry Pi for this project, he threw in an LCD for a great user interface.

As with all digital recorders, the money is in the analog to digital converters. [Daniel] is using a 24-bit, 216kHz, four-channel chip, Texas Instruments’ PCM4204. That’s more than enough to confuse the ears of an audiophile, although that much data will require a hard drive. Good thing there will be SATA.

Although you can buy an eight-channel solid state recorder for a few hundred dollars – and [Daniel] will assuredly put more than that into this project, it’s a great application of a ubiquitous Linux computer for a device that’s very, very useful.


Raspberry_Pi_LogoSmall

The Raspberry Pi Zero contest is presented by Hackaday and Adafruit. Prizes include Raspberry Pi Zeros from Adafruit and gift cards to The Hackaday Store!
See All the Entries || Enter Your Project Now!


Filed under: digital audio hacks, Raspberry Pi

from raspberry pi – Hackaday http://ift.tt/1V4t4Ue
via Hack a Day

Birthday Celebrations The Pi Way

Home automation with your Pi – Part 2

Control your automated system

We are going to use heimcontrol.js as the control software for our automated system. This is a home automation web interface written in Node.js that runs on the Raspberry Pi, and sends low level serial commands to an Arduino connected via USB to control various hardware connected to it. Although some of the things the Arduino does can be done with the Raspberry Pi in theory, the Raspberry Pi does not have the ability to read analogue voltages, so temperature and light sensors would not be possible in this case. Also, the Raspberry Pi only has one hardware pulse width modulation output and three are needed for the LED strip.

Raspberry Pi prep

Use the latest Raspbian image as a starting point for this project. Log into the Pi using the default username of “pi” and default password “raspberry”. The first thing you’ll need to do is use sudo raspi-config to enable the camera and resize the root filesystem so the image uses all of the available space on the SD card. Once this is done, we can update our packages to the latest version and then install some extra packages that will be required later on:

sudo apt-get update

  sudo apt-get upgrade

  sudo apt-get install libboost-dev arduino streamer

Next, we need to download a precompiled Node.js package and a MongoDB package (both are required by heimcontrol.js. Packages can be found at http://ift.tt/1pgBuLC, in case they go missing.

  wget http://ift.tt/1UpNpTl

  sudo dpkg -i node_0.10.36_armhf.deb

Check it has installed correctly:

  pi@raspberrypi ~ $ node -v

  v0.10.36

Time to install MongoDB…

  wget http://ift.tt/1pgBxqL

releases/download/v2.1.1-1/mongodb_2.1.1_armhf.deb

  sudo dpkg -i mongodb_2.1.1_armhf.deb

  # Start service:

  sudo /etc/init.d/mongodb start

  # Automatically start service at system startup:

  sudo update-rc.d mongodb defaults

Now it’s time to install heimcontrol.js, which our expert had to fork on GitHub to fix a couple of issues.

  npm config set python python2.7

  git clone http://ift.tt/1c4zvf9

heimcontrol.js.git

  cd heimcontrol.js

  npm install

RaspberryPi&Speaker

The install process will take a while as there’s quite a lot of stuff to compile. Before you can access heimcontrol.js, you will need to know the IP address of your Raspberry Pi. You can find this out using the ip addr command. Our address was 172.17.173.41. Run heimcontrol.js by typing:

  node heimcontrol.js

Note that you have to be in the directory where you cloned the repository for this to work. This is probably /home/pi/heimcontrol.js. Heimcontrol runs on port 8080, so type the IP address of your Pi into your web browser followed by :8080 – in our case the correct URL was: http://ift.tt/1UpNpTp. We have applied a patch that disables authentication by default, because it gets annoying if you have to log in every time you want to use the web interface. You can re-enable authentication by editing config/development.js inside the heimcontrol.js directory.

Now that we know heimcontrol is working, Ctrl+C out of it because we have more work to do before we can start using it. We need to load the video for the Linux camera driver for the Raspberry Pi camera so that it can be used with the streamer software we installed earlier. To do this, you need to edit
/etc/modules using sudo and your favourite text editor (use nano if in doubt, so sudo nano /etc/modules). Add the line “bcm2835-v4l2” to the end of the file so the driver is loaded at boot. To load it instantly, run sudo modprobe bcm2835-v4l2.

Arduino prep and remote control scanning

We need to write some software to the Arduino called duino, which allows the ports to be controlled over serial from heimcontrol.js. This way of working is elegant because it allows more sensors to be added to the Arduino without any need to reprogram anything. We have already installed the Arduino software, so now we need to copy some libraries required by duino to the Arduino installation directory so that the software can be compiled:

  cd /usr/share/arduino/libraries

  sudo cp -r /home/pi/http://ift.tt/1pgBxqP

duino/src/libs/* .

  cd ~

Pi Comparison

Before we write the duino software to the Arduino, we want to use the Arduino to sniff the messages sent by the remote for the remote control sockets. To do this, connect the 433MHz receiver module (the wider module of the two modules with four pins instead of three – see diagram to left) to the Arduino. Connect the data pin (either of the middle pins) to pin 2 of the Arduino, VCC to 5V, and GND to GND. Download the receiver software using:

  wget http://ift.tt/1pgBuLO

rc-switch/master/examples/ReceiveDemo_Simple/

ReceiveDemo_Simple.pde

… which is again mirrored over at http://ift.tt/1UpNsOP.

Now we have to start the Arduino software. If you are connecting to the Pi via SSH then you can enable X11 forwarding to your local machine by logging in with:

  ssh -X pi@172.17.173.41

Alternatively, you can type startx to start an x session if you have a screen and keyboard connected to the Pi. Once you have logged in with your desired method, type arduino into a terminal to start the Arduino programming software.

Open the ReceiveDemo_Simple.pde file that you just downloaded and upload it to the Arduino. Then open the serial monitor (Tools>Serial Monitor) and press the reset button on the Arduino. By pressing each button on your remote, you can see the code to switch each socket on and off. Make a note of the codes for each button because you will need to enter them later. Our output can be seen in the top-right image.

Once this is done, we can finally write the duino software to the Arduino. This process is the same as what you’ve just done except the file is located at /home/pi http://ift.tt/1pgBuLQ.

The software might take a minute to compile. Once it has been uploaded, you can exit the Arduino software and press the reset button on the Arduino. Now we can put everything together and start adding our sensors to heimcontrol.js.

Set up your control interface

Now is the time to start adding our sensors and devices to heimcontrol.js

1. Start heimcontrol.js on boot

Before we start adding devices, it makes sense to start heimcontrol.js on boot. To do this, we can add a line to /etc/rc.local which is a script that gets ran at boot by the root user. The file needs to be edited with sudo and your favourite editor, for example:

  sudo nano /etc/rc.local

Add the following line before the line “exit 0”:

  su pi -c “node /home/pi/http://ift.tt/1UpNsOR” &

Heimcontrol.js will be started automatically at boot from now on, but for now you can start it with node /home/pi/http://ift.tt/1UpNsOR.

webcam_view

2. Add the camera feed

Go to Settings and select Webcam. Set the method to Streamer and the devices as /dev/video0. Pick an interval; we picked two seconds but you can pick any interval you like. Shorter intervals are more feasible on a Raspberry Pi 2, as it is generally more responsive. Click Save and then go back to the home page.

3. Prepare remote control socket codes

This is where you need the codes that you sniffed from the remote earlier on. The heimcontrol.js web interface takes the code as a binary string of 1s and 0s. However, the code we sniffed is in a different format so you’ll need to convert it to binary using Python. Type python2 into the terminal to open a Python interpreter. Format the integer you captured as a binary string like so:

  >>> “{0:b}”.format(16738063)

  ‘111111110110011100001111’

4. Add the remote control socket

Go to the Settings menu and go to the Arduino section. Click the Add button and set the method to RC Switch. Set the code type to binary. Give the switch a name, enter the pin that the RF transmitter is connected to (in our case, pin 2) and enter the two codes that you just worked out for the on/off buttons. Go back to the home page and test that the switch works. If it doesn’t, you might need to add an antenna to the transmitter by making a loop of wire. Check everything is connected correctly.

5. Add the temperature sensor

The temperature sensor can be tricky because it needs calibrating. A multimeter is a good idea so you can accurately read the analogue voltage. Go to the Arduino settings page and add a sensor. The formula for the TMP36 is: [(Vout in mV) – 500] / 10. We read 718mV with a multimeter, which would put the temperature at 21.8°C. Experiment with the formula by seeing what the raw value of x is from your sensor, but ours ended up as: (((x+45) * (5000/1023.0)) – 500) / 10. (5000/1023 is because the Arduino has a 10-bit analogue-to-digital converter, ie 0-1023 to read a voltage up to 5V.) Note that you have to ensure you have perfectly matched brackets, otherwise the software will crash because it simply tries to eval the string you put in.

Home automation with your Pi - Part 2

6. Add the LED strip

Finally, it’s time to add the LED strip. Make sure the signal wires are connected to PWM-capable pins on the Arduino marked with a ~. We used pins 3, 5 and 6. Go to Settings>RGB Lights. Ensure you have the signal wires connected to the correct colours. We used 6 for red, 5 for green and 3 for blue. Click Save and turn on the 12V supply. Select a colour from the colour picker. Your strip should light up! Pick Red, Blue and Green to ensure everything is wired up correctly. 



from Linux User & Developer – the Linux and FOSS mag for a GNU generation http://ift.tt/1pgBv26
via IFTTT

Wifi Enabled Center Speaker

[Ronald] has been improving his audio set-up for a while now, his latest revision culminating in this WiFi enabled center channel speaker. It all started with feature creep as you can see in this direct quote, “Being an engineer, I couldn’t stop here, not now that I had a way of adding more features…”

He had purchased a new amplifier for his system, but was irritated that the loudness setting would re-enable itself every time he switched inputs. First he thought he might just have a little board that intercepted the signals from his remote and tacked on the loudness off signal. It occurred to him that it would be even cooler if he could control it from his computer or phone. So he opened the case on his new amp and discovered an i2c break-out. We can guess how it went after that.

In version 2.0 he kept most of his work from 1.0, but wanted to simplify the set-up and build it all into a center speaker unit since an amplifier and two speaker cabinets takes up too much room. He fit a similar set-up as before in the center speaker casing, but added a touch screen and a few other improvements.  Though, strangely, he ran into some problems upgrading to the Raspberry Pi 2.0 and had to revert.

The final result is very nice, though obviously not done. As the engineer’s mantra goes, “If it ain’t broke, it doesn’t have enough features yet.”


Filed under: musical hacks

from raspberry pi – Hackaday http://ift.tt/1pmSVel
via Hack a Day

Saturday, 12 March 2016

Use the Twitter streaming API in Django

languages over the years, and one of these is, of course, the very popular Python. In the past, we’ve done tutorials on using Twitter via Python to create little apps and streaming programs. The various libraries make good use of the API and, with a little bit of tweaking, you can carry out a lot of Twitter-powered functions.

Twitter is a web tool, though, but luckily there is a version of Python for the web: Django. Some of the tools have been further ported to Django and allow you to integrate it into websites fairly easily. This can be used for something like a sidebar that has a running stream of tweets from the website owner or from a list of relevant information, or for sniffing out a certain hashtag. Using these in web development requires you to have your own API key from Twitter, but those are fairly easy to get when you look in the right place, and we’ll show you where that place is shortly.

Getting a Twitter API key enables you to start accessing Twitter via a whole number of ways, not just for a bit of Django in this tutorial. Bear in mind that it still doesn’t guarantee full access to Twitter, though; there is a limit to the amount of requests that it can make and there are no push notifications available for anything but the homegrown Twitter applications. Still, you can carry out a lot more different functions with it than those you might see in more official efforts.

To get the API, you need to first head to the Twitter Developer site while logged in (http://dev.twitter.com). The layout has changed a bit recently, but to find your list of apps to manage and/or add a new one, scroll down to the bottom to find the ‘Manage Your Apps’ option. From there, go to ‘Create New App’ and fill out all the necessary details for whatever it is that you want to create, filling in any blanks in your profile that Twitter wants in the process.

django1-1

Get the library set up

We’re going to be using the excellent Django Twitter Stream library by user michaelbrooks (http://ift.tt/1YJe2mD) to create our own Twitter streams. It runs on tweepy, one of the better Python modules for using Twitter, and makes use of a database to store data. We first need to install it using:

  $ pip install -e git+http://ift.tt/1plSukj

django-twitter-stream.git#egg=django-twitter-stream

Once installed, you should now add it to the INSTALLED_APPS in the Django settings file:

  INSTALLED_APPS = (

      # other apps

      “twitter_stream”,

  )

If you’re using MySQL, you’ll need to make an entry that enables it to save the tweets the correct way; MySQL is set to only read standard utf8 characters sets, whereas tweets use 4-byte characters that aren’t supported by that. You can add an entry to your database settings to fix that, though:

  DATABASES = {

      ‘default’: {

          ‘ENGINE’: ‘django.db.backends.mysql’,

          # username, password, etc…

          ‘OPTIONS’: {

              ‘charset’: ‘utf8mb4’,

          },

      }

  }

Finally, you need to update your database for the installation to complete. Do this with:

  $ python manage.py syncdb

django4-1

Connect to Twitter

Now the Twitter stream module is installed, you’ll find a new section on the Django admin page for ApiKey. Here you can add your Twitter keys – get them from the settings of the application we created earlier, filling in all the requested fields from the ApiKey.

We can now add filtering terms to the Twitter stream. Bear in mind that when we say ‘filter’, we’re referring to a specific term in the Twitter API. It’s basically the same as the standard Twitter search function, but you can give it more precise parameters that will return very specific tweets, such as all posts from a certain user, hashtag, list or whatever you’d like the website to display. You can add whatever filters you want to use to the database using the Django Admin interface again. There are exact details on all available filters inside the documentation (bit.ly/1LfN2Gh).

Most of it is the way that it reacts to certain phrases. Words with no punctuation will lead it to look for any instance of that word on its own. This includes Twitter account names, hashtags, instances where the word has punctuation attached to it and even links with the term in.

Adding a space between words allows you to search for multiple words in one tweet, and they don’t have to be together or in a specific order. You can also add a comma between terms as an AND/OR statement, returning results that contain either or both set of words.

The GET user parameter can be used to returns results from specific users, either from just their feed or only certain results from that feed, based on the keywords. There are more ways to narrow it down, such as by location or via lists, and with a bit of ingenuity you can create a complicated string that handles all your needs.

django2-1

Start streaming tweets

To begin building the database that you can start drawing from, you need to start the streaming API using the following:

  $ python manage.py stream

This will fill up by polling the stream every ten seconds. You can limit this rate by instructing when the stream should poll, but you cannot get it to create multiple streams. You can try if you want, but you may get your own API banned, so it’s not worth it. Anyway, to change this rate you can instead use:

  $ python manage.py stream MyAPIKeys –poll-interval 30

You can also get the stream to save to a .json file. You can do this if you want to read the file rather than the database, or if you want to shut down the database. To redirect it, use:

  $ python manage.py stream –to-file [file].json

Tweet page

You can create a stream page to initially check the stream before you start adding elements from it into a website. To do this, you’ll first need to add a new URL line to the url conf like so:

  url(r‘^stream/’, include(‘twitter_stream.urls’,

namespace=“twitter_stream”)),

You’ll also need to add it as an app in the INSTALLED_APPS file, with a section like so:

  INSTALLED_APPS = (

      # other apps

      ‘django.contrib.humanize’,

      ‘bootstrap3’,

      ‘jsonview’,

  )

Create a settings file

If you want to start customising the Twitter streamer, you need to add specific settings to the Django settings file. You can’t just change one setting and ignore the rest, though, so you’ll need to add all the default settings before making any modifications. Here’s what you should start with in your settings file:

  TWITTER_STREAM_SETTINGS = {

  # Set to True to save embedded retweeted_status tweets

  # Normally these are discarded.

      ‘CAPTURE_EMBEDDED’: False,

  # Change the default term track & tweet insert interval

      ‘POLL_INTERVAL’: 10,

  # The name of the default keys to use for streaming.

  # If not set, we’ll just grab one.

      ‘DEFAULT_KEYS_NAME’: None,

  # Put the stream in a loop so random termination

  # will be prevented.

      ‘PREVENT_EXIT’: False,

  }

With this, you can start making permanent changes to the way the stream works, as well which API keys to use at any given time if you’ve decided to use multiple APIs in the app.

django3-1

Implement into your site

The API allows you to create a database or a file to keep the necessary tweets in. As with any database or list file in Django, you can start using data from it to fill up a page or part of a page. Tweets contain time data, among other things, so you can easily organise them into chronological order to create a more natural stream.

If you are looking at retweets, though, be aware that if you’re writing information to a file, new entries will overwrite other data, so you need to use a database for that.

With these tools you can start updating your website to be much more in line with modern social media practices, and help direct people to other avenues of information than the main website.

Test settings

Try the following settings file to get things working at first, and build upon it to make the code better and more efficient.

  from os.path import abspath, dirname, join, normpath

  # Absolute filesystem path to the

  # Django project directory:

  DJANGO_ROOT = dirname(dirname(abspath(__file__)))

  SECRET_KEY = ‘secret’

  DATABASES = {

      ‘default’: {

          ‘ENGINE’: ‘django.db.backends.sqlite3’,

          ‘NAME’: ‘test_database.db’,

      }

  }

  STATICFILES_FINDERS = (

      ‘django.contrib.staticfiles.finders.

FileSystemFinder’,

      ‘django.contrib.staticfiles.finders.

AppDirectoriesFinder’,

  )

  TEMPLATE_LOADERS = (

      ‘django.template.loaders.filesystem.Loader’,

      ‘django.template.loaders.app_directories.Loader’,

  )

  TEMPLATE_DIRS = (

      normpath(join(DJANGO_ROOT, ‘templates’)),

  )

  INSTALLED_APPS = (

      ‘django.contrib.humanize’,

      ‘django.contrib.staticfiles’,

      ‘bootstrap3’,

      ‘twitter_stream’,

      ‘south’,

 



from Linux User & Developer – the Linux and FOSS mag for a GNU generation http://ift.tt/1V0zq6Y
via IFTTT

Amazon

Donate

Donate Towards More Raspberry PI's for Projects