Sunday, October 27, 2013

I was wrong about a Linux "memory leak"

A few posts ago I was concerned about the apparent diminishing of available RAM as reported by checking "/proc/meminfo". But then I added this command to my midnight RAM test:

sudo /sbin/sysctl vm.drop_caches=3

Which causes the system to clear memory that is temporarily held -- just in case some data might be accessed again.

So, adding that command makes the MemFree number accurate, but probably lowers the efficiency of the OS slightly.

Duh. (but of course, the "/proc/meminfo" data is misleading)

Saturday, October 12, 2013

Controlling My Pi from the Internet

Back in post 28, I described my method for getting data from my Pi to its web page. That's been working for a few weeks now.

A few days back I added a FORM SUBMIT button that can control how the Pi operates. The new feature is at the bottom of http://raspi-online.info/. The button is labeled "LED On!".

When that button is clicked PHP code in that page writes a particular value into a data file on that server.

Once per minute the Pi reads that same file -- like so:

#!/bin/bash
while true
do
  a=`curl --silent --netrc -R ftp://ftp.???.com/data/led`
  if [ "$a" = 'ON' ] ;
  then
   curl --silent --netrc -T web/null ftp://ftp.???.com/data/led
   sudo python web/flashled.py
  fi
  sleep 60
done

So IF the file named "led" has the magic value "ON" THEN that file is erased AND the associated LED is turned on for 20 seconds. 

Note that the way I did this is rather inefficient -- but it works. If I can turn an LED on then I can control anything else the Pi is connected to -- e.g.:

lights, fans, thermostat, irrigation valves, ...

Of course, I'd have add some security to the web interface.

Thursday, October 10, 2013

Post 31: Expanding the number of IO ports with I2C
(added to a few hours later)

First I bought the MCP23008 8-port expansion chip from Adafuit.

Then I followed the install procedure given in:

http://www.raspberrypi-spy.co.uk/2013/07/how-to-use-a-mcp23017-i2c-port-expander-with-the-raspberry-pi-part-1/

(sorry about the line break)

Next I wired up a small breadboard as follows (nothing else on the board):

Here's the pin-out of a plain MCP23008 (there are several variants):

I have a Rev 2 Pi so I ran the following from SSH:

$ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --    

Which shows that the MCP chip is recognized and is at the expected address. Then I ran the command that set pins 0 - 6 as output:

$ sudo i2cset -y 0x20 0x00 0x80

And then I tried this--

$ sudo i2cset -y 0x20 0x14 0x01

Which should light the LED wired from GP0. But nothing happens. And no error messages.

Any comments?

LATER that same day:

I went to the site:

http://www.skpang.co.uk/blog/archives/637

And followed their procedure -- a directory of source written in C.

It didn't work either until I read the comments and made the change for my Rev. B Pi. Then the demo C program worked. However, I find the code obscure. I see how you turn an LED on but (not directly) how to turn it off. Plus, I'd much rather work in Python. Drat!

Comments?