Friday, October 30, 2015

Environmental hazards

I left the wifi temp sensor in a window overnight, it rained a bit, and in the morning it wasn't working.  It was out of direct rain but it was damp enough that, well, check it out:

A little electronics cleaner spray and a toothbrush and it's fine again, but it's definitely going to need a case of some kind to keep the moisture away.

Wednesday, October 28, 2015

ESP8266 temperature sensor final form


After toying with Lua on the ESP8266 and finding that it was not stable (stopped answering web requests after an hour or so) I went back to Arduino.  That seems stable, I let it run for two days hitting the server once a minute and it stayed up the whole time.


I cleaned up the code and am happy with the results now.  Here's a rundown of all the steps needed to replicate this.

First, I have the ESP8266 module, the one with an 8 pin header.  The wiring for it is as follows:

I created a home for it using a bit of perfboard. I really love these little board, you can buy them for pennies on eBay. I use them for all kinds of little junk like this.

On the left there is the power input.  The ESP board is plugged into a female header so it can be removed. Under the ESP board is a little slide switch; moving the switch up pulls GPIO0 down which puts it into bootloader mode.  The DS18B20 is plugged into the little 3 pin socket on the upper right there, the resistor is required for its operation.  The big black 5 pin connector on top goes to the serial programming interface.

Since taking that picture I've added a voltage regulator, which is mostly underneath, there's a capacitor on top now as well.
This is just a standard AMS1117 low dropout voltage regulator.

All the wiring was done underneath using wirewrap wire, which is convenient for simple circuits like this.

I'll try to do a schematic for this eventually, but mean time:

The power input (usually 5V) goes through the regulator and capacitors. 

The 3.3V output from the regulator then goes to the ESP module's VCC and CH_PD lines, the "not programming" side of the slide switch", one end of the resistor and the DS18B20's VCC.

Ground goes to the regulator's ground, ESP's ground, the "programming" side of the slide switch and the DS18B20's ground.

The other end of the resistor goes to the data pin on the temp sensor, then into GPIO2 on the ESP module.

GPIO0 on the ESP module goes to the center of the switch.

The TX line on the ESP goes to the RX on the serial programmer, and RX on the ESP goes to TX on the programmer.

Here's the code for this:
http://pastebin.com/F3fy4Ccr

There are instructions in the comments right at the top of that code on how to set up the Arduino environment and how to install the Dallas Temperature module.

YOU WILL HAVE TO PUT IN YOUR WIFI NETWORK'S SSID AND PASSWORD IN THE CODE. You may also opt to change the IP address up top too.  If you just comment out the "WiFi.config()" line, the module will automatically get an IP address from your network, but the downside is that you won't know what it is, though if you go to the router's configuration page you might see a connected device called ESP_(something)

To program, throw the switch so that GPIO is pulled to ground. Plug the serial programmer into the socket, then into the USB on your computer. Apply power to the module.  Now you should be able to hit "compile and upload"

Once it's done uploading, remove power and unplug the serial interface. Move the switch back to the position where GPIO is held high and reapply power.  When the system connects to your wifi (takes 5 to 10 seconds usually) the blue LED will come on.

You can now hit the IP address (192.168.1.99 unless you've changed it) and see this:
Temperature=22.94 celcius

PID control explained

This is excellent

Friday, October 23, 2015

What will I ever use a 3D printer for?

Good grief, what would you NOT use it for?

Just published custom mount for using a Harbor Freight welding helmet strap to mount a face mask for Halloween

https://www.youmagine.com/designs/mask-mount-for-welding-helmet-straps


Seriously, the number of people who say they can't imagine what they'd use a 3D printer for, combined with the fact that I didn't really know beforehand either, and the fact that I probably use it 2 or 3 times a week to solve little problems like this, are part of the reason I'm not worried about the fact that I really want to get a metal lathe and mill and I'm not entirely sure what I'll use them for either.

ESP8266 / LUA - Not for me, not right now.

The temperature web server that I put together on this post:

http://www.dragonflydiy.com/2015/10/esp8266-experimentation-continues.html

is just not stable. I've tried everything I can think of, looked at and tweaked the code. It just runs for an hour or two then stops answering web service requests.

It seems I'm not alone:

http://internetofhomethings.com/homethings/?p=424

Perhaps the maintainers will fix this eventually. For now, I guess I'm going to program using Arduino, which is a bit messier but will hopefully be stable.

Thursday, October 22, 2015

Today's irritating lesson

You can NOT just blow off the filter caps on an AMS1117 LDO regulator. It will go into oscillation or some damn thing and you'll get squat on the output.  That small input (and larger output) capacitor is actually necessary. Guess I'd better get a stock built up.


I've been trying to get into the modern era, getting away from the old 7805 and big through hole components, ordering up reels of passives and strips of regulators, but this is the first time I've used one of these. Spent an hour and tried 3 regulators, thought maybe the ebay vendor had slipped me some garbage.

Sunday, October 18, 2015

ESP8266 experimentation continues - Trying out LUA

In my previous video on the ESP8266, I used the Arduino environment to do a little bit of work with it. However, Arduino is a bit low level and the programming is tedious to get very much done. Another option with this chip is the language LUA, which is far more full featured. I'm going to talk about that a bit here.

I'm also going to use the original little board with the 8 pin header, because I have them sitting around and because the project I'm planning only needs one I/O pin. I don't recommend buying this module anymore, it's not really significantly cheaper than the ones with a ton of I/O broken out, so unless you have some specific use for one with almost no I/O buy the bigger modules.

I watched several videos and looked at a few wiring diagrams, there's a lot of info out there. I don't have anything original here, I'm just recording what worked for me, as much for my own memory as anything else. As such I hope this is useful to you but it's not a very polished article.



You need a USB to serial converter board that supports 3.3V - don't try to use a 5V one. I recommend one with the CH340 chip.  I bought this sweet looking board off eBay for about $3.50:

I don't know if Windows is now loading CH340 drivers, or they came in via Arduino. In any case if you plug yours in and it doesn't register as a com port, try this driver (I haven't tried it, it's just a link I found):

http://www.arduined.eu/files/windows8/CH341SER.zip

Installing LUA on your board

To hook the converter to the ESP8266, you need to wire things up like so:


Image from Arduino.cc
- Attach GND and GPIO0 to the GND pin in your converter (ONLY during this stage)
- Attach RX to TX on your converter and TX to RX on your converter
- Attach VCC and CH_PD to +3.3V supply
- if you're using a separate 3.3V supply, attach the ground of the supply to this ground also, for a common reference.
I had to use an external 3.3v power supply to run the ESP8266 board, it just draws too much power and the USB to serial converter just kept resetting and causing trouble.

To install LUA on your board, you need to download the software to do it at this location:

https://github.com/nodemcu/nodemcu-flasher/archive/master.zip

Unzip that wherever you like. 

Connecting GPIO0 to ground before applying power causes the ESP8266 to enter bootloader mode, which will make it sit and wait for you to upload new firmware to it when you turn it on.  Plug your USB to serial converter and if you don't already know what port it's on, look in device manager to see what serial port just appeared:



In the NodeMCU-Flasher that you extracted from the ZIP before, Go into the Win64/release or Win32/release directory as appropriate and run the ESP8266Flasher.exe program.  Make sure the correct COM port (discovered above) is selected and click the "Flash" button. You should get a pair of MAC addresses and it should start programming LUA into your ESP8266. Let it finish. You'll get a nice green check in the lower left when it's done.



Now in order to begin using LUA on your board, remove power from it and move the GPIO0 pin to VCC (3.3v) and power it back up again.

The program I found worked for me for experimenting with LUA is LUA Uploader, here's a video intro from the author:



From the links on that video, here's the URL for grabbing a copy:


Click on the latest version, then click the "Raw" button to download the ZIP. Extract that wherever you like.

When you run that you can connect to the COM port and start playing with LUA.

Here's a page that also covers everything I've said here and also has good example code for controlling a couple of LEDs from a web page. This is a really good thing to do for your first project, it's very straightforward and shows some useful functionality that you can expand on.

http://randomnerdtutorials.com/esp8266-web-server/

For my actual project, I wanted to create a temperature monitor.  I had a HELL of a time getting the board to talk to a DS18B20 temp sensor, there is some rather flaky example code out there that is just broken, but finally I found some that worked.

Here's a photo of the board I made.  The power goes in the left, the programmer (when needed) plugs in the top row of 5 pins. The DS18B20 attaches up top there.  There's a switch under the board that connects GPIO0 to ground for initial firmware flashing.


and with the programmer plugged in:
Hitting the server with the example code:

Here's the code that I finally got working:

Friday, October 9, 2015

Model repair services

Just a quick heads-up: I needed to fix up a shaky STL this evening and went searching for the old Netfabb services. Seems like it's been moved and vastly upgraded.  It's at the following link and it works really well. If you have a broken/non-manifold STL, this should take care of it for you. It took a broken STL from Thingiverse and fixed it, and in the process reduced it from 26 megs down to 4.5 megs with no apparently loss in quality.

Thursday, October 8, 2015

Sainsmart TPU flexible filament

I got a spool of TPU 1.75mm filament from Sainsmart (via Amazon) for about $32, it arrived yesterday. I don't have a real plan for it right now but I've had need for flex in the past so at that price I'll just throw it on the shelf.

It's really pretty flexible, but not floppy and also seems pretty tough.  With infill it's actually quite rigid not squishy, but it still has some give. I really like TPU for phone cases for instance - it's slippery enough to not gather lint like silicone does, but flex enough that it absorbs shock. It would be interesting to try printing this in a 2nd extruder with ABS or PLA and see if they bond, to use this as bumper material on harder prints.




I printed an experimental piece just now, a little evil duckie about 30mm tall. It prints smoothly. I heated the bed to about 50, printed on blue tape at 200. This is on the CTC and I think it's reading a bit low on temps, it's likely it was actually at 210 or even 215.

That's one knock on the CTC - I don't think they use PID on the temps at all, I think it's just bang-banging the temps, they jump around quite a lot compared to the RepRap. I really would like to port Marlin to the Mightyboard at some point if someone hasn't already done it. It would be a vast improvement (and get me away from having to use the horrid x3g files, and give control during printing - it's maddening to have to abort prints, reslice and restart if I decide I should be running a few degrees hotter or a few mm/s slower).

Saturday, October 3, 2015

Let's make something useful

I've been covering "block" i.e. "building blocks" for a while.

Now let's take a few Arduino building blocks and make a useful thing out of them. I want an alarm clock with all the features I like, and I can't buy it. All the clocks I've ever bought have shortcomings. The most irritating one is that they take a 9v battery for power failure backup, which should be able to run an RTC chip until the next ice age, but somehow they last about 2 months then die.

I would like it to be able to run during power failures (with the display off, or perhaps on demand), wake to alarm during those times. I also want an outdoor temperature sensor. Wireless would be super cool, if I can work out the power.

I also like the phone apps that start out the alarm quiet and it gets slowly louder. I'd like to incorporate that.


Recently I got some Arduino Uno clones for < $4 each. I also picked up some waterproof digital temperature sensors, and some little 4 digit displays that use the same driver chip as the 8 digit + switches display that we played with earlier.





The chip reads TM1637.  The first Google result from that is on Arduino Playground and gives a library for driving it. Here's the Github link referenced in that article:

https://github.com/avishorp/TM1637

From that page, click "Download ZIP" and save the file.  Start up Arduino and hit Sketch/Include Library/Add ZIP library. Now you can hit File/Examples/TM1637-master/TM1637Test.

If you look at the code, you'll see that it says that CLK should be wired to I/O pin 2 and DIO to pin 3.  Gnd and VCC should be wired to gnd and +5V.  Wire it up, upload the sketch and you should see the demo working:

Now, I have a little "real time clock" module. What that means is that I have a module that's essentially a watch with no display that can interface to the Arduino.

It says "Tiny RTC".  A little googling reveals that it appears to use a DS1307 real time clock chip. 

Turns out that there's a lib for the DS1307 already loaded in Arduino. Go to File/Examples and find and load the DS1307 sample code.

A quick Google indicates that SDA should go to pin 4 and SCL to pin 5.

To set the time, you would uncomment this line in Setup and fix the values to the current date/time:

    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));

Compile and upload the code, and start the serial monitor at 57600 baud as indicated in the code.

You'll get output like this:
2015/10/2 22:39:11 since midnight 1/1/1970 = 1443825551s = 16710d now + 7d + 30s: 2015/10/9 22:39:41
Now we have a basic start on a clock.

By combining lines from the two example sketches, we can get a clock display that works.

 // John Ridley Oct 2 2015  
 // nifty bedside alarm clock  
 // totally not a bomb.  
 //////////////////////////////////////////////////////////  
 // stuff for RTC DS1307 chip  
 #include <Wire.h>  
 #include "RTClib.h"  
 RTC_DS1307 rtc;  
 //////////////////////////////////////////////////////////  
 // stuff for display:  
 #include <Arduino.h>  
 #include <TM1637Display.h>  
 // Module connection pins (Digital Pins)  
 #define CLK 2  
 #define DIO 3  
 TM1637Display display(CLK, DIO);  
 //////////////////////////////////////////////////////////  
 void setup ()   
 {  
  // rtc initialization steps  
  Wire.begin();  
  rtc.begin();  
  display.setBrightness(0x0f);  
 }  
 //////////////////////////////////////////////////////////  
 void loop ()   
 {  
  DateTime now = rtc.now();  
  // show hour  
  int hrDisplay = now.hour();  
  // Let's do a 12 hour display  
  if (hrDisplay > 12) hrDisplay -= 12;  
  if (hrDisplay == 0) hrDisplay = 12;  
  display.showNumberDec(hrDisplay, false, 2, 0);  
  // show minute  
  display.showNumberDec(now.minute(), true, 2,2);  
  // delay, no point in beating on things more than once a second  
  delay(1000);  
 }  

This displays the time, but the colon in the display is not lit up. I'd like it to have it lit. Doing some searching indicates that the module had some pending commits that have not been rolled into the code yet, to control the colon.  We'll need to pick those up.

Go to https://github.com/avishorp/TM1637.  Click on "Pull requests" The top open requests says "Colon setter and brightness range fixed" (If it does not, maybe by the time you are reading this the changes have been included).  Click on that. Click on "Commits" tag and then click on the <> (browse files at this point) next to the top thing.  Now you'll need to download the .CPP file and the .H file, and save them over the top of the same files in the library. You'll find them in your "Documents" folder, under Arduino/Libraries/TM1637-master

Now we have control over the colon.  We can add this code around "loop":

 bool colon = true;  
 void loop ()   
 {  
  colon = !colon;  
  display.setColon(colon);  

Now the colon blinks once per second

This is probably enough for now. There's still a lot to be done. A second display for temperature, buttons to set the time and other features, an audio system for alarm, and other things.

Friday, October 2, 2015

3D printing basics: bed adhesion

One of the important things that FDM 3D printing hobbyists have to figure out is how to get their plastic to stick to the bed reliably, but lightly enough that it can be removed without the use of power tools and/or demolition charges. (Seriously, I've had prints stuck so tight that I had to use a chisel and hammer to get them off).

I'll start out by saying that my experience is fairly limited, but I've tried a few things and had some failures.

PLA

I print pretty much exclusively in PLA these days. It suits my needs, it's really easy to print with, it produces pretty looking prints, and most importantly it does not smell too bad. The downside being mainly that it becomes soft at lower temperatures than its main rival, ABS. This is not generally a problem for what I do.

You can theoretically print on heated Kapton at about 60*C, but that has led to ruined prints way too often for me.  These days I rely on blue painter's masking tape.


I've tried a few blue tapes. The canonical blue tape to print on is 3M original 14 day tape. This works pretty well and if it's all you can get, go for it. I find that there are some tapes that provide just a bit more adhesion to the plastic and I've had prints come off the 3M stuff.

Two tapes that I've found are good are Duck brand 14 day blue painter's tape, and Blue Hawk brand blue tape - I think this might be a house brand of Lowes home improvement stores. Both are a darker blue than the 3M stuff, and in fact I think they may be the same thing.

No matter what tape I use, I clean with isopropyl alcohol on a paper towel first. Not a thorough scrubbing, just enough to take off residual material and perhaps raise the fibers in the tape a tiny bit.

I've used blue tape for dozens of prints, but I think it's probably actually a better idea to replace it every 5 or so prints, because the surface starts to get a little grunged up and I've had bits of blue tape get permanently into the bottom of prints before.

With a trusted blue tape on the bed and the bed properly levelled, I'm perfectly comfortable hitting "print" on a 10 hour print and walking away.

ABS

When I started out, it was all ABS and the standard "knowledge" was that you put down Kapton tape, heated the bed to 110C and the ABS would stick beautifully and release when the bed cooled again.

This is bunk. I've had more prints break loose on bare Kapton than I care to think about. Certainly I've wasted entire spools of filament on ruined prints.  I no longer trust bare Kapton with any material.  

ABS slurry

A while back someone came up with an excellent method for ABS. Dissolve a bit of ABS in acetone and use that as a bonding agent. I actually stopped using ABS because I couldn't get good bed adhesion, but since trying this method I may start doing ABS again.  I found some little squeeze bottles in the camping section of the local hardware store and they work very well. Obviously be careful what containers you use, make sure that the acetone won't dissolve them.


I just cut up a failed print with diagonal cutters, crammed it in there and poured in some acetone. As you can see from the photo, the only ABS I have on hand is purple. It would probably be better to use clear/natural so you don't discolor other filament colors.

It took about an hour for the ABS to all dissolve. To use it, I just put a few drops on the print bed (on top of the Kapton tape) where the print will be done, smear it around with a fingertip, then start the print. The print bed still should go to 110*C for printing - this will evaporate the acetone quickly, before the print starts.

NOTE that this method WILL NOT WORK WITH PLA because acetone does not dissolve PLA. There are things that will, but those solvents are expensive and IMO this is just not necessary because blue tape is pretty much perfect anyway.