Category Archives: Programming

Endless delay …

Let’s not wait for this to be done:

// Delay for x milliseconds (at 8 MHz clock)
void delay_ms(uint16_t x) {
    uint8_t y, z;
    for (; x > 0; x--) {
        for (y = 0; y < 1000; y++) {
            for (z = 0; z < 8; z++) {
                asm volatile ("nop"); // one clock cycle 125 ns
            }
        }
    }
}

Hexadoku solver

The Elektor magazine has been entertaining its readers for close to 10 years with a Hexadoku puzzle. The first one was published in the edition of January 2006. Compared to the more common Sudoku puzzle, the range of possible values is extended from single digit decimals (1 – 9) to single digit hexadecimals (0x0 – 0xF). The size of the puzzle is increased from 9 x 9 cells to 16 x 16 cells and consists of 4 x 4 squares of 4 x 4 cells.

hexadoku Continue reading

Bending tubes for OpenFOAM

For some reason I have been looking for an easy method to create a meshed gas line with various bends. Our favourite search engine returned an undisclosed solution by Kjetil Moe: Automating blockMesh pipe geometries in OpenFOAM. Unfortunately, access to the OpenFOAM Pipemesher is restricted. So, how hard could it be to automate the creation of a blockMeshDict file from a list of tube bending parameters? Today I fixed the last bug to get a working Python script and could quickly create a couple of examples, as shown below in screenshots of Paraview. A next step could be to rewrite the code and make it look pretty.
example1
Continue reading

Instrument of Things

The Instrument of Things project shows how to extend your custom electrical instruments with industry-standard capabilities for remote control via a TCP/IP interface. The WIZnet WIZ550io module is used to enable a basic web server, a portmap service, and a server for the remote control of the instrument using the VXI-11 communications protocol. The ultimate goal for the Instrument of Things is to easily add the VXI-11 communications protocol and LAN eXtensions for Instruments (LXI) technology to any electrical instrument project.
WIZnetconnect_logo_horweb_550x
Continue reading

Spark Core browser control

The Spark Core is a tiny module with ARM Cortex M3 micro-controller and Wi-Fi interface. These devices will be connect with the Spark Cloud service for firmware updates and remote control. A limited amount of pins on the module can be used for analog and digital signals. The firmware of the Spark Core can be programmed, compiled and uploaded using the Spark Web IDE.

The following code is for a Spark Core installed on the Spark relay shield. All relays are controlled using a single function. Up to four functions are currently supported by Spark. The status of the four relays can be read through a single variable.

Continue reading

Zoomify, TilePic and other mosaic

Several sites are using the TilePic image format to show sections of a larger image. The TilePic file format contains the image data for a limited number of resolutions (zoom levels) and all image parts (tiles) have the same dimensions. The first level contains the full image scaled to a single tile. The second level could contain 4 tiles of the same size, each containing a quarter of the image data at twice the resolution of the first level. The third level then contains 4 tiles for each tile of the second level, resulting in a total of 16 tiles for the full image. The advantage of the TilePic format is that the client only needs to download the specific tiles for the shown part of the image from the level with the correct resolution. The websites usually provide zoom and scroll functions to magnify a part of the image.

Continue reading

DLP-TH1b Temperature Humidity Sensor

Recently I have ordered a FT2232HQ mini-module from the webshop of Future Technology Devices Ltd. for use in an ongoing project with a Xilinx Spartan FPGA. In addition, I ordered a DLP-TH1b data acquisition module as a working application of a FTDI USB UART to play around with. Unfortunately, the source code for Linux systems on the website of DLP Design did not work at all. Opening the black sensor box revealed a Sensirion SHT11 humidity and temperature sensor. The source code has been changed a little using the datasheet of this device and the D2xx programmer’s guide of FTDI. My version is available for download using this link: dlp_th1b.tar.gz.

Tilepic scripts (2)

On request, the script to download and reconstruct TilePic images was modified for Windows users in a quick and dirty way. The requirements for using the script are installed versions of ImageMagick and wget for Windows. Place the following code in a text file, adjust the first two lines to point to the TilePic image and the locations of the installed programs, and change the extension of the filename to .bat to make it an executable script. The script will download all tiles with the highest resolution data. It can take several minutes to append all rows of tiles to make the final image, so be patient.
Continue reading

Tilepic scripts

Several sites are using the Tilepic image format to show sections of a larger image. The Tilepic file format contains the image data for a limited number of resolutions (levels) and all image parts (tiles) have the same dimensions. The first level contains the full image scaled to a single tile. The second level could contain 4 tiles of the same size, each containing a quarter of the image data at twice the resolution of the first level. The third level then contains 4 tiles for each tile of the second level, resulting in a total of 16 tiles for the full image. The advantage of the Tilepic format is that the client only needs to download the specific tiles for the shown part of the image from the level with the correct resolution. The websites usually provide zoom and scroll functions to magnify a part of the image.

Downloading the high-resolution image from the Tilepic file requires some knowledge on the location of the file on the server. This information can be found in the source code of the webpage and may for example be /photo/tilepic/image.tjp. The following script will download all tiles from all levels of the Tilepic image defined by $file.
Continue reading