Weather Station Mk2

I’ve redesigned my Arduino weather station to incorporate a P-channel MOSFET to switch power to the peripherals on and off to hopefully save battery life. The ATmega328P always gets 3.3v, but then uses Sleepy() to conserve power anyway, but the DHT11, BMP085, DS18B20 and nRF24L01+ get powered off when not in use. Oddly enough the voltage seems to drop to 0.7v rather than 0v completely, but I guess no current flows.

I had to change my code a little to re-initialise the radio once per loop and control the MOSFET from a digital pin: download.

I tidied up the veroboard a bit – pink wires are 3.3v constant for the ATmega, red wires are controlled by the MOSFET, black is GND, blue is data:

I hard a hard time finding a through-hole MOSFET than worked at TTL voltage (the FQP7P06 I first tried only worked properly at CMOS 5v) but I eventually settled on the NDB6020P which can be switched using as little as 2.5v.

I’m currently calibrating the DHT11 and keeping an eye on how long the battery lasts, so for the moment the weather station is in the house rather than the shed, here’s some results (its also tweeting using Python/C++ on the RaspberryPi, I didn’t need to update them):

Update: it seems that turning the peripherals on and off is making the readings from them more reliable, as the BMP085 and DS18B20 readings are almost identical and the DHT11 is within one degree – given that it uses integers this is as near as it will get.

Update 2: the weather station has been running on 2xAA’s for over 12 days now, without the MOSFET it would last under 8 days.

Update 3: the board eventually stopped after 30 days, although since then I’ve been having problems with it stopping even though the battery is not dead – perhaps a range problem…. Anyway I’ve added the boards.txt definition I used below:

atmega328bb.name=ATmega328 on a breadboard (3.3v, 8 MHz internal clock)
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.protocol=usbasp
atmega328bb.upload.using=usbasp
atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xD8
atmega328bb.bootloader.extended_fuses=0x07
atmega328bb.bootloader.path=atmega
atmega328bb.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex
atmega328bb.bootloader.unlock_bits=0x3F
atmega328bb.bootloader.lock_bits=0x0F
atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=8000000L
atmega328bb.build.core=arduino
atmega328bb.build.variant=standard

Pi Radio Redesign

I’ve redesigned my internet radio project – now it features an amplifier with 12v 2A power supply, which is split off to a 5v UBEC to power the Pi via its GPIO pins. The amplifier powers the speakers so the only USB connections are the DAC and wifi dongle.

The sound is much louder and there is no hum or whine like before – I think that was a ground loop or antenna issue with all the USB cables and hub.

I’ve got to solder a little daughterboard together to tidy up the power splitter (shown on breadboard in the photo) and replace the wires on the speakers, as they are so brittle one has already fallen off. I’ve also got to add a pushbutton and voltage divider for controlling the play/pause/stop, probably on the same board.

I also am now using a i2c backpack for my LCD, so only need a set of 4 dupont cables instead of a dozen or more cables, potentiometer etc. I wrote a simplified version of the pi-libs library and made some minor changes to my main pi-radio script here.

As I had lost the SDcard image of my previous installation, I had to start all of the configuration from scratch, so made sure to note everything down this time!

1. Install dependencies:

dpkg -i python3-rpio_0.10.1_armhf.deb python-rpio_0.10.1_armhf.deb
apt-get install mpd mpc autofs

2. Edit /etc/mpd.conf

music_directory "/mnt/data2/music/sorted"
bind_to_address "any"
auto_update "yes"
zeroconf_enabled "no"
audio_output {
	type		"alsa"
	name		"DAC"
	device		"hw:0,0"	# optional
	format		"44100:16:2"	# optional
	mixer_device	"default"	# optional
	#mixer_control	"PCM"		# optional
	#mixer_index	"0"		# optional
}

3. Create MPD database:

mpc update

4. Comment out/add these lines in /etc/modprobe.d/alsa-base.conf to make the DAC the default device with lower latency:

#options snd-usb-audio index=-2
options snd-usb-audio nrpacks=1

5. Comment out these lines in /etc/modprobe.d/raspi-blacklist.conf to stop blacklisting the I2C/SPI modules:

#blacklist spi-bcm2708
#blacklist i2c-bcm2708

6. Add these lines to /etc/modules to load the I2C kernel modules on boot:

i2c-dev
i2c-bcm2708

7. Setup autofs to automatically mount the NFS4 fileserver:

echo 'data2 -fstype=nfs4,hard,timeo=60,ro,rsize=32768,wsize=32768 vader:/data2' > /etc/auto.nfs
echo '/mnt /etc/auto.nfs --timeout=60 --ghost' > /etc/auto.master

8. Copy everything into place and setup the init script to run on boot:

cp pi-radio /etc/init.d/
cp radio.py pylcd2.py /usr/local/bin/pi-radio
cp pylcd2.py /usr/local/bin/
cd /usr/local/bin/
chmod 755 pi-radio pylcd2.py
update-rc.d pi-radio defaults
update-rc.d nfs-common enable
update-rc.d rpcbind enable

Update: I’ve soldered/heatshrinked everything together and it works wonderfully! I didn’t use a resistor divider for the pushbutton, I just connected it to 3.3v, GND and GPIO24 using dupont cables and a pullup resistor, which actually makes it nicely modular. I could add another button by making another board in the same way and linking 3.3v/GND via headers like here.

I’ve got to gluegun some of the connectors to give some strain relief and then look into mounting everything in a case. At the moment everything but the LCD and button fit in the box I bought.

Update 2: I’ve switched to 3 buttons now (uses 3 GPIO pins plus 3.3v/GND) so we have play/pause, skip track, stop/shutdown. I noticed that the speakers sound much better when placed on a wooden table, so I think I’ll have to look for an old wooden subwoofer or speaker box I can gut and screw everything inside.

Time Lapse Photography With Pi

I thought I’d do something with my Pi camera board, so took my Dremel to my Pi’s case and cut a slot for the camera cable to go through it. I also made a protective cover for the camera board out of a SD card case.

I took a still photo every minute for 2.5 hours (about 148 images total) at 720p using the following syntax:

raspistill -o image%04d.jpg -t 9000000 -tl 60000 -w 1280 -h 720

Then merged them all into a soundless 5fps x264 video using mencoder:

mencoder mf://*.jpg -mf fps=5:type=jpg -ovc x264 -x264encopts \
   pass=1:bitrate=8000:crf=20 -nosound -lavfopts format=mp4 -o video.mp4

Or to make an mpeg4 AVI:

mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=8000000 \
   -mf type=jpeg:fps=24 mf://*.jpg -o video.avi

Then uploaded to YouTube:

Pi Radio (again?)

I’m thinking of getting back to my Raspberry Pi internet radio project again. A few weeks ago I found that the pulsing from the wifi card was caused by a ground loop problem with the USB hub, as I got the exact same problem on the BeagleBoneBlack.

So I’ve bought a Lepai TA-2020A+ amplifier and 12V 2A PSU to power it. I plan on making a little board to tap off 5V 1A via a 7805 to power the Pi. Therefore I won’t need a powered USB hub, as I’ll only have the wifi dongle and USB DAC plugged into the two onboard USB ports and the speakers will be powered by the amp, not USB. And I still manage to keep it to one mains plug.

It also means I can get rid of some cabling and the little volume/power board into the speakers. I may need a bigger box, and I wonder about the heat coming off the 7805. I may screw everything into a wooden baseboard perhaps too.

Update: I’ve decided to ditch the 7805 idea as I’ll need a huge heatsink to dissipate a potential 7-14W, so I’ve bought a UBEC and a DC-DC step-down regulator to try.

Saving Battery Life

I found that my weather station only lasted for about 7 hours on 2xAA batteries last night. The culprit could be the boost regulator, but before I investigate that I’ve reworked my Arduino code and moved away from manually tinkering with the avr/power.h stuff to using JeeLib. Its greatly simplified my code too. I removed the code that was measuring the voltage as that always returned 3.37v from the boost, so a bit pointless, plus it kept the ADC awake draining power.

The reduction in packet size meant I could move the dewpoint calculation back to the Arduino side, so all my data was being transmitted to and stored on the Pi via the C++ rather than it being calculated in the Python code temporarily before being Tweeted.

I’ve also made the Arduino and radio sleep for 30mins to reduce power consumption, then it wakes and transmits for about 5secs and then goes back to sleep. Plus the Pi process sleeps for 10mins to reduce the number of disk writes it makes (and CPU time) without missing the transmissions. So hopefully I’ll achieve the months/years of battery life that I keep hearing about.

All the sourcecode including the Pi stuff is here.

Update: I take it back, the culprit is shitty NiMH batteries. I’ve been running for 22 hours on a pair of Alkalines and still have 2.79v coming out of them! So I’m discharging and fully recharging a pair of 2900mAh NiMH’s to see how they go. I’ve also ordered some brand new 1900mAh Sanyo Eneloop 3rd generation NiMH batteries that apparently store their charge very well.