Vending Library

Post by Luke Dearnley, Kaho Cheung and Paula Bray.

Something strange is in our foyer.  It’s a vending machine full of printed Library collection items!

The State Library of NSW has a history dating back to 1826. Its renowned historical and contemporary collections, comprising more than six million items, hold the growing memory of our state and nation. However we are a research library not a lending library and there is only a small percentage of the collection that can be physically displayed at a given time. The DX Lab has played with the idea of the Library not being a ‘lending’ library and turned our latest experiment into the ‘Vending’ Library, a recycled vending machine that dispenses a printed collection suprise.

The Vending Library project uses a Twitter bot, @vendinglibrary, to suggest a personalised collection item for the user based on their previous Twitter content, who then obtains it from the vending machine.

The physical vending machine was sourced surprisingly easily and cheaply from eBay. It is filled with a curated selection of reproductions, made by the Research and Discovery team, of items from the Library’s collection. The Node.js based Twitter bot was built to help the user choose which of the 56 items they should obtain from the Vending Library.

The curators chose seven themes to inspire which collection items they would select. These include:
• Curios
• Love
• Maps
• Travel
• Portraits
• Animals
• Quotes

In order to suggest an item, the Twitter bot tries to classify you as interested in one of those seven themes, based on your previous tweets.

Vending Library content
A small subset of Vending Library collection item examples.

We used the Twit package to simplify interaction with the Twitter API and NaturalSynaptic, a neural network based natural language text classifier.

It listens to the Twitter firehose for tweets sent to its @VendingLibrary handle that contain the hashtag #suggest. It then ingests the last 40 tweets of the user who tweeted asking for the suggestion, assembles a random selection of about three quarters of those into a text string, adds the user description and then feeds that to the text classifier which returns a theme.

At this point it is necessary to describe the vending machine a bit further. It contains 56 coils into each of which about 20 items can be slotted. The coil turns 360 degrees and the front-most item drops out for the lucky user. These 56 coils are arranged into seven rows of eight. So each row is dedicated to the items of one theme. Each theme has eight unique items.

Vending Library, stacked and ready to go!
Vending Library, stacked and ready to go!

Once the @vendinglibrary bot has determined your theme it knows which row to suggest and which of the eight items in that row then it simply picks one at random. It tweets back to you saying something along the lines of From the look of your tweets you might be interested in [theme]. Enter [code] on the keypad. [shortURL]

Each of the printed collection items has a short URL on it which links back to the item’s entry in the Library’s catalogue. This allows people to find out more about their item. Less typing with one’s thumbs. Of course this has the side effect that the items in each row must be placed in the correct order when the Vending Library is being stocked.

We experimented with printing the collection items in-house but in the end sent the job to a printer. Of course they then needed to be folded and stuffed into the envelopes which fitted into the coils.

Vending Library stuffing party
Vending Library production party.

Moving the vending machine around the Library is slightly tricky as, while it is on wheels, it is just too tall to trundle into the lifts, meaning it has to be tipped when moving in and out of the lift. Luckily each row of coils is removable from the body of the machine making it much lighter to handle. This also had the side-effect of making stacking the envelopes into the coils much easier.

Vending Library, stacking in progress.
Vending Library collection item stacking in progress.

Spark Festival

On the 13th October the Library hosted the Spark Festival launch event at the Library and the DX Lab were invited to host a roadshow of our experiments shown on the night. This seemed like a  perfect opportunity to test out the Vending Library on a real crowd!

Curator Anna Corkhill using the Vending Library at Spark Festival
Curator Anna Corkhill using the Vending Library at Spark Festival

Several people who used the machine didn’t have Twitter and preferred to simply chose an item at random. For the 26 people who did ask for suggestions, the breakdown of how it classified people is as follows:

Curios: 1
Love: 7
Maps: 1
Travel: 0
Portraits: 3
Animals: 1
Quotes: 13

These results seem oddly skewed toward Quotes and then Love, which highlights an important aspect of using neural networks: using suitable training data. It is quite possible that the training text we used has caused this skewing.

In the early stages of making the Twitter bot we were using a ‘test’ twitter account for the bot (rather than the final @VendingLibrary) but tested it initially using our own Twitter accounts. This turned out to be somewhat unwise as numerous followers saw our activity and began to re-tweet our tests!

Consequently a second test account was set up to tweet to the bot’s test account. Of course that account needed a Twitter history so the bot could analyse its tweets. We copied tweets from the accounts of various gallery, library, archive and museum sector luminaries and tweeted them from the test account to give it some ‘genuine’ history which could be analysed.

Unit Testing

Next we set up unit testing which allowed us to simulate ‘suggestion request’ tweets from any account. The testing file simply needed the Twitter handle of the requester and the ID of their account which this site helped with.

These tests didn’t actually return tweets to the requester, but simply logged what the bot would have tweeted. This allowed us to repeatedly ‘request’ from the same account to see how consistent the text classifying was. By using a wide range of accounts in testing we also checked that the themes the bot was suggesting were not skewed to one theme in particular. A fair amount of time was spent tweaking the training text in an attempt to minimise any skewing from the bot’s suggestions.

Despite this, the results above suggest more work may be needed here although 26 uses is a pretty small sample size.

The next step was deploying the bot and testing it outside of a local development environment. We used Zeit’s Now, a simple command line driven service that deploys to a ‘multi-cloud’ architecture. It is an abstraction on traditional cloud services like AWS, Google and Azure, with Now taking care of scaling, cost and performance. We are still experimenting with it and hope to use Now for other projects.

The bot was quite stable while deployed by Now, however the day before the Spark Festival launch, it went rogue and was un-killable, despite our best attempts! We noticed this because we were getting double replies to tweet requests. Eventually the rogue bot died off and we were back in business.

Feel free to check out the Twitter bot code in our git repo.

The Hardware

It was clear when we collected the machine from its previous owner that we would need to replace the generic signage at the top of the unit with some custom designed Vending Library signage. Kaho used his graphic design skills and we decided to use an online laser cut/etching service and make the signage from a matt frosted acrylic for both the backlit top sign on the machine and also two instructional panels that were positioned above and below the keypad. There was still plenty of space left on the 900mm x 600mm sheet, so Kaho designed a bunch of DX Lab and State Library key chains for promotional swag, some of which can be seen in the first photograph of this post.

Laser cut vending machine before protective layer was peeled.
Laser cut vending machine before protective layer was peeled.

The machine itself is based on a 1989 vintage 8-bit microprocessor (the Intel 8032AH, a ROMless MCS-51) connected via numerous ribbon cables to the coin slot assembly, the 16 button keypad with two line display and lastly several daughterboards which then lead to the motors driving the coils.

vending machine 8-bit CPU
Vending machine 8-bit CPU
vending machine daughterboard
Vending machine daughterboard
vending machine motors
Vending machine motors

All programming of the machine had to be done via the 4×4 keypad and 16-character 2-line display screen. This proved quite arduous as each of the 56 items needed to have its price set (to 10c), be assigned to one of the coil locations, and have a product name entered. Only having 16 keys on the keypad meant the product names (we used the item’s theme) have to be entered as a string of ASCII values! Fun 80s 8-bit times!

When we originally obtained the machine we were not 100% sure exactly how we would use it as a DX Lab experiment but the assumption was it would probably be somehow hooked up to the internet. So I (Luke) set about reverse engineering the electronics that controlled the motors so see if we could control them via an Arduino micro-controller which was easily done.

Each daughterboard has two sockets on it for outbound ribbon cables that run to one row of 8 motors. They also have a pair of smaller sockets via which they are daisy-chained together for eventual connection to the CPU – let’s call this the motor bus. The main action on the daughterboard is a 4514 4-to-16 line decoder chip, the 16 outputs of which run through two ULN2803 Darlington transistor arrays functioning as line drivers for the two rows of motors.

The motor bus has 4 lines (ABCD) for selecting 1 of 16 motors to turn, and then 4 more lines which are connected to each of the 4514’s inhibit inputs. To engage a particular motor the inhibit line for the daughterboard that motor is connected to needs to go low, while also setting the binary value for which of the 16 motors is to activated via the ABCD lines. Then a strobe line jolts the 4514 into action. Each motor has a cam attached to its backside against which a microswitch is positioned. This allows the motor to know when it has done a full 360 degree rotation and stop.

Reverse engineering the vending machine electronics
Reverse engineering the vending machine electronics

Thus by highjacking the 4 inhibit lines, the 4 ABCD lines and the strobe line it would be possible to control any motor in the vending machine via another system such as an internet connected Arduino. A mere nine wires. (and yes I know it could be done in seven, it’s a shame the inhibit lines aren’t also binary encoded.)

At one stage we were considering the idea that users could tweet directly to the machine to obtain their collection item, however we soon realised this would allow any Twitter user anywhere to cause the machine to drop items, leading to it being emptied quickly without the items really being seen by anyone.

Next Steps

We are considering using the Vending Library for other uses such as specific exhibition content or theming it to a festival.  One of our initial ideas was to have time-based content that you could choose that is relevant to your daily commuting time.  For now we hope you enjoy this playful experiment by the DX Lab while it is located in the Library’s foyer.

1 response to Vending Library

  1. Jenny Kirkby says:

    What a great idea! I think this is really cute and clever. But I”m not surprised that Love and Quotes are you top sellers. Personally I’d probably go for Portraits, but that’s just me. Lovely way to make some little bits of the Library’s collection more accessible.

Leave a Reply to Jenny Kirkby Cancel reply

Your email address will not be published. Required fields are marked *