Clock Step 2: Initial Configuration

After the Pi Zero has booted and rebooted after resizing the OS partition on the SD card. You will want to login, using the username: pi and password: raspberry. Then need to configure the SSH to allow us to remote into the unit, change the default password, and connect it to the wifi. So we need to run the raspbian configuration utility:-

First off change the default password, to whatever you want.

Second I changed the hostname to: Clock.

Third, enable SSH by choosing option 5 Interfacing Options, then option 2 for SSH and select YES.

Then we need to get the wireless working.

I then added the following lines to the file

This works for connecting to out WPA2 Cisco Meraki MX65W network at work. Ctrl+X then tap Y to save the file. Shutdown the Pi.

Wait for the light to go out, disconnect the power and unplug the keyboard and connect the wifi dongle to the Pi.

Onto Step 3: Updates and Github Repos

Settings up the Scroll Phat HD to build a clock

For this I am using a Raspberry Pi Zero, a slightly older generation without the built in wifi. The headers have been soldered to the zero and scroll phat. Not the best job in the world but it will do. Due to the fact that the Pi Zero only has two usb ports, 1 for power and the other will have to switch between keyboard and Wifi Dongle. So getting this headless as fast as possible is key.

Raspberry Pi Zero and SD CardThe 16gb SD card is a tad over kill but I just generally buy the most cost effective one.

Scroll Phat HD with Soldered HeaderScroll Phat HD BackScroll Phat HD is available from those pirates over at Pimoroni

Adapters for Power and VideoUsing an old iPhone charger to power this, hope its enough.

Edimax Wifi and OTG AdapterUsing an Edimax Wifi adapter, its a Realtek RTL8188CUS. Then you need the OTG adapter to make it fit the micro usb port on the Pi Zero.

Completed PiHere is the completed setup, ready to plug into a hdmi monitor.

Anemometer coding woes

Turns out all my anemometer code so far is wrong, equations is not my strong suit and I seemed to be always trying to overwork the equation.

The above is mostly the code I am using now. I have tweaked it since to allow float seconds so I can use the same procedure to work out the gusting speed.

The above code is borrowed from Sparkfuns Weather Station Tutorial.

Arduino Uno to the rescue

Basically I was having all types of trouble trying to get the sensors working on the Pi, different versions of python (mainly due to library limitations) and probably just poor coding. The Lux sensor was the biggest headache, the returning values were all over the place.

So I decided to try the Arduino Uno, since most of the Adafruit tutorials use a Uno to get them working and it uses C programming language, which is a lot less annoying than python. Basically in the space of the weekend I have all four sensors working and even have the interrupt programming done for the rain sensor.

2014-05-04 12.43.15I also order the UV sensor from Pimoroni, which simply returns values for the UV index, which is something I also wanted to capture data for, to see if the index is slightly raising, which might be a sign of global warming/ozone depletion.

SI1145The SI1145 can also read visible light and IR but those returning values are not calibrated, so I am not going to bother with those.

Although I have found out that my RGB Leds that I have are around the wrong way, the common anode needs to be positive and not neutral, so ebay to the rescue again.

Got a little more work to do with code, then I can figure out how to get the Pi talking to the Uno and get the values posted to the web, so I can start getting that sorted.

Moon Phases, Sunrise and Sunset

So I want the web front end to give some other data, that might be of use to people.

Since I am also into astronomy, I would like to know what phase the moon is in (not that we’ve seen all that much of it recently). Turns out some clever bloke has written a php class to tell you what phase the moon is in, source is available via github.

PHP 5.1+ contains functions for calculating sunrise and sunset. As far as I can see there’s 3 functions, date_sunrisedate_sunset and date_sun_info. The latter looks like the best bet as you don’t have to supply as many variables.

Now I just need to get the GPS coords for my flat.

Nwazet Case Tyler Issues

I did post a product review to for the Nwazet Tyler case, but for some unknown reason it’s not been posted. I definitely think people should be aware of a few issues with the case.

1. No Manual

There is only the online manual and its a bit vague about which screws to use in which part. You do have to be careful as the threads are different on some of the screws. Plus some of the critical shots on the website of the screws are blurred making it difficult to identify the correct screws.

2. Foot Piece Broke

The feet is made up of two pieces that fit into each other making a cross, but the machining was a touch tight and when pushing the pieces together, one side broke into two pieces. Luckily I was able to use a plastic bonding solution to repair the piece and then file away some of the plastic, so as to make it fit together without breaking again.

3. Product Shots are not accurate

The Tyler case is supplied with a clear red insert to sit behind the face and red LED’s. It is mentioned in the product description on modmypi, but the pictures are misleading. The finished article will look quite different to the product shots. Nwazet allows you to set the colour when buying, but modmypi doesn’t offer the colour combinations.

Since I will be using multi-colour LED’s, I will have to source another piece of perspex that is opaque white. It does seem a little weird that such a happy case is supplied with red face bits and not a more neutral/happy colour scheme.



It’s not really a case a child could put together because of the lack of a manual. Other than the issues mentioned here, it’s a nice case and only having the base constructed makes for a nice bed to work around whilst I sort out my wiring and code. Scored: 3 out of 5.

I will update the article when I’ve finished my case and post some pictures.

Wind Sensor Testing

UPDATE2: yeah ignore the drivel in this post and check this post for correct equation for the anemometer.

UPDATE: So it turns out that I haven’t a clue about how you measure wind speed with an anemometer. I found the datasheet for the sensors, which gives 1.492mph per pulse on the anemometer over 1 second, so I have had to rework the equation and procedure below. So the screen shot below gives wrong values, but is an example of the scripts output.

Just started testing with the Anemometer N96FY. I have the anemometer connected to GPIO pin 18 and 3.3 volt supply. This wind sensor is like a switch and it’s default state is closed, meaning electricity with flow through the anemometer except for two opposing points during a full revolution where the voltage will briefly fall to zero.

I work out the equation to be

wind speed = half the circumference / time taken

Wind speed will be in metre per second. Half the circumference is 0.21994 metres.



Database Testing

I am going to use a local and remote mysql database to host the weather information. So I had to think about which variables to store and at 1 minute resolution, how much space would I need to accomplish this, as I want to store the information year on year. So I will store the following information:-

  • Date and Time of the reading
  • Humidity Outside
  • Temperature on the Humidity Sensor
  • Temperature on the Barometric Sensor
  • Humidity Inside
  • Temperature Inside
  • Wind Speed Average over 1 Minute
  • Wind Gusting Speed
  • Wind Lowest Speed
  • Light Full
  • Light Visible
  • Light Infrared
  • Barometric (Pressure)

This works out to 1,440 readings a day (60 minutes x 24 hours). Which is 525,600 readings a year, so making the database as small as possible is critical. For this I will be using the DECIMAL data type, so you can specify exactly how much information to store. So the rough table looks something like this:-

So using a local database on a desktop PC via phpMyAdmin, I used a store procedure to generate the dummy information. First create and store the procedure:-

Note: The dummy database name is “pi”. Then you can just call:-

Which will take a few minutes (~10 mins) to finish populating the database. You’ll notice on the stored procedure that I counted for 366 days, rather than 365, just to simulate what a leap year would be.

Final size on disk of the database is ~61MB. Plus a bit more for the unique index on the time_stamp column.

Issues encountered: 1. Day light saving time. I was originally trying to store the timestamp, but on the 30th March 2014 at 2am I would get 60 rows with exactly the same date and time and since the time_stamp field needs to be unique, this was a massive issue, so to cure the problem, I changed the store value to DATETIME and inserted the utc_timestamp() value, so I will probably need to convert the utc timestamp to localised time allowing for day light saving time if I need to refer to a date and time specifically.

2. Log files. During my testing and repeated procedure running, I managed to generate a >600MB log file. So disabling the log files on the testing and production machine will need to be done. Find the following in your my.ini or my.cnf file:-

find the line “log-bin=mysql-bin” and place a # and space in front of it, this will disable the log file generation.

The next step will be see how fast the hour average calls are for the last 24 to 48 hours for the chart mapping.