Thursday, November 20, 2014

new Raspberry PI Monitor

I bought one of these - what sold me was the price, the 800x600 resolution  and the 7"size.
I had a Dangerous Prototypes ATX breakout board hooked up to an old power supply, thinking that the 12 v could be supplied to the monitor.  However I found that if you draw current from only the 12v supply and nothing from the 5v rail the power supply thinks something bad is happening and shuts down.

I had an radio shack wall wart power supply with multiple jack sizes that plugged in - the holes looked suspiciously the same size as the pin spacing on a screw terminal that i had -  so i tried that. Voila the monitor powered up. {note to self - add picture or find link}

The second issue was even though it powered up - plugging it into the rca video gave no picture. Turns out that you had to edit the /boot/config.txt on the PI. NOOBS sets it to only work with HDMI and I had to comment out a few lines.

# NOOBS Auto-generated Settings:
#hdmi_force_hotplug=1
#config_hdmi_boost=4
#overscan_left=24
#overscan_right=24
#overscan_top=16
#overscan_bottom=16
#disable_overscan=0

Now I had video from the pie - it was a bit pixely - but entirely readable.
The arduino IDE in the GUI is larger than the screen resolution. But right clicking on the taskbar at the bottom of the screen and selecting maximize fixed that. or should i say i could now select the menu items - but editing in this mode would be impossible - So its plug in the big monitor when editing, and just use the little monitor to view output.

Opening LOCALHOST on the browser gave a perfectly readable weewx screen.

Monday, November 10, 2014

Installing weewx and Arduino on the Raspberry PI

Screen shot on the pc

This took awhile - so give yourself time.

I did not want to get mired with any customization the first time around, so I decided I would always take the defaults whenever possible. After I fully understand all that got installed, I could mess things up with customization later on. Come on - you have never bollixed up a working system trying to customize it, have you.  My primary goal was a simple, no fills, working system.

WhatIDidWas:

Downloaded NOOBS

Formatted a class10 16gb sd card with sdformatter.exe

After booting set the timezone to New York
set up the wireless since I don't have a hard wire to the PI.

Updated the locations and got all changed modules for raspian
  
  sudo apt-get update
  sudo apt-get upgrade

Installed arduino on the pi

  sudo apt-get install arduino

Set up the board to match my hardware and selected the serial port (there was only one)
Loaded, compiled, and uploaded the blink sketch to test - OK

Opened http://davies-barnard.co.uk/2013/12/weewx-rasp/  for guidance.
and used a lot from How to install weewx for Debian (pi) Linux
http://www.weewx.com/docs/debian.htm This last link has lots of information - especially where the various parts of weewx gets installed from the deb package.

Added weewx user
  sudo suadded 
  adduser weewx 
  usermod -a -G sudo weewx

Downloaded weewx package to a thumb drive on the pc
http://sourceforge.net/projects/weewx/files/   Found weewx_2.7.0-1_all.deb (YRMV)

Then plugged thumb drive into powered hub on the pi and copied to my home directory on the pi using the GUI file manager.

Installed weewx

  dpkg -i weewx_2.7.0-1_all.deb


Make sure you have the latitude, longitude and altitude available. It will be asked for in the installation.  This saves editing config files after install. I chose the Simulator driver just to get something on the screen.

Got a lot of missing warnings  one of the informational messages was to do this command - it resolved all missing pieces and installed all but the python serial

  sudo apt-get -f install


Installed Python serial. I will use this to get serial data from Arduino.

  sudo apt-get install python-serial 

Picked NGINX as my web server and installed

 sudo apt-get install nginx

I kind of got stumped then - I found that the nginx had set up its root to point to /usr/share/nginx/www.  Weewx was putting its files at /var/www/weewx.

I tried to set a link from one to another - but the Linux LN link documentation read like graduate physics to me - so I just edited the ngnix conf file - but not the one that is documented.
The basic conf file is located @ /etc/nginx/nginx.conf - this file loads other config files. The one that contained the root location was /etc/nginx/sites-available/default
So I edited that with:

  sudo nano default

Commented out the line:

   #root /usr/share/nginx/www;

added the line:

   root /var/www/weewx; (the semicolon is important)

Voila the pi was serving demo pages on the pi at localhost, and from the pc
  
   http://pi-ip#/weather/index.html

and on my MotoX 

  http://pi-ip#/smartphone/index.html

So now I have all three pieces. The weather station transmitting, The Arduino inside receiving, and weewx running.  Not all I have to do is get the serial data from the arduino into weewx.

Stay tuned - film at 11 ...





Thursday, November 6, 2014

Weather Station part deaux

2) SOFTWARE

I am still working on the receiver part - but i think i have the outside part pretty much figured out.

My goals are


  • Interface with the Sparkfun Weather instruments
  • Use a battery and charger to keep it running as long as possible before replacing.  The well head i am using as a mounting base - is 80 or so feet from the back door. Plus i have alread tun over a previous setup's rain gauge cable - never want to do that again.
Interfacing with Sparkfun weather instrument.

I grabbed some code from here and hooked it up and tested it.  The code uses interrupts to get the values from the Anemometer and Rain Gage -  and relies on Millis() to calculate the values display.  It is a single source Solution - and uses the most power since the the Arduino runs at full power all the time.

Power Down sleep mode turns off all the clocks and counters on the chip.  I thought through many scenarios to try and figure a way to use other timing sources. One promising one is using a 32,767 watch crystal - but since i am using a pro-mini - getting to the pins was more than I wanted to deal with. Then I saw something on the forums and had a DUH moment - use the outside to gather the raw data - and do data processing on the receiver.


I used the RF24Network library and added these parts 

//nrf2l01 stuff
#include
#include
#include
#include "printf.h"
#include
#include
/*
  nc---n/c---8  7--miso--12  
  11-- mosi--6  5--sck---13 
  08-- csn---4  3--ce----09 
  ++-- Vcc---2  1--gnd---gnd

RF24 (cepin, cspin)
*/
#define CE_PIN 9
#define CS_PIN 8
RF24 radio(CE_PIN, CS_PIN);
RF24Network network(radio);

// Address of our node
const uint16_t this_node = 1;

// Address of the other node
const uint16_t other_node = 0;
/*

then  in setup added
... 
//nrf24l01 setups
  SPI.begin();
  radio.begin();
  network.begin(/*channel*/ 90, /*node address*/ this_node);
...

to setup the structure of the packet to send

// Structure of our payload
struct payload_t
{
  float Temperature;//4 bytes
  double unitWind;//4 bytes
  double Gust; //4 bytes
  int WindVane;//2 bytes
  unsigned int UnitRain;//2 bytes
  unsigned long ms;//4 bytes
  long vcc;//4 bytes
  
};

The network header adds 8 bytes so I had to fiddle with the types to make it all fit in 32 bytes.




This time I am going to do it!!!!



So far I have spent way more than a good Davis weather station would cost - and I am still not getting weather data to the web.  So i am going to start all over, again.  I can definately say it all has been a ton of fun so far, but it's just not what I wanted to accomplish

GOAL
Publish Weather information to the web.

So far I have  a weather instrument from Sparkfun, a temperature sensor , all hooked up to an arduino mini clone. A sketch on the arduino gets the sensor data and sends it via an NRF24l01+ . Power is supplied by a solar cell charging an old laptop lithium battery.

Its the inside part that has always been the rub.  I have tried with various arduino sketches to get the data and send it out to a PC then on to the weather site.  This time I am going to plug the arduino into a Raspberry PI and use weewx. Low power and always on - plugged into the big screen to look every once in a while.

Now all I have to do is conquer Python to interface the weather data to Weewx.   Wish Me Luck

wwall sent me an email outlining the task at hand



if the sparkfun weather station is one-wire, then you can use the OWFS driver.  you will have to make a few modifications, depending on the rain bucket and anemometer you use.

https://sourceforge.net/p/weewx/wiki/owfs/
otherwise, you will probably have to write a driver.  it is pretty easy to write a driver, and there are now many examples.  first read the "porting to new weather station hardware" section of the weewx customization guide:

http://weewx.com/docs/customizing.htm#porting
for your problem, there are (at least) two approaches:

1) the driver reads data directly from the serial port

2) the driver reads data from the log file

the first approach would have fewer moving parts, but you will need to know how to read/write serial.  this is really easy to do inpython using pyserial, but if the device has odd protocol or semantics then you might have to use fctl/select, which is considerably more challenging.

the second approach would let you get something running in about 10 minutes.  install weewx, then install this AcuLink driver in the user folder, then modify that driver to parse your "log file" (look for the 12 july posting with aculink.py v0.4):

https://groups.google.com/forum/#!topic/weewx-user/bT0mCwMScuI
the aculink.py v0.4 driver is misnamed.  actually it is a "FileInput" driver - it simply reads name=value pairs from a file then inserts them into weewx loop packets for processing.