Monday, 20 July 2015

Communicating with the Arduino

After connecting the Raspberry Pi to the Arduino, the next step was to communicate with it programmatically rather than simply uploading sketches.

As a first attempt I decided to try using Nanpy. This is a library that allows you to drive the Arduino from the Raspberry Pi using Python scripts. The version I tried to install was v0.94.

This wasn't successful. When I ran a simple script to blink the on-board LED on the Arduino I got the following error:

nanpy.serialmanager.SerialManagerError: Serial timeout

I edited the Nanpy sketch to enable some basic "Logging", again using the LED. This resulted in the discovery that the serial communications were not being set-up correctly. In particular:

if (ComChannel::available()))

was not evaluating to true.

I wasn't able to discover why so I've decided to park Nanpy for the time-being. If I get it working then I'll post full details for setting it up.

But there are always many ways to solve a problem in computing, without even harming any cats! I checked serial communication was working by running the ASCIITable example sketch on the Arduino IDA and viewing data in the Serial Monitor. This was OK, so I could try writing some code to simply switch on the on-board LED using Python.

I uploaded this sketch to the Arduino

// SerialTest
byte inByte;

void setup() {
   // initialise serial comms at 9600 baud
   Serial.begin(9600);
   pinMode(13,OUTPUT);

   // The on-board LED is explicitly off. 
   digitalWrite(13, LOW);
}

void loop() {
  while (Serial.available() > 0)
  {
     inByte = Serial.read();
     // If the byte is a digit in the range 0-9, light the LED
     // otherwise, turn it off
     if (inByte > 47 && inByte < 58)
     {
         digitalWrite(13, HIGH); 
     }
     else
     {
        digitalWrite(13, LOW);
     }
  }
}

Finally I wrote a very simple python script to write characters to the serial port. This should wait 5 seconds, turn on the LED, wait 5 seconds and turn off the LED, and repeat.

from time import sleep
import serial
arduino = serial.Serial('/dev/ttyUSB0')

sleep(5)
arduino.write('5')
sleep(5)
arduino.write('x')
sleep(5)
arduino.write('2')
sleep(5)
arduino.write('x')

I ran the script and the LED turned on and off as expected.

Monday, 13 July 2015

Halo?

It's always worth looking up every so often because there are often surprises when you least expect it. Saturday was a nice summer's day, warm but not hot and with a fair few clouds. However when I got home from shopping I saw a very well pronounced arc of a halo. It's not something I've seen too often, especially with the sun high in the sky, so I had to get the camera out.



* These pictures were taken from London on the 11th July 2015 at 11:40 BST.

So, what's going on here? There's quite a bit on the internet about the science of halos. On this day there was a lot of high level cirrus cloud as well as the Cumulus in the pictures. The ice crystals in the high-altitude cirrus are perfect for creating these optical effects.

It could have been a 22' circular halo, which is the most common. However, the sun in this case wasn't in the centre of the arc; it was instead just off to the top left corner of these pictures. The rule of thumb that 22 degrees is the size of your outstretched hand at arms length also wasn't quite right here, as well as the fact that there was no red/blue hues on the inner and outer edges and the inner sky didn't appear darker.

On the left of the arc as seen here there was a tiny hint of a red/blue spectrum (seen best in the top image). So putting this together with the rest of the observations perhaps I was seeing a Parhelic circle. The small spectrum being a fragment of a 22' halo intersecting it.

A Parhelic circle is rarer than the 22' halo and caused by millions of vertical ice crystals reflecting the sun's light.

I'm no expert and perspective can play tricks so I'm not a hundred percent confident in this but it does make some sense (to me at least!)

Never look directly at the sun. Also, a camera will likely suffer damage when the sun is high and never, ever look through a SLR viewfinder or other optics at the sun.