Category: DIY Projekte

Python Uncertainty

Maybe one of my readers is a bit more experienced when it comes to Python – probably not that hard – and can explain to me why my first script does not work and the second one on the other hand does. Biteule and I only came as far as to suspect, that it has something to do with the threading of the GPIO-callbacks but what exactly the problem is neither of us understands. It’s not like zerorpc is not imported and available in the first script when it gets executed, after all it is able to throw an error (LostRemote: Lost remote after 10s heartbeat), so why does it make a difference where I import the module?

import RPi.GPIO as GPIO
import time
import zerorpc

nodebridge = zerorpc.Client()
nodebridge.connect("tcp://127.0.0.1:4242")

GPIO.setmode(GPIO.BCM)
GPIO.setup(27, GPIO.IN)

def switchview(switchview_taster):
    nodebridge.switchview()

try:
    GPIO.add_event_detect(27, GPIO.FALLING, callback=switchview, bouncetime=600)
    while 1:
        time.sleep(100)
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(27, GPIO.IN)

def switchview(switchview_taster):
    import zerorpc
    nodebridge = zerorpc.Client()
    nodebridge.connect("tcp://127.0.0.1:4242")
    nodebridge.switchview()

try:
   GPIO.add_event_detect(27, GPIO.FALLING, callback=switchview, bouncetime=600)
   while 1:
      time.sleep(100)
var io = require('socket.io').listen(1234);
var zerorpc = require("zerorpc");

var pythonbridge = new zerorpc.Server({
  switchview: function(reply) {
    io.sockets.emit('switchview');
    reply(null);
  }
});

pythonbridge.on("error", function(error) {
  console.error("RPC server error:", error);
});

pythonbridge.bind("tcp://0.0.0.0:4242");

UPDATE 12.02.15 – 14:51:

The Magic Mirror – EMC interference

Quick Update! My uncle got me a mirror sample, so this is how the whole thing looks with glass in front of it 🙂
Spiegelmuster

As it seems my components interfear somehow and influence each other… I recently added a button to shutdown the mirror. It works by constantly setting a GPIO-pin to 3.3V, pressing the button grounds the pin and draws the voltage to 0V. A Python script registers this change and shuts down the OS. Strangely this also happens if the motions sensor enables the monitor. At first I assumed there might be something wrong with my circuits, so my uncle and I thought about how the 230V from the monitor could influence the Pi over the relays. Another guess was, that the monitor drains to much power at startup and with that collapses the 3.3V for a really short amount of time. Later I realized that this was also happening if I connected the monitor directly to a power outlet without the relay in-between.

alte LampeI just picked up this old lamp, because I needed some light to correctly judge how reflective the mirror actually was when used normally.  Well, I didn’t quite expect what happened next… Turning on (and off) the lamp (when placed a certain points near the other components) turns of the monitor for about two seconds. It does not seem to influence the Pi though but probably something similar is going on with the shutdown triggers.

UPDATE 22:22

I experimented a bit further with the lamp or to be precisely with its power cable. If I place the lamp’s cable over the Pi, the same thing happens, as if I turn on the monitor, a shutdown gets triggered as soon as the lamp is turned on or turned off. The problem therefore probably really is some kind of electromagnetic radiation.

The Magic Mirror – Raspberry Pi

I recently started a new projected, which of course is a great reason to write an article about it!

I had a DVI-monitor laying around in my room for quite a considerable time now. It was always connected to my Raspberry Pi with ever changing functionality. In the beginning I used it as a XBMC media center to watch movies and listen to music on my stereo. After that I wanted to use it to display useful information but found it strange pretty quickly to have a monitor standing around just to display information. Besides I didn’t even know what kind of information to show on it, so I again used it as a media center again.

Some time ago – while searching for interesting Raspberry Pi projects – I rediscovered the “Magic Mirror” build by Michael Teeuw and spontaneously decided to build one myself. I then found my self dissembling the monitors housing and starting to think how to best accommodate the Pi in this setup. I also changed some bits of Michaels original interface, from showing the same compliments in the UI all day to showing compliments based on the time of the day (my first Git-Pull-Requests; yeah!).

I didn’t really like the idea of having a monitor in my room, running 24/7 even if no-one was present who could actually look at the screen, so I ordered a relay and a motion sensor and wrote a small Python script to turn the monitors power only on when someone is in the room. Jonathan from Studio Einz helped me build this small circuit to switch the relay’s 5V circuit with the 3V from the Pi’s GPIO-pin’s. (Look at that fancy LED! We sadly didn’t have a diode so the LED had to do the trick :D)

Transistor Board

Relais

Bewegungsmelder

Raspberry Pi

Some users of the FRITZ!Box (a German internet router and phone system) may know: The device has a build in call monitor, which is easily read for example with Node.js and this handy module. Incoming calls then get redirected  to the web interface trough Socket.IO, which further displays this nice alert.

Anruf

There also is a feature to alert me when someone is ringing at the door in my code but before that’ll work I first have to connect my bell to the FRITZ!Box. Now I just need an actual mirror and a housing for the project.

Oh! If someone has an idea what else I could display on the mirror: I am listening!

Copyright © 2024 MeType

Theme by Anders NorenUp ↑