Author Topic: Simple weather LCD program  (Read 4255 times)

acadiel

  • Newbie
  • *
  • Posts: 2
Simple weather LCD program
« on: April 18, 2013, 12:18:53 pm »
I recently soldered my Digispark, and hooked it up to the LCD shield as well as uploaded the USB2LCD program to it.


I wanted a cool weather info LCD, and started work on a shell script on my Mac that uses some logic as well as the "send" executable to scroll weather information for me.  The only bad part is that my keyboard and mouse freeze every three seconds on my 2010 Mac Mini while running this.  Also note that I'm not fully qualifying the paths, as I'm running this from the "DigiUSB programs" directory. :)



#!/bin/sh
# Get weather script 1.0
# acadiel - http://www.hexbus.com
# Licensed under GPL V2

function parsexml
{
retval=$(echo $1 | cut -f2 -d'>' | cut -f1 -d'<')
echo "$retval"
}

function getdata
{
wget http://w1.weather.gov/xml/current_obs/KBMI.xml -O weather.xml 2>/dev/null
# Change KBMI to whatever your weather station is


function printit
{
#set -x
cat weather.xml | while read category # Reads the xml file in one line at a time
do
   catdesc=$(echo $category | cut -f1 -d '>' | cut -f2 -d '<')
   catval=$(parsexml "$category")
     case $catdesc in 
     # Note that if you don't want a category reported on, delete it.
     # The logic below will null any category that isn't in the case
     # statement, and it will be skipped by the logic.  You can also
     # add any other categories that aren't in here and it will include
     # them.
     location)
        newdesc="Location:"
        newval=$(echo $catval) # No change
        ;;
     station_id)
        newdesc="Station ID:"
        newval=$(echo $catval) # no change
        ;;
     latitude)
        newdesc="Latitude:"
        newval="$(echo $catval) degrees"
        ;;
     longitude)
        newdesc="Longitude:"
        newval="$(echo $catval) degrees"
        ;;
     observation_time)
        newdesc="Observ Time:"
        newval="$(echo $catval | awk '{print $4 " " $5 " " $7 " " $8}')"
        ;;
     observation_time_rfc822)
        newdesc="Observ Time:"
        newval="$(echo $catval | awk '{print $2 " " $3 " " $5}')"
        ;;
     weather)
        newdesc="Weather:"
        newval="$(echo $catval)"
        ;;
     temperature_string)
        newdesc="Temperature:"
        newval="$(echo $catval)"
        ;;
     temp_f)
        newdesc="Temperature (F):"
        newval="$(echo $catval) F"
        ;;
     temp_c)
        newdesc="Temperature (C):"
        newval="$(echo $catval) C"
        ;;
     relative_humidity)
        newdesc="Relatv Humidity:"
        newval="$(echo $catval) %"
        ;;
     wind_string)
        newdesc="Wind:"
        newval="$(echo $catval | awk '{print $1 " - " $3 " " $4 " " $5}')"
        command
        ;;
     wind_dir)
        newdesc="Wind Direction:"
        newval="$(echo $catval)"
        ;;
     wind_degrees)
        newdesc="Wind Degrees:"
        newval="$(echo $catval) degrees"
        ;;
     wind_mph)
        newdesc="Wind speed:"
        newval="$(echo $catval) MPH"
        ;;
     wind_kt)
        newdesc="Wind speed:"
        newval="$(echo $catval) knots"
        ;;
     pressure_string)
        newdesc="Barom. pressure:"
        newval="$(echo $catval)"
        ;;
     pressure_mb)
        newdesc="Barom. pressure:"
        newval="$(echo $catval) mb"
        command
        ;;
     pressure_in)
        newdesc="Barom. pressure:"
        newval="$(echo $catval) inches"
        ;;
     dewpoint_string)
        newdesc="Dewpoint:"
        newval="$(echo $catval)"
        ;;
     dewpoint_f)
        newdesc="Dewpoint (F):"
        newval="$(echo $catval) F"
        ;;
     dewpoint_c)
        newdesc="Dewpoint (C):"
        newval="$(echo $catval) C"
        ;;
     windchill_string)
        newdesc="Wind Chill:"
        newval="$(echo $catval)"
        ;;
     windchill_f)
        newdesc="Wind Chill (F):"
        newval="$(echo $catval) F"
        ;;
     windchill_c)
        newdesc="Wind Chill (C):"
        newval="$(echo $catval) C"
        ;;
     visibility_mi)
        newdesc="Visibility:"
        newval="$(echo $catval) miles"
        ;;
     *)
        newdesc=""
        newval=""
        ;;
     esac
if ! [ -z "$newdesc" ]
   then
   ./send "$newdesc"
   ./send "$newval"
   sleep 3
fi
done
}

# Main section
while true
do
   getdata
   printit
done

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: Simple weather LCD program
« Reply #1 on: April 18, 2013, 04:51:20 pm »
I use Digispark with two mac's - a macbook air, and a 2011 mac mini. I've never experienced the freezing on my mac mini, but I do not use usb keyboard or mouse - I use the apple bluetooth ones, and I think this makes quite a difference!


On my macbook air during program uploads often my keyboard and mouse will freeze for a few seconds during upload. I'm not sure why this is, but I don't think it's the digispark because it seems to happen when I click the upload button, regardless of if I plug a digispark in or not! Maybe the supplied digiusb send program is using the same code my micronucleus upload tool uses, and therefore has the same issue on Mac? In any case, I've not observed any freezing when using the rubygem.


It probably isn't useful in your case, but I also want to mention that on my macbook air if i keep wiggling my finger on the trackpad at the same time I use cmd+u to start program upload and plug the digispark in, nothing freezes up at all. Weird, huh? Merely using the input devices somehow stops them from getting all confused seems like.

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: Simple weather LCD program
« Reply #2 on: April 19, 2013, 12:25:46 am »
send uses the c++ libusb calls - pretty standard stuff, so I have no idea why some USB controllers choke on it - the send code is right there in the source folder if anyone wants to try adding some delays to it - I haven't been able to reproduce this on my Mac (mac mini mid-2011) or any other test machine I have, so I don't have a good way to fiddle with it