Opening my window with the Raspberry Pi

Episode 1

Sa 23 Mai 2015 JST

So hay, I've finally built something that combines a computer and moving components.

RasPi hooked up to the Arduino shield Pretty whack, right?

So what you see here is a Raspberry Pi B+, an Adafruit motor shield, and a little motor (楽しい工作シリーズNO.189 with 4 different selectable speeds, currently in the 9RPM/0.14Nm mode) and a not entirely irrelevant Edimax (Ralink RT2870) stick (this thing is really nice, thank you again, moepi). I've been using the RasPi as a WiFi router and file server (there is a 3TB HDD attached over USB) for quite a while, but I decided that this is becoming too boring.
In winter, a colleague was annoyed that his room was cold when he came home and wanted to hook up a little servo to press the button from wherever he was. That project didn't get realized, for $REASONs. Now, it's summer and my eastward facing room is getting uncomfortably hot in the mornings, which makes me get up at 7AM and open my window for fresh air.
And there was the idea: Open the window automatically, depending on temperature.

From there on, I did a bit of poking around, and decided that I wanted to buy a L293D for the motor control. Strangely, the most convenient alternative for acquiring one was buying an Adafruit motor shield. So I did.
Already having the motor shield, I decided to use it, so I bought a few convenient cables to hook it up. Finding out what goes where took me quite a bit of poking around with: Adafruit Motor Shield Schematics Now there were two worries left: First, the Arduinos supply 5V on all their pins, and significantly higher current. Fortunately, this turned out to not be a problem. Second, the whole thing is supplied by a single 12V, 1.5A power source, the Pi and the motor power are hooked up by a DC/DC-converter. I can only hope that everything is thick enough…

So, the wiring right now is:

ShieldPi
GND39 GND
12 DIR_LATCH37 GPIO
8 DIR_SER35 GPIO
7 DIR_EN33 GPIO
4 DIR_CLK31 GPIO
11 PWM2A (unneded)1 - 3.3V
5 PWM0B17 - 3.3V
Motor hooked up to M3.
I also used this document for understanding the motor shield library, mainly because it has a nice and short explanation on the meaning of DIR_SER and friends.

So yeah, it moves: So, here's the script I'm using: .

Episode 2

So 31 Mai 2015 21:13:40 JST

So, I've visited a few hardware stores (special thanks to 川口先生 for pointing me to 梅澤無線), gotten myself a few nice connectors, a few switches (SS-5GL2), some double stick tape, curtain hangers and, a stake. Now there's two mysterious items here…
The curtain hangers have about the shape of a winch, so that's why I bought them. One of them is visible directly at the start of the video. The stake on the other hand side is not for stabbing vampires but for screwing the motor onto there. It was the cheapest piece of wood thick enough.

All that was left to was a bit of sticking and screwing and a few wires. I wired the switch up to pins 9 and 11, set pin 11 to pull-up and shwoop, there you go. The box hanging there is just to keep the whole thing under tension, even when unrolling the thread. And yes, that is dental floss.

I've split the scripts into a little library and the actual control.

There is just one little problem left to deal with: The stake hasn't been fixed to anything, so while making the video I was standing on there with one foot. Let's see what kind of whacky solution I can find to fix that.

Episode 3

So 7. Jun 17:41:12 JST 2015

Today, the temperature sensors were scheduled to be delivered, so I started to build a system that records the temperatures. Because I like it easy to access, I wanted to make it into a website. Due to the lack of available sensors, I started working with the thermal_zone0 data.

Problem 1: The data is produced on the Pi, which may or may not always have a network connection. So I want to store it there. But to show the data, I don't want my webserver to open a connection to the PI. So stuff has to be synced around. What made things worse is that I am still too lazy to switch from MySQL to Postgres on my webserver and I did not want to go for MySQL on the PI, so I couldn't use any of the ready solutions I found.
I ended up writing a little hacky script that copies over all the unseen indices from the PI to the webserver. Not the most beautiful thing to do, but packed into a frequent cronjob it does the thing.

Problem 2: The data needs to be visualized. I ended up going for CanvasJS to do the job, for no real reason. Works, but now I got php-generated JavaScript. To which hell did I go?

So the result of a day of work: JP was faster than me and the sensors are already here, but eh, the temperature line plot works.

Episode 4

Do 11. Jun 23:45:40 JST 2015

So hay, I finally got one of the temperature sensors working. And I only started directly after writing the last episode.

But first of, a little headscratcher. When wanting to connect the temperature sensor, I was looking for a free 3.3V power source pin. I remembered that I connected the enabler pin for the first motor slot of the motor shield to that pin, which is not really needed, so I removed it. And suddenly, my little motor didn't want to spin backwards anymore. Whatthe…?
Spinning backwards had been kind of weird from the start. It felt like it had a ramp-up, as if the transistors didn't activate fully immediately. So I guess that was because the power for them had been coming from somewhere it shouldn't have.
Anyway, I decided to take my chances and switched pin 5 of the motor shield to pin 2 of the RasPi, a 5V pin. And it worked, better than before. Guess that is what I get for doing this kind of whack.

And why did the thing with the temperature sensors, the DS18B20 take so long? Well, basically because I didn't know that the bus they use for communication, i2c, is an on-circuit-board bus. 3m of unshielded cable, two soldering points and two surface contacts is just too much. How I originally wanted to connect the DS18B20. Yup, I suck at soldering. The quality of my soldering points likely has a slight influence, too… *cough*

So I re-did the whole thing. As short as possible, as simple as possible. Works, the results get pushed to the temperature line plot.

End

Sa 11. Jul 01:25:09 JST 2015

Since I do not want to let this end in the open, I'm writing one last entry. The opener works and is nicely temperature controlled, so I'm kind of considering this project done.

The opener has got a few flaws, most notably that the motor is loud and wakes me up, if in doubt at 6 in the morning. I've been trying to fix this by switching to an electromagnet and a weight instead of the motor. However, the resulting system is too delicate. Either the weight does not detach from the magnet, or it detaches if you only look at it. Also, even though I switched to way stronger fishing line and actual pulleys, if something is just a bit too long, the weight falls freely and tears the threads.

Another very strange thing I noticed is that VCC on the motor driver board was not connected, and it worked. I was assuming that the jumper on the motor driver connects VCC and the motor supply, but it only connects the motor supply and VIN, which is meant to supply the Arduino, which in turn is meant to supply the board. I fixed that by adding a jumper wire between the motor supply and VCC.
Sounds good at first, but why has it been working till now? A hint is that now the enable-pin for the motors is now being ignored. That makes me wonder if the enable pin connected transistor gate is not part of a FET but of a normal transistor, and I have just been using it like a diode. The more likely option is some internal resistors I don't know about. But screw it, it does what I want and I want nothing more.

In the meantime, I've been directing my attention to other things, namely a camera that follows your face.