Monday, September 30, 2013

Raspberry Pi and a solution waiting for a problem…

Well, not quite, maybe. Let me explain. In previous posts, I played around getting the Nokia 5110 LCD to properly work with the Raspberry Pi. After the usual set of problems, it fully cooperated and I incorporated it as my display in my carputer.

Now, I would like to mount the display on the dash of my car somewhere, but, although the Pi is small, it is still too big to fit in properly.

So I got to thinking, what if I place the display at some distance from the Pi? But how? I decided to go out on a limb and use RJ45 connectors and jacks.

I bought some RJ45 jacks via Ebay and some RJ45 breakout boards from Cooking Hacks. These breakout boards, at a whopping $0.50 a board, allow for easy hookups of the RJ 45 jack to the wires that lead either from the Pi’s GPIO pins or go to the input pins on the Nokia LCD.

After soldering the jacks and the wires to the breakout boards, it was time to grab an Ethernet cable (6 feet in this case), slip the ends into the jacks and turn on the Pi. At first, the results were ambiguous. Sometimes, the display showed correct results, sometimes there were errors in the text, sometimes nothing. So I decided to do some experimenting.

I noticed that the speed at which the Nokia LCD was processing data was set at 5Mhz. I reduced this to .5 Mhz. Voila, it worked.

Next, I tried a longer cable, 24 feet. No problem! I don’t have a longer cable, it would be interesting to see what would happen.

Here’s the 24 foot cable in action (the error message on the display has nothing to do with this project).

 IMG_9673

So, if you need a display a long way away from the Pi itself, may be this is the way to go…

Tuesday, September 03, 2013

Raspberry Pi and “sudo poweroff”

A few weeks ago I ordered a power switch for the Raspberry Pi from www.mausberrycircuits.com with the aim of using this on my Raspi Fuel Miser setup. (see previous post).

Illuminated LED shutdown switch

When this switch is situated between your Raspberry Pi’s power jack and your phone charger and you plug in the phone charger, nothing happens. You first need to press the button before the Pi lights up. Then, once you are through using it, you keep the button pressed for 2 seconds and the Pi powers off.

You need to hook up 2 wires from the switch to the GPIO pins, suggested are 23 and 24. If you do use other ones, then you need to modify /etc/switch.sh after you run setup .sh.

I first ran it using the switch.sh configuration, but then I got to thinking, why run it separately when it can be included in my Python script, which is running continuously anyway, dutifully computing gas mileage.

So I amended my script, created a new function has_ShutdownButtonBeenPressed and inserted a call to it at the start of the main loop in the obd_capture.py program. This way, it will check for a pressed key once every 3/4 second or so, the time it takes to complete a cycle of OBDII readings. I disabled the switch.sh and remove the entry in /etc/rc.local which started up switch.sh upon start up.

The ‘sudo poweroff’ command, by the way, cuts all power to the board, so it is completely disabled, unlike the ‘shutdown’ command, which still leaves the main red LED lit.

Now, at the end of my trip, if I have used the fuel miser, all I need to do is press the power button for 2 seconds, and the Python script will close the SQlite database gracefully before issuing the os.system(“sudo poweroff”) command.