Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Monday, 16 May 2011

How to: Connecting and receiving data from remote environmental sensors

This weekend I finally managed to complete my interface that will allow an anemometer (wind sensor) to control kinetic sculptures which could (theoretically) be placed on the moon. This post acts mainly as a log/set of instructions for myself and also for my own troubleshooting when I come to set up my installation at the gallery!! - those interested in using arduino and processing however, may find it useful...


1) download the Firmata arduino library for processing from here and put inside the libraries folder in the processing sketchbook.


2) upload OldStandardFirmata to the arduino board. I’m using an Arduino uno and find that this version of firmata works best. Note that arduino uno installs as '/dev/tt/usbmodem621' not 'dev/tt/usbSerial' as the older arduinos do...


3) Test that processing can access the serial data sent from arduino by running a sample processing sketch of a graph controlled by a simple arduino potentiometer circuit. I had a bit of trouble at this point – processing version 1.5 seemed to have trouble communicating with the serial port. I was getting all kinds of strange RXTX library conflict errors. There is a way around this by apparently deleting RXTX.comm.jar and librxtxSerial.jnilib from /library/java/extensions and replacing them with the same files from the arduino directory /Application/Arduino.app/Contents/Resources/Java. I could’t be bothered spending any more time on this problem so I simply reverted back to processing 1.2.1 and everything worked fine.


4) Now comes the tricky bit, I had to configure my Sky (netgear) router to allow for port forwarding for all traffic attempting to connect to my server (mac pro) on port 5210 - since my ip address was a local network address (beginning 192.168.x.x) and not the actual address that external site can see (http://whatismyip.com) . More info on configuring netgear routers to enable port forwarding can be found here you could of course use dynamic dns


5) Once that was set up it was time to test my feed. I setup a simple arduino/potentiometer ciruit and used processing to read the value of the potti. Make sure the EEML library for processing is installed at this point, this is the Extended Environments Markup Language and is a protocol for sharing data between remote responsive environments. Processing then broadcasts this data in a simple xml format. Providing the port forwarding works correctly, you can access this xml file, and subsequent potentiometer reading from your browser http://localhost:5210 - amazingly, this worked first time for me!!


6) If that works its time to setup the internet stream. A processing sketch reads the serial data and uploads this to the remote site. Test the feed works in the browser.


7) Once the feed is tested and working ok, its time to build the system that is to be controlled by the remote sensor. To test this I used a simple servo connected to arduino. I uploaded the ServoFirmata that is included with the Arduino IDE. Another processing sketch runs on the remote machine (again using both the firmata arduino library and EEML library) which pulls down the data from the live feed and moves the servo accordingly. The code for this sketch took aaaages to write and was really really messy. Thats the hard bit done woohooooo, all thats left to do now is make my kinetic sculptures.


If you like anymore info on this please leave a comment or email me.


Friday, 20 August 2010

Background on pseudorandom numbers

A pseudorandom number generator (PRNG), is a computer program algorithm for generating sequences of numbers that appear random in their inception. Pseudorandom numbers are an important practice for simulations (e.g. of physical systems with the Monte Carlo method - such computer simulation methods are especially useful in studying systems with a large number of degrees of freedom, such as fluids, disordered materials, strongly coupled solids, and cellular structures), and are central in the practice of cryptography (practice and study of hiding information) and procedural generation.

A Pseduorandom number can be started from an arbitrary starting state using a seed. It will always produce the same sequence thereafter when initialized with that state. The maximum length of the sequence before it begins to repeat is determined by the size of the state, measured in bits. However, since the length of the maximum period potentially doubles with each bit of 'state' added, it is easy to build Pseudorandom numbers with periods long enough for many practical applications. Although PRNGs will repeat their results after they reach the end of their period, a repeated result does not imply that the end of the period has been reached, since its internal state may be larger than its output.

Most pseudorandom generator algorithms produce sequences which are uniformly distributed by any of several tests. It is an open question, and one central to the theory and practice of cryptography, whether there is any way to distinguish the output of a high-quality pseudorandom number from a truly random sequence without knowing the algorithm(s) used and the state with which it was initialized. The security of most cryptographic algorithms and protocols using PRNGs is based on the assumption that it is infeasible to distinguish use of a suitable PRNG from use of a truly random sequence.