chemicaloliver

experimentation, criticism and geekyness

Listing wordpress pages with descriptions

Whilst building this site I wanted to implement wordpress in a way which didn’t make the site stand out as mainly being a blog. This approach led me to set up a number of static pages and I wanted to have an index of these pages for the projects page which would automatically update as I added new projects. Currently wordpress provides a function to list the titlesĀ  of all static pages, as links, using the wp_list_pages() method, however I wanted each page to be listed with a description, a task for which wordpress doesn’t provide a function so to solve this I wrote my own script which queried the appropriate bits of the database and made the page I wanted:

First I created a new php page template which would act as the index page.

Then I wrote a SQL query which extracts all the pages which are set as children of the index page (this requires that all pages you wish to appear in the index are set as children of the page).

$querystr = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'page' AND $wpdb->posts.post_parent = '68' ORDER BY $wpdb->posts.post_title ASC";

Then executed the query. Now the appropriate data has been retrieved all that remains is to loop through it and process it and add it to the page:

<h3><a title="Permanent Link to &lt;?php the_title(); ?&gt;" href="&lt;?php the_permalink() ?&gt;"></a></h3>

To add the description to each page I used a custom field when adding each page, in this case I called it “des”. Custom fields are stored as a multi dimensional array named $custom_fields in each post from which the appropriate field can be retrieved:

$my_custom_field = $custom_fields['des'];
<?php echo '<div id="des">'.$my_custom_field[0].'</div>';

Now the page can be completed by adding any footer or sidebar required and added to the site as normal as a new blank page using the page just created as a template.

The whole script can be downloaded here.

a new start

This blog has now superseeded the blog at newsofthewolf.wordpress.com. All previous posts have been copied over and there is a little duplication between the projects area and the details in the blog posts.

In future blog posts will detail new and interesting things I learn or come across whilst working on projects and details of completed projects will appear in the projects section.

twitterpop – hardware

The hardware for the system discussed in my previous post consists of an arduino, arduino ethernet shield, 2x 595 shift registers and one 8×8 common anode LED Matrix from china via ebay. Basically the arduino requests the page containing the current popularity metric and then adds it to an array containing the states of the currently lit LEDs which is then pumped out to the shift registers to update the display. The circuit lights the correct LEDs.

The circuit design is based on a design featured on the arduino playground for lighting 8 LEDs but was slight adapted to deal with the matrix. The schematic can be found here.

I have also attempted to form this into a new arduino shield so I can reuse the LED matrix circuit quickly for other projects, a PCB is currently with BatchPCB

twitterpop – Code

Recently I’ve been working on a popularity meter which searches twitter and displays a bar graph of the popularity of the search term on an LED Matrix driven by an Arduino. It currently relies on a PHP script on my webserver to do the actual twitter search and the arduino reads the page via ethernet and then displays the number on it bar graph.

The PHP script searches twitter receiving the results as a JSON feed and counting the results, this is just a basic script I threw together and is still very much work in progress as if there are more than ten results the arduino gets a bit confused. This is an abbreviated version of my code which is still functional.

$q = "%40chemicaloliver";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://search.twitter.com/search.json?q=".$q."");
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($curl);
$json_result = json_decode($result);
$count = 0;
foreach ($json_result->results as $res)
{
$count++;
}
curl_close($curl);
echo $count;

This searches for replies to my posts and displays in a number in a minimal html page.

The arduino then reads this page every time its main loop is executed and adds a new bar to the LED bar graph using the following code and using the TimerOne library. The full sketch can be downloaded here.

More information about the hardware will be included in a later blog post.

powershell and arduino serial communication

After struggling to get a bash script to send data from curl correctly to my arduino over serial I resorted to windows and found that communication over serial can be quickly achieved using the Powershell (the new cmd). I naively assumed it would be easier in linux than windows however the Powershell does seem to be quite a match for bash. I achieved what had taken me hours in Linux in about 10 minutes. The following example code shows the connection to the arduino and how to send data to any serial device This can of course be formed into a more sophisticated script or just run line by line:

$port= new-Object System.IO.Ports.SerialPort COM3,9600,None,8,one #opens serial port - adjust parameters accordingly
$port.open() #opens serial connection
$port.Write("Hello World") #writes your content to the serial connection
$port.Close() #closes serial connection

If you are not sure of the name of your serial ports then you can list them in the powershell:

[System.IO.Ports.SerialPort]::getportnames()

Fritzing!

While I’ve been experimenting with circuits and ardunio stuff recently I’ve been looking for a simple solution for converting a schematic to a breadboard/stripboard design, I’ve explored a few options like stripboard magic and eagle and non seem to be ideal however today I came across a new project via twitter.

Fritzing is an open-source initiative to support designers, artists, researchers and hobbyists to take the step from physical prototyping to actual product”

Available here

It allows the user to create circuits in a simple drag and drop environment on a 3D breadboard complete with arduino template, it can then convert this design into a schematic or etchable pcb and vice versa. It is still very much in development but from my initial playing looks like a very promising project.

writing a GUI in processing

When I first started looking into the Processing language it is quickly apparent that out of the box there is very little in the way of handling user input by way of GUIs. This has been rectified in a very nice way by the team who developed controlP5 this is in my opinion the easiest GUI library I’ve ever used enabling me to create sliders and knobs in a matter of minutes, having programmed very little in processing before. What I came up with is the start of the interface for my planned ardunio controlled synth system:

Continue reading writing a GUI in processing…

my first synthesizer

Today I started the first stage in what may become online collaborative synth music performance system, I built a very basic synthesizer.

My design is based on one kindly posted on hackaday which I built on stripboard (very badly). It produces a simple square wave using a hex inverter IC and a capacitor and resistor, the hackaday article also details how to build in an LFO and other bits and pieces however I’ve saved for the next version which intend to package in a nice box al la amazing rolo.

I have often noted people having difficultly locating reasonably priced parts for this type of project online, all parts for this project were sourced in the UK from http://www.bitsbox.co.uk who I found to provide exemplary service for a very good price, especially if you order only a small number of items.

The next version will have more controls and in parallel to this I’ve just received an arduino, this will be used with a digital potentiometer to control the synth parameters in the first instance via a GUI probably written in java or processing and then eventually PHP.

face tracking for virtual reality

Whilst studying for my masters I came accross various videos of the Nintendo wiimote being used for motion tracking to control 3d movement, and subsequently webcams being used for the same application. However there had been no work on how effective the webcam is at creating a 3d effect in comparison to traditional input methods such as the conventional mouse. Based on this I decided to design, build and test such a system for my masters thesis

The project can be considered in two discreate parts, the design, implementation and testing of the software and the testing of usefulness of the webcam in the system as an input device.

system structure

The development of the software can be divided into three discreet systems:

interfacing hardware and software

The system requires that images are captured from the webcam at high speed, to perform this OpenCV provides a simple cross platform interface which is able to grab images in all common formats from a video stream. DirectX based options were also explored for this task but they proved to be much more complex, requiring many more lines of code to achieve the same result.

Continue reading face tracking for virtual reality…

twitterpop

After buying an arduino and some 8×8 LED matrices I really needed a project to make good use of them. At a similar time I also had become a bit addicted to twitter and had been reading up on the API with the intention of doing something cool with it,somehow these ideas all got rolled into one to give a twitter popularity meter. The system uses a PHP script to search twitter for a predefined term, #tag or @reply and then presents the result of this as a webpage with number of results. The page is then read by an arduino with associated Ethernet shield and displayed on a bar graph format on the LED matrix.

Continue reading twitterpop…