[Hack a Day] 6 New Entries: Simulated annealing

Simulated annealing


annealing

Here’s an update on our earlier post about genetic programming. Altered Qualia has posted a new implementation of [Ron Alsing]’s idea. It starts with 50 polygons and then randomly changes one parameter with each optimization step. If the the change results in fewer differences from the target image, it’s kept as the new best DNA. This search method is similar to simulated annealing. The image above is the result of 1500 good mutations out of 35900 possible. The implementation lets you choose any image, but smaller means the fitness calculation is faster. It’s written in JavaScript using the <canvas> environment. You’ll definitely get better performance using newer browser builds.

[Original image by R Stevens]

[via Waxy]

      

WordPress 2.7 upgrade in one line


wordpress

BadPoetry WordPress 2.7 has just been released and features a complete interface overhaul. Hack a Day runs on WordPress MU hosted by WordPress.com, so we got this update last week. We run standard WordPress.org on all of our personal blogs though. We recommend it because it’s free, has a massive userbase, and if you host it yourself, you can do whatever you want with it.

To make the upgrade process as simple as possible (and for the sheer rush of ‘rm -rf’), we use a one line command.

$ curl http://wordpress.org/latest.zip -o "wp.zip" && unzip wp.zip && rm -rf ./wordpress/wp-content/ && cp -r ./wordpress/* ~/www/

curl downloads the latest version from wordpress. unzip unpacks all of the files into a directory called ‘wordpress’. rm -rf removes everything in the ‘wp-content’ directory. Otherwise, you will overwrite your images, themes, and plugins. cp -r copies everything to your http document root, overwriting the previous install.

Naturally, you should back up your current install and database beforehand. We tend to use the one-liner with reckless abandon. If you’re wondering about the terseness, it was designed to fit inside the 140 character limit of Twitter.

[Thanks, Chris Finke]

      

Parts: 1-Wire temperature sensor (DS1822)


1wire

Download: buspirate.v0d.zip

Dallas/Maxim’s 1-Wire protocol is the most requested addition to the Bus Pirate.  We finally got some 1-Wire parts, and today we’ll demonstrate the DS1822 1-Wire digital thermometer. Grab the datasheet (PDF) and follow along.

This post is accompanied by release v.0d of the Bus Pirate firmware for hardware version 0. This includes the new 1-Wire protocol library, more configuration options, and other improvements.

DS1822 Economy Digital Thermometer (Digikey #DS1822+-ND, $3.87) We found a footprint in the 1-wire library for Eagle on the Cadsoft download page.

The 1-Wire protocol uses a single wire for data transfer, and sometimes power. Data is transferred in time-sensitive ’slots’ because there isn’t a separate clock to delineate bit periods.

ds1822cct

Bus Pirate
DS1822
SDA
DQ
+5volts Vdd
Ground
GND

The DS1822 connections are shown in the table. We used the Bus Pirate’s 5volt supply to power the DS1822, but it also works at 3.3volts. A resistor (R1, ~5K) holds the bus high.

All 1-Wire commands start with a reset procedure, followed by one of five ROM commands.

Command Description
0×33 READ ROM. Read single device address.
0×55 MATCH ROM. Match device address, followed by 64bit address.
0xCC SKIP ROM. Address all devices together.
0xEC ALARM SEARCH. Search for alarm condition.
0xF0 SEARCH ROM. Part of address enumeration procedure.

ROM commands are described on page 10 of the datasheet. All ROM commands are available as macros in the Bus Pirate 1-Wire library, see (0) for a menu. ROM command macros include the 1-Wire bus reset procedure.

Single device

singli-4501

All 1-Wire devices have a unique 64bit (8 byte) address, and some 1-Wire devices are used exclusively to give electronics a unique tracking number. When a single device is connected to a 1-Wire bus, the READ ROM command will extract its address.

1-WIRE>{ 0×33 r:8 <–command
xxx 1WIRE BUS RESET OK
xxx 1WIRE WRITE: 0×33 <–READ ROM
xxx 1WIRE BULK READ, 0×08 BYTES:
0×22 0×47 0×45 0×22 0×00 0×00 0×00 0×29 <–ID#
1-WIRE>

The command sends a bus reset ({), the READ ROM command (0×33), and reads the 64bit address (r:8, 8 bytes *8bits/byte=64bits).

The first byte (0×22) identifies this as a DS1822 thermometer. The next 6 bytes are unique to this device, and the final byte is a CRC of the previous 7 bytes.

Now we can address the device with the MATCH ROM command and send it further instructions.

1-WIRE>{ 0×55 0×22 0×47 0×45 0×22 0×00 0×00 0×00 0×29 0×44
xxx 1WIRE BUS RESET OK
xxx 1WIRE WRITE: 0×55<–MATCH ROM command
xxx 1WIRE WRITE: 0×22<–start address
xxx 1WIRE WRITE: 0×47
xxx 1WIRE WRITE: 0×45
xxx 1WIRE WRITE: 0×22
xxx 1WIRE WRITE: 0×00
xxx 1WIRE WRITE: 0×00
xxx 1WIRE WRITE: 0×00
xxx 1WIRE WRITE: 0×29
xxx 1WIRE WRITE: 0×44 <–start conversion
1-WIRE>

First, we send the MATCH ROM command (0×55) and the device address (8 bytes).  Next is the CONVERT T command (0×44, datasheet page 11) that starts the temperature conversion.

A second command sequence retrieves the temperature reading from the DS1822.

1-WIRE>{ 0×55 0×22 0×47 0×45 0×22 0×00 0×00 0×00 0×29 0xbe r:9
xxx 1WIRE BUS RESET OK
xxx 1WIRE WRITE: 0×55
xxx 1WIRE WRITE: 0×22
…long 1-Wire address…
xxx 1WIRE WRITE: 0×29
xxx 1WIRE WRITE: 0xBE <–read scratchpad command
xxx 1WIRE BULK READ, 0×09 BYTES:
0×71 0×01 0xFF 0×00 0×7F 0xFF 0×0F 0×10 0xF8
1-WIRE>

The READ SCRATCHPAD command (0xBE, datasheet page 11) returns 9 bytes. We only care about the first two bytes, the rest can be decoded according the the table on page 7 of the datasheet. Temperature is calculated according to page 4 of the datasheet: 0×0171 HEX=369 DEC, 369*0.0625=23C  (74F).

Multiple devices

multi-450

When multiple 1-Wire devices share a bus it’s more difficult to determine all the addresses. The fastest way to find attached devices is with the SEARCH ROM command (0xF0) and a binary branching procedure. The Bus Pirate automates this with macro (240).

1-WIRE>(240) <–macro 240
xxx 1WIRE ROM COMMAND: SEARCH (0xF0)
Found devices at:
Macro     1-WIRE address
1.0×22 0×50 0×28 0×22 0×00 0×00 0×00 0×0A <–address
*DS1822 Econ Dig Therm <–type according to family code
2.0×22 0xD0 0xC7 0×1A 0×00 0×00 0×00 0×01
*DS1822 Econ Dig Therm
3.0×22 0×47 0×45 0×22 0×00 0×00 0×00 0×29
*DS1822 Econ Dig Therm
Found 0×03 devices.
The first 10 device IDs are available by MACRO, see (0).
1-WIRE>

The SEARCH ROM command shows the devices it found, and the type according to the family code.

We think typing 8 byte 1-Wire addresses is really tedious, so the first 10 device addresses are stored in memory and can be accessed with the macros (1)…(10). A buffer for up to 50 device addresses can be defined in the 1-Wire library at compile time. Ideally, this data will be stored in a global scratch buffer shared by all modules in a future firmware update.

1-WIRE>(0) <–show macro list
0.Macro menu
Macro     1-WIRE address <–enumerated device addresses
1.0×22 0×50 0×28 0×22 0×00 0×00 0×00 0×0A
*DS1822 Econ Dig Therm
2.0×22 0xD0 0xC7 0×1A 0×00 0×00 0×00 0×01
*DS1822 Econ Dig Therm
3.0×22 0×47 0×45 0×22 0×00 0×00 0×00 0×29
*DS1822 Econ Dig Therm
1-WIRE ROM COMMAND MACROs:<–normal commands
51.READ ROM (0×33) *for single device bus
85.MATCH ROM (0×55) *followed by 64bit address
204.SKIP ROM (0xCC) *followed by command
236.ALARM SEARCH (0xEC)
240.SEARCH ROM (0xF0)
1-WIRE>

The macro menu (0) will also include the device addresses stored in the roster. Now we can just address devices by macro, rather than typing the whole 64bit address every time.

1-WIRE>(85) (1) 0×44 <–start conversion
xxx 1WIRE BUS RESET OK
xxx 1WIRE WRITE ROM COMMAND: MATCH (0×55) *follow with 64bit address
xxx 1WIRE ADDRESS MACRO 1: 0×22 0×50 0×28 0×22 0×00 0×00 0×00 0×0A
xxx 1WIRE WRITE: 0×44
1-WIRE>(85) (1) 0xbe r:9 <–fetch reading
xxx 1WIRE BUS RESET OK
xxx 1WIRE WRITE ROM COMMAND: MATCH (0×55) *follow with 64bit address
xxx 1WIRE ADDRESS MACRO 1: 0×22 0×50 0×28 0×22 0×00 0×00 0×00 0×0A
xxx 1WIRE WRITE: 0xBE
xxx 1WIRE BULK READ, 0×09 BYTES:
0×81 0×01 0×4B 0×46 0×7F 0xFF 0×0F 0×10 0×71
1-WIRE>

(85) is a shortcut for a bus reset and MATCH ROM command. (1) is the device address macro, and 0×44 is the command to begin a temperature conversion. Retrieving the reading involves the same macros, but substitutes the command to read the device (0xBE) and grabs 9 bytes (r:9). The temperature is 0×0181, or 24C next to the PC fan.

Taking it further

We used the Bus Pirate to give a visual demonstration of the 1-Wire protocol, but the real challenge is integrating it into your own design. Maxim provides example code, Microchip has an app note (PDF), and you can check out the example code we used.

Firmware download: buspirate.vod.zip

      

Edge-lit holiday cards


edgelit

Got 30 minutes for a holiday project and don’t want to get wrangled into some sort of decoupage disaster? Evil Mad Scientist Laboratories can show you just how easy it is to do edge lighting effects. Pictured above are three holiday cards constructed using scored plastic. You can use many different types of clear plastic for this, not just acrylic. The lighting is just an LED on a coincell. Black tape is used to prevent light leaking from the edges. The red and green version above is two stacked layers. This looks like something fun to scale up for a larger project or just to kill some time.

      

GigaPixel Panorama


gigapixel

[Ewout] sent us some info on this Automated Gigapixel Panorama Acquisition system.  The system automates the process of taking the large amounts of images required to do gigapixel panoramics. You tell it key information, like what lens, and what percent overlap you want and the system will calculate how many images it will take, as well as the gigapixel count. The results are quite stunning, no visible seams with fantastic detail.  Interestingly, this was created for a class in embedded system design (ECE4180) at Georgia Institute of Technology and so was our post earlier today on Digitally Assisted Billiards. Is Hack a Day part of the class curriculum? It should be.

      

Digitally assisted billiards


pool

[Justin] sent in his Digitally Assisted Billiards project. Using a web cam, a computer and a projector, these guys have set up a system that shows you the trajectories of your current shot.  It detects the angle of the cue and displays a glowing blue line showing where each ball would go and where the collisions would be. It is a bit slow right now, and made somewhat less accurate by a low resolution web camera. This could be a fantastic teaching tool if it were to get some more polish. The source code is available on the site, so you could try this one out at home.

      

You received this email because you are subscribed to the real_time feed for http://hackaday.com/feed/. To change your subscription settings, please log into RSSFWD.

No comments: