Odds & Ends

You are currently browsing the archive for the Odds & Ends category.

tl;dr

The ESP-12F ADC pin appears to consistently read higher values at times when the processor is not as busy. I worked around this by taking the average of multiple reads, and discarding any averages where the number of samples varied dramatically from expectations.

My Application

I’m using an ESP-12F and a TEMT6000 module to measure brightness in an area that also has PWM-modulated LED lighting. I have an AMS1117 providing pretty consistent 3.3V to the circuit and it draws about 41mA. The ESP doesn’t have hardware PWM, so I’m suing the software version with analogWrite(), and I have the PWM frequency set down to about 200Hz because that seems to resolve some flickering issues.

I’m using MQTT (PubSubClient) and the AutoConnect library in my project. I take a brightness measurement every 5 seconds, and, if the resulting value has changed since the previous measurement, I publish the result to a related MQTT topic.

I’m using a 10k/4.7k voltage divider to step down the output of the TEMT6000 module to 1.055V. This circuit switches a separate 12V source that drives the LEDs, and that switching is optically isolated.

ADC analogRead() averaging with PWM LEDs

Because the LEDs turn on and off repeatedly to give the effect of dimming, I sample the ADC pin repeatedly for two PWM wavelengths (100Hz) and average the results. This seems to work out pretty well and is reasonably consistent. I get typically about 45 samples during that time in production. I’ll refer to this average in this post as “the value” or “the brightness” — it’s not an instantaneous value, but an average of several samples. This value is scaled to 0-1000 to approximate the number of mV read. I yield() inside of the sample loop as well.

Stability Techniques Already Employed

I have a 0.1uF tantallum across the ADC pin and GND, and when I sample the ADC pin, I do it twice in a row, ignoring the first sample, because I read somewhere that the first sample can be a bit inconsistent sometimes.

The Problem

From time to time I observed pretty erratic ADC fluctuations, notably right after start-up, and then periodically throughout the day. I haven’t taken the time to figure out if there’s a larger pattern here, but while I was debugging this I started writing out the number of samples actually taken when calculating the brightness value. That’s when I discovered a positive correlation between samples taken and brightness value.

Brightness value on the left, and sample count on the right

The PWM duty cycle is consistent, as is the length of time I take samples for each reading. In this graph, I was doing some extra serial communication, so the number of samples per 100Hz period is lower than the ~45 or so I consistently get in production.

I used my KORAD KA3005P to feed 0.05V to the ADC pin for this test. Note that a value of 61 is usually read when the number of samples is lower than 40, but that value goes up to 68 when the number of samples if over 70. I ruled out a math error — each individual reading does in fact average 68 when more samples are taken.

The Diagnosis

Although I wasn’t able to correlate things like WiFi status with this variation, my guess is that the power used for wireless communication is affecting the ADC readings — when the ESP12F isn’t very busy and can take more samples in the allotted time, then the voltage it reads is a tiny bit higher (~7mV). It’s not a lot, but when you values you expect to see only range 1-60 or so, then it’s significant.

The Work-around

I still haven’t nailed down the exact problem, and I’m not sure I even want to spend the time doing that if this work-around works out, but here’s how I chose to resolve this:

  • I’ve added some code that compares the number of samples actually taken to the number of samples I expect (those that provide a more consistent result).
  • If this “expected sample count” value is zero, then I’ll let the circuit operate normally, and report out the number of samples taken with each reading. This will allow me to figure out how many samples to expect in production.
  • When the “expected sample count” value is greater than zero, I basically just ignore the reading and pretend it hasn’t changed from the previous reading.

This seems to do a great job of smoothing out these erratic ADC fluctuations and providing more consistent brightness readings for my application. I hope others will find this helpful, too, and I’ll update here if I decide to look into it further.

I picked up a $9 Comidox logic analyzer for some ESP8266 work I’m doing, and so far it works great. You really can’t beat the price. Plus, it’s not just for Linux. Here’s how I got it up and running on Windows 10.

  1. Install PulseView software (it’s free). You can find it at sigrok.org. Navigate to Downloads, scroll down to Windows, and select the appropriate PulseView nightly build installer. (I used 64 bit.) Then install the software. This also installs the Zadig USB driver installation tool.
  2. Plug in the logic analyzer — it’ll probably show up as an unrecognized device.
  3. From the Start menu, type Zadig to run the driver installer, select the unrecognized device. Click Edit to change the name to something you recognize like Comidox Logic Analyzer. Be sure WinUSB is selected and click Install. This part can take a few minutes.
  4. From the Start menu, type PulseView. At the top, click where it says Demo Device, change the driver to fx2lafw, choose USB, and then Scan for devices. Select Saleae Logic with 8 Channels and click OK.
  5. Hook up the wires — don’t forget GND — and click Run in the software to start capturing.

I’m rolling my own home security system for pennies on the dollar (and lots and lots of time, but this kind of stuff is fun to me). Here’s what I ended up with for the kitchen. It controls three distinct lighting zones and three entry points (two doors and one window). It has its own captive portal for network/LED/sensor configuration (using Autoconnect) and it’s fully connected. So far it’s testing out pretty well. Here are the notable parts:

  1. ESP-12F ($1.09 from Aliexpress). This is the brain — the venerable ESP8266 module, with some custom code to control the lights, sensors, and communications. I used pins 5, 4, and 15 (with a 10K to ground) as PWM outputs, and pins 12, 13, and 14 as inputs. I broke out pins EN and 0, as well as VCC and GND and soldered up the wires so I could re-insert it into the programmer in case the OTA updates failed.
  1. Cat-5E network cable (free, on hand). I use this stuff a lot. I used all eight wires in the cable, plus a couple more for VCC and GND.
  2. Resistor Header (a couple cents). I broke out EN and pin 0 so I could place 10K resistors and remove them again if necessary to program.
  3. Dual MOSFET Trigger ($0.84 at Aliexpress). This triggers with 3.3V and drives up to 36V, 400W — plenty for each of my three 12V LED lighting zones. There’s one of these per output channel. The one on pin 15 also contains a 10K resister to ground, which is necessary for normal operation.
  4. Mini DC Step-down Buck Converter, 3A ($0.50 on eBay). This takes the power from the 12V LED power supply and efficiently converts it down to the ~3.3V operating voltage of the ESP-12F. I originally planned on using a linear regulator thinking that this might cause some interference with the ESP, but that turned out to not be a problem. (The AMS 1117 regulator would have probably run hot, but not too hot.)
  5. Power (free, on hand). This connects to the 12V power supply. I used green for 12V because that’s what I had on hand.
  6. Input Sensor Header (free, on hand). This breaks out the three input pins in a 2×3 header, once side of which is all GND.
  7. Output Header (free, on hand). This breaks out the three output pins in a 2×3 header, once side of which is all GND.
  8. Removable 10K resistor (pennies). The third output channel MOSFET driver has this resistor soldered on, but it basically takes pin 15 low, which is required for normal operation.

Here’s how I planned out the wiring and headers:

We just remodeled our kitchen. A few months ago we had an electrician come out to give us an idea of what it would cost to add in under-cabinet lighting. Five fixtures came in at about $1,800 with a few hundred of that going to a circuit extension. I’m a tinkerer, and that just seemed excessive to me, so I decided to do it myself and saved over 95%.

Now, for about $56 plus time, I have a much better lighting system with three zones of under-cabinet lights, each with its own dimmer, and in-cabinet lighting for some of the deeper cabinets. Here’s how I did it.

The Plan

Here’s the main part of our kitchen. The plan is to add lighting in zones in the following order of priority: 1, 2, 5, 7, 8, 4, 3, 6.

This image has an empty alt attribute; its file name is image.png
  • Zone 1: There’s an outlet for the microwave in here, and I added one for a 12V power supply, which will power all of the kitchen LED lights.
  • Zone 2: These five cabinets (in three distinct sections) should get bright white double-row 5730 LEDs, and will all be controlled by a single dimmer knob in the middle section.
  • Zone 3: Optionally, the drawers should get single-row 5730 lighting when the deeper drawers are opened.
  • Zone 4: Also optionally, each deep cabinets should get single-row 5730 LED lighting when the cabinet doors are opened.
This image has an empty alt attribute; its file name is image-1.png
  • Zone 5: This is a coffee station, so bright white, double-row 5730 LEDs here, on its own dimmer.
  • Zone 6: Optionally, single-row 5730 LEDs to light the lower cabinet — one on each side, that lights when the door is opened.
  • Zone 7: This is a desk, and a computer lives here. We’ll install double-row 5730 LEDs for consistency, and keep them on their own dimmer so they’re not too bright for the monitor.
  • Zone 7: This is our pantry, so I’ll install single-row 5730 LEDs on each side that light up when that side’s door is opened, plus a main switch that can cut these lights off entirely should either of the door switches fail. The bottom doors definitely need it, but these are optional on the top.

Sourcing the Supplies

I order a lot of tinkering supplies direct from China, and this project is no exception. It can take some time for the supplies to arrive that way, but I’ve never had a problem with the quality. With the exception of the one power supply everything is 12V.

From Amazon.com:

Home Depot:

From various AliExpress vendors: (I actually ordered a lot more than I needed for the kitchen here because I’m adding lighting to other areas of the house, too…)

Mounting the LEDs

I cut tiny squares of 1/4″ plywood and screwed the LED channel mounting brackets to them, and then I hot gorilla glued those plywood spacers at the front of the cabinet, directly behind the face frame. This extends them just enough so that the shadow of the face frame falls just outside of the countertop itself and provides a little more opportunity for air cooling. (You can’t just hot glue the LED sticks to the cabinet because the LEDs will just melt the glue. Even with the wood to insulate it, hot glue fixing the bracket to the cabinet failed occasionally.)

Hiding the Wires

The wires are pretty well hidden and they look tidy. For the upper cabinets, the wires usually enter the top cabinet right behind the face frame at one side, travel all the way down through the cabinet fastened to the back of the face frame, and exit at the bottom. There, they enter either one of the 70x45x18 boxes if the zone needs a dimmer, or one of the 50x28x15 boxes if I’m just hiding the connectors.

Reworking the Dimmers

I used the 70x45x18 project boxes when I needed to include any of the dimmer electronics, and basically drilled holes where I needed them based on what wires were present and where they needed to enter for each specific location. The original boxes were pretty big and ugly, and the result is much cleaner.

These photos are for the desk lighting (Zone 7). You should probably be comfortable with a soldering iron before you try this modification, that that’s really easy to do.

Zone 1 – Power Supply Cabinet

This cabinet contains the 12V, 33A power supply, which will be the sole power source for all the LEDs in the kitchen. (The currently installed lighting draws 11.73A with everything on.) This cabinet also contains most of the the dimmer electronics for Zone 2, but not the dimmer knob.

Exiting this cabinet are:

  • three dimmer-controlled 12V wires for each of the three sections of Zone 2
  • one 12V wire leaves goes through the wall and into the lower cabinets in order to power Zones 3 & 4
  • three strands of a Cat5 network wire so the dimmer knob can be positioned on the bottom of the corner cabinet. These are very low current wires, and the length does not affect the dimmer functionality.
  • two additional 12V wires go to the different areas of the kitchen defined below (Zones 5 & 6, and 7 & 8).

Zone 2 – Main Kitchen Under-Cabinets

The three network wire strands and the dimmer-controlled 12V wire enter the top of the corner cabinet at the left and exit at the bottom front left. There, they enter one of the 70x45x18 boxes, where the dimmer knob is mounted and the wires are connected. Remember that the dimmer electronics are actually in the power supply cabinet (Zone 1), because this cabinet is the most convenient location to serve the three distinct areas of the zone (left of the microwave, the corner, and right of the sink).

In the box, the 12V line is split to power the 12 segments under Cabinet 2 (on the left), and the 12 total segments for Cabinets 3 & 4 on the right. (When possible feed the power into the middle of a run like this or else you might start to notice that the LEDs at the end of a run are not quite as bright as the others.)

This zone uses a total of 48 segments (four 50cm LED sticks, with one cut into two parts), and draws 5.23A (62.8 watts) when fully on. This is 0.11A/segment.

  • Cabinet 1 (left of microwave): One 12-segment (50cm) U-shaped LED bar with double-row 5730 LEDs
  • Cabinets 2, 3, & 4 (in the corner): One 12-segment bar of the same for Cabinet 2, and then another cut into one 7-segment bar for the corner, and one 5-segment bar on the right
  • Cabinet 5 (right of the sink): Another single 12-segment (50cm) U-shaped LED bar with double-row 5730 LEDs

Zones 3 & 4 – Main Kitchen Base Cabinets

I haven’t installed these yet, apart from running a single 12V wire from the power supply cabinet through the wall, and then entering the back of the drawer cabinet to the right of the oven. It’s capped off there for later use.

Zones 5 & 6: Coffee Station

The un-dimmed 12V wire from the Power Supply Cabinet is split above the cabinet, with one branch enters the cabinet at the top left and going through to the bottom left, and another branch going through the wall to the back of the lower cabinet (where it’s capped off for later installation). The wire for the under cabinet LEDs enters a 70x45x18 box containing a dimmer (both the electronics and the knob), and the dimmer-controlled output that that feeds the LEDs.

Zone 5 uses a total of 21 segments (1.75 50cm LED sticks), and draws 2.36A (28.3 watts) when fully on. This is 0.11A/segment.

  • One 21-segment U-shaped LED bar with double-row 5730 LEDs, made by joining a 12-segment (50cm) bar with three segments cut from another bar.

Zone 7: Desk

An undimmed 12V wire from the Power Supply Cabinet enters the left glass cabinet at the top left and goes through to the bottom left, where it enters a 70x45x18 box. The box splits the undimmed 12V into two branches: One goes behind the LED strips to the left and into the pantry (described in the next section), and the other goes into the dimmer housed in the same box.

The dimmer has two outputs: One serves a 6-segment bar on the left, and the other serves a 15-segment bar on the right–both made from original 50cm stock. (Note that our kitchen actually ended up with three glass doors instead of four, which is why the cabinet on the left is smaller than the one on the right.)

This zone uses a total of 21 segments (1.75 50cm LED sticks), and draws 1.74A (20.9 watts) when fully on. This is 0.08A/segment. This seems a little lower than it should be, so I still need to debug that. Like before, I try to run the power to the middle of the zone.

  • One 6-segment U-shaped LED bar with double-row 5730 LEDs, made by cutting a 12-segment (50cm) bar in half.
  • One 21-segment U-shaped LED bar with double-row 5730 LEDs, made by joining a 12-segment (50cm) bar with three segments cut from another bar.

Zone 8: Pantry

The pantry wire enters straight into the lower part of the pantry from the junction box in the middle of Zone 7. The wire first goes through a switch that can be used to cut the power to the whole pantry in case any of the limit switches fail closed (on). Then it splits into two: one wire for the bottom left of the pantry, and one for the bottom right. (The upper pantry doors get more natural light than the lower ones, so we didn’t wire those up.)

The wire for each side of the lower pantry first goes through a limit switch wired up as normally closed (NC). This means that when the switch is pressed when the door is closed, the circuit will open and cut the power, and when the door is open, the circuit will close and the lights will turn on.

The in-cabinet lighting doesn’t need to be as bright, so it’s just used single-row 5730 LED bars for these, but two on each side, and again with power going to each set instead of stringing them together. I used V-shaped channels, too, mounted vertically along the inside of the face frame so that the light is projected into the middle of the cabinet instead of toward the back.

This zone uses a total of 48 segments (1.75 50cm LED sticks), and draws 2.4A (28.8 watts) when everything is on. This is 0.05A/segment.

  • Four 12-segment V-shaped LED bar with single-row 5730 LEDs, two for each side.

Conclusion

Not all zones are complete, and I’m not even convinced that we need more lighting at this point. I think I will try to add some of the lower cabinet lighting, though, just for kicks.

Although I spent a more in total on supplies (because I ordered more than I needed for just the kitchen, and there’s still more to install), the total cost of the supplies I’ve actually used in this project is about $56 — just over 3% of the original $1,800 quote. It’s a lot more functional that what was originally quoted, has more fixtures, and probably looks a lot more custom… and I had a lot of fun doing it.

We got a Mazda CX-5 and so far we’re pretty happy with it. We wanted an organizer in the back, though, to help prevent things from falling over and rolling around, and we wanted it to be easy to collapse if necessary. Here’s how we made one for less than $15. Add a few extra dollars for bungee cords to hold the organizer in place if you want. (Mazda recommends that you secure the stuff you put in the back.)

The bins were designed to accommodate our reusable grocery bags, with some tight nooks in the back for things like baseballs, pencil kits, and books. (The kids can open up the middle section and reach back.) Placed close to the back seats, this design still allows access to things stored with the spare tire. It can be disassembled pretty quickly if necessary. 

20130805-131227.jpg

Supplies:

  • 1 piece of 1x6x10′ pine (whiteboard) lumber, and be sure it’s not splitting at the ends. This should cost about $10 at the home center — ask them to cut it in half for you and you’ll be able to fit it into the CX-5.
  • 1 can of flat black spray paint. I got Painter’s Touch, which was labeled “primer + paint” for less than $4.
  • 2 bungee cords, approximately 18″ long unstretched. We had these laying around from a Harbor Freight assortment kit we got a while back. They’re probably about $1 each, and are use to secure both the organizer to the floor, and secure bags in the two outer bins.
  • 4 3/4″ felt pads. These are really optional, but might help prevent damage to the interior of the car. We had them on had, but you can also pick them up at the home center for a couple dollars.

Directions:

  1. From each 5-foot length, cut one 41″ board, and one 17″ board.
  2. On both 17″ boards, measure in 1 3/4″ from each end and cut a 3/4″ slot across half the width of the board. Cut both boards together.
  3. On both 41″ boards, measure 13″ from each end and cut a 3/4″ slot across half the width of the board. Cut both boards together.
  4. Also on both 41″ boards, measure about 2 1/2″ from each end and drill a 1/2″ hole so it overlaps the edge of the board enough to fit a bungee cord. Do this on the opposite side from the slots if you want the 41″ boards to hold down the 17″ boards, or on the same side to make the weak ends of the 17″ boards a little more protected from accidental breaks.
  5. Sand, assemble, and paint.
  6. Attach a felt pad to the middle of the end of each 41″ board, and install into car. Run the bungee from the back hook, through the drill holes, and up to the front hook. You can tie a knot in the bungee where it passes through the board to help keep it in place if it slides.

Boards

It’s important to note that the small sections of 17″ board on the outside of the 41″ boards will be weak because there’s only 2.5″ against the grain holding them in place. If you’re going to be disassembling/reassembling this a lot, you might want to glue some blocks to those weak areas to strengthen them.

[sc:3dclub-intro]

We’ve learned a lot while implementing our 3D Printer Club project plan at a local elementary school, and in the process, we’ve come up with a number of guidelines and ideas to help you get started doing the same thing in your own school. We’ll use this page as a landing page for resources and information on how to get started. As we add new content, we’ll link to it from here, so please check back from time to time for new articles.

Who Is This For?

Parents, teachers, students, makers, administrators, and more—techie or not. We’ve found that a number of different types of people would like to get started with a project like this, and each one has a slightly different perspective and purpose. While it’s not easy to write a single article for multiple audiences, we’ll try to address these different perspectives throughout. At the end of the day, though, all you really need is time, dedication, and some help from time to time.

What Are We Starting?

First of all, we recommend a project-based approach in a weekly after-school club format—the journey is a big part of the destination here, and an after school club should allow you to pull interested students from a number of grade levels, get a bit more help from parents, and potentially even pull in resources from other schools. The weekly format allows enough time between meetings for individual teams to work independently.

With the help of teachers, parent volunteers, and possibly a couple of older students, the members of the 3D Printer Club will be responsible for researching, documenting, sourcing, building, and operating an open hardware 3D printer. “Open hardware” means that the technology has been developed upon over a period of time by many (possibly hundreds or thousands) or people with a genuine interest in improving and promoting the technology and making it available for the greater good. It’s an organic approach to hardware development, and there are usually no patents or copyrights to contend with. Like Wikipedia is to information, open hardware is to physical technology.

Find a Subject Matter Expert

Some parents or teachers may be perfectly comfortable diving into this project with little or no expertise, but others may feel it’s too far over their heads. In either case, we recommend locating a subject matter expert (SME) to assist you throughout the process. This should be a person—hopefully nearby—with some experience in open hardware 3D printers. Contact a local hackerspace (visit hackerspaces.org to find one) and explain that you need some help with a 3D printer build at a local school.

Hackerspaces are part of the “maker” culture—they are groups of people who like to make or build things themselves, and they will almost certainly have someone with the expertise required and interest required to help with an open hardware 3D printer build. If there is no local hackerspace or if you’re having trouble finding a local SME, contact different hackerspaces in your state or region—most members of the open hardware 3D printer community are willing to help remotely (for example via Skype, email, or chat) as well.

The SME will be a valuable resource throughout the build and will be able to help your team solve problems as they move forward with the build. The SME should also be able to help you arrange demonstrations, or provide access to a reference machine or two to base your build upon.

[sc:3dclub-intro]

Here’s the design for the shirt the kids wear when they want to teach people how to get into building 3D printers. (Click to download SVG, resize, and print on a t-shirt transfer.)

IBuild3DPrinters

Here’s a short documentary, produced by onshoulders TV, that describes what the RepRap project is all about. Yes — we’re in it.

theFrankes.com proudly introduces ToddleBot: Your toddler’s first 3D printer! toddlebot

This came out a couple of years ago, but someone reminded me of it just this weekend so I thought I’d share it. It’s a great little introduction to soldering. Click on the image or the following link to visit the site and see the full cartoon tutorial. (http://log.andie.se/post/397677855/soldering-is-easy)

soldering_howto_cartoon

Make Magazine also did a great “How to Solder” round-up a couple years ago. Visit that site here: http://blog.makezine.com/2009/07/21/super-learn-to-solder-its-fun-round/

« Older entries