Featured

MolPad released to Windows App Store

Description

MolPad is a chemical structure drawing app specifically designed for tablets. It allows you to draw chemical structures freehand with a finger, stylus or mouse, just as you would with pencil and paper. The raw ink is converted on the fly to an underlying connection table. Both chemical bonds and handwritten atomic symbols are recognised, cleaned and incorporated into the structure.
screenshot_11222014_123756

Features

  • Intuitive to use
  • Designed specifically for tablets
  • Chemically intelligent
  • Recognises bonds and basic atomic symbols
  • Gesture support for drawing rings
  • Supports industry-standard Molfile format

Find MolPad here.

Feedback and suggestions for improvement welcome!

Lego Music

Description

This project describe the construction of a tangible user interface which allows the creation of music from an arrangement of physical blocks.

Coloured blocks are laid out on a flat surface and observed by an overhead camera. Computer vision algorithms are used to convert the pattern of blocks into a set of musical notes. Changing the position of the blocks changes the audio output in real-time.

Inspired by Yamaha’s Tenori-on

Details

Lego blocks (other plastic blocks are available) are arranged on a virtual 16 by 16 grid layout and a virtual cursor repeatedly scans the grid from left to right. As the cursor reaches each grid column, the blocks in that column trigger a note to be played, the pitch of which is determined by the vertical position of the block. Multiple blocks in a column result in multiple notes being played simultaneously.

Here’s a diagram to show the principle more clearly. Time is on the horizontal axis and pitch on the vertical axis. (For simplicity this shows an 8 by 8 grid)

 

This arrangement of blocks would play an ascending scale. When the cursor is at the position shown a three note chord would be played.

The final pitch of a note is not only determined by the position on the grid, but also by the user-selectable scale. There are nine scales in the software which map position to pitch. The pitch can also be globally transposed in semitone or octave increments.

Hardware design

The hardware consists of a webcam and some blocks. The webcam is connected to a laptop where all image processing and sound generation takes place.

To keep it simple Lego blocks were used. They have a consistent size and shape and should make it easier for the computer vision system to reliably track them. It was found that yellow blocks were not reliably detected and are more sensitive to lighting conditions. Other darker colours worked better.

The webcam used was a “GUCEE HD92 720P” model. A resolution of 640 x 480 is sufficient for this project so most webcams should work OK.

The webcam was mounted directly over the blocks using a hacked IKEA Tertial lamp. The original webcam clip was removed and the lamp bracket drilled out to accept the fitting.

 

For audio output the built-in PC sound card was used.

Software Overview

The overview of the system is as follows:

On the left are the vision components. These are responsible for getting images of the blocks from the webcam and converting them into a set of notes to be played. Open CV is a well known library for image processing and here we use the Emgu.CV wrapper for C#/.Net

On the right are the audio components. These convert the extracted notes into sound. The NAudio library is used for MIDI sound synthesis.

Software – Audio subsystem

The key component here is the Sequencer. This maintains the sequence of notes to be played and steps from one set of notes to another on receipt of a timer tick. Once the last note has been played it repeats from the beginning.

The human ear is very sensitive to changes in timing of sounds, so it’s important to use a regular beat for the timer. Standard Windows timers have a resolution of about 15 ms which is not quite good enough. Using the multimedia timer gives a resolution down to 1 ms and can be set to generate a periodic time tick with good consistency.

To simplify the audio output code MIDI synthesis is used. This avoids having to deal with analogue waveforms and keeps all audio in the digital domain. For this project the built-in Windows Microsoft GS Wavetable MIDI Synth is used. This is not the best sounding, but it allows up to 32 notes to be played simultaneously from a selection of 127 instruments and is adequate for our purposes.

The sequencer component can be run and tested independently. A sequence can be loaded using the SetNotes method which takes a 2-dimensional array of Notes and will then play that sequence in a loop until stopped.

Software – Vision subsystem

The job of the vision subsystem is to keep the sequencer updated as the arrangement of the blocks is changed.

The software continually grabs video frames from the webcam, identifies the block positions and maps them to cells on a 16 by 16 virtual grid. These cells are then converted to an array of notes for loading into the sequencer.

To identify the blocks the “SimpleBlobDetector” class from Emgu.CV is used. As the name suggests this identifies blobs in an image and outputs a list of the blob centroids (the coordinates of the block centres). The blob detector can be configured to only accept blobs in a certain size range, which can be optimised by trial and error for the particular blocks used.

Once the block coordinates are obtained they can be mapped to the nearest grid cells and then to an array of notes, the cell row and column giving the pitch and order of the notes respectively. The note array is then loaded into the sequencer.

This process runs independently of the sequencer so differences in frame rate or blob detection time do not affect the timing of the audio output.

The video sub system also displays the captured images and overlays some markers showing the positions of detected blocks and the current grid column being played.

User Interface

In addition to the tangible blocks interface there is a traditional Windows Forms user interface. This allows parameters such as tempo, instrument, transposition and octave parameters to be set. These parameters can be altered while the audio is playing and it will react in real time.

The user interface also shows the view from the webcam and overlays some markers showing the positions of detected blocks and the current grid column being played.

 

Demo Videos

 

 

 

References

Software available for download from:https://github.com/ynformatics/LegoMusic

Yamaha Tenori-on https://en.wikipedia.org/wiki/Yamaha_Tenori-on

Ohaus Scout Pro Wireless Interface Hack

Introduction

A potential project required wireless connectivity to an Ohaus Scout Pro SPU401 balance.

This balance takes a proprietary USB or RS232 adaptor which plugs into a 2×6-way edge connector on the PCB, but as an adaptor costs more than the balance cost on eBay it was decided to hack it.

Tracing out the edge connector pins on the balance PCB to the NXP LPC2103 micro-controller revealed the following circuit fragment:

An extra menu item only appears on the balance’s display when a serial adaptor is plugged in, so a reasonable guess was that the lines with pull-up resistors are pulled low in some combination by the adaptor to enable the unit to recognise it. And indeed after some experimentation it was found that starting the unit up with pin 8 grounded adds the Print and USB options to the menu. Grounding pin 35 on startup adds Print and RS232 items.

Navigating through the new menu options, setting baud rate to 9600,N,1 and print setting to continuous non-stable showed the expected serial output on TXD0 pin.

Hardware

The idea was to use an ESP8266 module to send and receive serial data from the balance to an MQTT topic. The edge connector has a 3.3V pin available, however the balance powers off if more than about 100 mA current is drawn. This was not enough to power the ESP8266 so a mini-buck regulator was used and fed directly from the 12V input jack.

Final hardware schematic:

And all wired together on a small strip-board. A 12 way, 2 row, 2.54mm pitch female edge connector (RS718-8245) from TE was used:

Software

A simple program to send/receive any serial traffic to an MQTT topic was downloaded to the ESP8266. Commands can be sent to/from the balance by publishing/subscribing to the “ohaus” topic.

Arduino powered Vileda cleaning robot – Part 2 (software)

Part 1 described the hardware portion of this project. TL;DR: the existing microprocessor was replaced with an Arduino.

Part 2 covers the low level robot control and iRobot Create emulation software.

A couple of hardware modifications have been made since part 1 was written:

  1. The Arduino Uno was replaced by a Nano. This is not only a lot smaller but also has a couple of extra IO ports.
  2. A battery voltage sensor was added in the form of a simple 4:1 resistor divider.

Thearduino pin mapping is now:

μC Pin Function Arduino Pin/Dir Notes
1 Right Bumper D6 In HIGH on bump
2 Over current In Unused
3
4 Right wheel forward D10 Out PWM IN1
5 Right wheel backward D9 Out PWM IN2
6
7 Fan & Side brush motor Out Unused
8 Wheels up D11 In All 3 wheels OR’ed
9 L switch D12 In LOW when pressed
10 L switch LED D13 Out Active LOW
11
12 M switch A6 In LOW when pressed
13 S switch A7 In LOW when pressed
14 Green LED A2 Out Active LOW
15 Red LED A3 Out Active LOW
16 M switch LED A4 Out Active LOW
17 S switch LED A5 Out Active LOW
NC Battery Voltage A0 In Via 4:1 divider
19
20 GND GND
21 Left wheel forward D3 Out PWM IN4
22 Left wheel backwards D5 Out PWM IN3
23 Left bumper D2 In HIGH on bump
24 Speaker D4 Out
25
26 Main brush motor A1 Out Unused
27
28
29
30
31
32
33
34
35 Left wheel encoder D7 In
36
37
38
39 Right wheel encoder D8 In
40 +5V regulated 5V

 

For the software it was decided to emulate an iRobot Create 2. This has a documented API (iRobot Create 2 Open Interface) so all design decisions have already been made. Also, because this is a popular platform, third party software exists to directly control the robot and a driver for ROS integration is available.

Not all of the Open Interface commands were implemented, just those required for motor control, odometry and common sensors. The source code can be extended as needed. Some constants may need changing.

The code is straight forward in operation:

  • The serial port is monitored for any incoming commands. The commands are parsed and executed which results in motors running, sensor data being returned or robot state being updated.
  • Wheel encoder pulses are accumulated via two interrupt handlers
  • Every 15ms the internal state is updated. Sensor data is streamed out if requested. If the robot is moving, the motor power is updated. In normal driving mode (velocity and radius specified) a PID controller for average velocity is cascaded with another PID controller to keep the wheel speeds in the required ratio for the specified turn radius. In “Direct” driving mode (velocity of each wheel specified), two PID controllers, one for each wheel, are used to keep the velocities at the requested values
  • The Arduino PID Library is used with some modifications including bias value support

Full code available on GitHub here.

To verify compatibility the code was tested with the following:

  • The Create.1.0.1.2.exe program from here. (If running on Windows 10 need to run as administrator). Local copy here.
  • The create_autonomy ROS driver

 

 

 

 

Arduino powered Vileda cleaning robot

Part 2 (software) now available

I needed a robot platform for a project and bought a Vileda A3 cleaning robot cheaply from ebay, advertised as not working but a new battery fixed that! (Battery for Vileda M-488a fits this A3 model)

Opening it up:

we find the expected motors for the wheels, fan, main brush and edge brush. The wheels are equipped with optical encoders. Other sensors include the left and right bumpers, wheel drop switches and cliff detectors. The top lid holds three buttons and a red and green LED. There is a 360 IR reflector installed but this is not populated with a detector.

There is a self-contained NiMH battery charger board under the top lid:

Rather than totally replace the existing PCB I decided to just replace the microcontroller (an 8051 clone) so I could keep the existing motor drivers, connectors etc

After a bit of reverse engineering I came up with the following PCB pin assignments:

μC Pin Function Arduino Pin/Dir Notes
1 Right Bumper D6 In HIGH on bump
2 Over current In Unused
3
4 Right wheel forward D10 Out PWM IN1
5 Right wheel backward D9 Out PWM IN2
6
7 Fan & Side brush motor Out Unused
8 Wheels up D13 In All 3 wheels OR’ed
9 L switch D12 In LOW when pressed
10 L switch LED D11 Out Active LOW
11
12 M switch A0 In LOW when pressed
13 S switch A1 In LOW when pressed
14 Green LED A2 Out Active LOW
15 Red LED A3 Out Active LOW
16 M switch LED A4 Out Active LOW
17 S switch LED A5 Out Active LOW
18
19
20 GND
21 Left wheel forward D3 Out PWM IN4
22 Left wheel backwards D5 Out PWM IN3
23 Left bumper D2 In HIGH on bump
24 Speaker D4 Out
25
26 Main brush motor Out Unused
27
28
29
30
31
32
33
34
35 Left wheel encoder D7 In
36
37
38
39 Right wheel encoder D8 In
40 +5V regulated

N.B. pin 9 was wired as an 8051 interrupt circuit so I modified PCB to make it a simple switched input (removed C23 and R89 and wired J7 pin 4 directly to μC pin 9).

I didn’t need the cliff sensors so didn’t trace those out.

The motor driver chip is an Allegro A4954 dual 2A/40V h-bridge. Current limit is pre-set. Pins IN1-IN4 of this chip are routed to the microcontroller.

Not much room around the PCB in-situ so I removed the microcontroller, soldered flying leads directly to the PCB and routed them to the indicated arduino pins. I wanted to keep the Rx/Tx pins free so only had 18 pins to play with. It should be possible to multiplex some inputs if needed in the future. Here is the hacked board under test:

and here it is embedded back in the robot:

The PCB is a tight fit and once the main brush motor is removed there is just enough space for the Arduino to sit in its place.

A simple program was written to exercise the main features. Here is a short video showing the response to bumpers and a quick demo routine that cycles through the LEDs, plays a tune and does a little dance.

 

 

 

Scratchy

 

Santa delivered a vinyl record player this year! We had great fun listening to old records from our past. One of the best things about the vinyl experience is the excellent user interface, with touch, feel and even smell. But our record collection is not in the best shape and after a while I missed the less scratchy digital downloads I’d become used to. So I looked for a way to combine the user interface of vinyl with the more predictable quality of mp3 files, and the result wasScratchy!

The idea is to connect the turntable audio output via a black box to an Android app, which listens to what is being played, identifies the album, and plays a digital version of it. At the top level the system looks like this:

Record Player -> Black Box -> Android App -> Amplifier -> Speakers

The black box has two main purposes:

  1. to trick the android phone into thinking there is a microphone attached. This just requires a 2.2k resistor from the mic input to ground. Any value resistor above 1k will do, lower values may trigger the phone to mute the audio.
  2. to drop the voltage from line level to mic level and to combine the stereo channels into one. A simple 100:1 resistor divider does the job. This is not needed if the turntable outputs a low level signal.

Here is the schematic:

And here is a view inside the black box:

 

In normal operation the android app runs in a loop as follows:

  1. Listen for a new record being played
  2. Identify the album
  3. Play a digital version of the album
  4. Continue to listen to the turntable output and stop the currently playing album if a period of silence is heard (needle up)
  5. Back to 1

Album identification is done by listening to the first five seconds of audio, fingerprinting it, and then looking up the fingerprint in a database. Fingerprinting is based on an algorithm published by Shazam (ref). The incoming audio is split into 0.1 second samples which are Fourier-transformed, and a set of representative note pairs extracted. See the linked reference for more details on how this works.

The app is trained to recognise new albums by switching to Learn mode, entering the name of the m3u file that it corresponds to, and then playing the album. When audio starts, the app will fingerprint about 7 seconds of it and store the fingerprint together with the m3u filename in a database.

The source album doesn’t need to be of high quality – old scratched records work just as well, as long as the first few seconds can be played and recognised. It is even possible to associate a digital album with a completely different physical record!

Here is a short video of Scratchy in operation:

The android app was written in C# using the Xamarin framework. Full source code can be found here: https://github.com/ynformatics/scratchy

I hope you find it useful.

iPhone Polarisation Camera

This project describes the construction of an iPhone accessory which allows pictures of polarised light to be captured. It is based on previous work by David Prutchi which should be referred to for more details.

Principles of operation

The device is based on a screen from an auto-darkening welder’s mask purchased on eBay. This is constructed from a liquid crystal panel sandwiched between two cross polarised sheets. When no voltage is applied to the liquid crystal it rotates incident light by 90 degrees and so the light passes through fairly unimpeded. When about 5V is applied the rotation drops to zero degrees and blocks the light.

Removing one of the polarised sheets produces a voltage-controlled polariser. Prutchi showed that there exists a voltage between 0 and 5V where the incident light is rotated by 45 degrees. By taking three images at 0, 45 and 90 degrees the degree and angle of polarisation can be determined for each pixel in the scene and visualised.

The precise voltage at which 45 degree rotation occurs varies over time so a way is need to calibrate the polariser. In this design a piece of polarising sheet is placed at 45 degrees and light from the iPhone’s flash-light is shone through and detected with a photo-transistor. By varying the voltage across the polariser, a minima in transmitted light occurs when the 45 degree polarisers cross. This minima can be detected and used to set the corresponding 45 degree voltage reference.

ds1054
Bottom trace – polariser voltage. Top trace – light detected by the photo-transistor. A clear minima can be seen.

The iPhone’s flash-light is also used to synchronise the change in polarisation with the image taking. The iPhone blinks the flash-light after every three images have been taken. The device uses this flash to reset the 0,45,90 sequence to a known state.

ds1054
Top trace (blue) – light pulses from photo-transistor. Bottom trace (purple) – synchronised voltage applied to the polariser.

Firmware

An Arduino is used to control the polariser. A photo-transistor located facing the iPhone’s flash-light LED is connected to both an external interrupt pin and an analog pin. Short pulses on the LED cause interrupts in the Arduino code which are used to synchronise the polariser. Long pulses on the LED cause the Arduino to enter calibration mode.

The time interval between synchronisation pulses is continuously measured and divided into three equal parts. On receiving a synchronisation pulse the voltage is set to 0V for one part, to the 45 degree voltage for one part and finally to 5V for one part.

Voltage for the polariser is supplied from an Arduino PWM output pin. To get a reasonably stable output the PWM frequency was increased to 32 kHz and smoothed with a second order RC filter.

The liquid crystal display will be damaged by a constant DC voltage so a CMOS switch is used to alternate the polarity. A 2 kHz square wave generated from a free running Arduino timer is used to drive the switching.

schematic

 

Hardware

The polariser was mounted on a cheap iPhone cover so that it covered the camera lens and the flash-light led. The photo-transistor was mounted in a strip of wood and taped to the polariser facing the iPhone flash light. For calibration a small strip of polarising film was cut at a 45 degree angle and inserted between the photo-transistor and the polariser. The circuit was made up on a scrap of strip-board. A separate battery pack was used to power the device.

IMG_6112
Assembled device
head detail
Camera head detail

iPhone App

The iPhone app is responsible for the UI and image processing. It is written in Swift.

Image frames are continuously captured from the camera. The time for three images to be captured is measured. A minimum of 60 ms per image is required and if needed intermediate frames are skipped to allow the polariser enough time to change between states. The flash-light is blinked after every 3 images to synchronise the polarisation. The blink is delayed by a variable amount to shift the alignment of frames to the changes in polarisation. A slider is provided to alter the alignmentdelay.

When three images have been received corresponding to 0, 45 and 90 degrees polarisation, they are processed to generate a representation of the scene which is displayed on the screen. Custom GL kernels are used to solve the Stokes equations and generate either an RGB or HSV visualisation of polarisation parameters. These calculations run on the phone’s GPU and so are easily able to keep up with the camera’s frame rate.

A “Calibrate” button turns on the flash-light for 2 seconds. This triggers the Arduino to run a calibration of the 45 degree voltage level, and provides the light to do so.

A selector allows a choice between RGB or HSV visualisation.

A “Shutter” button takes a picture by saving the latest processed image to the camera roll.

Full source code for the Arduino and iPhone is available here.

Example Images

IMG_6002[1]
Laptop cover illuminated at a shallow angle from rear showing horizontal polarisation (HSV)
IMG_6075
CD jewel case in front of laptop screen showing stress patterns (HSV)

 

IMG_6111
Car, RGB visualisation
IMG_6106
Car, HSV visualisation

Nixie voltmeter clock

IMG_5882

I recently acquired a vintage nixie tube multi-meter on eBay, with the not so original idea of converting it into a clock.

However, rather than hack around with the internal circuitry, I decide to see if I could keep the meter intact and use the existing voltmeter functionality to display time.  The basic idea is to send the meter a voltage corresponding to the time, so e.g. 12:45 becomes 12.45V. The meter has a 20V range which displays a fixed 2 decimal places which suits my purpose just fine. Unfortunately there is a hard limit to 20V on this range so a full 24 hour clock is not possible, but a 12 hour clock and maybe a 20 hour clock are.

The high level schematic is:

RTC -> Arduino -> DAC ->Multi-meter

IMG_5880

 

Each minute on the display corresponds to 10mV so the DAC must be at least this resolution. I used an AD5501 which has 12bit resolution and can work at up to 60V. For my needs I used the 30V range which works out at 7.3mV per bit, just enough. This DAC also has an integrated voltage reference which reduces the component count. It comes in a TSSOP package so was soldered onto a breakout board for easier prototyping.

For the RTC I used a DS3231 module. This is accurate to about 1 min/year and has a battery backup. It can be controlled from the arduino over an I²C bus.

The Arduino runs a simple program which at every new minute gets the current time, calculates the required voltage for the time, offsets it by a calibration factor and sends it to the DAC. The program also accepts a few commands over the serial port to calibrate the display and set the current time.

Here is everything running on a breadboard:

Breadboard layout

For power, rather than tap into the internal multi-meter power buses I hooked up a simple 240VAC/5VDC module with a cheap Chinese boost converter to give 15V for the analogue power.

The meter has space inside for a battery so there was no need to miniaturise the component layout and I just wired the modules together on a bit of strip-board, fixed it to an insulating base and popped it into the meter.

 

Capture

Connecting various lab instruments to ethernet

I have an assortment of lab instruments that I’d like to control from a PC. They have a range of connection options: RS232, USB, GPIB, Ethernet and support the SCPI protocol. Decided to standardise on Ethernet.

The three Rigol devices all have Ethernet connectivity so I assigned them all fixed IP addresses via the front panels, plugged into the LAN, and then connected via telnet (putty) to port 5555.

Rigol DP832

Responded to *IDN? query OK

Rigol DS1054Z

Responded to *IDN? query OK

Rigol DSA815

No reply to *IDN? query. I suspected the DSA815 did not like the CRLF line termination from putty and sure enough, sending just a LF terminator (0x0a) from a simple test program worked OK.

The other two older machines did not have an Ethernet port, so I connected via two Ethernet/RS232 adapters. I used the USR-TCP232-2 module from eBay. This doesn’t provide any hardware flow control so will need to bear that in mind for the PC control software.

The instructions were not the clearest but in the end configuration was straightforward. Plug the device into the LAN and run the USR-TCP232-T24V5.1.0.1.exe setup program. Click “Search in LAN” and you should see your device in the list. Select “TCP Server” mode, give it a new IP address and set the subnet mask and default gateway for your router. Set the module port to 5555 to match that used by the Rigols. Configure the RS232 port as needed. Then click “Set selected item via LAN”.

Keithley 2015 THD

Set RS232 comms to 19200,N,1,1 from the front panel. The 2015has a female RS232 connector and needs a M/M serial cable (crossover 2<>3, 3<>2, 5<>5). Set to no flow control for now. It also has the option of XON/XOFF flow control which might come in handy.

HP 33120A

Set RS232 comms to 9600,N,1 from the front panel. This unit requires 2 stop bits. It also requires pin 6 (DSR) to be held high when hardware flow control is not used. The unit has a male RS232 connector and needs a M/F null modem cable (2<>2, 3<>3, 5<>5, 6<>6). On the USR-TCP232-2 module I soldered a jumper lead from the +5V power pin to pin 6. Does the job.

IMG_5852

HP 34401A

Same as HP 33120A above.