Archive | Electronics RSS for this section

Stepper Gauge

VID_20170316_082442-2

Today seemed like a good day for cleaning out junk drawers, and I’m proud to say I successfully completed half that job!  While looking through the heaps of crap I absolutely need, I came across a questionable stepper motor driver and stepper motor. Odds are the reason I had it is because it doesn’t work, but of course I’m not going to throw it out without testing, and with a three year old repeatedly asking “what’s that?” it seemed like I had no choice but to hook it up and start screwing around.

2017-03-16 09.02.372017-03-16 09.02.19

The stepper driver is a pretty standard type, it takes two input signals, one tells it which way and the other says how many. Steps that is. So where do I get these signals? I have a raspberry pi that floats around my bench that I can make use of when I need some GPIO. Ignore the rainbow of other wires going to the right in the photo, they’re from another project that I can’t disconnect because I’m totally going to finish it someday. The only ones that matter here are the three wires going southbound. Those three wires are STEP, DIR, and GND.

2017-03-16 09.04.28

The only thing left was motor power. If you’re looking for something to add to your test bench at home, go to ebay and pick up one of these XL6009 step up DC-DC converters and stick a couple 2.1mm barrel connectors on each end. (pick up a couple 10 packs of 2.1mm barrel connectors too while you’re there.) So handy. It turns any wall wart you have kicking around into an adjustable voltage source. I used mine to boost from my 12v adapter to the 24vdc that this motor requires.

2017-03-16 09.03.53

Here’s the whole package assembled. Nothing to it really.

2017-03-16 09.09.44

The other only thing left was to hack up some software. Toggling the outputs manually proved that the drive and the motor worked. I can move the motor. But then what? Steppers are so easy, all you need to do in order to make them move is turn that STEP line  on and off a bunch of times and the motor will move 0.1 degree that same bunch of times, so the code is kind of boring. The fun had to come from what numbers to send. The pi was connected to the same wifi that my thermostat/gaslogger/powelogger was on, so I had plenty of numbers to choose from. Using my socket for realtime power monitoring  seemed like the most logical choice, so the code below was the result. It polls the power consumption every two seconds and moves the stepper 1 step per watt. I threw a little cardboard pointer on it to make it easier to see the movement.

2017-03-16 18.19.10

Then I added a cardboard backing to make it even more gauge like….. This is the gif from before my assistant helped out with some decorations. Aww yeah, that’s some awesome, shoddy ass gauge at work.

VID_20170315_185341-2

I was really entertained by this bout of screwing around, it made for a fun afternoon. More entertained than my kid it seems….something about having to turn on the microwave, or wait for the furnace to start before seeing anything happen wasn’t compatible with her attention span I guess. Maybe I’ll hook a joystick up to it or something for a bit more instant gratification, or I’ll just cut up more cardboard for drawing on…yeah, probably the cardboard thing.

It is worth noting that you can make up something like this really damn cheap these days. On ebay, an equivalent stepper driver can be had for around 2$, stepper motors anywhere from 5$ to 20$ depending on how much you need to move. Stick a 5$ esp8266 based controller on there and you can have a wifi connected stepper, or steppers, somewhere in your house doing…. I dunno… something!?

The python code is pretty simple, but it’s available here if you’re interested

Power Logger

With a design along the same lines as the Gas Sensor Logger, I made up a power consumption monitor for the house.
I installed 4 clamp on current transformers in my panel, one on each of the 230v legs coming in, and two that can be clamped on any circuits of interest. With the transformers and an arduino wired up pretty much exactly as described at this link I was able to load up a sketch that would provide a accumulated total of power consumed.

 

The arduino is connected to one of the USB ports on the raspberry pi that’s running my Thermostat Project, which means I was able to write an additional daemon that could poll the arduino for power measurements and log them to the same mysql database that all of my environmental data gets logged to. With that data being logged I’m able to make some pretty graphs to display power consumption.

The code for both the arduino and the raspberry pi side of things is on github at https://github.com/rhasbury/GasSensorLogger. I might break it into its own repo at some point but for the moment the two are so similar they can hang out in the same place.

I found that having the graph for reviewing the days consumption was cool, but for finding out what the different items in the house draw I really wanted to have a gauge with a needle, so one addition to the power logger that isn’t in the gas logger is a tcp socket that is made available for requesting realtime (down to ~2 sec) power measurements. If you send a “get_powers” string to port 50008 on the pi it’ll send you back a json string like so:

{“onetwentywatts”: 676.87, “clamp1watts”: 97.17, “clamp2watts”: 12.43, “twofortywatts”: 226.56, “totalwatts”: 903.43}

So with the help of a php script and some borrowed d3 code I got something rough put together. These are hosted on that same thermostat pi, so these graphs and gauges are available to any device connected to the lan. It’s nice to have this graph on my phone while I’m wandering around trying to figure out what’s burning so much power!!$!$$

The code for the graphs and gauges are in the github repo as well, under the rpi/http folder.

 

 

Motorcycle Temp/Information Display Unit

A while back I built up a temperature monitoring project for my motorcycle. The idea was to add a small LCD screen somewhere on the bike that would display cylinder head temperature to help give an idea if anything was amiss. It worked ok, but proved too bulky to really mount anywhere, was too hard to read in sunlight, and was ultimately too ugly to really make use of. Since then I’ve been gradually accumulating parts to create version 2.0. It’s not installed yet but its starting to resemble something that could be installed:

2016-10-21-09-43-01

To break down whats in that photo, in the aluminium box at the top there is

  • Raspberry pi Zero
  • DC-DC Step down power supply to take 12v down to 5Vdc for the Pi

Attached to the box via the black connectors, from left to right:

When its installed, that aluminium box will be hidden somewhere on the frame of the bike and the various sensors will be installed in appropriate locations so they can see or feel what they’re supposed to.

Enough stuff has been swapped out that it’s an entirely different project from the last one. The Netduino has been replaced with a Raspberry Pi zero. The difference this makes is pretty enormous. Before, the board I had built could read temperatures and write them to a screen. With the new board I can read temperatures and write them to a screen, save them to a MySQL database, host an http server that can plot the saved data, host a WiFi access point so I can connect with my phone and view that data, and all this in addition to GPS data or any other data I like. It’s really staggering the processing power you can get for under 20$ these days.

The old 6100 LCD has been replaced with a tiny (and I mean tiny) I2C OLED module that I’ve put in a plastic enclosure that is small enough to be cleanly zip tied to my handle bar. A thought that occurred somewhat late was that it would be nice to have multiple display modes (readout mode, graph mode, clock mode, etc) however I hadn’t planned in any way to switch between modes. The 4 conductor I2C wire going into the LCD box didn’t have any spare wires for a GPIO, and I wasn’t going to run any more, and I didn’t like the idea of trying to find a place on the bike for a single mode change button all by itself. Turns out I2C really is a great thing, because I was able to squeeze a tiny ADS1115 module and a button into this matchbox sized enclosure, and that gave me the ability to add a button without running any additional wires. Sweet!oled_pic

With the GPS and the Mysql database on board it makes for some really interesting data mapping potential. I have yet to make a fully automated version of this, but with with some manual steps I’ve been able to make use of output files and the tools at http://www.gpsvisualizer.com/ to draw gps tracks colourised by temperature data. In time I’m hoping to build this into a one click view. tempmap

At the moment it can only be viewed once I get back home and the bike connects up with the home wifi, but with some configuring it may also be possible to have it connect to my phone as an internet hotspot and view it while out and about.

The Accelerometer/Gyro module and the LED ring are both items that got added without really knowing why. The LED ring seemed like it could make a neat light up gauge, but I’m not sure where to mount it, or what to display. Something to mull over for the winter I suppose.

With winter coming this whole thing won’t likely be installed on the bike any time soon, potentially it never will because I have a feeling the ignition noise generated by my old Kawi will wreak havoc on all of these sensitive 3.3v data lines, but it’s been an endless supply of learning and entertainment putting the thing together.

Code for the project is up at https://github.com/rhasbury/MotorcycleMU At the time of writing this code is functional but oh so ugly… It grew out of an old application I hacked together quickly for saving sensor data to MySQL , and there’s alot of stuff in it that needs to be cleaned out. But it’s up for anyone that wants to have a look. Who knows, there might be something useful to you in there.

Red River Thermostat 2.0

I’ve made enough changes to the thermostat project that I figured it was worth an update. Firstly, I changed the way the web interface interacts with the thermostat daemon. Previously the web interface was hosted on a http server that was built into the webiopi package. This worked ok but it limited things like php scripting and methods for connecting to the database. Now, all of the web stuff is hosted on a separate lighthttpd daemon and it fetches information about the sensors and the state of the thermostat via a socket to the running thermostat daemon. PHP scripts on the http server take care of connecting to either the daemon or the mysql database and pass information to the javascript in a sensible way which makes things…….simpler(?)  It’s easier for me to know what’s going on anyhow, and it’s forcing me to learn alot more about javascript, PHP, and web app development

With the more capable http server I was able to incorporate some more interesting visualizations for the temperature display (gauges came from here).

Screenshot from 2016-04-23 07:05:11

 

The reasoning behind creating the socket based communications with the thermostat was that it would make creating new control applications simpler. In the long run I might make an android app that’ll be a bit snappier than the web interface. A kodi plugin is another possibility, to allow me to see/change the thermostat from our media pc. Both of these are made easier by having a socket based connection that spits out easy JSON blobs for processing. Here’s an example of what comes from a request for sensor parameters:

{“LocalSensors”:
{ “Living Room”: { “humidity”: 0, “i2c_address”: “0x77”, “pressure”: 97281.0, “read_successful”: true, “temperature”: 29.4544021645641, “type”: “bmp”, “webiopi_name”: “bmp0” } },
“RemoteSensors”:
{ “Bedroom”: { “humidity”: 0, “ip”: “192.168.0.103”, “pressure”: 0, “read_successful”: true, “temperature”: 29.46, “type”: “tmp”, “webiopi_name”: “bmp0” } },
“webiopi”: 1 }

Here’s an example page showing environmental data for the past few days. The outdoor temp looks a little crazy because the sensor catches some sun in the middle of the day. You can see the inclusion of the Time v Gases in the bottom right graph, that’s data being logged from the gas sensor board, which turns out is pretty boring. I guess that’s a good thing though…

Graph_Frame

Below is a run time graph for the equipment being controlled. Should give an idea of my energy consumption once the database get’s more filled out.

Runtime_graph

The next thing I’m planning to add is an electricity monitoring page. I ordered some cheap clip on current transformers that I can stick in the panel to read current draw, they can be used to log  our power consumption to the same db, and hopefully can be used to work towards getting our outrageous hydro bills down…

Code is up as always at https://github.com/rhasbury/Thermproject

 

 

 

 

Gas Sensors

Since I’m addicted to cheap ebay electronics, I had to pickup an assortment of these MQ Gas sensor modules. I got an MQ-5, 9, and 135. I initially thought that these would all measure different levels of different types of gasses, but after more reading and experimenting it seems like they all seem to measure the same gasses just with different sensitivities. So my board with three of them on it might be overkill but they’re so cheap!

Anyhow, I made use of an arduino nano to serve as a USB ADC. The super basic sketch running on it simply waits on the serial port for “get_aX” command and returns the value read from X analog input as an integer. The connections to these things are dead simple, just provide VCC and GND and then connect the A0 pins to the Ain pins of the arduino. The only catch I found was that they draw about 100-200mA each, which means that if you feed them and the arduino from the USB 5V it can be too much for the USB port. I’m planning on plugging mine into a raspberry pi that doesn’t have much to spare, so I feed the Vcc of the sensors from a separate 5V supply.

IMG_20160401_130922

 

The idea is to hook this up to the Raspberry Pi in my basement, that’s already operating as my thermostat/data logger, and have it start logging what it sees….I’m not sure what that’ll be, but I’m curious to see if it can detect any leakage from the water heater or furnace exhaust. After I get some bulk data I might be able to even set it up with an email notification for higher than normal levels of CO or natural gas detected, not that it’ll ever be a replacement for the real CO alarms that’re installed throughout the house.

It works pretty well so far. Tested on the bench it could definitely detect the gases coming off a little butane torch. We’ll see what it shows after spending a week in the basement, I don’t expect to see many gas leaks but it might be able to tell me when it’s time to change the litter box…

GasPlot

It’ll connect up to my thermostat project board via USB. A small python application will be running on the Pi to pull the values off the arduino and log them to the mysql database. Code’s up at https://github.com/rhasbury/GasSensorLogger for anyone interested

Red River Thermostat

This is a project that I’ve been slow to post about because it’s been hard to decide when to call it complete enough, I may not be there yet but something’s gotta be posted.

Our house is heated and cooled with forced air, it’s either on or it’s off, and the thermostat was mounted in the living room that we’re not always in. This means that during the night, when we have our bedroom door closed and are evidently acting like food fueled space heaters, the temperature climbs to uncomfortable levels and the thermostat at the other side of the house is unaware of that. During the day, when the sun warmed up the living room through our large window, the thermostat thought all was perfectly fine while the kids in my wife’s daycare downstairs are getting very chilly.

So what I needed was a way to control the thermostat based on the temperature in different locations at different times of the day. Since I have raspberry pi’s scattered around the house for various other purposes it made sense to make them do dual duty as temperature sensors. The diagram below gives a rough idea of the system layout.

Thermostat.png

The temperature sensors are a mix but all I2C. HTU21D, BMP085, and TMP102s are all compatible. Here’s a picture of the Main Thermostat Pi. The I2C connections tie into the terminal strip on the top left. The two sensors on this one are at the ends of about 10′ of cable. I’m likely breaking some rules when it comes to I2C there, but I don’t seem to have any communication errors so I’m not gonna think to hard about it. One thing to note is that these 5v relays can’t get their power from the RPi header, they pull enough current that it’s a problem (sd corruption and brownout issues), so they need to be fed from the power supply directly.

IMG_20160214_205512

The thermostat status and settings are accessible via a web interface hosted on the same pi. It’s so nice to be able to call this up on my phone and bump up the heat without getting out of bed 🙂

ThermoWebinterface

As it is now, the program is built around the Webiopi package, which takes care of the IO management as well as the web interface. As things progress, I’m moving away from webiopi http hosting and gradually building up a standalone html/javascript interface that can do some fancier graphs and visualizations. All of the temperature data that’s being monitored is also being logged in a mysql database. As of today it’s been running for just about 10 months. The only big hiccups I’ve had are with some unique exceptions not being dealt with properly, and the SD card filling up at one point because I was logging about 4000 times more data then was really necessary.

The code is up at https://github.com/rhasbury/Thermproject if anyone’s interested, but at the moment (Feb 15, 2016) what’s checked in doesn’t actually match what’s running, and likely doesn’t even work. It’s in the middle of a large rewrite that changes the way the UI interfaces with the controller. So stay tuned for an update when version 0.2.0 appears.

 

 

DIY Bluetooth Headset for KZ750

I like to have some tunes on when I’m out riding and the way I’d been doing it was to squeeze a set of  headphones under my helmet, run a cable down to my phone in my pocket, and control volume and track by pressing the side buttons through my jeans. Not the best solution, and often when wearing gloves it was next to impossible to tell where the buttons were.

My answer was to try out one of these ebay bluetooth modules. For around 7$ these things can pair with your phone to provide audio output as well as a way to hook up custom play/pause/back/next buttons. The version I got was called a XS-3868 but they all seem to be based on the OVC-3860 chipset. My idea was to stick one of these in a project box and hide it somewhere on the bike, then run wires up for a place to connect the headphones and come up with some sort of handlebar switches for changing tracks.

 

xs-3868

 

The schematic is nothing special, the only notes are that the regulator section was replaced with one of these modules. On ebay they can be had for under 2$ a piece and they just simplify voltage sourcing so much. Last time I ordered some I got a 10 pack 🙂  The other note is that some filtering had to be added to the switch inputs. The GPIOs on this board only draw about 40 microamps at 1.8v, it’s awfully easy to pick up stray voltage that’ll trip those once you have a cable attached of any length. So there are 1uf caps in parallel with 4.7k resistors close to the module to help filter out unwanted inputs.

Blutooth_Schematic

 

So the schematic looks all well and good, and the module looks pretty, but they came together to make something much much uglier…

IMG_20140624_145633

I did attempt an an etched PCB layout for this board but the fine pitch on the module made it very difficult to get it soldered down without shorts, so that was abandoned and instead the module was stood off from a piece of copper clad board and fly wired down to a set of pads that I cut out with a dremel. It started off crude, and got even worse when I realized that the extra filtering was required for the switches. Cramming those in was not easy.

 

IMG_20140627_184756

 

But the project box hides all sins, and even the project box will be hidden under one of the bikes side covers, so that’s good enough for me.

For the control switches, I’ve taken the smallest die cast aluminum project box I could find and put three push button switches in it. I used two black zip ties pulled through holes in the rear of the box to attach it to the handle bars, it actually came out alot cleaner looking than I expected.

IMG_20140709_135125

I also routed the audio connection under the tank to a spot that I could connect my headset to but I since it turns out that all of the controls work whether the headset is plugged into the phone or into the bluetooth module, so I’ll likely just leave them plugged into my phone. It’s audio quality is better anyhow, and it’ll reduce the chances of me ripping something off when I inevitably forget to disconnect before getting off the bike.

Bench Amplifier

I’ve been working with some AD9850 ebay modules that are serving well as function generators, but they’re a bit limited output power wise. I needed something to boost its signals into the 1/4 to 1/2 watt range and the designs at SM0VPO’s page look to be pretty close to what I need.

Building off the design posted at the very bottom of the page, I’ve come up with my own board based on SMT parts because apparently I have a masochistic need to work with 805 components, but also because it would meant that even with the clumsiest layouts I could still fit it into the small die cast aluminum project boxes that I like.

Image

Using the toner transfer method and the HCl+H2O2 DIY etchant process I had the PCB laid out in just a couple hours, it’s not the prettiest board but it should do the job. I’ll post the eagle files at some point for anyone who’s interested… though it can very likely use some optimization… 🙂

Part placement went not too but there was one rather significant hangup. I had two types of transistor on hand, some BC847 and some 2SC4081. I thought I was placing the 847s, which would line up with SM0VPO’s design, but it turns out I was actually placing the 2SC4081s. This might have been a waste of time but I figured it was worth a go.

Image

When the board was fired up and fed a 1Mhz signal it did manage to amplify but it had a pretty distorted output. With the biasing set the way it was it seems like these little chips weren’t able to do what I was asking of them.
Image

I ended up swapping out these little guys for some higher power capable 2n4401 chips that I had to scrounge around for. I also added a pot for the biasing on the input transformer to see if I could tune in a little better. The emitter resistor also needed to be changed out. The value stayed the same but it turned into a 1/4W axial style in order to better deal with the power dissipation, even if only during my messing around with biasing values. Perhaps on revision 2 I might actually get a full SMT version of this amplifier, but this will do for now.

Here’s the whole package put together and in it’s new home.

Image

With a 0.5 Vrms input I get about 3.3 Vrms output (both into 50ohms), so that’s not a bad performance for a rev A boards I’d say 🙂

Cylinder Head Temperature Display Unit

In the summer of 2012 I went on a great motorcycle trip. On my trusty old 1981 KZ750, myself and a few friends headed north in the general direction of Sudbury. It was a great trip with a lot of really excellent sights and increasingly twisty roads as you head North. Through about 800 km of riding everything went quite smoothly, but an unpleasant thing happened when we were just north of Barrie on the ride back. I was noticing that something was sounding slightly off, and my suspicions were confirmed when I tried to catch up to the bike ahead of me and there was no power to get me there. After doing some roadside diagnosis, it was clear that I had a dead cylinder. Back at the garage the full tear down showed that one of my exhaust valves had stuck open and got a nasty bend in it. Thankfully it didn’t break right off, so apart from a small dent in the piston the engine was otherwise unharmed. This was likely due to overheating as a result of a low oil condition. I guess all the high RPM freeway riding had eaten though a lot more oil than I was expecting.

Dented piston :(

Dented piston 😦

Anyhow, this was a lousy thing to have happened, and it likely could have been avoided or at least mitigated if the bike had some method of indicating its engine temperature, (this is assuming I’d pay more attention to a gauge than I would to my oil level.. 🙂 ) This seemed like as good a reason as any to build something. I looked through my pile of assorted boards and quickly stuck together a Netduino Plus, a Nokia 6100 LCD Shield, and some TMP102 temperature sensors to do some experimenting.

Guelph-20120612-00003

This was a reasonably good setup, but it would need some changes if it would be useful on the bike.

1. The TMP102 wouldn’t do the job. They’re good sensors, but their temperature limit is much lower than alot of the temps they’d have to deal with in the engine. These will get replaced by a pair of MAX 6675 thermocouple amplifiers and some K-type thermocouples

2. The netduino plus is big. If I wanted something small enough to potentially mount on my handlbars I’d need it shrunk down, so it’ll get replaced by a Netduino Mini stuck on a custom PCB to accommodate some of the additional bits and pieces needed to run this off the bike’s 11-15 volt supply.

Here’s the circuit and PCB layout that I eventually ended up with.

Schematic PCB

There are two voltage regulators, one to bring the bike’s voltage down to the 8v for the netduino, and another to provide the 3.3v needed for the LCD and the sensor digital parts. There are a couple of discrete parts tied to the unregulated input voltage that divide it down and clamp it to a safe level before passing it in to an analog input, this is for showing the bike’s charging voltage while running, an added bonus.

Here’s the final etched PCB with all the components  placed. It ain’t pretty, but hey, it’ll be in a box 🙂

TempBoard

And here’s the whole arrangement with the LCD installed, powered up with the display showing the running info. The silver ring at the top of the picture is one of the k type temperature probes, these ones are meant to fit under a 14mm spark plug.

TempBoard2

I did finally end up putting this in a project box and riding around a fair bit with it strapped to my handlebars but eventually it was removed for a few important reasons. One, it’s hard to see in sunlight. That little LCD just can’t compete with a nice sunny day, and as it happens, that’s when I prefer to do my riding 🙂 Two, it’s ugly. The project box I crammed this thin into is quite…boxy,  and there weren’t really any good places on the dash of the bike to clamp it. It rode around in my tank bag window for a while, but that wasn’t the most convenient of places either..

It served it’s purposes though, after rebuilding the engine in the bike I was able to install this thing and monitor for at least the first few rides to ensure that it wasn’t going to blow up a second time, and more importantly it gave me a project to fiddle with in my spare time.

Netduino Weather Board with Humidity and Barometric Pressure

Had a few modules kicking around that I ordered on a whim a while back. Figured it’d be worth making something interesting out of them as an excuse to learn a little more about i2c. Slapped together this board with a couple of sensor breakouts on it and stuck it on the back of a Netduino Plus. I like the netduino boards because they’re hardware compatible with the arduino shields, but being able work in C# makes them a little more familiar. The sensors are a Bosch BMP085 barometric pressure sensor and a HTU21D. The HTU21D is on a Sparkfun breakout board, the BMP085 is a 3$ ebay dealie. Forgive the ugly solder job.

IMG_20140203_133920

The idea is to stick this board in various locations around the house and see how the temperature and humidity vary throughout the day. Want to get an idea of just how dry it gets in this place during the winter and how well the furnace pushes the warm air around. This board will quietly log all of these items in a csv file on the SD card installed in the Netduino.

It took a fair bit of monkeying around but I managed to get two fairly useful classes for reading from both of these sensors. The I2C methods came from the library referenced in this post. The logic for the BMP085 sensor was modified from this Arduino specific tutorial to create the Netduino version.

I’ve posted the source in a github at for anyone that might be able to make use of it. The code might not be pretty but it might help if you’re trying to deal with either of these two sensor modules on the Netduino platform.

The data logs pretty well, the only thing I might need now is a real time clock module though because right now all I can record is the relative time from the board booting and beginning to log.

Temp Sensor1 23.05 Relative Humidity 29.3546143 Barometric Pressure 97889 Altitude(m) 290.07
Temp Sensor1 23.20 Relative Humidity 28.5993042 Barometric Pressure 97891 Altitude(m) 289.90
Temp Sensor1 23.14 Relative Humidity 27.9889526 Barometric Pressure 97897 Altitude(m) 289.38