IR bed level

After chatting with Pelrun, I am trying to put together some IR distance sensors for 3d printer use. He has one of this design on his current printer.

Source; https://easyeda.com/l.shearer/IR_Level_Detector-SslDVd7pH

Firmware; https://github.com/dc42/OrmerodSensorBoard

License; CC BY-NC

Derived from
Omerod Sensor board (https://miscsolutions.wordpress.com/ormerod-hot-end-board-v2/)

Status: WIP

PCB has been sent for fab
Components (Osram IR LED and phototransistor, ATTiny)

To do;

  • Await component delivery
  • Await PCB delivery
  • Adjust current limiting resistors;
  • original design has relatively low current, with 866/1kR coming out of the ATTiny’s 4.8+v Source and a 1.3+v drop across the IR.
  • If current is increased slightly, the far diode can be twice the intensity at ~1.5x the distance making it just about the same intensity at the phototransistor due to the inverse-square law.
  • Correct Silkscreen error

Done;

  • Port schematic to a CAD
  • Design first run PCB
  • Order main components from RS-online
  • Order PCB from Seeedstudio

Schematic and PCB

Boards spoken for from first run of 10

  • As many as it takes for me to make at least one sucessful board (4 sets of components ordered)
  • up to 3 for the space
  • at least 1 for Pelrun
  • at least 1 for Nogthree
  • 1 for spotting silkscreen inconsistency
3 Likes

Hi Lauren

I love you project it looks like you have put heaps of effort into it. I really hope your project is a success however I can only imagine how it will work and the engineer in me wonders if it will ever be practical.

IR is excellent for object detection its just not good for distance measuring. In industry we don’t use IR for really accurate things because IR sources are everywhere from fluro lights to the big ball of fire in the sky. One way to stop this would be for the led to transmit a code so you know if it is your light source. You could transmit different signals for each of the leds so you know which one is triggering them.

You have used resistors to limit the current, the resistance will change depended on temperature. It could ether go up or down depending on the material it is made out of. Probably the longer you run the led the darker it will get. A constant current led driver should solve that problem.

Going by the data sheet of the SFH 3100 F the arrangement you have it in will give you a logarithmic voltage value dependent on the amount of IR is on the gate. Just something to think about when coding the height values. Its just a math problem.

What sort of bed are you going to be using to reflect the ir light?

Welcome to the world of analogue electronics or as some call it black magic link

I look forward to seeing your project at HSBNE

Hey Lauren,

I’d be interested in one or two of these, I’ve been following with interest people using DC42’s design and currently use FSRs on my delta.

Thanks for the comments.

@denominator

I can only imagine how it will work and the engineer in me wonders if it will ever be practical.

The good thing is, it’s a proven circuit; Pelrun has one on his Prusa i2 at the space at the moment.

IR is excellent for object detection its just not good for distance
measuring. In industry we don’t use IR for really accurate things
because IR sources are everywhere from fluro lights to the big ball of
fire in the sky. One way to stop this would be for the led to transmit a
code so you know if it is your light source. You could transmit
different signals for each of the leds so you know which one is
triggering them.

That’s exactly what the ATTiny does; the two IR LEDs are alternated, and a “blank”: period allows adjusting for ambient conditions to be measured. The resistor choice is about presuming they hit at about the same point on the bed (easy) but take different lengths (easy; offset, angle and SOHCAHTOA ) meaning that at a particular distance the intensity at the receptor is the same (slightly less easy)

In the PCB above (and I apologise in advance for the slavery units) the emitter or the close LED is 0.4in from the phototransistor, and the emitter of the far LED is 0.6in. The close LED is at 45deg and the far is at ~35deg.

At roughly 0.2in above a reflective surface, the near LED will travel just under 0.57in
At this height, the far LED will travel 0.89in. The ratio of the two is 1.56:1. They will both be reflected at the halfway point, and have proportionate losses that muck up the maths, but bear me out.
If we want the two to hit the phototransistor at the same intensity and presume perfect reflectance (an incorrect but useful assumption) and we use the inverse square rule, we need the far transistor to emit at 2.43 times the intensity (1.56 squared).
Chosing a convinient starting point, such as forward current If = 20mA we can use the charts in the datasheet (pdf) to find another curret that gives 1/2.43 (i.e. 0.41) times the emmision intensity.

Of course the bed isn’t perfect. I can’t easily recall / google whether the loss of light on reflection is linear or not. If it’s linear, at the desired distance the beamlength ratio will be the same to and from the point of reflection, so the point of equal intenisty should be the same.

Because of the inverse squareness, the narrow half-ange (9degrees) of IR emissions, and the logarithmic responde of the phototransistor, there is a very rapid fall-off of the far beam intenisty if we’re too far, and a very rapid gain on the near beam intensity if we are too close (until we go outside the beam, where it drops off again, but we will also be outside the beam of the far LED too)

You have used resistors to limit the current, the resistance will change
depended on temperature. It could ether go up or down depending on the
material it is made out of. Probably the longer you run the led the
darker it will get. A constant current led driver should solve that
problem.

After making my poor head hurt (although not as much as when trying to understand MRI sequence and phase encoding; at least we’re sticking with real numbers and out of k-space here) I’m going to start with the values that work for the original board and then consider fiddling.

I thought of a constant-current source (e.g. through an opamp) but it pushed up the BOM and would require making modifications to the basic circuit; that will have to wait for a proven need and v0.2.

I was also including the voltage drop out of the ATTiny in calculating resistances.

As for temperature; the current at 9-20mA for a voltage drop of about 3.6v is relatively small, well less than a 1/8 watt. The environment will be an issue (I.E. hotend distance) but given other components are tolerant to about 85 degrees, that will be the maximum envelope I’ll have to think about. Thanks for making the point.

Thankfully the emission intensity is relatively linear to forward current in the range we are looking at, thus the ratio of intensity should be preserved if the resistance increase is relatively linear, so hopefully things will even out? I could presume the intensity will be lower, but we’re looking for a similar intensity rather than absolute intensity (differential comparison rather than absolute value)

@nogthree

Hey Lauren,
I’d be interested in one or two of these, I’ve been following with
interest people using DC42’s design and currently use FSRs on my delta.

I’ve go about 10 boards coming and parts for about 4; the key components are;

  • ATTiny 25 or 45 SOIC-8
  • 1uH inductor
  • OSRAM SFH 3100F (RS-Online 654-8738)
  • OSRAM SFH 4141 (RS-Online 876-8741)
  • some resistors (0603), an optional 0603 status LED, and some 0.1" headers

Of those four I’ll probably kill 2, so the other was for the space. The PCBs were earmarked as follows;

  • as many as it takes forme to make one working one for me; parts for up to 3 space printers
  • 1 or 2 for Pelrun to make / kill
  • 2 or 3 for the printers currently at the space. If I don’t kill too many,

The rest are first-come-first served.

As an aside, there is a silkscreen error sent to the fab; free PCB to whoever picks & posts the inconsistency here first :smile:

1 Like

Here’s a video of one in action - https://www.youtube.com/watch?v=SNyn1L8CTCo

There’s a trick for young players if you’re using PEI, you’ll want to have painted the back of the PEI sheet matt black before assembling your bed stack otherwise it’ll be too reflective for these to work.

Jimmy, this is a differential sensor, so non-linearities in surface reflectivity and led output are cancelled out. The probe on my printer which uses this exact circuit/firmware has been incredibly reliable and accurate. All it needs to be is more accurate than a manual levelling operation (which it manages handily) and it’s a net win.

I can’t recommend these enough - my printer went from worthless to doing 3 months of perfect prints without needing any sort of supervision. It works perfectly with glass beds if you ensure the bottom surface is less reflective than the top - so mirrors are out, but everything else works great.

I was the one who initially was going to do this production run, until Lauren took the idea and ran with it (and did a great job of it to boot!) So no raining on her parade, please. :smile:

Thanks for the support.

I took @denominator 's comments as being in the vein of “are you sure you’re not a bit under-skilled and overenthusiastic?” and trying to stop me wasting time; so I appreciated the concern.

As an aside, I’ve got 20 of the diodes and 10 of the phototransistors coming (minimum order size) so hopefully no one needs to order that. I don’t have enough ATtinies for general consumption.

Yeah, he actually bothered to read the datasheet, which is more than can be said for those who are just negative. :slight_smile:

Would it be possible in the f/w to have it indicate to assist a manual bed level aswel?
Ie check the corners and let you know what corners need to go up or down to get the bed pretty damn close to start with?

Not so much under-skilled more “it may be a learning curve” and a bit of have you thought about blah. I had many more questions but I didn’t want to make the post tldr.

@pelrun I didn’t know you had one up and running. I wasn’t trying to rain on the parade I thought it was unproven pro-type so my bad.

Its not orientation of some of your letters is it. Like ƖƆ

I suppose you could make D3 flash when the board is in a sweet spot then drive head to each corner and adjust.

@AussieLauren Keep up the good work it looks like you are onto a winner. I will probably end up putting one on my printer aswell.

I don’t actually need any myself, so that one can go to someone else. For the same reason I can see exactly what the error is but I’ll keep my mouth shut :smiley:

Thanks for the support.

@denominator
No worries, were there other thoughts or suggestions?
And no, label orientation is, although not optimal, not the complete snafu like the real mistake.

Boards are apparently “traceable” so presumably they come out of the process okay and are in the lap of China post.

Status update;
Rs-components sent most of the parts with invalid tracking numbers. Poo. I have asked them to resend, no reply yet. Annoyed as typical courier behaviour of “residential address-back to depot!” Despite extra instructions (which, in fairness, don’t look like they were passed on from Rs-components to Toll)

PCBs are “processing” with SeeeD, having come back from the fab on 28/2 so and delisted as processing on 3/3, so probably another week

1 Like

RS components has kindly redispatched the missing items. Unfortunately to the home address so we still rely on the time/intelligence pressure on the courier (I had asked prior to and within 1 hour of notification of reshipping to send to work; oh well)

SeeeD sent via sing post; AusPost too it on 15/3. Tracking stops there :frowning:

Any tips for helping couriers deliver to residential properties in large developments?

Aaaaaand having refused to change the delivery address as requested prior to them re-shipping, because it was “already dispatched”, I recieved dispatch advice for part of the order today

:rolling_eyes:

Additionally the ATTinies they sent me were the last in stock, so they aren’t expected to be dispatched until about late May :sweat:

So I’m going to pick up some ATTiny85 s from Altronics, along with some IR LEDs. I might also get some inductors but they only have big coils or through-hole.

Almost completely over this moopoo.

On the PCB front; nothing. SingPost say that it was “Arrival at Destination Post (Country: AU)” on 15/3. Australia’s fairly big, so that’s a bummer. Track17 suggests that AusPost might deliver it but AusPost don’t have a tracking number. Auspost, Toll, Couriers Please all deny any knowledge. I’ve filled in SingPost’s query form, so we’ll see if anything pops up.

Thankfully a few more phonecalls to Singapore Post turned up a “we attempted delivery” notice fom AusPost last night, so the PCBs are in-hand.

Overall quality is good, some of the drills are off-center (most notable on some of the vias) but they pass visual inspection.

Found a stray via I didn’t know about, but it’s appropriately isolated on the other side so :thinking: must be my fault.

RS components shipped from GB with a “5 day delivery schedule” for inductors and LEDs. I’ll probably get to Altronics before then, though, so I’ll just use their stuff in the meantime. The IR LEDs would be nice to have, though.

Well, after braving BrisVegas busses yesterday, I ended up buying the nessesary from Altronics. Of course, today there’s a couriers please slip so maybe the rest of the RS stuff will arrive (mostly wanting the inductor and the sidelooking IR LEDs)

So I soldered one up today. Three lessons;

  • 0603 is doable
  • I can pack 0603 closer together by half
  • recommended pads are intended for PnP machines; thus, to hand solder the SOIC ATTiny, I had to (gently) bend the leads in slightly

The ATTiny was sitting beautifully but without enough pad to easily get the solder tip on to ensure a good join/wetting

Voilà;
(Or at least, voilà would be if I could attaché a photo; I keep getting an error saying its above the max size of ~10,000kb although I know it’s only about 350kb)

I’ve tacked some Amber LEDs on in place of the IR just to double check they’re all getting lit.

1 Like

For future reference, packages from the various Posts (and EMS) will always come via AusPost, not the domestic courier services. So if it’s not coming via DHL/UPS/FedEx, you know who to bug about it.

You can tell by the tracking number as well: AAnnnnnnnnnAA, where the first two letters are the type of parcel, and the last two letters are the code for the origin country (between are only digits). The couriers use distinctly different formats.

Progress has been made;

  • 1 board hand soldered with Amber LEDs
  • 1 board “frypan” reflowed chip & cap only

My USBASP was having the “no response” error whenever I tried to upload a blink sketch. Thus making up the chip & cap board to see if I could reproduce the issue.

Same error.

Then I remembered; AVR chips come stock at 1MHz and you need to go slow, homie, until you change the fuses. Will try again tomorrow with AVRdude’s -B flag.

I’m also face palming for realising that AVR studio is Win Only, so I’ll be brewing my firmware in an alternate IDE than the source. The C++ classes used don’t seem to be liked by my GCC setup. Poop.

Nonetheless, the source structure is straightforward;

  1. It has an timer compare interrupt-driven state machine to sense the phototransistor on alternate LEDs and samples 3x for each state in turn (timed to let the ADC do it’s work) (4 states; Off, near, Off2 (dummy), Far LED)
  2. An array which holds the recent values for the last three values of each state, and returns the average (I think)
  3. The main loop, which updates when the sensor is saturated as per the average of the three values

The startup also tries to sense if the output pin is attached to a pull-up, and if not goes into a trinary output (low, approaching and saturated) instead of the binary one.

I’m likely to skip that if I have to recook the firmware.

(Picture upload still borked)

Edit: the -B 4 flag worked; however Arduino IDE doesn’t seem to be setting the fuse right to use the 8MHz internal clock (1000ms delay coming as 8000ms)

Edit2: burning the boot loader with -B 4 set the fuses. Voila we have good timing again!

Soooo… That happened.

,[flashback]
In the mid to late nineties, I had a lovely science Teacher, Mr Bowen. Tall, red curly hair, absolutely stereotypical science teacher type. He was also into Christianity in a big way; when they built him a new science classroom, some seniors climbed onto the roof and welded a small cross on the gable.

The other thing I clearly remember, is being taught by him about Cations; how the “t” makes a cross which is positive.
[/flashback]

And now I realise the side-looking LEDs have the emitter facing the opposite way from the bed. Because the cathode led must be the positive one, it has a “t” and everything.

Now, I realise that the side of the LED that faces the ground pole is “emitting” current, much like the cathode of a battery; but for some reason I’ve somehow wired myself to put it facing the “+” terminal,

Thus the “cathode” on the LED (the one to your left as you look at the emitter / “patient’s right”) got translated into the current source coming from the micro, instead of emitting it to ground.

Which is why my LEDs are now facing the wrong way (or need to be on the wrong side of the board.

Now, I may have stuffed up the phototransistor too, in which case I can just mount the thought-hole stuff on the opposite side. I’m too tired to check now - I’ve been working since 3am yesterday.

2 Likes